Skip to content

ROX-10304: Remove NoValidRole error sentinel#1409

Merged
mtodor merged 28 commits intomasterfrom
mtodor/ROX-10304-remove-generic-no-valid-role-error
Apr 28, 2022
Merged

ROX-10304: Remove NoValidRole error sentinel#1409
mtodor merged 28 commits intomasterfrom
mtodor/ROX-10304-remove-generic-no-valid-role-error

Conversation

@mtodor
Copy link
Copy Markdown
Contributor

@mtodor mtodor commented Apr 25, 2022

Description

Removed GenericNoValidRole error. We have added new Error sentinel in pkg/auth/role.

Note: This PR is based on mtodor/ROX-10303-replace-new-error-wrappers branch. After PR #1389 is merged, we will change the base branch.

Checklist

  • Investigated and inspected CI test results
  • [ ] Unit test and regression tests added - nothing is added
  • [ ] Evaluated and added CHANGELOG entry if required - not relevant
  • [ ] Determined and documented upgrade steps - nothing relevant for upgrade steps
  • [ ] Documented user facing changes (create PR based on stackrox/openshift-docs and merge into rhacs-docs) - no user-facing changes

Testing Performed

1. Compare in UI - No change - no change
Screenshot 2022-04-25 at 12 01 28

2. REST request with token without Role - no change

{"error":"access for this user is not authorized: no valid role, please contact your system administrator","code":16,"message":"access for this user is not authorized: no valid role, please contact your system administrator","details":[]}

3. Request with not Admin role: - no change

❯ ./bin/darwin/roxctl --insecure-skip-tls-verify --insecure --endpoint https://localhost:8000 --token-file ./token.txt  central backup
ERROR:  Invalid credentials. Please add/fix your credentials

❯ ./bin/darwin/roxctl --insecure-skip-tls-verify --insecure --endpoint https://localhost:8000 --token-file ./token.txt  central debug log
ERROR:	could not get log level from central: rpc error: code = Unauthenticated desc = access for this user is not authorized: no valid role, please contact your system administrator

Additionally, default checks are also done:

  • make image works
  • make style works so that the linting of all go files is correct

@ghost
Copy link
Copy Markdown

ghost commented Apr 25, 2022

Tag for build #486192 is 3.69.x-556-g91bf9b4558.

💻 For deploying this image using the dev scripts, run the following first:

export MAIN_IMAGE_TAG='3.69.x-556-g91bf9b4558'

🕹️ A roxctl binary can be downloaded from the CircleCI artifacts.

@mtodor mtodor marked this pull request as ready for review April 25, 2022 16:26
@mtodor mtodor requested a review from a team as a code owner April 25, 2022 16:26
@mtodor mtodor requested review from parametalol and rukletsov April 25, 2022 16:26
// 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{}, errox.NotAuthorized.CausedBy("no valid role")), nil
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return context.WithValue(ctx, identityErrorContextKey{}, errox.NotAuthorized.CausedBy("no valid role")), nil
return context.WithValue(ctx, identityErrorContextKey{}, errox.NotAuthorized.CausedBy("only service identities can have no roles assigned")), nil

func (p *roleChecker) checkRole(roleNames []string) error {
if len(roleNames) == 0 {
return errox.NoValidRole
return errox.NotAuthorized
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about adding more context here e.g.

Suggested change
return errox.NotAuthorized
return errox.NotAuthorized.CausedBy("no roles assigned to the user"))

userRoles := userInfo.GetRoles()
if len(userRoles) == 0 {
err := errox.GenericNoValidRole()
err := errox.NotAuthorized.CausedBy("no valid role for the user")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about adding explicit information about missing roles. no valid role sounds like there are some roles but not valid for this situation

Suggested change
err := errox.NotAuthorized.CausedBy("no valid role for the user")
err := errox.NotAuthorized.CausedBy(fmt.Sprintf("%s has no roles", userInfo.GetFriendlyName()))

Copy link
Copy Markdown
Member

@rukletsov rukletsov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe 401 is the right choice of error here, see https://issues.redhat.com/browse/ROX-8092 including comments. cc @rhybrillou

I'd suggest to introduce a new sentinel error in pkg/grpc/auth, maybe in none.go or in a new file, that will replace both NoValidRole and GenericNoValidRole(), e.g.

ErrNoValidRole := errox.NoCredentials.New("access for this user is not authorized: no valid role," +
    " please contact your system administrator")

@mtodor mtodor changed the base branch from mtodor/ROX-10303-replace-new-error-wrappers to master April 26, 2022 15:15
@mtodor mtodor changed the base branch from master to mtodor/ROX-10303-replace-new-error-wrappers April 26, 2022 15:17
@@ -0,0 +1,11 @@
package role
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe put this file directly into pkg/auth/? This way we avoid having a auth/role package with just an error definition and the call sites look sleeker: auth.ErrNoValidRole.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

@md2119 md2119 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes are fine, but is there an easy way for developers to look for sentinal values, especially if they are scattered in different pkgs?

@gitguardian
Copy link
Copy Markdown

gitguardian bot commented Apr 27, 2022

⚠️ GitGuardian has uncovered 2 secrets following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secrets in your pull request
GitGuardian id Secret Commit Filename
3038029 Generic High Entropy Secret 138264d qa-tests-backend/src/main/groovy/services/NotifierService.groovy View secret
3038029 Generic High Entropy Secret c751bce qa-tests-backend/src/main/groovy/services/NotifierService.groovy View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secrets safely. Learn here the best practices.
  3. Revoke and rotate these secrets.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

Our GitHub checks need improvements? Share your feedbacks!

@mtodor mtodor requested a review from rukletsov April 27, 2022 09:15
@rukletsov
Copy link
Copy Markdown
Member

The changes are fine, but is there an easy way for developers to look for sentinal values, especially if they are scattered in different pkgs?

For global sentinels — for sure, but you already know that : ). For package-level sentinels, we can say that those changing or using a package shall be able to discover errors defined in that package but I think your comment is valid. Maybe we can have a gentlemen's agreement (and a linter) that all package sentinels must be defined in errors.go file in that package?

Base automatically changed from mtodor/ROX-10303-replace-new-error-wrappers to master April 28, 2022 08:12
@mtodor mtodor merged commit 27e775a into master Apr 28, 2022
@mtodor mtodor deleted the mtodor/ROX-10304-remove-generic-no-valid-role-error branch April 28, 2022 10:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants