- Notifications
You must be signed in to change notification settings - Fork1k
feat: implement composite API key scopes for workspaces and templates#19945
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
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
-- No-op: keep enum values to avoid dependency churn. | ||
-- If strict removal is required, create a new enum type without these values, | ||
-- cast columns, drop the old type, and rename. |
ThomasK33 marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
-- Add high-level composite coder:* API key scopes | ||
-- These values are persisted so that tokens can store coder:* names directly. | ||
ALTERTYPE api_key_scope ADD VALUE IF NOT EXISTS'coder:workspaces.create'; | ||
ALTERTYPE api_key_scope ADD VALUE IF NOT EXISTS'coder:workspaces.operate'; | ||
ALTERTYPE api_key_scope ADD VALUE IF NOT EXISTS'coder:workspaces.delete'; | ||
ALTERTYPE api_key_scope ADD VALUE IF NOT EXISTS'coder:workspaces.access'; | ||
ALTERTYPE api_key_scope ADD VALUE IF NOT EXISTS'coder:templates.build'; | ||
ALTERTYPE api_key_scope ADD VALUE IF NOT EXISTS'coder:templates.author'; | ||
ALTERTYPE api_key_scope ADD VALUE IF NOT EXISTS'coder:apikeys.manage_self'; |
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -2,6 +2,7 @@ package rbac | ||
import ( | ||
"sort" | ||
"strings" | ||
"testing" | ||
"github.com/stretchr/testify/require" | ||
@@ -18,7 +19,7 @@ func TestExternalScopeNames(t *testing.T) { | ||
sort.Strings(sorted) | ||
require.Equal(t,sorted,names) | ||
// Ensure each entry expands to site-only | ||
for_,name:=rangenames { | ||
// Skip `all` and `application_connect` since they do not | ||
// expand into a low level scope. | ||
@@ -27,6 +28,20 @@ func TestExternalScopeNames(t *testing.T) { | ||
continue | ||
} | ||
// Composite coder:* scopes expand to one or more site permissions. | ||
ifstrings.HasPrefix(name,"coder:") { | ||
s,err:=ScopeName(name).Expand() | ||
require.NoErrorf(t,err,"catalog entry should expand: %s",name) | ||
require.NotEmpty(t,s.Site) | ||
ThomasK33 marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
expected,ok:=CompositeSitePermissions(ScopeName(name)) | ||
require.Truef(t,ok,"expected composite scope definition: %s",name) | ||
require.ElementsMatchf(t,expected,s.Site,"unexpected expanded permissions for %s",name) | ||
require.Empty(t,s.Org) | ||
require.Empty(t,s.User) | ||
continue | ||
} | ||
// Low-level scopes must parse to a single permission. | ||
res,act,ok:=parseLowLevelScope(ScopeName(name)) | ||
require.Truef(t,ok,"catalog entry should parse: %s",name) | ||
@@ -46,6 +61,7 @@ func TestIsExternalScope(t *testing.T) { | ||
require.True(t,IsExternalScope("workspace:read")) | ||
require.True(t,IsExternalScope("template:use")) | ||
require.True(t,IsExternalScope("workspace:*")) | ||
require.True(t,IsExternalScope("coder:workspaces.create")) | ||
require.False(t,IsExternalScope("debug_info:read"))// internal-only | ||
require.False(t,IsExternalScope("unknown:read")) | ||
} |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.