Skip to content
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

Change user to principal in example schema #301

Merged
merged 5 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions deploy/schema.ksl
Original file line number Diff line number Diff line change
@@ -1,32 +1,44 @@
version 0.1
namespace rbac

public type user {}
public type principal {}

public type group {
relation member: [Any user or group.member]
relation member: [Any principal or group.member]
}

public type role {
relation view_the_thing: [bool]
}

public type role_binding {
relation subject: [Any user or group.member]
relation subject: [Any principal or group.member]
relation granted: [AtLeastOne role]

relation view_the_thing: subject and granted.view_the_thing
}

public type workspace {
relation parent: [AtMostOne workspace]
relation user_grant: [Any role_binding]

relation view_the_thing: user_grant.view_the_thing
}

public type thing {
public type widget {
relation workspace: [ExactlyOne workspace]

relation view: workspace.view_the_thing
@add_permission(name:'view_widget')
relation view: workspace.view_widget or use
@add_permission(name:'use_widget')
relation use: workspace.use_widget
}

internal extension add_permission(name) {
type role {
private relation ${name}: [bool]
}

type role_binding {
internal relation ${name}: subject and granted.${name}
}

type workspace {
internal relation ${name}: user_grant.${name} or parent.${name}
}
}
41 changes: 25 additions & 16 deletions deploy/schema.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,39 @@
schema: |-
definition rbac/user {}
definition rbac/principal {}

definition rbac/group {
relation member: rbac/user | rbac/group#member
permission member = t_member
relation t_member: rbac/principal | rbac/group#member
}

definition rbac/role {
relation view_the_thing: rbac/user:*
permission view_widget = t_view_widget
relation t_view_widget: rbac/principal:*
permission use_widget = t_use_widget
relation t_use_widget: rbac/principal:*
}

definition rbac/role_binding {
relation subject : rbac/user | rbac/group#member
relation granted: rbac/role

permission view_the_thing = subject & granted->view_the_thing
permission subject = t_subject
relation t_subject: rbac/principal | rbac/group#member
permission granted = t_granted
relation t_granted: rbac/role
permission view_widget = (subject & t_granted->view_widget)
permission use_widget = (subject & t_granted->use_widget)
}

definition rbac/workspace {
relation parent: rbac/workspace
relation user_grant: rbac/role_binding

permission view_the_thing = user_grant->view_the_thing
permission parent = t_parent
relation t_parent: rbac/workspace
permission user_grant = t_user_grant
relation t_user_grant: rbac/role_binding
permission view_widget = t_user_grant->view_widget + t_parent->view_widget
permission use_widget = t_user_grant->use_widget + t_parent->use_widget
}

definition rbac/thing {
relation workspace: rbac/workspace

permission view = workspace->view_the_thing
}
definition rbac/widget {
permission workspace = t_workspace
relation t_workspace: rbac/workspace
permission view = t_workspace->view_widget + use
permission use = t_workspace->use_widget
}
23 changes: 14 additions & 9 deletions deploy/schema.zed
Original file line number Diff line number Diff line change
@@ -1,33 +1,38 @@
definition rbac/user {}
definition rbac/principal {}

definition rbac/group {
permission member = t_member
relation t_member: rbac/user | rbac/group#member
relation t_member: rbac/principal | rbac/group#member
}

definition rbac/role {
permission view_the_thing = t_view_the_thing
relation t_view_the_thing: rbac/user:*
permission view_widget = t_view_widget
relation t_view_widget: rbac/principal:*
permission use_widget = t_use_widget
relation t_use_widget: rbac/principal:*
}

definition rbac/role_binding {
permission subject = t_subject
relation t_subject: rbac/user | rbac/group#member
relation t_subject: rbac/principal | rbac/group#member
permission granted = t_granted
relation t_granted: rbac/role
permission view_the_thing = (subject & t_granted->view_the_thing)
permission view_widget = (subject & t_granted->view_widget)
permission use_widget = (subject & t_granted->use_widget)
}

definition rbac/workspace {
permission parent = t_parent
relation t_parent: rbac/workspace
permission user_grant = t_user_grant
relation t_user_grant: rbac/role_binding
permission view_the_thing = t_user_grant->view_the_thing
permission view_widget = t_user_grant->view_widget + t_parent->view_widget
permission use_widget = t_user_grant->use_widget + t_parent->use_widget
}

definition rbac/thing {
definition rbac/widget {
permission workspace = t_workspace
relation t_workspace: rbac/workspace
permission view = t_workspace->view_the_thing
permission view = t_workspace->view_widget + use
permission use = t_workspace->use_widget
}
7 changes: 5 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ go 1.22.7
require (
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.35.2-20241127180247-a33202765966.1
github.com/MicahParks/keyfunc/v3 v3.3.5
github.com/authzed/grpcutil v0.0.0-20240123194739-2ea1e3d2d98b
github.com/authzed/authzed-go v1.2.0
github.com/authzed/grpcutil v0.0.0-20230908193239-4286bb1d6403
github.com/bufbuild/protovalidate-go v0.8.0
github.com/go-kratos/kratos/v2 v2.8.2
github.com/golang-jwt/jwt/v5 v5.2.1
Expand Down Expand Up @@ -54,6 +54,7 @@ require (
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/cel-go v0.22.1 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/subcommands v1.2.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/mux v1.8.1 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
Expand Down Expand Up @@ -82,11 +83,13 @@ require (
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect
golang.org/x/mod v0.22.0 // indirect
golang.org/x/time v0.6.0 // indirect
golang.org/x/tools v0.27.0 // indirect
golang.org/x/net v0.32.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/time v0.6.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241118233622-e639e219e697 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
9 changes: 7 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEV
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8D7ML55dXQrVaamCz2vxCfdQBasLZfHKk=
github.com/antlr4-go/antlr/v4 v4.13.0 h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8TVTI=
github.com/antlr4-go/antlr/v4 v4.13.0/go.mod h1:pfChB/xh/Unjila75QW7+VU4TSnWnnk9UTnmpPaOR2g=
github.com/authzed/grpcutil v0.0.0-20240123194739-2ea1e3d2d98b h1:wbh8IK+aMLTCey9sZasO7b6BWLAJnHHvb79fvWCXwxw=
github.com/authzed/grpcutil v0.0.0-20240123194739-2ea1e3d2d98b/go.mod h1:s3qC7V7XIbiNWERv7Lfljy/Lx25/V1Qlexb0WJuA8uQ=
github.com/authzed/authzed-go v1.2.0 h1:Ep1sRJMxcArB++kYqHbYKQCb/GgdGZI0cW4gZrJ1K40=
github.com/authzed/authzed-go v1.2.0/go.mod h1:4lkFxvaCISG1roRdnUt35/Sk1StVuMD1QCwTd/BcWcM=
github.com/authzed/grpcutil v0.0.0-20230908193239-4286bb1d6403 h1:bQeIwWWRI9bl93poTqpix4sYHi+gnXUPK7N6bMtXzBE=
github.com/authzed/grpcutil v0.0.0-20230908193239-4286bb1d6403/go.mod h1:s3qC7V7XIbiNWERv7Lfljy/Lx25/V1Qlexb0WJuA8uQ=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
Expand Down Expand Up @@ -105,6 +105,7 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
github.com/google/subcommands v1.2.0 h1:vWQspBTo2nEqTUFita5/KeEWlUL8kQObDFbub/EN9oE=
github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
Expand Down Expand Up @@ -242,6 +243,8 @@ golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4=
golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down Expand Up @@ -321,6 +324,8 @@ golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps=
golang.org/x/tools v0.27.0 h1:qEKojBykQkQ4EynWy4S8Weg69NumxKdn40Fce3uc/8o=
golang.org/x/tools v0.27.0/go.mod h1:sUi0ZgbwW9ZPAq26Ekut+weQPR5eIM6GQLQ1Yjm1H0Q=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
33 changes: 19 additions & 14 deletions internal/data/spicedb-test-data/basic_schema.zed
Original file line number Diff line number Diff line change
@@ -1,33 +1,38 @@
definition rbac/principal {}

definition rbac/group {
permission member = t_member
relation t_member: rbac/principal | rbac/group#member
}

definition rbac/role {
permission view_the_thing = t_view_the_thing
relation t_view_the_thing: rbac/user:*
permission view_widget = t_view_widget
relation t_view_widget: rbac/principal:*
permission use_widget = t_use_widget
relation t_use_widget: rbac/principal:*
}

definition rbac/role_binding {
permission subject = t_subject
relation t_subject: rbac/user | rbac/group#member
relation t_subject: rbac/principal | rbac/group#member
permission granted = t_granted
relation t_granted: rbac/role
permission view_the_thing = (subject & t_granted->view_the_thing)
permission view_widget = (subject & t_granted->view_widget)
permission use_widget = (subject & t_granted->use_widget)
}

definition rbac/workspace {
permission parent = t_parent
relation t_parent: rbac/workspace
permission user_grant = t_user_grant
relation t_user_grant: rbac/role_binding
permission view_the_thing = t_user_grant->view_the_thing
permission view_widget = t_user_grant->view_widget + t_parent->view_widget
permission use_widget = t_user_grant->use_widget + t_parent->use_widget
}

definition rbac/thing {
definition rbac/widget {
permission workspace = t_workspace
relation t_workspace: rbac/workspace
permission view = t_workspace->view_the_thing
}

definition rbac/user {}

definition rbac/group {
permission member = t_member
relation t_member: rbac/user | rbac/group#member
permission view = t_workspace->view_widget + use
permission use = t_workspace->use_widget
}
Loading
Loading