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

OnCall plugin use service accounts instead of api keys #2385

Merged
merged 3 commits into from
Jun 29, 2023

Conversation

mderynck
Copy link
Contributor

@mderynck mderynck commented Jun 28, 2023

What this PR does

Changes OnCall plugin to use service accounts and api tokens instead of api keys. API keys will continue to work but if the plugin ever replaces them it will use a service account instead. Previously this was thought to be unnecessary but it was missing the case where the API key was converted to a service account which it could no longer find when searching the /api/auth/keys endpoint. That key would not be deleted and it would conflict with a newly created one of the same name.

Now the behaviour is as follows:

  1. Anytime a new token is needed all API keys and tokens under the service account matching the defined names will be deleted
  2. A service account will be created named sa-autogen-OnCall if one does not already exist
  3. An api token will be created under that service account named OnCall

Which issue(s) this PR fixes

#1806

Checklist

  • Unit, integration, and e2e (if applicable) tests updated
  • Documentation added (or pr:no public docs PR label added if not required)
  • CHANGELOG.md updated (or pr:no changelog PR label added if not required)

@mderynck mderynck added the pr:no public docs Added to a PR that does not require public documentation updates label Jun 28, 2023
@mderynck mderynck requested a review from joeyorlando June 28, 2023 17:13
@mderynck mderynck marked this pull request as ready for review June 28, 2023 23:25
@mderynck mderynck requested a review from a team June 28, 2023 23:25
@mderynck mderynck enabled auto-merge June 28, 2023 23:32
@mderynck mderynck disabled auto-merge June 28, 2023 23:34
@joeyorlando joeyorlando linked an issue Jun 29, 2023 that may be closed by this pull request
@Konstantinov-Innokentii
Copy link
Member

@mderynck will this changes work with older grafana versions ( for example OSS) with no service accounts?

@joeyorlando
Copy link
Contributor

joeyorlando commented Jun 29, 2023

@Konstantinov-Innokentii w/ this PR it might be worthwhile bumping our minimum required grafana version in grafana-plugin/src/plugin.json. API keys are slated to be deprecated in the "near future":

Screenshot 2023-06-29 at 10 07 43

Copy link
Contributor

Choose a reason for hiding this comment

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

nit PluginState.getGrafanaToken is called in the PluginState.syncDataWithOnCall method, there's a small comment there mentioning "API keys", we might to remove/update that comment

@joeyorlando joeyorlando merged commit 5b00956 into dev Jun 29, 2023
@joeyorlando joeyorlando deleted the mderynck/oncall-plugin-use-service-accounts branch June 29, 2023 11:37
brojd pushed a commit that referenced this pull request Sep 18, 2024
# What this PR does
Changes OnCall plugin to use service accounts and api tokens instead of
api keys. API keys will continue to work but if the plugin ever replaces
them it will use a service account instead. Previously this was thought
to be unnecessary but it was missing the case where the API key was
converted to a service account which it could no longer find when
searching the `/api/auth/keys` endpoint. That key would not be deleted
and it would conflict with a newly created one of the same name.

Now the behaviour is as follows: 
1. Anytime a new token is needed all API keys and tokens under the
service account matching the defined names will be deleted
2. A service account will be created named `sa-autogen-OnCall` if one
does not already exist
3. An api token will be created under that service account named
`OnCall`

## Which issue(s) this PR fixes
#1806 

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not
required)

---------

Co-authored-by: Joey Orlando <joey.orlando@grafana.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr:no public docs Added to a PR that does not require public documentation updates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Transition OnCall plugin to use Grafana service account
3 participants