- Notifications
You must be signed in to change notification settings - Fork1k
feat: add multi-scope support to API keys#19917
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
This change unifies scope handling by migrating special scopes to thecoder:* namespace while maintaining backward compatibility:- Database: 'all' -> 'coder:all', 'application_connect' -> 'coder:application_connect'- API accepts both legacy and canonical forms in requests- Responses maintain legacy format for existing client compatibility- Scope catalog returns all public scopes including canonical specials- Validation enforces public scope requirements using unified logicThe migration preserves existing API key functionality while establishingconsistent scope naming conventions for future extensibility.
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
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.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -67,18 +67,39 @@ func (api *API) postToken(rw http.ResponseWriter, r *http.Request) { | ||
} | ||
// Map and validate requested scope. | ||
// Accept legacy special scopes (all, application_connect) and external scopes. | ||
// Default to coder:all scopes for backward compatibility. | ||
scopes:= database.APIKeyScopes{database.ApiKeyScopeCoderAll} | ||
iflen(createToken.Scopes)>0 { | ||
scopes=make(database.APIKeyScopes,0,len(createToken.Scopes)) | ||
for_,s:=rangecreateToken.Scopes { | ||
name:=string(s) | ||
if!rbac.IsExternalScope(rbac.ScopeName(name)) { | ||
httpapi.Write(ctx,rw,http.StatusBadRequest, codersdk.Response{ | ||
Message:"Failed to create API key.", | ||
Detail:fmt.Sprintf("invalid or unsupported API key scope: %q",name), | ||
}) | ||
return | ||
} | ||
scopes=append(scopes,database.APIKeyScope(name)) | ||
ThomasK33 marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
} | ||
}elseifstring(createToken.Scope)!="" { | ||
name:=string(createToken.Scope) | ||
if!rbac.IsExternalScope(rbac.ScopeName(name)) { | ||
httpapi.Write(ctx,rw,http.StatusBadRequest, codersdk.Response{ | ||
Message:"Failed to create API key.", | ||
Detail:fmt.Sprintf("invalidor unsupportedAPI key scope: %q",name), | ||
}) | ||
return | ||
} | ||
switchname { | ||
case"all": | ||
scopes= database.APIKeyScopes{database.ApiKeyScopeCoderAll} | ||
case"application_connect": | ||
scopes= database.APIKeyScopes{database.ApiKeyScopeCoderApplicationConnect} | ||
default: | ||
scopes= database.APIKeyScopes{database.APIKeyScope(name)} | ||
} | ||
} | ||
tokenName:=namesgenerator.GetRandomName(1) | ||
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.