-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat: constrain the OAuth2 client type column #27931
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
12 commits
Select commit
Hold shift + click to select a range
8b0eb45
feat(coderd/database): constrain the OAuth2 client type column
BobbyHo c258668
test(coderd/database/migrations): cover the client type constraint an…
BobbyHo f4b0c5f
test(coderd/database/migrations): drop a reference to a symbol not in…
BobbyHo 3eff0a0
fix(coderd/database/migrations): repair any invalid confidential auth…
BobbyHo c28798d
test(coderd/database/migrations): fix subtest deadline and NULL-blind…
BobbyHo 1a54ff7
refactor(coderd/database/migrations): address review nits on the clie…
BobbyHo de359a6
refactor(coderd/database/migrations): finish the CRF-10 comment pass
BobbyHo 05f72ab
Merge branch 'main' into oauth2-client-type-constraint
BobbyHo b254294
test(coderd/database/migrations): revert an out-of-scope stepper loop…
BobbyHo e983ec4
test(coderd/database/dbauthz): give InsertOAuth2ProviderApp a valid c…
BobbyHo 0f40876
Merge branch 'main' into oauth2-client-type-constraint
BobbyHo 6bca0ee
docs(coderd/database/migrations): trim the auth method backfill comment
BobbyHo 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
coderd/database/migrations/000565_oauth2_client_type_constraint.down.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,5 @@ | ||
| ALTER TABLE oauth2_provider_apps | ||
| ALTER COLUMN client_type DROP NOT NULL; | ||
|
|
||
| ALTER TABLE oauth2_provider_apps | ||
| DROP CONSTRAINT oauth2_provider_apps_client_type_check; |
19 changes: 19 additions & 0 deletions
19
coderd/database/migrations/000565_oauth2_client_type_constraint.up.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,19 @@ | ||
| -- client_type decides whether the token endpoint validates a client secret at | ||
| -- all. Constrain it at the schema level: no Go path can write a bad value | ||
| -- today, but a future migration writing 'public' onto a row that holds a secret | ||
| -- would turn off client authentication for that app with nothing to catch it. | ||
| -- | ||
| -- A non-NULL value outside the two canonical strings fails ADD CONSTRAINT and, | ||
| -- because all migrations share one transaction, blocks the upgrade. That is | ||
| -- deliberate: coercing an unexplained value would hide whatever wrote it. | ||
| -- | ||
| -- This should touch zero rows: migration 000344 added the column with a default | ||
| -- of 'confidential' and backfilled existing rows with COALESCE. | ||
| UPDATE oauth2_provider_apps SET client_type = 'confidential' WHERE client_type IS NULL; | ||
|
BobbyHo marked this conversation as resolved.
BobbyHo marked this conversation as resolved.
|
||
|
|
||
| ALTER TABLE oauth2_provider_apps | ||
| ADD CONSTRAINT oauth2_provider_apps_client_type_check | ||
| CHECK (client_type IN ('confidential', 'public')); | ||
|
|
||
| ALTER TABLE oauth2_provider_apps | ||
| ALTER COLUMN client_type SET NOT NULL; | ||
7 changes: 7 additions & 0 deletions
7
coderd/database/migrations/000566_oauth2_auth_method_backfill.down.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,7 @@ | ||
| -- Deliberately a no-op. | ||
| -- | ||
| -- The up migration does not record which rows it touched, so the previous | ||
| -- values cannot be restored, and restoring them would only reinstate metadata | ||
| -- that tells a client to authenticate in a way the server rejects. The schema | ||
| -- is unchanged either way, so rolling back past this migration needs no | ||
| -- structural work. |
31 changes: 31 additions & 0 deletions
31
coderd/database/migrations/000566_oauth2_auth_method_backfill.up.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,31 @@ | ||
| -- token_endpoint_auth_method is the client's declared auth method (RFC 7591 | ||
| -- section 2); client_type is Coder's own field, and it is what the token | ||
| -- endpoint actually enforces. The two can disagree: registration used to | ||
| -- persist a client's "none" declaration while hardcoding client_type to | ||
| -- confidential, so some clients declare themselves public while still | ||
| -- holding, and needing, a real secret. | ||
| -- | ||
| -- Align the declaration to what is enforced, not the reverse: deriving | ||
| -- enforcement from the declaration would silently stop requiring the secret | ||
| -- those clients already hold. | ||
| -- | ||
| -- Each branch repairs anything outside the valid set for its client_type, | ||
| -- not just the one bad value seen so far, so a stray '' or unrecognized | ||
| -- method can't slip through and later pass a client_type/auth_method | ||
| -- consistency check unnoticed. | ||
| -- | ||
| -- The IS NULL arm matters: NULL NOT IN (...) evaluates to NULL, and WHERE | ||
| -- only admits true, so without it NULL rows would stop being repaired. | ||
| UPDATE oauth2_provider_apps | ||
|
BobbyHo marked this conversation as resolved.
|
||
| SET token_endpoint_auth_method = 'client_secret_basic' -- the RFC 7591 section 2 default for a client with a secret | ||
| WHERE client_type = 'confidential' | ||
| AND (token_endpoint_auth_method IS NULL | ||
| OR token_endpoint_auth_method NOT IN ('client_secret_basic', 'client_secret_post')); | ||
|
|
||
|
BobbyHo marked this conversation as resolved.
|
||
| -- The mirror case is not reachable through any current code path, since a public | ||
| -- client is only ever created by requesting 'none'. Included so the invariant | ||
| -- holds for the whole table rather than for the half that had a known bug. | ||
| UPDATE oauth2_provider_apps | ||
| SET token_endpoint_auth_method = 'none' | ||
| WHERE client_type = 'public' | ||
| AND (token_endpoint_auth_method IS NULL OR token_endpoint_auth_method <> 'none'); | ||
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
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.