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 universal rights effect on batch gateway rights assertions #6711

Merged
merged 1 commit into from
Nov 16, 2023
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
32 changes: 24 additions & 8 deletions pkg/identityserver/gateway_access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,15 +590,14 @@ func TestGatewayBatchAccess(t *testing.T) {
locUserCreds := rpcCreds(locUserKey)

testWithIdentityServer(t, func(is *IdentityServer, cc *grpc.ClientConn) {
is.config.AdminRights.All = true

reg := ttnpb.NewGatewayBatchAccessClient(cc)

for _, tc := range []struct {
Name string
Credentials grpc.CallOption
Request *ttnpb.AssertGatewayRightsRequest
ErrorAssertion func(error) bool
Name string
Credentials grpc.CallOption
Request *ttnpb.AssertGatewayRightsRequest
ErrorAssertion func(error) bool
LimitedAdminRights bool
}{
{
Name: "Empty request",
Expand Down Expand Up @@ -771,6 +770,20 @@ func TestGatewayBatchAccess(t *testing.T) {
Credentials: collaboratorCreds,
ErrorAssertion: errors.IsPermissionDenied,
},
{
Name: "Universal rights for admin",
Request: &ttnpb.AssertGatewayRightsRequest{
GatewayIds: []*ttnpb.GatewayIdentifiers{
gtw3.GetIds(),
},
Required: &ttnpb.Rights{
Rights: []ttnpb.Right{
ttnpb.Right_RIGHT_GATEWAY_SETTINGS_API_KEYS,
},
},
},
Credentials: adminCreds,
},
{
Name: "Limited rights for admin",
Request: &ttnpb.AssertGatewayRightsRequest{
Expand All @@ -783,8 +796,9 @@ func TestGatewayBatchAccess(t *testing.T) {
},
},
},
Credentials: adminCreds,
ErrorAssertion: errors.IsNotFound,
Credentials: adminCreds,
ErrorAssertion: errors.IsPermissionDenied,
LimitedAdminRights: true,
},
{
Name: "Read Stats Failure",
Expand Down Expand Up @@ -945,6 +959,8 @@ func TestGatewayBatchAccess(t *testing.T) {
} {
tc := tc
t.Run(tc.Name, func(t *testing.T) {
is.config.AdminRights.All = !tc.LimitedAdminRights

_, err := reg.AssertRights(ctx, tc.Request, tc.Credentials)
if err != nil {
if tc.ErrorAssertion == nil || !a.So(tc.ErrorAssertion(err), should.BeTrue) {
Expand Down
11 changes: 6 additions & 5 deletions pkg/identityserver/rights.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func (is *IdentityServer) assertGatewayRights( // nolint:gocyclo
return err
}
if len(gtws) != len(gtwIDs) {
if is.IsAdmin(ctx) {
if authInfo.IsAdmin {
// Return the cause only to the admin.
// This follows the same logic as in ListRights.
return errSomeGatewaysNotFound.New()
Expand Down Expand Up @@ -322,6 +322,11 @@ func (is *IdentityServer) assertGatewayRights( // nolint:gocyclo
if len(entityIDs) == 0 {
return nil
}
if authInfo.IsAdmin {
if authInfo.GetUniversalRights().IncludesAll(requiredGatewayRights.GetRights()...) {
return nil
}
}
membershipChains, err := st.FindAccountMembershipChains(
ctx,
ouID,
Expand All @@ -332,10 +337,6 @@ func (is *IdentityServer) assertGatewayRights( // nolint:gocyclo
return err
}
if len(membershipChains) != len(entityIDs) {
// Some memberships were not found.
adriansmares marked this conversation as resolved.
Show resolved Hide resolved
if is.IsAdmin(ctx) {
return errSomeGatewaysNotFound.New()
}
return errInsufficientRights.New()
}
for _, chain := range membershipChains {
Expand Down
Loading