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

server: Return permission error if one occurs for Events endpoint #72416

Merged
merged 1 commit into from
Nov 4, 2021
Merged

server: Return permission error if one occurs for Events endpoint #72416

merged 1 commit into from
Nov 4, 2021

Conversation

nathanstilwell
Copy link
Contributor

Events in DB Console (/#/events) would show an internal server error
to the user if they did not have admin permissions to view events. The
error logged in the server is indeed a permissions error, but this is
confusing to the user. To accurately show a permission error on the
FrontEnd, I added an AND statement to the Events endpoint to only return
a server error if an error exists and is not a permission error.

Release note (ui change): Node events will now display a permission
error rather than an internal server error when user does not have admin
privileges to view events.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@nathanstilwell nathanstilwell linked an issue Nov 3, 2021 that may be closed by this pull request
Copy link
Collaborator

@dhartunian dhartunian left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r1, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @koorosh and @Santamaura)

Copy link
Collaborator

@koorosh koorosh left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r2, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @nathanstilwell and @Santamaura)


pkg/server/admin.go, line 1222 at r2 (raw file):

	// just do it here.
	defer func() {
		if retErr != nil && error.Is(retErh, errRequiresAdmin) {

Just wondering if we need to handle the same permission error with other endpoints?
If yes, then it might be better to move this extra validation into serverError func.

Copy link
Collaborator

@koorosh koorosh left a comment

Choose a reason for hiding this comment

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

LGTM, only a question to make sure if we need to make this more generic

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @nathanstilwell and @Santamaura)


pkg/server/admin.go, line 1222 at r2 (raw file):

Previously, koorosh (Andrii Vorobiov) wrote…

Just wondering if we need to handle the same permission error with other endpoints?
If yes, then it might be better to move this extra validation into serverError func.

func (s *adminServer) serverError(err error) error {
	log.ErrorfDepth(context.TODO(), 1, "%s", err)
        if error.Is(err, errRequiresAdmin {
                return err
        }
	return errAdminAPIError
}

@nathanstilwell
Copy link
Contributor Author


pkg/server/admin.go, line 1222 at r2 (raw file):

Previously, koorosh (Andrii Vorobiov) wrote…
func (s *adminServer) serverError(err error) error {
	log.ErrorfDepth(context.TODO(), 1, "%s", err)
        if error.Is(err, errRequiresAdmin {
                return err
        }
	return errAdminAPIError
}

David and I talked about that, but serverError is used in so many places I fear unintended consequences. If we find ourselves doing this in more places that might be something we consider in the future.

Copy link
Collaborator

@koorosh koorosh left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @Santamaura)


pkg/server/admin.go, line 1222 at r2 (raw file):

Previously, nathanstilwell (Nathan Stilwell) wrote…

David and I talked about that, but serverError is used in so many places I fear unintended consequences. If we find ourselves doing this in more places that might be something we consider in the future.

Got it!

@nathanstilwell
Copy link
Contributor Author


pkg/server/admin.go, line 1222 at r2 (raw file):

Previously, koorosh (Andrii Vorobiov) wrote…

Got it!

Good call out though. I'm glad we all had the same thought. 😄

Events in DB Console (`/#/events`) would show an internal server error
to the user if they did not have admin permissions to view events. The
error logged in the server is indeed a permissions error, but this is
confusing to the user. To accurately show a permission error on the
FrontEnd, I added an AND statment to the Events endpoint to only return
a server error if an error exists and is not a permission error.

Release note (ui change): Node events will now display a permission
error rather than an internal server error when user does not have admin
priviledges to view events.
@nathanstilwell
Copy link
Contributor Author

bors r+

@craig
Copy link
Contributor

craig bot commented Nov 4, 2021

Build succeeded:

@blathers-crl
Copy link

blathers-crl bot commented Nov 4, 2021

Encountered an error creating backports. Some common things that can go wrong:

  1. The backport branch might have already existed.
  2. There was a merge conflict.
  3. The backport branch contained merge commits.

You might need to create your backport manually using the backport tool.


error creating merge commit from f085778 to blathers/backport-release-20.2-72416: POST https://api.github.com/repos/cockroachdb/cockroach/merges: 409 Merge conflict []

you may need to manually resolve merge conflicts with the backport tool.

Backport to branch 20.2.x failed. See errors above.


🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan.

@dhartunian
Copy link
Collaborator

blathers backport 21.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ui: DB Console metric panels do not load for non-admins
4 participants