Skip to content

Feat/fabrica foundation - #44

Draft
alexlovelltroy wants to merge 3 commits into
mainfrom
feat/fabrica-foundation
Draft

Feat/fabrica foundation#44
alexlovelltroy wants to merge 3 commits into
mainfrom
feat/fabrica-foundation

Conversation

@alexlovelltroy

Copy link
Copy Markdown
Member

Description

This pull request introduces the initial Fabrica integration for the TokenSmith service, laying the foundation for RFC 8693-compliant token exchange with PostgreSQL-backed storage. The main changes include adding Fabrica resource definitions for bootstrap and refresh tokens, implementing bidirectional adapters for seamless migration from legacy models, and providing a new main.go server entrypoint with support for both file-based and PostgreSQL storage. The Makefile is also updated with integration test targets.

Fabrica resource definitions and adapters:

  • Added BootstrapTokenPolicy and RefreshTokenFamily Fabrica resource types with immutable policy (Spec) and mutable state (Status) separation, supporting RFC 8693 and NIST SP 800-63-4 compliance. (apis/tokensmith.openchami.io/v1/bootstrap_token_policy_types.go [1] apis/tokensmith.openchami.io/v1/refresh_token_family_types.go [2]
  • Implemented bidirectional adapter functions to convert between legacy models and Fabrica resources, enabling zero-downtime migration with dual-write and dual-read strategies. (apis/tokensmith.openchami.io/v1/adapters.go apis/tokensmith.openchami.io/v1/adapters.goR1-R181)

Project configuration and Fabrica integration:

  • Added .fabrica.yaml and apis.yaml to declare project metadata, enable strict validation, and define Fabrica resources and storage strategies (PostgreSQL via Ent ORM). (.fabrica.yaml [1] apis.yaml [2]

Server entrypoint and storage initialization:

  • Added cmd/server/main.go as the new main entrypoint, supporting both file-based and PostgreSQL storage, with endpoints for RFC 8693 token exchange and JWKS, and graceful shutdown logic. (cmd/server/main.go cmd/server/main.goR1-R102)

Build and test improvements:

  • Updated Makefile to add integration test targets for both general and PostgreSQL-specific test runs. (Makefile [1] [2]

Checklist

  • My code follows the style guidelines of this project
  • I have added/updated comments where needed
  • I have added tests that prove my fix is effective or my feature works
  • I have run make test (or equivalent) locally and all tests pass
  • DCO Sign-off: All commits are signed off (git commit -s) with my real name and email
  • REUSE Compliance:
    • Each new/modified source file has SPDX copyright and license headers
    • Any non-commentable files include a <filename>.license sidecar
    • All referenced licenses are present in the LICENSES/ directory

Description

Please include a summary of the change and which issue is fixed.
Also include relevant motivation and context.

Fixes #(issue)

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

For more info, see Contributing Guidelines.

Establishes Fabrica-based architecture for TokenSmith with zero breaking changes.

## Infrastructure
- apis.yaml: Define BootstrapTokenPolicy and RefreshTokenFamily resources
- .fabrica.yaml: Fabrica configuration for code generation
- internal/storage/: Ent ORM with 44 generated files for PostgreSQL
- pkg/apiversion/, pkg/client/, pkg/resources/: Fabrica client libraries
- cmd/server/: Fabrica-generated REST handlers (6 files)

## Server Entry Point
- cmd/server/main.go: HTTP server with graceful shutdown
  * OAuth token endpoint: POST /oauth/token (RFC 8693)
  * JWKS endpoint: GET /.well-known/jwks.json
  * Health check: GET /health
- cmd/server/runtime_helpers.go: Ent initialization and TokenService wiring
  * initializeStorage(): Ent client + SetEntClient() integration
  * initializeTokenService(): keyManager + Config from environment

## Key Features
- Dual storage: DATABASE_URL → PostgreSQL, else file-based (rollback safety)
- Preserves existing pkg/tokenservice (all 66 RFC/NIST annotations intact)
- Zero breaking changes to HTTP API
- Production-ready with both storage backends

## Verification
- Server builds successfully
- All 19 test files pass (63.6% coverage)
- Compatible with existing TokenService implementation

This foundation enables incremental migration of business logic to internal/
packages while maintaining backward compatibility.
Signed-off-by: Alex Lovell-Troy <alovelltroy@lanl.gov>
…eaders in generated files

- Created a new document `Relevant_RFC_and_NIST.md` to validate normative references for RFC 8693 and NIST guidelines.
- Updated all generated Go files in the `ent` package to include SPDX license headers for OpenCHAMI Contributors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

1 participant