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

permit unconfigured permission checks #217

Merged
merged 1 commit into from
Feb 5, 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
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 if set to true, will allow all permissions checks 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("permissions-default-allow", false, "grant permission checks when url is not set")
viperx.MustBindFlag(v, "permissions.defaultAllow", flags.Lookup("permissions-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
Loading