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

Fix inversion of exclusion permissions and model validation #50

Merged
merged 3 commits into from
Jul 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
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ module github.com/aserto-dev/azm

go 1.22

toolchain go1.22.5

// replace github.com/aserto-dev/go-directory => ../go-directory

require (
Expand Down
2 changes: 0 additions & 2 deletions go.work
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
go 1.22

toolchain go1.22.5

use (
.
./cmd/azmcmd
Expand Down
6 changes: 6 additions & 0 deletions graph/check_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ types:
can_share: can_write & parent->can_share
can_invite: parent->can_read - viewer

# viewer can be user or group but owner can only be user
negation_type_subset: viewer - owner

# viewer can be user or group but owner can only be user
intersection_type_subset: viewer & owner

cycle:
relations:
parent: cycle
Expand Down
16 changes: 16 additions & 0 deletions model/inverse.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@ func (i *inverter) invert() *Model {
}
}

for _, o := range i.im.Objects {
for _, p := range o.Permissions {
if !p.IsExclusion() {
continue
}

if p.Exclusion.Exclude == nil {
// It is possible for the 'Exclude' term to be empty in in inverted model if the object type
// cannot have the relation/permission being excluded.
// In this case, the exclusion permission becomes a single-term union.
p.Union = PermissionTerms{p.Exclusion.Include}
p.Exclusion = nil
}
}
}

return i.im
}

Expand Down
3 changes: 3 additions & 0 deletions model/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ type PermissionTerm struct {
}

func (pr *PermissionTerm) String() string {
if pr == nil {
return "<nil>"
}
s := string(pr.RelOrPerm)
if pr.Base != "" {
s = string(pr.Base) + "->" + s
Expand Down
6 changes: 6 additions & 0 deletions model/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ func (v *validator) validateObjectPerms(on ObjectName, o *Object) error {
}

for _, term := range terms {
if term == nil {
errs = multierror.Append(errs, derr.ErrInvalidPermission.Msgf(
"permission '%s:%s' has an empty term", on, pn),
)
continue
}
switch {
case term.IsArrow():
// this is an arrow operator.
Expand Down
Loading