Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: add allow list to API keys#19972

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
ThomasK33 wants to merge1 commit intomain
base:main
Choose a base branch
Loading
fromthomask33/09-25-resource_scoped_api_keys_in_codersdk

Conversation

ThomasK33
Copy link
Member

@ThomasK33ThomasK33 commentedSep 25, 2025
edited
Loading

Add API key allow list to the SDK

This PR adds an allow list to API keys in the SDK. The allow list is a list of targets that the API key is allowed to access. If the allow list is empty, a default allow list with a single entry that allows access to all resources is created.

The changes include:

  • Adding a default allow list when generating an API key if none is provided
  • Adding allow list to the API key response in the SDK
  • Converting database allow list entries to SDK format in the API response
  • Adding tests to verify the default allow list behavior

Fixes#19854

@ThomasK33Graphite App
Copy link
MemberAuthor

ThomasK33 commentedSep 25, 2025
edited
Loading

@ThomasK33ThomasK33 linked an issueSep 25, 2025 that may beclosed by this pull request
@ThomasK33ThomasK33force-pushed thethomask33/09-25-resource_scoped_api_keys_in_codersdk branch from05cdebd to5442fcdCompareSeptember 25, 2025 21:20
@ThomasK33ThomasK33force-pushed thethomask33/09-25-feat_add_allow_list_field_api_keys branch from1fea0d8 to8013625CompareSeptember 26, 2025 07:45
@ThomasK33ThomasK33force-pushed thethomask33/09-25-resource_scoped_api_keys_in_codersdk branch 2 times, most recently fromda32dec tof2fbea4CompareSeptember 26, 2025 08:25
@ThomasK33ThomasK33force-pushed thethomask33/09-25-feat_add_allow_list_field_api_keys branch from8013625 to4382587CompareSeptember 26, 2025 08:25
@ThomasK33ThomasK33force-pushed thethomask33/09-25-resource_scoped_api_keys_in_codersdk branch fromf2fbea4 to847f52eCompareSeptember 26, 2025 09:31
@ThomasK33ThomasK33force-pushed thethomask33/09-25-feat_add_allow_list_field_api_keys branch from4382587 tofb2440eCompareSeptember 26, 2025 10:16
@ThomasK33ThomasK33force-pushed thethomask33/09-25-resource_scoped_api_keys_in_codersdk branch from847f52e to1361b86CompareSeptember 26, 2025 10:17
@ThomasK33ThomasK33force-pushed thethomask33/09-25-feat_add_allow_list_field_api_keys branch fromfb2440e toce693c0CompareSeptember 26, 2025 10:20
@ThomasK33ThomasK33force-pushed thethomask33/09-25-resource_scoped_api_keys_in_codersdk branch from1361b86 to581bc52CompareSeptember 26, 2025 10:20
@ThomasK33ThomasK33 marked this pull request as ready for reviewSeptember 26, 2025 11:24
@ThomasK33ThomasK33force-pushed thethomask33/09-25-resource_scoped_api_keys_in_codersdk branch from581bc52 to6d17ef1CompareSeptember 26, 2025 12:24
@ThomasK33ThomasK33force-pushed thethomask33/09-25-feat_add_allow_list_field_api_keys branch fromce693c0 tof1a4e56CompareSeptember 26, 2025 12:24
@ThomasK33ThomasK33force-pushed thethomask33/09-25-feat_add_allow_list_field_api_keys branch fromf1a4e56 toa591e0aCompareSeptember 26, 2025 14:00
@ThomasK33ThomasK33force-pushed thethomask33/09-25-resource_scoped_api_keys_in_codersdk branch from6d17ef1 to6fa5fe1CompareSeptember 26, 2025 14:00
@ThomasK33ThomasK33force-pushed thethomask33/09-25-resource_scoped_api_keys_in_codersdk branch from56cd860 tod38ed5bCompareOctober 2, 2025 17:37
@ThomasK33ThomasK33force-pushed thethomask33/09-25-feat_add_allow_list_field_api_keys branch 3 times, most recently from5dd3400 to5a6e8ccCompareOctober 3, 2025 17:59
@ThomasK33ThomasK33force-pushed thethomask33/09-25-resource_scoped_api_keys_in_codersdk branch fromd38ed5b to5cb53f7CompareOctober 3, 2025 17:59
@ThomasK33ThomasK33force-pushed thethomask33/09-25-feat_add_allow_list_field_api_keys branch from5a6e8cc to73a65faCompareOctober 6, 2025 09:42
@ThomasK33ThomasK33force-pushed thethomask33/09-25-resource_scoped_api_keys_in_codersdk branch from5cb53f7 to6248fffCompareOctober 6, 2025 09:42
@ThomasK33ThomasK33force-pushed thethomask33/09-25-feat_add_allow_list_field_api_keys branch 2 times, most recently from7d422aa tod590c1dCompareOctober 6, 2025 10:09
@ThomasK33ThomasK33force-pushed thethomask33/09-25-resource_scoped_api_keys_in_codersdk branch from6248fff to67ed32bCompareOctober 6, 2025 10:09
@ThomasK33ThomasK33force-pushed thethomask33/09-25-feat_add_allow_list_field_api_keys branch fromd590c1d to49af2b4CompareOctober 6, 2025 10:35
@ThomasK33ThomasK33force-pushed thethomask33/09-25-resource_scoped_api_keys_in_codersdk branch 2 times, most recently from4beef99 to86f7de9CompareOctober 6, 2025 11:18
@ThomasK33ThomasK33force-pushed thethomask33/09-25-feat_add_allow_list_field_api_keys branch from49af2b4 tofa53285CompareOctober 6, 2025 11:57
@ThomasK33ThomasK33force-pushed thethomask33/09-25-resource_scoped_api_keys_in_codersdk branch from86f7de9 to854efb0CompareOctober 6, 2025 11:57
@EmyrkEmyrk self-assigned thisOct 6, 2025
@ThomasK33ThomasK33force-pushed thethomask33/09-25-feat_add_allow_list_field_api_keys branch fromfa53285 tod7df2aaCompareOctober 6, 2025 21:16
@ThomasK33ThomasK33force-pushed thethomask33/09-25-resource_scoped_api_keys_in_codersdk branch 2 times, most recently from87fb51c to3bdb267CompareOctober 6, 2025 21:40
Comment on lines 54 to 59
funcAPIAllowListTarget(entry rbac.AllowListElement) codersdk.APIAllowListTarget {
target:=codersdk.AllowAllTarget()
ifentry.Type!="" {
target.Type=codersdk.RBACResource(entry.Type)
}
ifentry.ID!="" {
target.ID=entry.ID
}
returntarget
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I know we have to figure out the semantics of an empty string for theid, but it should not be treated as a wildcard imo.

I think we should just pass the rbac entry to the SDK as is. Do not do:target := codersdk.AllowAllTarget() as the default.

ThomasK33 reacted with thumbs up emoji
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

updated

Comment on lines 1599 to 1601
allowList:=db2sdk.List(k.AllowList,db2sdk.APIAllowListTarget)
iflen(allowList)==0 {
allowList=append(allowList,codersdk.AllowAllTarget())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I still think we should never have an empty allow list. The db migration handles this iirc, so defaulting toall if the list is empty feels like it's hiding some other issue.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yeah, that's true. I've added an assert here since something else must have gone horribly wrong then.

@ThomasK33ThomasK33force-pushed thethomask33/09-25-feat_add_allow_list_field_api_keys branch fromd7df2aa toa1346f5CompareOctober 7, 2025 16:38
@ThomasK33ThomasK33force-pushed thethomask33/09-25-resource_scoped_api_keys_in_codersdk branch from3bdb267 toc41112aCompareOctober 7, 2025 16:38
@ThomasK33ThomasK33 changed the base branch fromthomask33/09-25-feat_add_allow_list_field_api_keys tographite-base/19972October 9, 2025 12:53
@ThomasK33ThomasK33force-pushed thethomask33/09-25-resource_scoped_api_keys_in_codersdk branch fromc41112a toa3de31eCompareOctober 9, 2025 12:53
@graphite-appgraphite-appbot changed the base branch fromgraphite-base/19972 tomainOctober 9, 2025 12:54
@ThomasK33ThomasK33force-pushed thethomask33/09-25-resource_scoped_api_keys_in_codersdk branch froma3de31e toad057a4CompareOctober 9, 2025 12:54
Add allow_list field to API key data structures and ensure properJSON serialization across backend and frontend. Initialize with default wildcard entry (*:*) for backward compatibility withexisting API keys that don't have explicit resource restrictions.Fixes#19854
@ThomasK33ThomasK33force-pushed thethomask33/09-25-resource_scoped_api_keys_in_codersdk branch fromad057a4 to79107e6CompareOctober 9, 2025 13:06
Comment on lines +1600 to +1602
iflen(allowList)==0 {
panic(fmt.Sprintf("developer error: API key %s has empty allow list",k.ID))
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I know it is annoying, but we should never panic. Should either return an error, or just leave the list empty

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Why not?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The caller of this function is always an http route, which is able to handle and properly return an error.

This should be an internal server error. I know we have a recover MW, but that is a last resort to catch uncaught errors.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Right, but this isn't just about returning or bubbling up an error—it's about making our assumptions explicit. We assume that an empty allow list will never be stored in the database.

Therefore, this code path should only occur if something is seriously wrong with our database. In such a case, I don't think we should treat it as a typical application error. Instead, we should signal clearly that our foundational assumptions have been violated and something beyond our control is wrong.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@EmyrkEmyrkEmyrk requested changes

Requested changes must be addressed to merge this pull request.

Assignees

@ThomasK33ThomasK33

@EmyrkEmyrk

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

SDK (Go): codersdk types for scopes[] + allow_list[]
2 participants
@ThomasK33@Emyrk

[8]ページ先頭

©2009-2025 Movatter.jp