Skip to content

Commit ed70e71

Browse files
authored
fix(controlplane): skip allow-list for API tokens (#1071)
Signed-off-by: Miguel Martinez Trivino <[email protected]>
1 parent 6c2353d commit ed70e71

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

app/controlplane/internal/usercontext/allowlist_middleware.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ func CheckUserInAllowList(allowList *conf.Auth_AllowList) middleware.Middleware
3535
return handler(ctx, req)
3636
}
3737

38+
// API tokens skip the allowlist since they are meant to represent a service
39+
if token := CurrentAPIToken(ctx); token != nil {
40+
return handler(ctx, req)
41+
}
42+
3843
// Make sure that this middleware is ran after WithCurrentUser
3944
user := CurrentUser(ctx)
4045
if user == nil {

app/controlplane/internal/usercontext/allowlist_middleware_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ func TestCheckUserInAllowList(t *testing.T) {
7272
selectedRoutes []string
7373
runningRoute string
7474
email string
75+
isAPIToken bool
7576
wantErr bool
7677
customErrMsg string
7778
}{
@@ -85,6 +86,12 @@ func TestCheckUserInAllowList(t *testing.T) {
8586
rules: []string{"[email protected]"},
8687
wantErr: true,
8788
},
89+
{
90+
name: "is an API token so allow-list gets skipped",
91+
isAPIToken: true,
92+
rules: []string{"[email protected]"},
93+
wantErr: false,
94+
},
8895
{
8996
name: "user not allowed to access the route",
9097
@@ -159,7 +166,10 @@ func TestCheckUserInAllowList(t *testing.T) {
159166
ctx := context.Background()
160167
if tc.email != "" {
161168
ctx = WithCurrentUser(ctx, &User{Email: tc.email, ID: "124"})
169+
} else if tc.isAPIToken {
170+
ctx = WithCurrentAPIToken(ctx, &APIToken{ID: "124"})
162171
}
172+
163173
if tc.runningRoute != "" {
164174
ctx = transport.NewServerContext(ctx, &mockTransport{operation: tc.runningRoute})
165175
}

0 commit comments

Comments
 (0)