diff --git a/.agents/notes/verified/architecture/2026-09-30-git-credential-broker-verified.md b/.agents/notes/verified/architecture/2026-09-30-git-credential-broker-verified.md index c9c99394..0b13bdf7 100644 --- a/.agents/notes/verified/architecture/2026-09-30-git-credential-broker-verified.md +++ b/.agents/notes/verified/architecture/2026-09-30-git-credential-broker-verified.md @@ -90,7 +90,7 @@ deploy-sidecar.sh 写容器内路径)就不会有这个问题;把两者合 五个 shell 脚本已全部改成 CLI 子命令,并随包发布到 npm(`git-credential-broker`):`setup` (原 container-setup.sh)、`init`(原 host-setup.sh)、`compose`(原 deploy-sidecar.sh 的 compose 生成)、`probe`、`diagnose`。宿主不再需要 checkout 或构建 —— `compose` 产出的 sidecar -直接 `npx` 拉取已发布的包。同一个 bin 既是 git 的 credential helper(`get|store|erase`), +使用已发布 host 镜像里的 `gcb`。同一个 bin 既是 git 的 credential helper(`get|store|erase`), 也是管理 CLI。 **新增 `stage`:把"代码在哪"变成一条命令。** 原 `deploy-sidecar.sh` 会拒绝脏工作树,合并成 CLI 时我把 diff --git a/.changeset/compose-host-image.md b/.changeset/compose-host-image.md new file mode 100644 index 00000000..46bcac4b --- /dev/null +++ b/.changeset/compose-host-image.md @@ -0,0 +1,7 @@ +--- +"gcb-host": patch +--- + +`compose` now emits the released `ghcr.io/code-vaults/gcb-host:` image and runs its installed +`gcb daemon` binary. It no longer generates an `npx --package gcb-host` command or accepts `--package`. +The `--code` staged-code mode is unchanged. diff --git a/.renovaterc b/.renovaterc new file mode 100644 index 00000000..bebeb9d0 --- /dev/null +++ b/.renovaterc @@ -0,0 +1,6 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": [ + "github>1stG/configs" + ] +} diff --git a/AGENTS.md b/AGENTS.md index f3a477d8..5de4c166 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -77,7 +77,7 @@ sources must stay erasable (`erasableSyntaxOnly` is on: no enums, no parameter p - **Only cover the deployment shapes this project actually supports.** The supported shapes are the installed `gcb-client` in the container, the installed `gcb-host` (or a staged commit with its production dependencies) on the host, the rendered sidecar, and a source checkout with a - `gcb` shim for development. Do not add guards, probes, commands or tests for one-off `npx` + `gcb` shim for development. Do not add guards, probes, commands or tests for one-off execution setup, direct imports of command modules, arbitrary later PATH changes, or native Windows beyond the existing refusal and its real-platform CI job. `setup` cannot know the PATH of a later git process; do not pretend a setup-time check is a diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 129809c8..66a41903 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -119,12 +119,6 @@ gcb compose --dir "$DEPLOY" --socket-dir "$SOCKET_DIR" \ > "$DEPLOY/docker-compose.yml" ``` -Change only the `exec npx --yes --package … gcb` prefix to `exec gcb`, keeping `daemon --config …`: - -```sh -exec gcb daemon --config /etc/git-cred-broker/config/broker.config.yml -``` - The dev image already installs the package; do **not** keep a staged `/opt/gcb` mount, or the image's code is ignored. Then recreate from the deployment directory, choosing the proxy at runtime: diff --git a/README.md b/README.md index 1e21e322..c2080cad 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ npm install -g gcb-host `gcb-client` has no runtime dependencies. `gcb-host` depends on `yaml`; npm installs it there. Do not install both globally on the same machine: they race for the same `gcb` bin. Run `setup` from the -installed client; one-off `npx` execution is not a supported installation shape. +installed client; one-off execution is not a supported installation shape. Or run from a checkout. Node 24 strips TypeScript types, but the workspaces still need their dependencies: @@ -108,10 +108,8 @@ the compose command in [Quick start](#quick-start-sidecar): docker build --target host -t code-vaults/gcb-host:dev . ``` -The image's `CMD` starts `gcb daemon`, but `compose` still renders the registry-fetching `npx` -command by default. Keep the rendered `sh -c` wrapper (it applies `GCB_PROXY`) and change only its -final `exec npx ...` to `exec gcb daemon --config ...`; see -[DEVELOPMENT.md](DEVELOPMENT.md#use-your-build). +The image's `CMD` starts `gcb daemon`; the rendered command runs that installed binary and keeps the +`sh -c` wrapper that applies `GCB_PROXY`. See [DEVELOPMENT.md](DEVELOPMENT.md#use-your-build). Debian packages use the Aliyun mirror by default in this image; pass `--build-arg APT_MIRROR=` to build against another mirror. @@ -177,9 +175,8 @@ The exact command, flags and required values come from ## Quick start: sidecar -Docker only. Run `init` and `compose` from an installed `gcb-host`. The image is stock `node:24-slim`; -the default sidecar fetches `gcb-host` with `npx` at start, while `--code` runs a staged commit with no -registry access at boot. +Docker only. Run `init` and `compose` from an installed `gcb-host`. The default sidecar uses the +released `gcb-host` image and runs its installed `gcb daemon`; `--code` runs a staged commit instead. ```sh DEPLOY=/srv/git-cred-broker # the deployment directory @@ -229,8 +226,7 @@ guess. The runtime route is deliberately a superset: a directory bind-mounted in counts as shared, because any container that can rewrite the broker's code is as good a reason not to stage there as the agent is. -The sidecar fetches the published `gcb-host` package with `npx` at start. To pin a reviewed commit -instead, run `gcb stage --to "$DEPLOY/app"`, install its dependencies in that directory with +The sidecar runs the installed `gcb` from the released host image. To pin a reviewed commit instead, run `gcb stage --to "$DEPLOY/app"`, install its dependencies in that directory with `corepack yarn install`, and pass `--code "$DEPLOY/app"` to `compose`. Run `stage` from the repository root you intend to export, or pass `--repo `: it defaults to the current directory and exports that repository's `HEAD`, never the working tree. `stage` is export-only: it does not install @@ -268,7 +264,7 @@ gcb setup install and a dev shim) and `credential.useHttpPath` (without the latter, git sends no repository path and the broker can only authorize host-wide). The helper is resolved by the git process later, not by `setup`: that process must have `gcb` on its PATH. Run setup from the installed client, not -a one-off `npx` process. +a one-off execution. It also rewrites `git@github.com:` remotes to https **inside the container only** so the host's SSH workflow is untouched, and writes a CA bundle @@ -348,8 +344,7 @@ a sidecar it is inside the container: ```sh DEPLOY=/srv/git-cred-broker -cd "$DEPLOY" && docker compose exec gcb \ - npx --yes --package gcb-host gcb \ +cd "$DEPLOY" && docker compose exec gcb gcb \ diagnose --config /etc/git-cred-broker/config/broker.config.yml ``` @@ -810,6 +805,36 @@ its own `corepack` and `npm`, and a whole-directory copy would replace them. Tha local build; CI and production pass a published version instead, e.g. `--build-arg GCB_CLIENT_IMAGE=ghcr.io/code-vaults/gcb-client:`. +### Updating the sidecar + +Pin a released `gcb-host` image by version or digest; do not use `:dev` or `pull_policy: never` for +updates. The generated service is named `gcb` by default (`gcb compose --name ` changes it). + +The released image contains the `gcb` binary and starts `gcb daemon`. Keep the generated `sh -c` +wrapper: it applies `GCB_PROXY`, and its final `exec` already runs the installed binary. Do not replace +the whole `command` with a bare `gcb daemon` list. + +```sh +docker compose pull gcb +docker compose up -d --no-deps --force-recreate gcb +``` + +Verify the running sidecar, not just the host CLI: + +```sh +docker compose exec gcb gcb --version +docker compose exec gcb gcb doctor --config /etc/git-cred-broker/config/broker.config.yml +gcb --version # in the pushing environment; must be the same release line +``` + +`gcb doctor` checks configuration and the audit path; it is not a daemon-liveness probe. Check +liveness from the pushing environment with `gcb probe --repo `: exit `0` means allowed, +`1` denied, and `3` means the broker is unreachable. Alert on a non-zero doctor result; restart only +when `probe` returns `3` or the socket is gone; a configuration error needs an operator. + +Use the same release line on both sides. Typed host replies and the active-audit ping need at least +`0.3.0`; `gcb authorize --broker-container` needs host `0.8.0`. + ## App permissions by action The action catalog is the source for these requirements; `gcb gh --help` prints the same diff --git a/docker-compose.example.yml b/docker-compose.example.yml index 115b8675..df622ab2 100644 --- a/docker-compose.example.yml +++ b/docker-compose.example.yml @@ -13,10 +13,10 @@ services: git-cred-broker: - # The usual NAS case. The image installs the package at start, so there is no checkout to copy + # The usual NAS case. The released image contains gcb-host, so there is no checkout to copy # and nothing to build. Only this container mounts the private key; the socket directory is # the only thing shared with the DSH container. - image: node:24-slim + image: ghcr.io/code-vaults/gcb-host:0.8.0 container_name: git-cred-broker restart: unless-stopped # Must match the uid/gid of the container that will use the socket, or it is unusable. @@ -24,15 +24,12 @@ services: user: '1000:1000' read_only: true tmpfs: - # npx needs somewhere writable for its cache; /tmp is a tmpfs above. - /tmp cap_drop: - ALL security_opt: - no-new-privileges:true environment: - # npx needs somewhere writable for its cache; /tmp is a tmpfs above. - - npm_config_cache=/tmp/npm-cache # Egress: the socket needs no proxy, the broker's own calls to github.com do. - http_proxy=${http_proxy:-${HTTP_PROXY:-}} - https_proxy=${https_proxy:-${HTTPS_PROXY:-}} @@ -41,7 +38,7 @@ services: command: - sh - -c - - exec npx --yes --package 'gcb-host' gcb daemon --config /etc/git-cred-broker/config/broker.config.yml + - exec gcb daemon --config /etc/git-cred-broker/config/broker.config.yml volumes: # The configuration directory, not one file: an atomic replacement on the host must stay # visible to the container's watcher. Put broker.config.yml in ./config; the key and refresh @@ -72,9 +69,7 @@ services: # The same host directory the broker binds, or the two are not sharing a socket at all. - /srv/git-broker-socket:/run/git-broker -# Pin a released version (`npx --yes --package 'gcb-host@'`) if you would rather not -# resolve latest on every start; `compose` pins the version it was generated from. The first -# functional release is 0.0.1; 0.0.0 is an empty placeholder. +# Pin the released image tag or digest; `compose` pins the version it was generated from. # # The host-process alternative, for a host that has Node and a service manager: # diff --git a/packages/host/src/commands/compose.ts b/packages/host/src/commands/compose.ts index 216e3f52..b0216a74 100644 --- a/packages/host/src/commands/compose.ts +++ b/packages/host/src/commands/compose.ts @@ -3,8 +3,8 @@ * * The broker runs in its own container with the private key mounted read-only, no published ports, * no capabilities and a read-only root filesystem; the only surface it shares with anything else is - * the socket directory. The container fetches the published package, so there is no checkout to - * copy and nothing to build on the host. + * the socket directory. The released image contains the package, so there is no checkout to copy and + * nothing to build on the host. * * The mount targets are constants from `deployment.ts`, shared with `init --mode sidecar`, so the * paths recorded in `broker.config.yml` and the paths this file mounts cannot drift apart. @@ -33,16 +33,14 @@ export interface ComposeInput { readonly socketDir: string /** `uid:gid` the sidecar runs as; must match the container that needs the socket. */ readonly user: string - /** Base image. */ + /** Base image; the released host image contains the `gcb` binary. */ readonly image: string - /** Npm spec to run, e.g. `gcb@0.0.0`. */ - readonly packageSpec: string /** Compose service and container name. */ readonly name: string /** * Host directory holding the broker's code, as `stage` exports it. When given, the sidecar runs - * that code with the image's Node instead of fetching the package at start: no registry access at - * boot, and the commit that runs is the one you reviewed. + * that code with the image's Node instead of running the image's installed binary: no registry + * access at boot, and the commit that runs is the one you reviewed. */ readonly code?: string } @@ -96,14 +94,8 @@ export function renderCompose(input: ComposeInput): string { ? `# It runs the code mounted read-only from ${input.code}, which is whatever \`stage\` put there — # see the STAGED.json beside it for the commit. stage does not install dependencies or build: # run \`corepack yarn install\` in that directory first, then the source entry point runs here.` - : `# The image fetches the published package at start: -# -# npx --yes --package '${input.packageSpec}' gcb daemon -# -# To avoid depending on the registry at boot, either render this file with --code to -# run staged code from a mount, or point --image at an image of your own that already has the -# package installed, and change \`command\` to the binary in it: -# ["gcb", "daemon", "--config", "${mountedConfigPath}"]` + : `# The image contains gcb-host and the command below runs its installed \`gcb\` binary. +# To pin a reviewed commit instead, render this file with --code .` // The egress lines belong to both renders: a --code deployment is a sidecar too, and without them it // would carry no proxy variables at all, so the daemon would go direct and hang rather than refuse. @@ -117,13 +109,8 @@ export function renderCompose(input: ComposeInput): string { # Runtime override: a URL pins a proxy, an empty value goes direct, unset keeps the above. - GCB_PROXY=\${GCB_PROXY-default}` - const environment = fromCode - ? ` + const environment = ` environment:${egress}` - : ` - environment: - # npx needs somewhere writable for its cache; /tmp is a tmpfs above. - - npm_config_cache=/tmp/npm-cache${egress}` // A bind mount for a path that does not exist becomes a directory, and the broker would then read a // directory instead of a token — for every action, not only the personal ones. Emit it once `authorize` @@ -134,7 +121,7 @@ export function renderCompose(input: ComposeInput): string { '\n # for a path that does not exist would become a directory, and the broker would read that.' const start = fromCode ? `exec node --conditions=development ${CODE_DIR}/packages/host/bin/gcb.js daemon --config ${mountedConfigArg}` - : `exec npx --yes --package '${input.packageSpec}' gcb daemon --config ${mountedConfigArg}` + : `exec gcb daemon --config ${mountedConfigArg}` const command = ` - sh - -c - | @@ -214,11 +201,10 @@ Print a Docker sidecar definition for the broker (to stdout). Pair it with a con --config The sidecar's config, checked before anything is printed (default: $GIT_BROKER_CONFIG, else ./broker.config.yml) --socket-dir Host directory the pushing container already mounts - --code Run code mounted from this host directory instead of fetching the package - at start (as \`stage\` exports it); nothing is fetched or built at boot + --code Run code mounted from this host directory instead of the installed binary + (as \`stage\` exports it); nothing is fetched or built at boot --user UID the sidecar runs as (default: this user) - --image Base image (default: node:24-slim) - --package npm spec to run (default: gcb-host@) + --image Base image (default: ghcr.io/code-vaults/gcb-host:) --name Service and container name (default: gcb) -h, --help Show this help ` @@ -235,6 +221,9 @@ export function runCompose(argv: readonly string[]): number { say(COMPOSE_USAGE) return 0 } + if (argv.some(argument => argument === '--package' || argument.startsWith('--package='))) { + fail('--package is not supported; pin the released image with --image instead') + } const explicitConfig = args.value('config') const dirArg = args.value('dir') const configPath = path.resolve( @@ -281,8 +270,7 @@ export function runCompose(argv: readonly string[]): number { configPath: configFile, socketDir, user, - image: args.value('image') ?? 'node:24-slim', - packageSpec: args.value('package') ?? `gcb-host@${PACKAGE_VERSION}`, + image: args.value('image') ?? `ghcr.io/code-vaults/gcb-host:${PACKAGE_VERSION}`, name: args.value('name') ?? 'gcb', code: args.value('code'), }), diff --git a/test/unit/commands.test.ts b/test/unit/commands.test.ts index 7c91017c..87d63cb5 100644 --- a/test/unit/commands.test.ts +++ b/test/unit/commands.test.ts @@ -27,6 +27,7 @@ import { helpRequested, } from '../../packages/core/src/support.ts' import type { BrokerConfig, GithubAppHostConfig } from '../../packages/core/src/types.ts' +import { PACKAGE_VERSION } from '../../packages/core/src/version.ts' import { renderCompose, runCompose } from '../../packages/host/src/commands/compose.ts' import { runDiagnose } from '../../packages/host/src/commands/diagnose.ts' import { @@ -1723,11 +1724,20 @@ describe('compose', () => { dir: '/volume1/docker/git-cred-broker', socketDir: '/srv/shared/git-broker', user: '1026:100', - image: 'node:24-slim', - packageSpec: 'gcb-host@0.0.0', + image: 'ghcr.io/code-vaults/gcb-host:0.0.0', name: 'git-cred-broker', }) + it('rejects the removed --package option', () => { + const result = spawnSync( + 'node', + ['--conditions=development', 'packages/host/bin/gcb.js', 'compose', '--socket-dir', '/tmp', '--package', 'gcb-host@0.7.0'], + { cwd: path.resolve('.'), encoding: 'utf8' }, + ) + assert.equal(result.status, 1) + assert.match(result.stderr, /--package is not supported/u) + }) + it('mounts the key read-only and publishes no ports', () => { assert.match(rendered, /app\.pem:\/etc\/git-cred-broker\/app\.pem:ro/) assert.match(rendered, /volume1\/docker\/git-cred-broker:\/etc\/git-cred-broker\/config:ro/) @@ -1801,6 +1811,12 @@ describe('compose', () => { }) as typeof process.stdout.write try { assert.equal(runCompose(['--socket-dir', '/srv/sock']), 0) + assert.match( + output, + new RegExp( + `image: ghcr[.]io/code-vaults/gcb-host:${PACKAGE_VERSION.replaceAll('.', '[.]')}`, + ), + ) } finally { process.stdout.write = original if (previous === undefined) { @@ -1818,8 +1834,7 @@ describe('compose', () => { configPath: '/srv/custom/broker.yml', socketDir: '/srv/shared/git-broker', user: '1026:100', - image: 'node:24-slim', - packageSpec: 'gcb-host@0.0.0', + image: 'ghcr.io/code-vaults/gcb-host:0.0.0', name: 'git-cred-broker', }) assert.match(custom, /\/srv\/custom:\/etc\/git-cred-broker\/config:ro/) @@ -1832,8 +1847,7 @@ describe('compose', () => { configPath: '/srv/custom/broker live.yml', socketDir: '/srv/shared/git-broker', user: '1026:100', - image: 'node:24-slim', - packageSpec: 'gcb-host@0.0.0', + image: 'ghcr.io/code-vaults/gcb-host:0.0.0', name: 'git-cred-broker', }) assert.match(custom, /--config '\/etc\/git-cred-broker\/config\/broker live\.yml'/) @@ -1842,8 +1856,7 @@ describe('compose', () => { configPath: '/srv/custom/br$ker "x".yml', socketDir: '/srv/shared/git-broker', user: '1026:100', - image: 'node:24-slim', - packageSpec: 'gcb-host@0.0.0', + image: 'ghcr.io/code-vaults/gcb-host:0.0.0', name: 'git-cred-broker', }) assert.match(dollar, /--config '\/etc\/git-cred-broker\/config\/br\$\$ker "x"\.yml'/) @@ -1863,8 +1876,7 @@ describe('compose', () => { configPath: link, socketDir: '/srv/shared/git-broker', user: '1026:100', - image: 'node:24-slim', - packageSpec: 'gcb-host@0.0.0', + image: 'ghcr.io/code-vaults/gcb-host:0.0.0', name: 'git-cred-broker', }) assert.equal( @@ -1924,8 +1936,7 @@ describe('compose', () => { dir: '/srv/broker #1', socketDir: '/srv/socket #2', user: '1026:100', - image: 'node:24-slim', - packageSpec: 'gcb-host@0.0.0', + image: 'ghcr.io/code-vaults/gcb-host:0.0.0', name: 'git-cred-broker', }) assert.equal(custom.includes('- "/srv/broker #1:/etc/git-cred-broker/config:ro"'), true) @@ -1943,8 +1954,9 @@ describe('compose', () => { assert.match(rendered, /user: "1026:100"/) }) - it('runs the daemon from the published package, not from a copied checkout', () => { - assert.match(rendered, /npx --yes --package 'gcb-host@0\.0\.0' gcb daemon/) + it('runs the installed gcb binary from the host image', () => { + assert.match(rendered, /exec gcb daemon/) + assert.equal(/npx/.test(rendered), false) assert.match(rendered, new RegExp(`--config '${SIDECAR.configPath}'`)) }) @@ -1953,8 +1965,7 @@ describe('compose', () => { dir: '/volume1/docker/git-cred-broker', socketDir: '/srv/shared/git-broker', user: '1026:100', - image: 'node:24-slim', - packageSpec: 'gcb-host@0.0.0', + image: 'ghcr.io/code-vaults/gcb-host:0.0.0', name: 'git-cred-broker', code: '/volume1/docker/git-cred-broker/app', })