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

Auth: Lock down Grafana admin role updates if the role is externally synced #72677

Merged
merged 8 commits into from Aug 1, 2023

Conversation

IevaVasiljeva
Copy link
Contributor

What is this feature?

Roles should either be manually updated or externally synced. If they are externally synced, we lock manual role updates.

Why do we need this feature?

For clearer and more secure role management.

Who is this feature for?

Anyone who uses external auth providers to sync user's roles.

Special notes for your reviewer:

Please check that:

  • It works as expected from a user's perspective.
  • If this is a pre-GA feature, it is behind a feature toggle.
  • The docs are updated, and if this is a notable improvement, it's added to our What's New doc.

@grafana-delivery-bot
Copy link
Contributor

Hello @IevaVasiljeva!
Backport pull requests need to be either:

  • Pull requests which address bugs,
  • Urgent fixes which need product approval, in order to get merged,
  • Docs changes.

Please, if the current pull request addresses a bug fix, label it with the type/bug label.
If it already has the product approval, please add the product-approved label. For docs changes, please add the type/docs label.
If the pull request modifies CI behaviour, please add the type/ci label.
If none of the above applies, please consider removing the backport label and target the next major/minor release.
Thanks!

return cfg.JWTAuthAllowAssignGrafanaAdmin
default:
return oAuthAndAllowAssignGrafanaAdmin
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

question: am I correct in assuming that Grafana Admin role can only be synced for JWT and OAuth providers?

I'm also not keen on the variable naming here, but couldn't come up with anything better.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think only JWT, OAuth and LDAP

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the heads up about LDAP, I had missed that one.

@IevaVasiljeva IevaVasiljeva changed the title Auth: lock down Grafana admin role updates if the role is externally synced Auth: Lock down Grafana admin role updates if the role is externally synced Aug 1, 2023
Comment on lines +172 to +175
oAuthAndAllowAssignGrafanaAdmin := false
if oauthInfo := hs.SocialService.GetOAuthInfoProvider(strings.TrimPrefix(authInfo.AuthModule, "oauth_")); oauthInfo != nil {
oAuthAndAllowAssignGrafanaAdmin = oauthInfo.AllowAssignGrafanaAdmin
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

note: annoyingly, I couldn't pass in the whole oauthInfo or SocialService, as that creates a circular dependency.

@IevaVasiljeva IevaVasiljeva merged commit d3b481d into main Aug 1, 2023
13 checks passed
@IevaVasiljeva IevaVasiljeva deleted the lock-down-server-admin-updates branch August 1, 2023 15:39
@grafana-delivery-bot
Copy link
Contributor

The backport to v10.1.x failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new branch
git switch --create backport-72677-to-v10.1.x origin/v10.1.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x d3b481dac87aaeae26195bbedfd80ed33a1cebed
# When the conflicts are resolved, stage and commit the changes
git add . && git cherry-pick --continue

If you have the GitHub CLI installed:

# Create the PR body template
PR_BODY=$(gh pr view 72677 --json body --template 'Backport d3b481dac87aaeae26195bbedfd80ed33a1cebed from #72677{{ "\n\n---\n\n" }}{{ index . "body" }}')
# Push the branch to GitHub and a PR
echo "${PR_BODY}" | gh pr create --title "[v10.1.x] Auth: Lock down Grafana admin role updates if the role is externally synced" --body-file - --label "type/bug" --label "area/backend" --label "area/frontend" --label "add to changelog" --label "backport" --base v10.1.x --milestone 10.1.x --web

Or, if you don't have the GitHub CLI installed (we recommend you install it!):

# If you don't have the GitHub CLI installed: Push the branch to GitHub and manually create a PR:
git push --set-upstream origin backport-72677-to-v10.1.x
# Remove the local backport branch
git switch main
git branch -D backport-72677-to-v10.1.x

Unless you've used the GitHub CLI above, now create a pull request where the base branch is v10.1.x and the compare/head branch is backport-72677-to-v10.1.x.

@grafana-delivery-bot grafana-delivery-bot bot added the backport-failed Failed to generate backport PR. Please resolve conflicts and create one manually. label Aug 1, 2023
sarahzinger pushed a commit that referenced this pull request Aug 1, 2023
…synced (#72677)

* lock down server admin role updates on the frontend if the user is externally synced

* add tests

* lock Grafana Server admin role updates from the backend

* rename variables

* check that the user has auth info

* add LDAP to providers for which Grafana Server admin role can be synced

* linting
chauchausoup pushed a commit to chauchausoup/grafana that referenced this pull request Sep 15, 2023
…synced (grafana#72677)

* lock down server admin role updates on the frontend if the user is externally synced

* add tests

* lock Grafana Server admin role updates from the backend

* rename variables

* check that the user has auth info

* add LDAP to providers for which Grafana Server admin role can be synced

* linting
@zerok zerok modified the milestones: 10.2.x, 10.2.0 Oct 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
add to changelog area/backend area/frontend backport v10.1.x backport-failed Failed to generate backport PR. Please resolve conflicts and create one manually. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants