Skip to content

fix(security): add explicit permissions to sweeper workflow - #63

Merged
pranav-new-relic merged 1 commit into
masterfrom
fix/codeql-NR-560180-workflow-permissions
Aug 11, 2026
Merged

fix(security): add explicit permissions to sweeper workflow#63
pranav-new-relic merged 1 commit into
masterfrom
fix/codeql-NR-560180-workflow-permissions

Conversation

@pranav-new-relic

@pranav-new-relic pranav-new-relic commented Aug 11, 2026

Copy link
Copy Markdown
Member

What and Why

Fixes CodeQL alert #1 (actions/missing-workflow-permissions), tracked in NR-560180.

Change

Added permissions: contents: read at the workflow level in .github/workflows/sweeper.yml.

Why it matters: Without an explicit permissions: block, GitHub Actions gives the GITHUB_TOKEN broad default write-access to the repository. This means if any step or dependency in the workflow were ever compromised, it could push code, create releases, or delete branches.

The sweeper workflow only needs two things:

  • actions/checkout to clone the code — requires contents: read
  • The sweep script calls external New Relic APIs using repository secrets (NEW_RELIC_API_KEY etc.) — these are passed directly as environment variables and don't use the GITHUB_TOKEN at all

So contents: read is the minimum correct permission.

Testing

The permissions: block is additive-only — it restricts what the token can do but doesn't affect how the workflow runs. The sweep itself will continue to execute identically.

🤖 Generated with Claude Code

Adds 'permissions: contents: read' to sweeper.yml. Without an explicit
permissions block, GITHUB_TOKEN inherits broad default write-access.
This workflow only reads code (actions/checkout) and calls external
New Relic APIs via secrets — contents: read is the minimum required.
# Everyday at 13:00 UTC (06:00 PST)
- cron: "0 13 * * *"

permissions:

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Why add permissions: contents: read?

By default, a GitHub Actions workflow run's GITHUB_TOKEN gets broad write-access to the repository (push branches, create releases, open issues). This is convenient but violates the principle of least privilege — code should only have the access it actually needs.

This workflow does two things:

  1. Checks out the code with actions/checkout → needs contents: read
  2. Runs the sweep script, which calls New Relic APIs using repository secrets (the NEW_RELIC_API_KEY etc. env vars) — the GITHUB_TOKEN is never involved here

So contents: read is the minimum correct permission. If a supply-chain attack ever compromised actions/setup-go or actions/checkout, the attacker's access would be limited to reading files rather than pushing malicious code back to the repo.

Fixes: https://github.com/newrelic/observability-as-code/security/code-scanning/1

@pranav-new-relic
pranav-new-relic merged commit 352d3e1 into master Aug 11, 2026
6 checks passed
@pranav-new-relic
pranav-new-relic deleted the fix/codeql-NR-560180-workflow-permissions branch August 11, 2026 06:17
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.

2 participants