Use RSA keys for openid token signing#2777
Merged
Merged
Conversation
Contributor
j-chmielewski
commented
Apr 22, 2026
- Adds openid key settings column
- Copies the key from config to db if present during migration, generates new one otherwise
- Introduces "hmac" flag for backwards compatibility
There was a problem hiding this comment.
Pull request overview
This PR migrates OpenID token signing to use an RSA private key stored in the settings table (DER-encoded), with an opt-in deprecated hmac flag to force legacy HS256 behavior.
Changes:
- Add a new
settings.openid_signing_key_dercolumn (BYTEA) and remove the previousopenid_signing_keycolumn. - Generate/validate/persist the RSA signing key via
Settings::initialize_runtime_defaults()and expose runtime retrieval viaSettings::openid_key_required(). - Update OpenID handlers and integration tests to use the DB-backed key, plus add a test for the “missing RSA key” failure path.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| migrations/20260422113000_[2.0.0]_openid_signing_key_der.up.sql | Drops legacy OpenID signing key column and adds DER-backed key column. |
| migrations/20260422113000_[2.0.0]_openid_signing_key_der.down.sql | Reverts schema back to the legacy text signing key column. |
| crates/defguard_common/src/db/models/settings.rs | Adds openid_signing_key_der storage, validation, RSA key generation, and required-key accessor. |
| crates/defguard_core/src/handlers/openid_flow.rs | Switches JWKS discovery and token signing to use the runtime settings-backed RSA key (or HS256 under hmac). |
| crates/defguard_core/tests/integration/api/openid.rs | Adds helpers/coverage for RSA key seeding and missing-key behavior in OpenID integration tests. |
| crates/defguard_common/src/config.rs | Deprecates config-provided OpenID RSA key and adds deprecated hmac compatibility flag. |
| crates/defguard/src/main.rs | Updates startup logging to reflect RSA-by-default and deprecated HMAC forcing. |
| .sqlx/query-*.json | Updates SQLx offline metadata for settings SELECT/UPDATE to include openid_signing_key_der. |
Comments suppressed due to low confidence (1)
crates/defguard_core/tests/integration/api/openid.rs:497
- Like
test_openid_flow, this test performs/oauthdiscovery + token exchange but doesn’t seedsettings.openid_signing_key_der(and the shared test harness doesn’t initialize runtime defaults). With RSA now required by default, this will fail unless the signing key is generated/seeded before discovery/token requests.
let (client, _) = make_test_client(pool.clone()).await;
let issuer_url = IssuerUrl::from_url(Settings::url().unwrap().clone());
// discover OpenID service
let provider_metadata =
CoreProviderMetadata::discover_async(issuer_url, &|r| http_client(r, &client))
.await
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
moubctez
reviewed
Apr 22, 2026
moubctez
reviewed
Apr 22, 2026
moubctez
reviewed
Apr 22, 2026
moubctez
reviewed
Apr 22, 2026
moubctez
approved these changes
Apr 22, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.