-
Notifications
You must be signed in to change notification settings - Fork 24
feat(policy): namespace root certificates #2771
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
926f5ab
Extend authentication exclusions and update namespace policy definiti…
pflynn-virtru 48c4e62
Add X.509 certificate management to namespace policy definitions.
pflynn-virtru f61ecc0
Introduce namespace-to-certificate RPCs for X.509 certificate managem…
pflynn-virtru 0187c8d
Remove namespace policy routes from public access and associated tests.
pflynn-virtru a57e637
Introduce X.509 certificate validation and enhance namespace policy f…
pflynn-virtru f0624f9
Remove unused error messages in namespace certificate assignment test.
pflynn-virtru 9669a30
Add schema and migration for namespace certificate management
pflynn-virtru 7b6f379
Introduce `is_root` flag to certificate schema for root/intermediate …
pflynn-virtru 964a6c3
Add `is_root` flag to certificate schema for root/intermediate distin…
pflynn-virtru 319f68b
Update all namespace-certificate management methods to use pointer-ba…
pflynn-virtru d1dca55
Change certificate field format from `x5c` to `pem` across schema, RP…
pflynn-virtru c5b2680
Merge remote-tracking branch 'origin/main' into feature/trust-by-name…
pflynn-virtru f7ed290
Remove deprecated `AttributeValueSelector` schema and update namespac…
pflynn-virtru 8311e79
Update SQL queries to return specific fields instead of all columns i…
pflynn-virtru b2f88fa
Add trigger for `certificates.updated_at` and handle trigger removal …
pflynn-virtru b4868b7
Add `metadata` field to certificate schema across protobuf, OpenAPI s…
pflynn-virtru f5d8101
Apply suggestion from Jake
pflynn-virtru 6454b1b
Update error logging in `namespaces.go` to use `slog.Any` for improve…
pflynn-virtru c9fdcea
Refactor error handling in `namespaces.go` to use `errors.Join` for e…
pflynn-virtru 2695891
Remove `is_root` flag from certificate schema, update related SQL que…
pflynn-virtru 80e7d39
Add validation for root certificates, improve namespace ID resolution…
pflynn-virtru 82ba7b1
Refactor `CreateCertificate` to return full certificate object, updat…
pflynn-virtru 0f478fb
Merge remote-tracking branch 'origin/main' into feature/trust-by-name…
pflynn-virtru b3e7bc3
Refactor error handling in `namespaces.go` and `errors.go` to add `Er…
pflynn-virtru a3a1b5a
Update test to expect `ErrFqnMismatch` instead of `ErrNotFound` for i…
pflynn-virtru 5fad1f5
Refactor `UnsafeDeleteNamespace` to replace generic errors with struc…
pflynn-virtru 3f0b299
Add certificate validation and signature checks; enhance root certifi…
pflynn-virtru File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
service/policy/db/migrations/20251002000000_add_namespace_certificates.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| # Add Namespace Certificates | ||
|
|
||
| ## Migration: 20251002000000_add_namespace_certificates.sql | ||
|
|
||
| ### Purpose | ||
|
|
||
| This migration adds support for associating root certificates with attribute namespaces to establish a chain of trust for the OpenTDF platform. | ||
|
|
||
| ### Changes | ||
|
|
||
| #### New Tables | ||
|
|
||
| 1. **`certificates`** - Stores root certificate data | ||
| - `id` (UUID, PRIMARY KEY) - Unique identifier for the certificate | ||
| - `x5c` (TEXT, NOT NULL) - Base64-encoded DER certificate in x5c format | ||
| - `metadata` (JSONB) - Optional metadata for the certificate (labels, etc.) | ||
| - `created_at` (TIMESTAMP) - Creation timestamp | ||
| - `updated_at` (TIMESTAMP) - Last update timestamp | ||
|
|
||
| 2. **`attribute_namespace_certificates`** - Junction table for many-to-many relationship | ||
| - `namespace_id` (UUID, FK to attribute_namespaces) - Reference to the namespace | ||
| - `certificate_id` (UUID, FK to certificates) - Reference to the certificate | ||
| - Composite PRIMARY KEY on (namespace_id, certificate_id) | ||
| - CASCADE deletion on both foreign keys | ||
|
|
||
| #### Indexes | ||
|
|
||
| - Primary key index on `certificates(id)` | ||
| - Composite primary key index on `attribute_namespace_certificates(namespace_id, certificate_id)` | ||
| - Foreign key indexes created automatically by PostgreSQL | ||
|
|
||
| ### Motivation | ||
|
|
||
| Root certificates need to be associated with namespaces to: | ||
| 1. Establish chain of trust for attribute-based access control | ||
| 2. Support certificate validation in the policy enforcement flow | ||
| 3. Enable namespace-scoped trust boundaries | ||
|
|
||
| The junction table design allows: | ||
| - Multiple certificates per namespace (certificate rotation/migration scenarios) | ||
| - Certificate reuse across namespaces (if needed) | ||
| - Clean cascade deletion when namespaces or certificates are removed | ||
|
|
||
| ### Certificate Format | ||
|
|
||
| Certificates are stored in **x5c format**: base64-encoded DER (Distinguished Encoding Rules) representation without PEM headers/footers, following the JWT/JWS standard (RFC 7515 Section 4.1.6). | ||
|
|
||
| ### Schema Relations | ||
|
|
||
| ``` | ||
| attribute_namespaces (1) ----< (N) attribute_namespace_certificates (N) >---- (1) certificates | ||
| ``` | ||
|
|
||
| - One namespace can have many certificates (one-to-many) | ||
| - One certificate can be assigned to many namespaces (many-to-one, though typically one-to-one) | ||
| - Junction table enables many-to-many flexibility | ||
|
|
||
| ### Backward Compatibility | ||
|
|
||
| This migration is **non-breaking**: | ||
| - Only adds new tables, does not modify existing tables | ||
| - No data migration required | ||
| - Existing functionality continues to work unchanged | ||
| - New certificate fields (`root_certs`) in Namespace proto are optional | ||
|
|
||
| ### Testing | ||
|
|
||
| Before merging, verify: | ||
| - [x] Migration up succeeds | ||
| - [x] Migration down succeeds and removes tables cleanly | ||
| - [x] CRUD operations on certificates work correctly | ||
| - [x] Foreign key constraints enforce referential integrity | ||
| - [x] CASCADE deletion works as expected | ||
| - [x] Schema ERD updated with new relations |
45 changes: 45 additions & 0 deletions
45
service/policy/db/migrations/20251002000000_add_namespace_certificates.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| -- +goose Up | ||
| -- +goose StatementBegin | ||
|
|
||
| CREATE TABLE IF NOT EXISTS certificates | ||
c-r33d marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ( | ||
| id UUID PRIMARY KEY DEFAULT gen_random_uuid(), | ||
| pem TEXT NOT NULL, | ||
| metadata JSONB, | ||
| created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP | ||
pflynn-virtru marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ); | ||
|
|
||
| COMMENT ON TABLE certificates IS 'Table to store X.509 certificates for chain of trust (root only)'; | ||
| COMMENT ON COLUMN certificates.id IS 'Unique identifier for the certificate'; | ||
| COMMENT ON COLUMN certificates.pem IS 'PEM format - Base64-encoded DER certificate (not PEM; no headers/footers)'; | ||
| COMMENT ON COLUMN certificates.metadata IS 'Optional metadata for the certificate'; | ||
| COMMENT ON COLUMN certificates.created_at IS 'Timestamp when the certificate was created'; | ||
| COMMENT ON COLUMN certificates.updated_at IS 'Timestamp when the certificate was last updated'; | ||
|
|
||
| CREATE TABLE IF NOT EXISTS attribute_namespace_certificates | ||
| ( | ||
| namespace_id UUID NOT NULL REFERENCES attribute_namespaces(id) ON DELETE CASCADE, | ||
| certificate_id UUID NOT NULL REFERENCES certificates(id) ON DELETE CASCADE, | ||
| PRIMARY KEY (namespace_id, certificate_id) | ||
| ); | ||
|
|
||
| COMMENT ON TABLE attribute_namespace_certificates IS 'Junction table to map root certificates to attribute namespaces'; | ||
| COMMENT ON COLUMN attribute_namespace_certificates.namespace_id IS 'Foreign key to the namespace'; | ||
| COMMENT ON COLUMN attribute_namespace_certificates.certificate_id IS 'Foreign key to the certificate'; | ||
|
|
||
| CREATE TRIGGER certificates_updated_at | ||
| BEFORE UPDATE ON certificates | ||
| FOR EACH ROW | ||
| EXECUTE FUNCTION update_updated_at(); | ||
|
|
||
| -- +goose StatementEnd | ||
|
|
||
| -- +goose Down | ||
| -- +goose StatementBegin | ||
|
|
||
| DROP TRIGGER IF EXISTS certificates_updated_at ON certificates; | ||
| DROP TABLE IF EXISTS attribute_namespace_certificates; | ||
| DROP TABLE IF EXISTS certificates; | ||
|
|
||
| -- +goose StatementEnd | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.