Secrets
A team secret is a named value the platform keeps for you, such as a registry password, a git token or an API key. Its value never enters a sandbox. The sandbox sends a placeholder. The egress proxy swaps the placeholder for the secret inside the sandbox’s TLS tunnel, and only for the host you bound the secret to.
import os
from svm import Sandbox, Secret
NAME = "DOCS_GITHUB_TOKEN"Secret.create(NAME, os.environ["GITHUB_TOKEN"], "GitHub token for the docs sample")try: print(Secret.exists(NAME)) # True Secret.update(NAME, os.environ["GITHUB_TOKEN_ROTATED"]) # rotate the value for info in Secret.list().items: print(info.name, info.version, info.updated_at)
# The value never enters the sandbox: it holds a placeholder, and the egress # proxy puts the secret in the Authorization header for api.github.com only. with Sandbox.create(template="base", envs={"GH_TOKEN": Secret.fill(NAME)}) as sandbox: sandbox.update_egress(enabled=True, default="deny", rules=[ {"action": "allow", "domain": "api.github.com", "inject": Secret.inject(NAME, ["Authorization"])}, ]) egress = sandbox.egress() # the proxy URL and the CA certificate the guest trusts sandbox.files.write("/tmp/egress-ca.pem", egress["ca_certificate"]) result = sandbox.commands.run( 'curl -s --cacert /tmp/egress-ca.pem -H "Authorization: Bearer $GH_TOKEN" https://api.github.com/user', envs={"HTTPS_PROXY": egress["proxy_url"]}, ) print(result.stdout)finally: Secret.destroy(NAME)import { Sandbox, Secret } from "@svm/sandbox";
const name = "DOCS_API_TOKEN";await Secret.create(name, process.env.MY_API_TOKEN ?? "example-value", { description: "token for api.example.com" });try { console.log(await Secret.exists(name)); // true const rotated = await Secret.update(name, "rotated-value"); console.log(rotated.version); // 2
const page = await Secret.list(); for (const s of page.items) console.log(s.name, s.version);
// The value never enters the sandbox: the egress proxy injects it into requests to the bound host. const sandbox = await Sandbox.create({ template: "base" }); try { await sandbox.updateEgress({ enabled: true, default: "allow", rules: [{ action: "allow", domain: "api.example.com", inject: Secret.inject(name, ["Authorization"]) }], }); // Or put the placeholder in a header yourself; the proxy swaps it for the value. const header = `Authorization: Bearer ${Secret.fill(name)}`; const r = await sandbox.commands.run(`curl -s -H '${header}' https://api.example.com/me`); console.log(r.stdout); } finally { await sandbox.kill(); }} finally { await Secret.destroy(name);}secrets := client.Secrets()const name = "DOCS_API_TOKEN"if _, err := secrets.Create(ctx, name, "first-value", svm.SecretOptions{Description: "docs sample"}); err != nil { return err}defer secrets.Destroy(ctx, name)
exists, err := secrets.Exists(ctx, name)if err != nil { return err}info, err := secrets.Update(ctx, name, "rotated-value", svm.SecretOptions{}) // rotateif err != nil { return err}fmt.Println("exists:", exists, "version:", info.Version)page, err := secrets.List(ctx, svm.ListSecretsOptions{})if err != nil { return err}for _, item := range page.Items { fmt.Println("secret", item.Name)}
// The value never enters the sandbox: it holds a placeholder that the egress proxy swaps for the// secret in HTTPS requests to the hosts an inject rule allows.placeholder, err := svm.SecretFill(name)if err != nil { return err}inject, err := svm.SecretInject(name, []string{"Authorization"}, "")if err != nil { return err}sandbox, err := client.CreateSandbox(ctx, svm.CreateSandboxOptions{ Template: "base", Envs: map[string]string{"API_TOKEN": placeholder},})if err != nil { return err}defer sandbox.Kill(ctx)rules := []svm.EgressRule{{Action: "allow", Domain: "api.example.com", Inject: inject}}if _, err := sandbox.UpdateEgress(ctx, true, "allow", rules); err != nil { return err}commands, err := sandbox.Commands()if err != nil { return err}result, err := commands.Run(ctx, `curl -s -H "Authorization: Bearer $API_TOKEN" https://api.example.com/me`, svm.RunOptions{})if err != nil { return err}fmt.Printf("%s\n", result.Stdout)require "svm"
SVM::Secret.create("GITHUB_TOKEN", ENV.fetch("GITHUB_TOKEN"), description: "CI bot token")box = nilbegin puts SVM::Secret.exists?("GITHUB_TOKEN") # true SVM::Secret.update("GITHUB_TOKEN", ENV.fetch("GITHUB_TOKEN_NEW")) # a new version SVM::Secret.list[:items].each { |s| puts "#{s.name} v#{s.version}" }
# The sandbox only ever sees a placeholder; the egress proxy swaps in the value, # in HTTPS requests to the host the rule allows. box = SVM::Sandbox.create(template: "base", envs: { "GH_TOKEN" => SVM::Secret.fill("GITHUB_TOKEN") }) box.update_egress(enabled: true, default: "deny", rules: [ { action: "allow", domain: "api.github.com", inject: SVM::Secret.inject("GITHUB_TOKEN", ["Authorization"]) } ]) egress = box.egress box.files.write("/tmp/egress-ca.pem", egress["ca_certificate"]) out = box.commands.run('curl -s --cacert /tmp/egress-ca.pem --proxy "$PROXY" ' \ '-H "Authorization: Bearer $GH_TOKEN" https://api.github.com/user', envs: { "PROXY" => egress["proxy_url"] }) puts out.stdoutensure box&.kill SVM::Secret.destroy("GITHUB_TOKEN")endimport dev.svm.sandbox.Client;import dev.svm.sandbox.Sandbox;import dev.svm.sandbox.Secret;import java.util.List;import java.util.Map;
public class SecretsExample { public static void main(String[] args) { Client client = Client.fromEnvironment(); String name = "DOCS_API_TOKEN"; Secret.create(client, name, System.getenv("DOCS_API_TOKEN"), "token for api.example.com"); try { System.out.println("exists: " + Secret.exists(client, name)); Secret.update(client, name, System.getenv("DOCS_API_TOKEN_NEW")); // rotate for (Secret.Info info : Secret.list(client)) System.out.println(info.name + " v" + info.version);
Sandbox.CreateOptions options = new Sandbox.CreateOptions(); options.envs = Map.of("API_TOKEN", Secret.fill(name)); // a placeholder, never the value options.wait = true; try (Sandbox sandbox = Sandbox.create(client, options)) { // The egress proxy swaps the placeholder for the value in requests to this host only. sandbox.updateEgress(Map.of("enabled", true, "default", "allow", "rules", List.of(Map.of( "action", "allow", "domain", "api.example.com", "inject", Secret.inject(name, List.of("Authorization"), null))))); sandbox.commands().run("curl -s -H \"Authorization: Bearer $API_TOKEN\" https://api.example.com/"); } } finally { Secret.destroy(client, name); } }}How injection works
Section titled “How injection works”- Bind a secret to a host with an allow egress rule that carries
inject. Give the rule an exact domain and the headers to fill. - In the sandbox, send
Secret.fill(name)as the header value, for exampleAuthorization: Bearer <placeholder>. - The value is read on every request, so a rotation applies at once. If the secret is gone, the request is refused with
503, never sent with the placeholder. - Injection works only over HTTPS and only while egress rules are enabled.
create refuses a name that already exists, and update refuses one that does not, so a typo never makes a second secret.
Values are never read back. get_info returns the name, description, metadata and version only.
From the CLI. The value is never a command-line argument:
printf %s "$TOKEN" | svm secret set GITHUB_TOKEN --description "CI token"svm network egress set <id> --inject api.github.com:Authorization=GITHUB_TOKEN