Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
bee77b1
Replaced deprecated errors - ErrReferencedByAnotherObject, ErrInvaria…
mtodor Apr 20, 2022
ce213c9
Replaced deprecated error - ErrAlreadyExists
mtodor Apr 20, 2022
f9af2c7
Replaced deprecated error - ErrInvalidArgs
mtodor Apr 21, 2022
4b4edba
Replaced deprecated error - ErrNotFound
mtodor Apr 21, 2022
3f180f3
Replaced deprecated error - GenericNoValidRole
mtodor Apr 21, 2022
ddf4771
Replaced deprecated error function - NewErrNoCredentials
mtodor Apr 21, 2022
e9aba67
Replaced deprecated error function - NewErrInvariantViolation
mtodor Apr 21, 2022
e69442e
Replaced deprecated error function - NewErrNotAuthorized
mtodor Apr 21, 2022
a0129aa
Replaced deprecated error function - NewErrInvalidArgs
mtodor Apr 21, 2022
dc345c3
Remove NewErrNoCredentials
mtodor Apr 22, 2022
a85e2d3
Remove NewErrInvariantViolation
mtodor Apr 22, 2022
0ab6c9f
Remove NewErrNotAuthorized
mtodor Apr 22, 2022
c6575d4
Remove NewErrInvalidArgs
mtodor Apr 22, 2022
18d1609
Exclude roxctl from wrapcheck
mtodor Apr 22, 2022
ec30dc8
Merge branch 'master' into mtodor/ROX-10303-replace-new-error-wrappers
mtodor Apr 25, 2022
daf991c
Remove NoValidRole error sentinel
mtodor Apr 25, 2022
92f3cfe
Fix regex and put roxctl back for linter wrapcheck
mtodor Apr 25, 2022
1e6a988
Merge branch 'master' into mtodor/ROX-10304-remove-generic-no-valid-r…
mtodor Apr 26, 2022
910d96f
Added ErrNoValidRole sentinel for authproviders
mtodor Apr 26, 2022
dcf60a2
Tweak comment
mtodor Apr 26, 2022
52e50ff
Merge branch 'master' into mtodor/ROX-10304-remove-generic-no-valid-r…
mtodor Apr 26, 2022
299b8a5
Merge branch 'master' into mtodor/ROX-10303-replace-new-error-wrappers
mtodor Apr 26, 2022
00591d8
Merge branch 'mtodor/ROX-10303-replace-new-error-wrappers' into mtodo…
mtodor Apr 26, 2022
138264d
Merge branch 'master' into mtodor/ROX-10303-replace-new-error-wrappers
mtodor Apr 27, 2022
9cde10b
Updated error messages - review comment discussion_r859310460
mtodor Apr 27, 2022
c751bce
Merge branch 'mtodor/ROX-10303-replace-new-error-wrappers' into mtodo…
mtodor Apr 27, 2022
7e39204
Move ErrNoValidRole to auth package
mtodor Apr 27, 2022
91bf9b4
Merge branch 'master' into mtodor/ROX-10304-remove-generic-no-valid-r…
mtodor Apr 28, 2022
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
5 changes: 3 additions & 2 deletions pkg/auth/authproviders/registry_httphandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/golang/protobuf/jsonpb"
"github.com/pkg/errors"
v1 "github.com/stackrox/rox/generated/api/v1"
"github.com/stackrox/rox/pkg/auth"
"github.com/stackrox/rox/pkg/auth/authproviders/idputil"
"github.com/stackrox/rox/pkg/auth/tokens"
"github.com/stackrox/rox/pkg/errox"
Expand Down Expand Up @@ -279,10 +280,10 @@ func (r *registryImpl) providersHTTPHandler(w http.ResponseWriter, req *http.Req
r.error(w, err, typ, clientState, testMode)
return
}

userRoles := userInfo.GetRoles()
if len(userRoles) == 0 {
err := errox.GenericNoValidRole()
r.error(w, err, typ, clientState, testMode)
r.error(w, auth.ErrNoValidRole, typ, clientState, testMode)
return
}

Expand Down
6 changes: 2 additions & 4 deletions pkg/auth/authproviders/registry_httphandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import (

pkgErrors "github.com/pkg/errors"
"github.com/stackrox/rox/generated/storage"
"github.com/stackrox/rox/pkg/auth"
"github.com/stackrox/rox/pkg/auth/authproviders/idputil"
perm "github.com/stackrox/rox/pkg/auth/permissions"
"github.com/stackrox/rox/pkg/auth/tokens"
"github.com/stackrox/rox/pkg/errox"
"github.com/stackrox/rox/pkg/grpc/requestinfo"
"github.com/stackrox/rox/pkg/testutils/roletest"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -238,9 +238,7 @@ func (s *registryProviderCallbackTestSuite) TestAuthenticationRejectsUserWithout
redirectURLFragments, _ := url.ParseQuery(redirectURL.Fragment)
s.assert.Equal(s.registry.redirectURL, redirectURL.Path, "callback activated for user without role "+
"should redirect to the registry redirect URL")
callbackError := fmt.Errorf("access for this user is not authorized: %w, please contact your system administrator",
errox.NoValidRole)
s.assert.Equal(callbackError.Error(), redirectURLFragments.Get("error"),
s.assert.Equal(auth.ErrNoValidRole.Error(), redirectURLFragments.Get("error"),
"callback activated for user without role should issue an explicit message")
}

Expand Down
11 changes: 11 additions & 0 deletions pkg/auth/error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package auth

import "github.com/stackrox/rox/pkg/errox"

var (
// ErrNoValidRole indicates that though user credentials have been
// provided, they do not specify a valid role. This usually happens because
// of misconfigured access control. The effect is similar to NoCredentials.
ErrNoValidRole = errox.NoCredentials.New("access for this user is not authorized: no valid role," +
" please contact your system administrator")
)
11 changes: 0 additions & 11 deletions pkg/errox/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ var (
// been provided. The request can not be processed.
NoCredentials = makeSentinel("credentials not found")

// NoValidRole indicates that though user credentials have been provided,
// they do not specify a valid role. This usually happens because of
// misconfigured access control. The effect is similar to NoCredentials.
NoValidRole = makeSentinel("no valid role")

// NotAuthorized indicates that valid credentials have been provided but are
// insufficient for processing the request.
NotAuthorized = makeSentinel("not authorized")
Expand All @@ -46,9 +41,3 @@ var (

// When adding a new error please update the translators in this package (gRPC, etc.).
)

// GenericNoValidRole wraps NoValidRole with a generic error message.
func GenericNoValidRole() error {
return NoValidRole.New("access for this user is not authorized: no valid role," +
" please contact your system administrator")
}
2 changes: 0 additions & 2 deletions pkg/errox/grpc/mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ func RoxErrorToGRPCCode(err error) codes.Code {
return codes.Internal
case errors.Is(err, errox.NoCredentials):
return codes.Unauthenticated
case errors.Is(err, errox.NoValidRole):
return codes.Unauthenticated
case errors.Is(err, errox.NotAuthorized):
return codes.PermissionDenied
case errors.Is(err, errox.NoAuthzConfigured):
Expand Down
3 changes: 2 additions & 1 deletion pkg/grpc/authn/interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"

"github.com/stackrox/rox/pkg/auth"
"github.com/stackrox/rox/pkg/contextutil"
"github.com/stackrox/rox/pkg/errox"
"github.com/stackrox/rox/pkg/grpc/requestinfo"
Expand Down Expand Up @@ -33,7 +34,7 @@ func (u contextUpdater) updateContext(ctx context.Context) (context.Context, err
if id != nil {
// Only service identities can have no roles assigned.
if len(id.Roles()) == 0 && id.Service() == nil {
return context.WithValue(ctx, identityErrorContextKey{}, errox.GenericNoValidRole()), nil
return context.WithValue(ctx, identityErrorContextKey{}, auth.ErrNoValidRole), nil
}
return context.WithValue(ctx, identityContextKey{}, id), nil
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/grpc/authz/user/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"

"github.com/stackrox/rox/pkg/auth"
"github.com/stackrox/rox/pkg/auth/permissions/utils"
"github.com/stackrox/rox/pkg/errox"
"github.com/stackrox/rox/pkg/grpc/authn"
Expand All @@ -30,7 +31,7 @@ func (p *roleChecker) Authorized(ctx context.Context, _ string) error {

func (p *roleChecker) checkRole(roleNames []string) error {
if len(roleNames) == 0 {
return errox.NoValidRole
return auth.ErrNoValidRole
}

for _, roleName := range roleNames {
Expand Down