Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Emyrk merged 24 commits intomainfromstevenmasley/rego_upgrade
May 15, 2024

Conversation

Emyrk
Copy link
Member

@EmyrkEmyrk commentedMay 14, 2024
edited
Loading

Supports#13226

What this does

Removes our pseudo rbac resources likeWorkspaceApplicationConnect in favor of additional verbs likessh. 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 nowpolicy.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 therbac.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.

funcNewStrictCachingAuthorizer(registry prometheus.Registerer)Authorizer {
auth:=NewAuthorizer(registry)
auth.strict=true
returnCacher(auth)
}

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

@EmyrkGraphite App
Copy link
MemberAuthor

Emyrk commentedMay 14, 2024
edited
Loading

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

Join@Emyrk and the rest of your teammates onGraphiteGraphite

@EmyrkEmyrkforce-pushed thestevenmasley/rego_to_policy branch from46dbb72 tob2f9524CompareMay 14, 2024 22:00
@EmyrkEmyrkforce-pushed thestevenmasley/rego_upgrade branch 4 times, most recently frome8977b6 to0089e1dCompareMay 14, 2024 22:16
ActionReadPersonal: actDef(fieldOwner, "read personal user data like password"),
ActionUpdatePersonal: actDef(fieldOwner, "update personal data"),
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

This used to beResourceUserData, but is now just additional verbs

@EmyrkEmyrkforce-pushed thestevenmasley/rego_upgrade branch 2 times, most recently from50aee62 to103ed1fCompareMay 14, 2024 22:34
@EmyrkEmyrk changed the titlechore: custom verbs for RBAC actionschore: remove rbac psuedo resources, add custom verbsMay 15, 2024
@EmyrkEmyrkforce-pushed thestevenmasley/rego_upgrade branch 2 times, most recently fromeeb6ac2 to116a38eCompareMay 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
MemberAuthor

Choose a reason for hiding this comment

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

Before this was manuallykept in sync. Or so we told ourselves

johnstcn reacted with laugh emoji
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
MemberAuthor

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
MemberAuthor

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
MemberAuthor

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
MemberAuthor

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
MemberAuthor

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
MemberAuthor

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...

@EmyrkEmyrkforce-pushed thestevenmasley/rego_upgrade branch 14 times, most recently from574d565 to6020cc2CompareMay 15, 2024 03:28
@EmyrkEmyrk marked this pull request as ready for reviewMay 15, 2024 03:39
Base automatically changed fromstevenmasley/rego_to_policy tomainMay 15, 2024 14:46
@EmyrkEmyrkforce-pushed thestevenmasley/rego_upgrade branch from6020cc2 to7262bd8CompareMay 15, 2024 14:47
@EmyrkEmyrk merged commit1f5788f intomainMay 15, 2024
31 checks passed
@EmyrkEmyrk deleted the stevenmasley/rego_upgrade branchMay 15, 2024 16:09
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsMay 15, 2024
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@johnstcnjohnstcnjohnstcn approved these changes

Assignees

@EmyrkEmyrk

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@Emyrk@johnstcn

[8]ページ先頭

©2009-2025 Movatter.jp