Skip to content

fix(setup): auto-bootstrap local OneCLI admin so first install completes#2052

Open
dooha333 wants to merge 3 commits into
nanocoai:mainfrom
dooha333:pr/setup-onecli-bootstrap
Open

fix(setup): auto-bootstrap local OneCLI admin so first install completes#2052
dooha333 wants to merge 3 commits into
nanocoai:mainfrom
dooha333:pr/setup-onecli-bootstrap

Conversation

@dooha333
Copy link
Copy Markdown
Contributor

@dooha333 dooha333 commented Apr 27, 2026

Type of Change

  • Fix - bug fix or security fix to source code

Description

What. Adds local-admin auto-bootstrap to setup's OneCLI step so the onecli CLI is authenticated immediately after a fresh local-vault install.

Why. On a fresh install, the OneCLI gateway starts empty and the onecli CLI has no API key. The next setup step that calls onecli secrets create (saving the Claude OAuth token) fails with AUTH_REQUIRED, surfacing as "Couldn't complete the Claude sign-in".

How it works. setup/onecli.ts makes a GET /api/user/api-key request with x-forwarded-for: 127.0.0.1. The gateway's local authMode treats that as a loopback request and runs its built-in local-admin bootstrap, returning an oc_… key. We persist via onecli auth login and add ONECLI_API_KEY to .env. No-op when the CLI is already authenticated.

How it was tested. Fresh privileged Proxmox LXC end-to-end: onecli step succeeded in 29s, Anthropic secret reached the vault, no AUTH_REQUIRED. pnpm exec tsc --noEmit clean. pnpm test 197/197.

Refs #1973, #1818

A fresh local OneCLI install leaves the `onecli` CLI unauthenticated, so the
Anthropic-token save step fails with `Unauthorized / AUTH_REQUIRED` and the
whole setup flow dead-ends. v1 wrote the key straight to .env; v2's vault
flow assumes the CLI is already logged in to the gateway, but for a brand-new
local install it isn't yet.

After `pollHealth` in both the install and `--reuse` paths, if
`onecli auth status` is unauthenticated, hit `GET ${url}/api/user/api-key`
with header `x-forwarded-for: 127.0.0.1`. The gateway in `local` authMode
treats that as a loopback request and runs its built-in `local-admin`
bootstrap (creates user + account + api_key in one call), returning the
`oc_…` key. Persist it via `onecli auth login --api-key` and `ONECLI_API_KEY`
in `.env` — same dual-surface pattern as commit f048447 added for remote-mode.

Why the XFF spoof: the Linux installer binds the gateway to docker0
(172.17.0.1) so containers can reach it, but that means host-side requests
don't look like loopback to OneCLI's auth check (which only inspects
`x-forwarded-for`, not the TCP source). Setting it ourselves opts back into
the existing local-admin bootstrap path without changing the bind address.

Refs nanocoai#1973, nanocoai#1818.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added follows-guidelines PR was created using the current contributing template PR: Fix Bug fix labels Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

follows-guidelines PR was created using the current contributing template PR: Fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant