mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: add allow_list to resource-scoped API tokens (#19964)
# Add API key allow_list for resource-scoped tokens This PR adds support for API key allow lists, enabling tokens to be scoped to specific resources. The implementation: 1. Adds a new `allow_list` field to the `CreateTokenRequest` struct, allowing clients to specify resource-specific scopes when creating API tokens 2. Implements `APIAllowListTarget` type to represent resource targets in the format `<type>:<id>` with support for wildcards 3. Adds validation and normalization logic for allow lists to handle wildcards and deduplication 4. Integrates with RBAC by creating an `APIKeyEffectiveScope` that merges API key scopes with allow list restrictions 5. Updates API documentation and TypeScript types to reflect the new functionality This feature enables creating tokens that are limited to specific resources (like workspaces or templates) by ID, making it possible to create more granular API tokens with limited access.
This commit is contained in:
@@ -225,6 +225,10 @@ func (s *MethodTestSuite) SubtestWithDB(db database.Store, testCaseF func(db dat
|
||||
if testCase.outputs != nil {
|
||||
// Assert the required outputs
|
||||
s.Equal(len(testCase.outputs), len(outputs), "method %q returned unexpected number of outputs", methodName)
|
||||
cmpOptions := []cmp.Option{
|
||||
// Equate nil and empty slices.
|
||||
cmpopts.EquateEmpty(),
|
||||
}
|
||||
for i := range outputs {
|
||||
a, b := testCase.outputs[i].Interface(), outputs[i].Interface()
|
||||
|
||||
@@ -232,10 +236,9 @@ func (s *MethodTestSuite) SubtestWithDB(db database.Store, testCaseF func(db dat
|
||||
// first check if the values are equal with regard to order.
|
||||
// If not, re-check disregarding order and show a nice diff
|
||||
// output of the two values.
|
||||
if !cmp.Equal(a, b, cmpopts.EquateEmpty()) {
|
||||
if diff := cmp.Diff(a, b,
|
||||
// Equate nil and empty slices.
|
||||
cmpopts.EquateEmpty(),
|
||||
if !cmp.Equal(a, b, cmpOptions...) {
|
||||
diffOpts := append(
|
||||
append([]cmp.Option{}, cmpOptions...),
|
||||
// Allow slice order to be ignored.
|
||||
cmpopts.SortSlices(func(a, b any) bool {
|
||||
var ab, bb strings.Builder
|
||||
@@ -247,7 +250,8 @@ func (s *MethodTestSuite) SubtestWithDB(db database.Store, testCaseF func(db dat
|
||||
// https://github.com/google/go-cmp/issues/67
|
||||
return ab.String() < bb.String()
|
||||
}),
|
||||
); diff != "" {
|
||||
)
|
||||
if diff := cmp.Diff(a, b, diffOpts...); diff != "" {
|
||||
s.Failf("compare outputs failed", "method %q returned unexpected output %d (-want +got):\n%s", methodName, i, diff)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user