-
Notifications
You must be signed in to change notification settings - Fork 894
feat: Implement allow_list for scopes for resource specific permissions #5769
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
212ebce
655e8db
5f5653d
4d66a03
f924578
b9fed91
504c54b
257701f
a9cf8f4
fa44bfe
94ad568
043a1d5
e0e6312
7492385
64a246d
ca88a38
9e4d72f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -8,39 +8,52 @@ import ( | |||||
|
||||||
type Scope string | ||||||
|
||||||
// TODO: @emyrk rename this struct | ||||||
type ScopeRole struct { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe this should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe, I am thinking of changing this plumbing, I just wanted to implement the allow_list into the rego policy. I will come back to this once I get There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still going to rename? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I renamed Will do now. |
||||||
Role | ||||||
AllowIDList []string `json:"allow_list"` | ||||||
} | ||||||
|
||||||
const ( | ||||||
ScopeAll Scope = "all" | ||||||
ScopeApplicationConnect Scope = "application_connect" | ||||||
) | ||||||
|
||||||
var builtinScopes map[Scope]Role = map[Scope]Role{ | ||||||
// TODO: Support passing in scopeID list for whitelisting allowed resources. | ||||||
Emyrk marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
var builtinScopes map[Scope]ScopeRole = map[Scope]ScopeRole{ | ||||||
Emyrk marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
// ScopeAll is a special scope that allows access to all resources. During | ||||||
// authorize checks it is usually not used directly and skips scope checks. | ||||||
ScopeAll: { | ||||||
Name: fmt.Sprintf("Scope_%s", ScopeAll), | ||||||
DisplayName: "All operations", | ||||||
Site: permissions(map[string][]Action{ | ||||||
ResourceWildcard.Type: {WildcardSymbol}, | ||||||
}), | ||||||
Org: map[string][]Permission{}, | ||||||
User: []Permission{}, | ||||||
Role: Role{ | ||||||
Name: fmt.Sprintf("Scope_%s", ScopeAll), | ||||||
DisplayName: "All operations", | ||||||
Site: permissions(map[string][]Action{ | ||||||
ResourceWildcard.Type: {WildcardSymbol}, | ||||||
}), | ||||||
Org: map[string][]Permission{}, | ||||||
User: []Permission{}, | ||||||
}, | ||||||
AllowIDList: []string{WildcardSymbol}, | ||||||
}, | ||||||
|
||||||
ScopeApplicationConnect: { | ||||||
Name: fmt.Sprintf("Scope_%s", ScopeApplicationConnect), | ||||||
DisplayName: "Ability to connect to applications", | ||||||
Site: permissions(map[string][]Action{ | ||||||
ResourceWorkspaceApplicationConnect.Type: {ActionCreate}, | ||||||
}), | ||||||
Org: map[string][]Permission{}, | ||||||
User: []Permission{}, | ||||||
Role: Role{ | ||||||
Name: fmt.Sprintf("Scope_%s", ScopeApplicationConnect), | ||||||
DisplayName: "Ability to connect to applications", | ||||||
Site: permissions(map[string][]Action{ | ||||||
ResourceWorkspaceApplicationConnect.Type: {ActionCreate}, | ||||||
}), | ||||||
Org: map[string][]Permission{}, | ||||||
User: []Permission{}, | ||||||
}, | ||||||
AllowIDList: []string{WildcardSymbol}, | ||||||
}, | ||||||
} | ||||||
|
||||||
func ScopeRole(scope Scope) (Role, error) { | ||||||
func ExpandScope(scope Scope) (ScopeRole, error) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure it makes sense to keep Scope as a string in the database once we are going to have things like an allowlist into it. Do we need to expand it to a JSON object? We're not going to be able to keep a map of all workspace scopes in memory. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We might need to, but we are going to create the workspace agent authorization context in memory, not from the db. Agent tokens right now do not have an RBAC subject related to it, it's not an APIKey. So when we implement agent tokens, we will use the workspace owner's roles and add the agent scope to it. Meaning the scope is not in the database. But you are correct if we use this for more and more cases, it might require us to elevate this to the DB in the future. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are agent tokens tied to a specific workspace at present (in the DB)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. coder/coderd/database/dump.sql Lines 437 to 438 in b9fed91
The connection is through the |
||||||
role, ok := builtinScopes[scope] | ||||||
if !ok { | ||||||
return Role{}, xerrors.Errorf("no scope named %q", scope) | ||||||
return ScopeRole{}, xerrors.Errorf("no scope named %q", scope) | ||||||
} | ||||||
return role, nil | ||||||
} |
Uh oh!
There was an error while loading. Please reload this page.