Repository navigation
feat: accept a private key as the client secret in snyk auth - #7441
nick-y-snyk wants to merge 3 commits into
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
5db3be9 to
dc7a36e
Compare
This comment has been minimized.
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.
dc7a36e to
009fd60
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ 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', |
There was a problem hiding this comment.
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)
Reviewed by Cursor Bugbot for commit f374de2. Configure here.
PR Reviewer Guide 🔍
|


Pull Request Submission Checklist
are release-note ready, emphasizing
what was changed, not how.
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:
snyk auth --client-id=<machine client id> --client-secret="$(cat key.pem)"snyk whoami --experimentalwith no flags succeeds.What's the product update that needs to be communicated to CLI users?
snyk authaccepts 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.ts12/12 on a public build; eslint, prettier, golangci clean;snyk-axi test sca0 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-frameworkfrom v0.35.1 to v0.38.0 incliv2andcliv2-privatesosnyk auth --client-id=… --client-secret=<PEM>can use OAuth client credentials with a private_key_jwt assertion (RFC 7523). Shared-secret--client-secretbehavior is unchanged.Acceptance coverage adds
auth.spec.tsscenarios that generate an RSA key, assert the CLI postsclient_assertion_type=jwt-bearerto/oauth2/token, checksINTERNAL_MACHINE_IDENTITY_STORAGE/INTERNAL_OAUTH_TOKEN_STORAGE, and verifies later API calls useBearervs legacytokenwhen auth fails.fake-server.tssimulates the JWT client-credentials grant (issuer check only), rejects wrongtokenauth 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.