Skip to content

Security: Make grafana org users to be able to publish grafana/prometheus package - #209

Open
itsmylife wants to merge 10 commits into
mainfrom
ismail/npm-release-permission-level-update
Open

Security: Make grafana org users to be able to publish grafana/prometheus package#209
itsmylife wants to merge 10 commits into
mainfrom
ismail/npm-release-permission-level-update

Conversation

@itsmylife

@itsmylife itsmylife commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Allow repository users with write or admin access to run the npm publish workflow.
  • Add a separate pre-publish permission gate that checks both original and rerun actors.
  • Split build, publish, and dry-run paths so OIDC/npm publishing permissions are only used for real publishes.

if [[ "$PERMISSION" != "admin" ]]; then
echo "::error::Only repository admins can run this workflow. Your permission level: ${PERMISSION}"
exit 1
check_permission() {

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.

this broadens the set of accounts that can publish to npm.

is the tradeoff that we reduce the use of admin accounts?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes. Less admins we have less issues potentially we might get. We can make the whole group as admin but I don't think it's a good idea. Or maybe that should be the idea we'd follow. I'm open suggestions.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

For instance github-datasource as all group members as admin https://github.com/grafana/github-datasource/settings/access

@itsmylife
itsmylife marked this pull request as ready for review July 4, 2026 13:45
@itsmylife
itsmylife requested a review from a team as a code owner July 4, 2026 13:45
local permission
permission=$(gh api "repos/${REPO}/collaborators/${actor}/permission" --jq '.permission')

if [[ "$permission" != "admin" && "$permission" != "write" ]]; then

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.

Both dispatching a workflow_dispatch run and re-running a workflow already require write access to the repo, so after the admin-to-write downgrade this gate no longer excludes anyone who could reach it. If a stronger control than GitHub's built-in write requirement is wanted, it might be worth putting required reviewers or a deployment policy on the npm-publish environment instead, since that is enforced at the job that actually holds the OIDC token.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good points and those are already in place.


check_permission "$ACTOR"
if [[ "$TRIGGERING_ACTOR" != "$ACTOR" ]]; then
check_permission "$TRIGGERING_ACTOR"

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.

Consider noting that this only covers reruns of the whole workflow. If someone re-runs just the failed publish job, this job does not re-execute, so the new triggering_actor is never checked and only GitHub's write requirement for reruns covers that path.

# Prevent overlapping publish runs from racing on the same package version.
concurrency:
group: npm-publish-grafana-prometheus
cancel-in-progress: false

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.

nit: even with cancel-in-progress: false, GitHub keeps only the newest pending run in a concurrency group, so if two releases are dispatched while one is publishing, the older queued run is silently cancelled. Probably acceptable here, but worth knowing when releases are dispatched in quick succession.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

in general there will be one person releasing the packages so I think it's fine to keep it.

publish:
name: Publish @grafana/prometheus
needs: build
if: needs.build.outputs.changed == 'true' && inputs['dry-run'] != true

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.

nit: the changed == 'true' half is already enforced by the "Abort if version not newer" step failing the build job, so this is defence in depth rather than load-bearing. Fine to keep, just flagging it so a future reader does not assume it is the only guard.

Comment thread .github/workflows/release-npm.yml
@adamyeats adamyeats self-assigned this Jul 10, 2026
@itsmylife
itsmylife requested review from adamyeats and beejeebus July 13, 2026 13:22
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.

4 participants