package provider import ( "encoding/json" "os" "reflect" "sort" "golang.org/x/sys/unix" ) // Claude's sign-in with no terminal (Paul, 2026-11-10): the unmodified // `claude setup-token` runs contained like every provider launch, in a // bubblewrap namespace whose only writable home is the launch's own // scratch home (the connection's dedicated home is not mounted: the // runner writes the token there itself), with no workspace, no tool // socket, no other home and no runner state, and egress only through the // relay to SignInHosts. Its policy is built here like a check's: no // account, no binding, a pinned binary. const signInPolicyVersion = "signin-v1" // SignInHosts are the hosts setup-token reaches, read from the pinned // CLI 2.1.312 statically (its production OAuth config): TOKEN_URL // https://platform.claude.com/v1/oauth/token, where the code is // exchanged for the token, and BASE_API_URL https://api.anthropic.com. // The authorize page (claude.com) is opened by the person's browser, // never by the CLI. Sorted. var SignInHosts = []string{"api.anthropic.com", "platform.claude.com"} // SignInBrowser stands in for a browser inside the namespace: setup-token // runs it with the URL and it opens nothing. const SignInBrowser = "/usr/bin/true" // SignInArgv is the CLI's argv inside the namespace. var SignInArgv = []string{"/opt/claude", "setup-token"} // SignInPolicyInputs are the pinned CLI and the host's bubblewrap. type SignInPolicyInputs struct { Binary, Bwrap string } // signInEnv is the CLI's environment: its config in the scratch home, // no nonessential traffic, no updater, a terminal, no browser. func signInEnv() map[string]string { return map[string]string{ "CLAUDE_CONFIG_DIR": "/home/runner", "CLAUDE_SECURESTORAGE_CONFIG_DIR": "/home/runner", "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1", "DISABLE_AUTOUPDATER": "1", "TERM": "xterm-256color", "BROWSER": SignInBrowser, } } // BuildSignInPolicy pins the CLI (mounted read-only at /opt/claude) and // the host's bubblewrap (certified, not mounted). func BuildSignInPolicy(in SignInPolicyInputs) (Policy, error) { m := effectiveManifest{Version: signInPolicyVersion, Provider: "claude", Argv: append([]string(nil), SignInArgv...), Env: signInEnv(), NamespaceArgs: NamespaceArguments(), EgressHosts: append([]string(nil), SignInHosts...)} sort.Strings(m.EgressHosts) cli := Mount{Source: in.Binary, Target: "/opt/claude", ReadOnly: true} m.OuterMounts = []Mount{cli} for _, mount := range []Mount{cli, {Source: in.Bwrap, Target: "/opt/bwrap", ReadOnly: true}} { fd, err := openNoLinks(mount.Source, unix.O_RDONLY|unix.O_CLOEXEC|unix.O_NONBLOCK) if err != nil { return Policy{}, ErrPolicy } f := os.NewFile(uintptr(fd), mount.Source) info, err := f.Stat() f.Close() if err != nil || !info.Mode().IsRegular() { return Policy{}, ErrPolicy } raw, err := os.ReadFile(mount.Source) if err != nil { return Policy{}, err } m.Files = append(m.Files, fileDigest{Mount: mount, SHA256: digest(raw)}) } raw, hash, err := hashJSON(m) if err != nil { return Policy{}, err } return Policy{Hash: hash, ManifestHash: hash, Manifest: raw, Mounts: m.OuterMounts, Env: signInEnv()}, nil } // IsSignIn says the policy is a sign-in's (BuildSignInPolicy). func (p Policy) IsSignIn() bool { var m effectiveManifest return p.ManifestHash != "" && digest(p.Manifest) == p.ManifestHash && json.Unmarshal(p.Manifest, &m) == nil && m.Version == signInPolicyVersion } // attestSignIn binds a sign-in launch to its policy: Claude and nothing // else selected, no binding, workspace, tool socket or session, the // policy's own argv, environment and mounts, the pinned files unchanged. func attestSignIn(l Launch, argv []string) (string, error) { p := l.Policy var m effectiveManifest if l.Selection != (Selection{Provider: "claude"}) || l.Binding != (Binding{}) || l.Workspace != "" || l.ToolSocket != "" || l.ResumeSessionID != "" || l.AttemptKey == "" || json.Unmarshal(p.Manifest, &m) != nil || digest(p.Manifest) != p.ManifestHash || p.Hash != p.ManifestHash || !reflect.DeepEqual(argv, m.Argv) || !reflect.DeepEqual(argv, SignInArgv) || !reflect.DeepEqual(p.Env, m.Env) || !reflect.DeepEqual(m.Env, signInEnv()) || !reflect.DeepEqual(p.Mounts, m.OuterMounts) || !reflect.DeepEqual(m.NamespaceArgs, NamespaceArguments()) || !reflect.DeepEqual(m.EgressHosts, SignInHosts) { return "", ErrPolicy } for _, f := range m.Files { raw, err := os.ReadFile(f.Mount.Source) if err != nil || digest(raw) != f.SHA256 { return "", ErrPolicy } } _, hash, err := hashJSON(struct{ Manifest, Attempt string }{p.ManifestHash, l.AttemptKey}) return hash, err }