Repository navigation
@blaxel/core 0.3.19: forks take their env on the fork request #7151
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,7 @@ | |
| * token — no relay hop, so websockets work and the sandbox can still sleep. | ||
| */ | ||
|
|
||
| import { SandboxInstance, settings, updateSandbox } from "@blaxel/core"; | ||
| import { SandboxInstance, settings } from "@blaxel/core"; | ||
| import { CLOUD_AGENT_LAUNCH_ENV_NAMES } from "@superset/shared/cloud-agent-launch"; | ||
| import { SANDBOX_CREDENTIAL_PLACEHOLDER } from "@superset/shared/constants"; | ||
| import { env } from "../../env"; | ||
|
|
@@ -81,33 +81,16 @@ async function forkSandbox( | |
| workspaceEnv: Record<string, string>, | ||
| ): Promise<SandboxInstance> { | ||
| const source = await SandboxInstance.get(sourceSandbox); | ||
| await source.fork(name); | ||
| const forked = await SandboxInstance.get(name); | ||
|
|
||
| const spec = structuredClone(forked.spec) as { | ||
| runtime?: { envs?: Array<{ name: string; value: string }> }; | ||
| }; | ||
| const inherited = spec.runtime?.envs ?? []; | ||
| const replaced = new Set<string>(); | ||
| const envs = inherited.map((entry) => { | ||
| const override = workspaceEnv[entry.name]; | ||
| if (override === undefined) return entry; | ||
| replaced.add(entry.name); | ||
| return { name: entry.name, value: override }; | ||
| }); | ||
| for (const [key, value] of Object.entries(workspaceEnv)) { | ||
| if (!replaced.has(key)) envs.push({ name: key, value }); | ||
| } | ||
| if (!spec.runtime) spec.runtime = {}; | ||
| spec.runtime.envs = envs; | ||
|
|
||
| await updateSandbox({ | ||
| path: { sandboxName: name }, | ||
| body: { | ||
| ...(forked as never as { sandbox: object }).sandbox, | ||
| spec, | ||
| } as never, | ||
| throwOnError: true, | ||
| // The fork request carries the workspace's env, so no spec update and no | ||
| // restart follow it. The values also ride on the boot script's own exec | ||
| // (see provisionSandbox): a golden whose sandbox runtime predates fork | ||
| // envs hands its children the source's env instead, and the script is | ||
| // what everything the workspace runs descends from. | ||
| await source.fork(name, { | ||
| envs: Object.entries(workspaceEnv).map(([envName, value]) => ({ | ||
| name: envName, | ||
| value, | ||
| })), | ||
| }); | ||
| return await SandboxInstance.get(name); | ||
| } | ||
|
|
@@ -188,10 +171,15 @@ export async function provisionSandbox(args: { | |
| // Start host-service and return — the only thing provisioning runs inside a | ||
| // sandbox, and it is not awaited. The script needs a second or two; the | ||
| // client discovers the result by polling the health endpoint it already | ||
| // polls, so there is nothing to wait for here. | ||
| // polls, so there is nothing to wait for here. A fork gets its env on this | ||
| // exec as well as on the fork request, which covers goldens whose sandbox | ||
| // runtime predates fork envs (docs/cloud-sandbox-mismatches.md). | ||
| await sandbox.process.exec({ | ||
| name: "host-service", | ||
| command: "/app/start.sh", | ||
| ...(args.environment.sourceKind === "fork" | ||
| ? { env: args.workspaceEnv } | ||
| : {}), | ||
| waitForCompletion: false, | ||
| } as never); | ||
|
|
||
|
|
@@ -226,7 +214,13 @@ export async function promoteSandboxToEnvironment(args: { | |
| }): Promise<string> { | ||
| configureBlaxel(); | ||
| const source = await SandboxInstance.get(args.sourceSandbox); | ||
| await source.fork(args.goldenName); | ||
| // A fork inherits the source's env and can only set or add variables, never | ||
| // drop one, so the promoting workspace's identity is blanked on the fork | ||
| // request: every later workspace forked from this environment would | ||
| // otherwise carry the promoter's git token and launch the promoter's agent. | ||
| await source.fork(args.goldenName, { | ||
| envs: [...INHERITED_IDENTITY_ENVS].map((name) => ({ name, value: "" })), | ||
|
Contributor
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. P2: The promote path now blanks identity envs (including the git token) with empty-string values on the fork request instead of removing them from the spec. This is secure only if the fork server actually applies empty-string overrides to inherited values; if it ignores or skips them, the golden keeps the promoter's token and every later workspace inherits it. Confirm empty-value override semantics on a fork, and add a test that a public-repo workspace forked from the promoted golden does not see SUPERSET_SANDBOX_GIT_TOKEN from the promoter. Prompt for AI agents |
||
| }); | ||
|
|
||
| const golden = await SandboxInstance.get(args.goldenName); | ||
|
|
||
|
|
@@ -248,29 +242,6 @@ export async function promoteSandboxToEnvironment(args: { | |
| waitForCompletion: true, | ||
| } as never); | ||
|
|
||
| // Blaxel copies the source's env into the fork and env is immutable after | ||
| // creation, so the promoting workspace's credentials would otherwise ride | ||
| // into a shared environment every later workspace forks from. The git token | ||
| // is the dangerous one: provisioning only sets it when the clone needs it, | ||
| // so a public-repo workspace would inherit the promoter's instead. | ||
| const current = await SandboxInstance.get(args.goldenName); | ||
| const spec = structuredClone(current.spec) as { | ||
| runtime?: { envs?: Array<{ name: string; value: string }> }; | ||
| }; | ||
| if (spec.runtime?.envs) { | ||
| spec.runtime.envs = spec.runtime.envs.filter( | ||
| (entry) => !INHERITED_IDENTITY_ENVS.has(entry.name), | ||
| ); | ||
| await updateSandbox({ | ||
| path: { sandboxName: args.goldenName }, | ||
| body: { | ||
| ...(current as never as { sandbox: object }).sandbox, | ||
| spec, | ||
| } as never, | ||
| throwOnError: true, | ||
| }); | ||
| } | ||
|
|
||
| return args.goldenName; | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.