Skip to content

Commit

Permalink
permit unconfigured permission checks
Browse files Browse the repository at this point in the history
Easily permit permission checks when the permission library doesn't have
a proper url configured.

This simplifies local development for service which implement
permissions checks allowing them to skip calling out to a permissions
service while developing locally by simply enabling `DefaultAllow`.

Signed-off-by: Mike Mason <[email protected]>
  • Loading branch information
mikemrm committed Feb 2, 2024
1 parent b5f6e6c commit cddfef1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pkg/permissions/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ import (

// Config defines the permissions configuration structure
type Config struct {
// URL is the URL checks should be executed against
// URL should point to a permissions-api authorization API route, such as https://example.com/api/v1/allow.
// If not set, all permissions checks will be denied by default. To override this behavior, set DefaultAllow
// to true.
URL string

// IgnoreNoResponders will ignore no responder errors when auth relationship requests are published.
IgnoreNoResponders bool

// DefaultAllow all permissions checks will be granted when URL is not set.
DefaultAllow bool
}

// MustViperFlags adds permissions config flags and viper bindings
Expand All @@ -22,4 +27,7 @@ func MustViperFlags(v *viper.Viper, flags *pflag.FlagSet) {

flags.Bool("permissions-ignore-no-responders", false, "ignores no responder errors when auth relationship requests are published")
viperx.MustBindFlag(v, "permissions.ignoreNoResponders", flags.Lookup("permissions-ignore-no-responders"))

flags.Bool("default-allow", false, "grant permission checks when url is not set")
viperx.MustBindFlag(v, "permissions.defaultAllow", flags.Lookup("default-allow"))
}
4 changes: 4 additions & 0 deletions pkg/permissions/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ func New(config Config, options ...Option) (*Permissions, error) {
p.url = uri
}

if config.URL == "" && config.DefaultAllow {
p.defaultChecker = DefaultAllowChecker
}

for _, opt := range options {
if err := opt(p); err != nil {
return nil, err
Expand Down
12 changes: 12 additions & 0 deletions pkg/permissions/permissions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ func TestPermissions(t *testing.T) {
nil,
nil,
},
{
"allow unconfigured checks",
permissions.Config{
DefaultAllow: true,
},
nil,
"",
"somersc-abc123",
"some-action",
nil,
nil,
},
{
"check allowed",
permissions.Config{
Expand Down

0 comments on commit cddfef1

Please sign in to comment.