-
Notifications
You must be signed in to change notification settings - Fork 937
fix: Fix incorrect gating of ACCESS_TOKEN for template commands #1315
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@e2b/cli': patch | ||
| --- | ||
|
|
||
| Allow template build and create commands to authenticate with either an API key or access token. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,26 @@ | |
| export let accessToken = process.env.E2B_ACCESS_TOKEN | ||
| export const teamId = process.env.E2B_TEAM_ID | ||
|
|
||
| function resolveAPIKey() { | ||
| // If apiKey is not already set (either from env var or from user config), try to get it from config file | ||
| if (!apiKey) { | ||
| const userConfig = getUserConfig() | ||
| apiKey = userConfig?.teamApiKey | ||
| } | ||
|
|
||
| return apiKey | ||
| } | ||
|
|
||
| function resolveAccessToken() { | ||
| // If accessToken is not already set (either from env var or from user config), try to get it from config file | ||
| if (!accessToken) { | ||
| const userConfig = getUserConfig() | ||
| accessToken = userConfig?.accessToken | ||
| } | ||
|
|
||
| return accessToken | ||
| } | ||
|
|
||
| const authErrorBox = (keyName: string) => { | ||
| let link | ||
| let msg | ||
|
|
@@ -45,17 +65,13 @@ | |
| } | ||
|
|
||
| export function ensureAPIKey() { | ||
| // If apiKey is not already set (either from env var or from user config), try to get it from config file | ||
| if (!apiKey) { | ||
| const userConfig = getUserConfig() | ||
| apiKey = userConfig?.teamApiKey | ||
| } | ||
| const resolvedApiKey = resolveAPIKey() | ||
|
|
||
| if (!apiKey) { | ||
| if (!resolvedApiKey) { | ||
| console.error(authErrorBox('E2B_API_KEY')) | ||
| process.exit(1) | ||
| } else { | ||
| return apiKey | ||
| return resolvedApiKey | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -69,20 +85,28 @@ | |
| } | ||
|
|
||
| export function ensureAccessToken() { | ||
| // If accessToken is not already set (either from env var or from user config), try to get it from config file | ||
| if (!accessToken) { | ||
| const userConfig = getUserConfig() | ||
| accessToken = userConfig?.accessToken | ||
| } | ||
| const resolvedAccessToken = resolveAccessToken() | ||
|
|
||
| if (!accessToken) { | ||
| if (!resolvedAccessToken) { | ||
| console.error(authErrorBox('E2B_ACCESS_TOKEN')) | ||
| process.exit(1) | ||
| } else { | ||
| return accessToken | ||
| return resolvedAccessToken | ||
| } | ||
| } | ||
|
|
||
| export function ensureAPIKeyOrAccessToken() { | ||
| const resolvedApiKey = resolveAPIKey() | ||
| const resolvedAccessToken = resolveAccessToken() | ||
|
|
||
| if (resolvedApiKey || resolvedAccessToken) { | ||
| return { apiKey: resolvedApiKey, accessToken: resolvedAccessToken } | ||
| } | ||
|
|
||
| console.error(authErrorBox('E2B_API_KEY')) | ||
| process.exit(1) | ||
| } | ||
|
|
||
|
Check warning on line 109 in packages/cli/src/api.ts
|
||
|
Comment on lines
+98
to
109
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 When neither Extended reasoning...What the bug isIn
So a user who normally authenticates with Why the existing code doesn't prevent it
Step-by-step proof
ImpactPurely a UX/diagnostic issue, not a functional break. The first line of the error ("Run How to fixAdd a combined branch to |
||
| /** | ||
| * Resolve team ID with proper precedence: | ||
| * 1. CLI --team flag | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,7 @@ | |
| import { | ||
| client, | ||
| connectionConfig, | ||
| ensureAccessToken, | ||
| ensureAPIKeyOrAccessToken, | ||
| resolveTeamId, | ||
| } from 'src/api' | ||
| import { configName, getConfigPath, loadConfig, saveConfig } from 'src/config' | ||
|
|
@@ -246,7 +246,8 @@ | |
| }) | ||
| } | ||
|
|
||
| const accessToken = ensureAccessToken() | ||
| const credentials = ensureAPIKeyOrAccessToken() | ||
| const dockerAuthToken = credentials.accessToken ?? credentials.apiKey! | ||
| process.stdout.write('\n') | ||
|
|
||
| const newName = opts.name?.trim() | ||
|
|
@@ -374,13 +375,13 @@ | |
| true | ||
| ) | ||
|
|
||
| if (imageUriMask == undefined) { | ||
| try { | ||
| child_process.execSync( | ||
| `echo "${accessToken}" | docker login docker.${connectionConfig.domain} -u _e2b_access_token --password-stdin`, | ||
| `echo "${dockerAuthToken}" | docker login docker.${connectionConfig.domain} -u _e2b_access_token --password-stdin`, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔒 Agentic Security Review Impact: Team-scoped API credentials can leak to other local processes/users, enabling unauthorized access to protected template and registry operations.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is supported by docker reverse proxy |
||
| { | ||
| stdio: 'inherit', | ||
| cwd: root, | ||
|
Check failure on line 384 in packages/cli/src/commands/template/build.ts
|
||
|
Comment on lines
378
to
384
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 After this PR, Extended reasoning...What changed Before this PR, const credentials = ensureAPIKeyOrAccessToken()
const dockerAuthToken = credentials.accessToken ?? credentials.apiKey!So
Why this is worth flagging The whole point of the PR (per the changeset and the README diff) is to let users run Step-by-step proof of the new code path
Addressing the refutation A refuting verifier argued that |
||
| } | ||
| ) | ||
| } catch (err: any) { | ||
|
|
@@ -449,7 +450,7 @@ | |
| await buildWithProxy( | ||
| userConfig, | ||
| connectionConfig, | ||
| accessToken, | ||
| dockerAuthToken, | ||
| template, | ||
| root | ||
| ) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
E2B_API_KEYis set on a machine that also has a saved~/.e2b/config.json, this still callsresolveAccessToken(), loads the saved access token, and returns both credentials. Callers such astemplate buildthen preferaccessTokenfor Docker auth, whiletemplate createsends both headers, so a stale or wrong local token can override the explicit API key and make the new API-key-only path fail or use the wrong account. Stop resolving the fallback token once an API key has been chosen, or otherwise preserve a single credential source.Useful? React with 👍 / 👎.