Skip to content

chore: remove rbac psuedo resources, add custom verbs #13276

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

Merged
merged 24 commits into from
May 15, 2024

Conversation

Emyrk
Copy link
Member

@Emyrk Emyrk commented May 14, 2024

Supports #13226

What this does

Removes our pseudo rbac resources like WorkspaceApplicationConnect in favor of additional verbs like ssh. This is to make more intuitive permissions for building custom roles.

Prior to this change, trying to create a custom role creator would not be intuitive or dynamic.

Screenshot from 2024-05-14 19-07-03

Implementation

The source of truth is now policy.go .

To prevent even more line changes by drastically changing the golang code, the previous resource list is autogenerated from this source of truth:

ResourceWorkspace = Object{
Type: "workspace",
}

The autogen is the easiest way to ensure consistency while still using the rbac.Object.

The codersdk authz constants are now also in sync via auto gen: https://github.com/coder/coder/blob/eeb6ac20988b77ae7bf577c79b304fa34a7848f5/codersdk/rbacresources_gen.go

Additional checks

The prior and current implementation do not force the caller to populate the object fields (owner, org, id, acls, etc) or use a correct action when calling the rego.

Now that we have a definitive policy location, we can add at least runtime checks for correctness. I have only added correctness checks for actions on unit tests.

coder/coderd/rbac/authz.go

Lines 243 to 247 in d60f65a

func NewStrictCachingAuthorizer(registry prometheus.Registerer) Authorizer {
auth := NewAuthorizer(registry)
auth.strict = true
return Cacher(auth)
}

This will prevent asserting actions that are not available for a given object.

Copy link
Member Author

Emyrk commented May 14, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @Emyrk and the rest of your teammates on Graphite Graphite

@Emyrk Emyrk force-pushed the stevenmasley/rego_to_policy branch from 46dbb72 to b2f9524 Compare May 14, 2024 22:00
@Emyrk Emyrk force-pushed the stevenmasley/rego_upgrade branch 4 times, most recently from e8977b6 to 0089e1d Compare May 14, 2024 22:16
ActionReadPersonal: actDef(fieldOwner, "read personal user data like password"),
ActionUpdatePersonal: actDef(fieldOwner, "update personal data"),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This used to be ResourceUserData, but is now just additional verbs

@Emyrk Emyrk force-pushed the stevenmasley/rego_upgrade branch 2 times, most recently from 50aee62 to 103ed1f Compare May 14, 2024 22:34
@Emyrk Emyrk changed the title chore: custom verbs for RBAC actions chore: remove rbac psuedo resources, add custom verbs May 15, 2024
@Emyrk Emyrk force-pushed the stevenmasley/rego_upgrade branch 2 times, most recently from eeb6ac2 to 116a38e Compare May 15, 2024 00:12
Comment on lines +617 to +618
codersdk/rbacresources_gen.go: scripts/rbacgen/main.go coderd/rbac/object.go
go run scripts/rbacgen/main.go codersdk > codersdk/rbacresources_gen.go
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this was manually kept in sync. Or so we told ourselves

Comment on lines 167 to 173
rbac.ResourceFile.Type: {policy.ActionRead},
rbac.ResourceSystem.Type: {rbac.WildcardSymbol},
rbac.ResourceTemplate.Type: {policy.ActionRead, policy.ActionUpdate},
rbac.ResourceUser.Type: {policy.ActionRead},
rbac.ResourceWorkspace.Type: {policy.ActionRead, policy.ActionUpdate, policy.ActionDelete},
rbac.ResourceWorkspaceBuild.Type: {policy.ActionRead, policy.ActionUpdate, policy.ActionDelete},
rbac.ResourceUserData.Type: {policy.ActionRead, policy.ActionUpdate},
rbac.ResourceAPIKey.Type: {rbac.WildcardSymbol},
rbac.ResourceFile.Type: {policy.ActionRead},
rbac.ResourceSystem.Type: {rbac.WildcardSymbol},
rbac.ResourceTemplate.Type: {policy.ActionRead, policy.ActionUpdate},
// Unsure why provisionerd needs update and read personal
rbac.ResourceUser.Type: {policy.ActionRead, policy.ActionReadPersonal, policy.ActionUpdatePersonal},
rbac.ResourceWorkspace.Type: {policy.ActionRead, policy.ActionUpdate, policy.ActionDelete, policy.ActionWorkspaceBuild},
rbac.ResourceApiKey.Type: {rbac.WildcardSymbol},
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ResourceWorkspaceBuild -> ResourceWorkspace: ActionWorkspaceBuild

(unsure why it needs this, keeping status quo)
ResourceUserData -> ResourceUser: ActionReadPersonal, ActionUpdatePersonal

Comment on lines 195 to 197
rbac.ResourceSystem.Type: {rbac.WildcardSymbol},
rbac.ResourceTemplate.Type: {policy.ActionRead, policy.ActionUpdate},
rbac.ResourceWorkspace.Type: {policy.ActionRead, policy.ActionUpdate},
rbac.ResourceWorkspaceBuild.Type: {policy.ActionRead, policy.ActionUpdate, policy.ActionDelete},
rbac.ResourceUser.Type: {policy.ActionRead},
rbac.ResourceSystem.Type: {rbac.WildcardSymbol},
rbac.ResourceTemplate.Type: {policy.ActionRead, policy.ActionUpdate},
rbac.ResourceWorkspace.Type: {policy.ActionRead, policy.ActionUpdate, policy.ActionWorkspaceBuild},
rbac.ResourceUser.Type: {policy.ActionRead},
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ResourceWorkspaceBuild -> ResourceWorkspace: ActionWorkspaceBuild

rbac.ResourceWorkspaceBuild.Type: {policy.ActionUpdate},
rbac.ResourceWorkspaceExecution.Type: {policy.ActionCreate},
rbac.ResourceUser.Type: rbac.ResourceUser.AvailableActions(),
rbac.ResourceWorkspace.Type: {policy.ActionUpdate, policy.ActionDelete, policy.ActionWorkspaceBuild, policy.ActionSSH},
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ResourceWorkspaceExecution -> ResourceWorkspace: ActionSSH

@@ -106,7 +106,7 @@ You can test outside of golang by using the `opa` cli.

**Evaluation**

opa eval --format=pretty 'false' -d policy.rego -i input.json
opa eval --format=pretty "data.authz.allow" -d policy.rego -i input.json
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a typo I found in the readme.

Comment on lines +62 to +66
// RBACPermissions is indexed by the type
var RBACPermissions = map[string]PermissionDefinition{
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new source of truth for our policies.

Comment on lines 568 to 580
// Only run these if the tests on top passed. Otherwise, the error output is too noisy.
if passed {
for rtype, v := range remainingPermissions {
// nolint:tparallel -- Making a subtest for easier diagnosing failures.
t.Run(fmt.Sprintf("%s-AllActions", rtype), func(t *testing.T) {
if len(v) > 0 {
assert.Equal(t, map[policy.Action]bool{}, v, "remaining permissions should be empty for type %q", rtype)
}
})
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this to force us to update this test if resources or actions are added. This is sort of our source of truth for our "policy".

Would be really awesome to come up with a custom syntax for making this more compressed...

@Emyrk Emyrk force-pushed the stevenmasley/rego_upgrade branch 14 times, most recently from 574d565 to 6020cc2 Compare May 15, 2024 03:28
@Emyrk Emyrk marked this pull request as ready for review May 15, 2024 03:39
Base automatically changed from stevenmasley/rego_to_policy to main May 15, 2024 14:46
@Emyrk Emyrk force-pushed the stevenmasley/rego_upgrade branch from 6020cc2 to 7262bd8 Compare May 15, 2024 14:47
@Emyrk Emyrk merged commit 1f5788f into main May 15, 2024
31 checks passed
@Emyrk Emyrk deleted the stevenmasley/rego_upgrade branch May 15, 2024 16:09
@github-actions github-actions bot locked and limited conversation to collaborators May 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants