mirror of
https://github.com/coder/coder.git
synced 2026-09-22 05:05:20 +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:
@@ -56,7 +56,7 @@ func main() {
|
||||
log.Fatalf("to typescript: %v", err)
|
||||
}
|
||||
|
||||
TsMutations(ts)
|
||||
TSMutations(ts)
|
||||
|
||||
output, err := ts.Serialize()
|
||||
if err != nil {
|
||||
@@ -65,7 +65,7 @@ func main() {
|
||||
_, _ = fmt.Println(output)
|
||||
}
|
||||
|
||||
func TsMutations(ts *guts.Typescript) {
|
||||
func TSMutations(ts *guts.Typescript) {
|
||||
ts.ApplyMutations(
|
||||
// TODO: Remove 'NotNullMaps'. This is hiding potential bugs
|
||||
// of referencing maps that are actually null.
|
||||
|
||||
@@ -42,13 +42,20 @@ func TestGeneration(t *testing.T) {
|
||||
err = gen.IncludeGenerate("./" + dir)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Include minimal references needed for tests that use external types.
|
||||
for pkg, prefix := range map[string]string{
|
||||
"github.com/google/uuid": "",
|
||||
} {
|
||||
require.NoError(t, gen.IncludeReference(pkg, prefix))
|
||||
}
|
||||
|
||||
err = TypeMappings(gen)
|
||||
require.NoError(t, err)
|
||||
|
||||
ts, err := gen.ToTypescript()
|
||||
require.NoError(t, err)
|
||||
|
||||
TsMutations(ts)
|
||||
TSMutations(ts)
|
||||
|
||||
output, err := ts.Serialize()
|
||||
require.NoError(t, err)
|
||||
|
||||
Reference in New Issue
Block a user