Skip to content

Commit 7064a66

Browse files
authored
permit unconfigured permission checks (#217)
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]>
1 parent b5f6e6c commit 7064a66

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

pkg/permissions/config.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,16 @@ import (
88

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

1416
// IgnoreNoResponders will ignore no responder errors when auth relationship requests are published.
1517
IgnoreNoResponders bool
18+
19+
// DefaultAllow if set to true, will allow all permissions checks when URL is not set.
20+
DefaultAllow bool
1621
}
1722

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

2328
flags.Bool("permissions-ignore-no-responders", false, "ignores no responder errors when auth relationship requests are published")
2429
viperx.MustBindFlag(v, "permissions.ignoreNoResponders", flags.Lookup("permissions-ignore-no-responders"))
30+
31+
flags.Bool("permissions-default-allow", false, "grant permission checks when url is not set")
32+
viperx.MustBindFlag(v, "permissions.defaultAllow", flags.Lookup("permissions-default-allow"))
2533
}

pkg/permissions/permissions.go

+4
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ func New(config Config, options ...Option) (*Permissions, error) {
201201
p.url = uri
202202
}
203203

204+
if config.URL == "" && config.DefaultAllow {
205+
p.defaultChecker = DefaultAllowChecker
206+
}
207+
204208
for _, opt := range options {
205209
if err := opt(p); err != nil {
206210
return nil, err

pkg/permissions/permissions_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@ func TestPermissions(t *testing.T) {
109109
nil,
110110
nil,
111111
},
112+
{
113+
"allow unconfigured checks",
114+
permissions.Config{
115+
DefaultAllow: true,
116+
},
117+
nil,
118+
"",
119+
"somersc-abc123",
120+
"some-action",
121+
nil,
122+
nil,
123+
},
112124
{
113125
"check allowed",
114126
permissions.Config{

0 commit comments

Comments
 (0)