Skip to content

feat: accept a private key as the client secret in snyk auth - #7441

Open
nick-y-snyk wants to merge 3 commits into
mainfrom
feat/CLI-2022_auth-private-key-assertion
Open

nick-y-snyk wants to merge 3 commits into
mainfrom
feat/CLI-2022_auth-private-key-assertion

Conversation

@nick-y-snyk

@nick-y-snyk nick-y-snyk commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Pull Request Submission Checklist

  • Follows CONTRIBUTING guidelines
  • Commit messages
    are release-note ready, emphasizing
    what was changed, not how.
  • Includes detailed description of changes
  • Contains risk assessment (Low | Medium | High)
  • Highlights breaking API changes (if applicable)
  • Links to automated tests covering new functionality
  • Includes manual testing instructions (if necessary)
  • Updates relevant GitBook documentation (PR link: ___)
  • Includes product update to be announced in the next stable release notes

What does this PR do?

snyk auth --client-id=<id> --client-secret="<PKCS#8 PEM>" logs in with the OAuth client credentials grant and a private_key_jwt client assertion (RFC 7523). The CLI stores the key and the minted token, so later commands work without the flags and mint a new token from the key when it expires. Other secrets are still sent as a shared secret. A rejected key exits with code 2 and keeps the existing login.

The logic is in snyk/go-application-framework#854. This PR pins GAF to that branch (d2f8720), which also brings in GAF v0.36.0. It stays a draft until #854 merges and the pin moves to a release.

Where should the reviewer start?

GAF #854, then test/jest/acceptance/auth.spec.ts.

How should this be manually tested?

On an instance with machine clients enabled:

  1. snyk auth --client-id=<machine client id> --client-secret="$(cat key.pem)"
  2. snyk whoami --experimental with no flags succeeds.

What's the product update that needs to be communicated to CLI users?

snyk auth accepts an unencrypted PKCS#8 RSA or P-256 private key as --client-secret.

Risk assessment (Low | Medium | High)?

Medium. Only PEM secrets take the new path, but the GAF bump includes v0.36.0.

Done: auth.spec.ts 12/12 on a public build; eslint, prettier, golangci clean; snyk-axi test sca 0 issues.
Pending: CI, GitBook docs.

What are the relevant tickets?

CLI-2022


Note

Medium Risk
Authentication and credential storage change via a multi-minor GAF bump; only PEM-shaped secrets take the new path, but the framework upgrade may affect other CLI behavior.

Overview
Bumps go-application-framework from v0.35.1 to v0.38.0 in cliv2 and cliv2-private so snyk auth --client-id=… --client-secret=<PEM> can use OAuth client credentials with a private_key_jwt assertion (RFC 7523). Shared-secret --client-secret behavior is unchanged.

Acceptance coverage adds auth.spec.ts scenarios that generate an RSA key, assert the CLI posts client_assertion_type=jwt-bearer to /oauth2/token, checks INTERNAL_MACHINE_IDENTITY_STORAGE / INTERNAL_OAUTH_TOKEN_STORAGE, and verifies later API calls use Bearer vs legacy token when auth fails. fake-server.ts simulates the JWT client-credentials grant (issuer check only), rejects wrong token auth on /authorization/*, and the suite uses a stable fake API token name.

Reviewed by Cursor Bugbot for commit 6bd39dd. Bugbot is set up for automated code reviews on this repo. Configure here.

@snyk-io

snyk-io Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues
✅ Code Security 0 0 0 0 0 issues
✅ Secrets 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@nick-y-snyk
nick-y-snyk force-pushed the feat/CLI-2022_auth-private-key-assertion branch from 5db3be9 to dc7a36e Compare October 29, 2026 17:28
@nick-y-snyk
nick-y-snyk marked this pull request as ready for review October 30, 2026 15:08
@nick-y-snyk
nick-y-snyk requested review from a team as code owners October 30, 2026 15:08
@snyk-pr-review-bot

This comment has been minimized.

`snyk auth --client-id=<id> --client-secret="<PKCS#8 PEM>"` now logs in
with the OAuth client credentials grant and a private_key_jwt client
assertion (RFC 7523). The CLI stores the key and the minted token, so
later commands authenticate without the flags and mint a new token from
the key when the old one expires. Any other secret is still sent as a
shared secret.

The behaviour lives in go-application-framework
(snyk/go-application-framework#854). This commit pins GAF to the head
of that branch, which also brings in GAF v0.36.0.

The fake server accepts a client credentials request whose JWT
assertion has an iss equal to the client id. Its authorization endpoint
now rejects an API token it did not issue, as the real API does. The
acceptance tests run the same checks for an accepted and a rejected
key: the exit code, the client assertion sent, what is stored, and the
credential a later `snyk ignore` sends.
@nick-y-snyk
nick-y-snyk force-pushed the feat/CLI-2022_auth-private-key-assertion branch from dc7a36e to 009fd60 Compare October 30, 2026 16:51
@snyk-pr-review-bot

This comment has been minimized.

@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor
Warnings
⚠️ There are multiple commits on your branch, please squash them locally before merging!

Generated by 🚫 dangerJS against 6bd39dd

@snyk-pr-review-bot

This comment has been minimized.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit f374de2. Configure here.

storedAccessToken: undefined,
// With nothing stored the host hands the legacy CLI its placeholder API token.
ignoreCode: 2,
authorization: 'token random',

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Tests inherit process token environment

Medium Severity

The new private-key cases expect Bearer access_token_value after a successful login and token random after a rejected key, but env still spreads process.env. A set SNYK_TOKEN or SNYK_OAUTH_TOKEN overrides the cleared config and the host placeholder, so those header and ignore exit assertions can fail in CI.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit f374de2. Configure here.

@snyk-pr-review-bot

Copy link
Copy Markdown

PR Reviewer Guide 🔍

🧪 PR contains tests
🔒 No security concerns identified
⚡ No major issues detected
📚 Repository Context Analyzed

This review considered 8 relevant code sections from 5 files (average relevance: 1.00)

🤖 Repository instructions applied (from AGENTS.md)

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