mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
79126ab6c7
# Add Composite API Key Scopes This PR adds high-level composite API key scopes to simplify token creation with common permission sets: - `coder:workspaces.create` - Create and update workspaces - `coder:workspaces.operate` - Read and update workspaces - `coder:workspaces.delete` - Read and delete workspaces - `coder:workspaces.access` - Read, SSH, and connect to workspace applications - `coder:templates.build` - Read templates and create/read files - `coder:templates.author` - Full template management with insights - `coder:apikeys.manage_self` - Manage your own API keys These composite scopes are persisted in the database and expanded during authorization, providing a more intuitive way to grant permissions compared to the granular resource:action scopes.
33 lines
728 B
Go
33 lines
728 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"sort"
|
|
|
|
"github.com/coder/coder/v2/coderd/rbac"
|
|
"github.com/coder/coder/v2/coderd/rbac/policy"
|
|
)
|
|
|
|
func main() {
|
|
seen := map[string]struct{}{}
|
|
var vals []string
|
|
for resource, def := range policy.RBACPermissions {
|
|
if resource == policy.WildcardSymbol {
|
|
continue
|
|
}
|
|
for action := range def.Actions {
|
|
vals = append(vals, fmt.Sprintf("%s:%s", resource, action))
|
|
}
|
|
}
|
|
// Include composite coder:* scopes as first-class enum values
|
|
vals = append(vals, rbac.CompositeScopeNames()...)
|
|
sort.Strings(vals)
|
|
for _, v := range vals {
|
|
if _, ok := seen[v]; ok {
|
|
continue
|
|
}
|
|
seen[v] = struct{}{}
|
|
_, _ = fmt.Printf("ALTER TYPE api_key_scope ADD VALUE IF NOT EXISTS '%s';\n", v)
|
|
}
|
|
}
|