Skip to content

feat: add legacy API key scope compatibility - #20021

Closed
ThomasK33 wants to merge 1 commit into
thomask33/09-29-feat_typed_rbac_allow_listfrom
thomask33/09-29-feat_legacy_apikey_backcompat
Closed

ThomasK33 wants to merge 1 commit into
thomask33/09-29-feat_typed_rbac_allow_listfrom
thomask33/09-29-feat_legacy_apikey_backcompat

Conversation

@ThomasK33

Copy link
Copy Markdown
Member

Add legacy API key compatibility

This PR adds support for legacy API keys that were created before the scopes migration. It ensures that API keys with empty scopes and allow lists are properly expanded to have full access permissions, maintaining backward compatibility.

Key changes:

  • Added a test helper LegacyToken to create API keys that mimic pre-migration database structure
  • Implemented automatic expansion of empty scopes to coder:all in the API key conversion logic
  • Added tests to verify that legacy tokens work correctly with the new scopes system
  • Ensured legacy tokens can be updated using the legacy scope field

This maintains compatibility with older API keys while preserving the new scopes functionality.

ThomasK33 commented Sep 29, 2025 •

Copy link
Copy Markdown
Member Author

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@ThomasK33 ThomasK33 linked an issue Sep 29, 2025 that may be closed by this pull request
@ThomasK33
ThomasK33 force-pushed the thomask33/09-29-feat_typed_rbac_allow_list branch from f38d137 to f8cddd7 Compare September 30, 2025 11:03
@ThomasK33
ThomasK33 force-pushed the thomask33/09-29-feat_legacy_apikey_backcompat branch from 9c44c4f to b11c4e8 Compare September 30, 2025 11:03
@ThomasK33
ThomasK33 force-pushed the thomask33/09-29-feat_legacy_apikey_backcompat branch from b11c4e8 to 0d9e60a Compare September 30, 2025 11:14
@ThomasK33
ThomasK33 force-pushed the thomask33/09-29-feat_typed_rbac_allow_list branch 2 times, most recently from 52770fc to 8390b78 Compare September 30, 2025 13:04
@ThomasK33
ThomasK33 force-pushed the thomask33/09-29-feat_legacy_apikey_backcompat branch from 0d9e60a to 90528a2 Compare September 30, 2025 13:04
@ThomasK33
ThomasK33 marked this pull request as ready for review September 30, 2025 13:35
@ThomasK33
ThomasK33 requested review from Emyrk and mafredri September 30, 2025 13:35
@ThomasK33
ThomasK33 force-pushed the thomask33/09-29-feat_typed_rbac_allow_list branch from c410a2c to 696cc1d Compare October 2, 2025 17:37
@ThomasK33
ThomasK33 force-pushed the thomask33/09-29-feat_legacy_apikey_backcompat branch from a482459 to 5e55406 Compare October 2, 2025 17:37
@Emyrk

Emyrk commented Oct 3, 2025

Copy link
Copy Markdown
Member

This PR adds support for legacy API keys that were created before the scopes migration. It ensures that API keys with empty scopes and allow lists are properly expanded to have full access permissions, maintaining backward compatibility.

Don't we have a migration to update these scopes + allow lists to convert them to the new api key?

Our customers get release by release, so there should be no window after the migration where the old api keys are created.

@ThomasK33
ThomasK33 force-pushed the thomask33/09-29-feat_legacy_apikey_backcompat branch 2 times, most recently from ecdebc1 to b07d6f5 Compare October 6, 2025 09:42
@ThomasK33
ThomasK33 force-pushed the thomask33/09-29-feat_typed_rbac_allow_list branch 2 times, most recently from 4bb9040 to cc44d1c Compare October 6, 2025 10:12
@ThomasK33
ThomasK33 force-pushed the thomask33/09-29-feat_legacy_apikey_backcompat branch 2 times, most recently from 31570ef to ab61e4e Compare October 6, 2025 10:48
@ThomasK33
ThomasK33 force-pushed the thomask33/09-29-feat_typed_rbac_allow_list branch from cc44d1c to 4c9762e Compare October 6, 2025 10:48
@ThomasK33
ThomasK33 force-pushed the thomask33/09-29-feat_legacy_apikey_backcompat branch from ab61e4e to 009ef1c Compare October 6, 2025 11:24
@ThomasK33
ThomasK33 force-pushed the thomask33/09-29-feat_typed_rbac_allow_list branch from 4c9762e to c9ad043 Compare October 6, 2025 11:24
@ThomasK33
ThomasK33 force-pushed the thomask33/09-29-feat_legacy_apikey_backcompat branch from 009ef1c to f5bfb50 Compare October 6, 2025 11:57
@ThomasK33
ThomasK33 force-pushed the thomask33/09-29-feat_typed_rbac_allow_list branch from c9ad043 to 610e5e7 Compare October 6, 2025 11:57
@ThomasK33
ThomasK33 force-pushed the thomask33/09-29-feat_legacy_apikey_backcompat branch from f5bfb50 to 5da9aa2 Compare October 6, 2025 13:30
@Emyrk Emyrk self-assigned this Oct 6, 2025
@ThomasK33
ThomasK33 force-pushed the thomask33/09-29-feat_legacy_apikey_backcompat branch from 5da9aa2 to 2307d62 Compare October 6, 2025 21:16
@ThomasK33
ThomasK33 force-pushed the thomask33/09-29-feat_typed_rbac_allow_list branch 2 times, most recently from 14537db to fd7df7c Compare October 6, 2025 21:40
@ThomasK33
ThomasK33 force-pushed the thomask33/09-29-feat_legacy_apikey_backcompat branch 2 times, most recently from d7b29da to 2d313ef Compare October 7, 2025 16:38
@ThomasK33
ThomasK33 force-pushed the thomask33/09-29-feat_typed_rbac_allow_list branch 2 times, most recently from 80f543a to c18adc2 Compare October 9, 2025 12:56
@ThomasK33
ThomasK33 force-pushed the thomask33/09-29-feat_legacy_apikey_backcompat branch from 2d313ef to d34dbe8 Compare October 9, 2025 12:57
This change introduces backwards compatibility for API keys created
before the scopes and allow-lists feature.

Previously, these legacy keys had empty scope and allow-list
definitions in the database. They are now dynamically interpreted as
having `coder:all` scope, granting them full access. This ensures that
old, unscoped tokens continue to function as they did before the
introduction of fine-grained permissions.
@ThomasK33
ThomasK33 force-pushed the thomask33/09-29-feat_typed_rbac_allow_list branch from c18adc2 to dda7c9a Compare October 9, 2025 13:06
@ThomasK33
ThomasK33 force-pushed the thomask33/09-29-feat_legacy_apikey_backcompat branch from d34dbe8 to 47cccd7 Compare October 9, 2025 13:06
@ThomasK33 ThomasK33 closed this Oct 9, 2025
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 9, 2025
@ThomasK33
ThomasK33 deleted the thomask33/09-29-feat_legacy_apikey_backcompat branch October 9, 2025 15:37
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Backward compatibility tests and fixtures

2 participants