diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..2cf3fae --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +* +!image-bin/** +!Dockerfile diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f96059b..6f12929 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -99,6 +99,62 @@ jobs: env: GH_TOKEN: ${{ github.token }} run: | + NOTE="Container image: ghcr.io/openabdev/openab-sb:${GITHUB_REF_NAME#v} is pushed after this release is created. A new GHCR package is private by default. Set it to Public once under Package settings before anonymous docker pull works. Stable tags also move :latest." gh release create "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" \ - --title "openab-sb ${GITHUB_REF_NAME#v}" --generate-notes \ + --title "openab-sb ${GITHUB_REF_NAME#v}" --generate-notes --notes "$NOTE" \ dist/openab-sb-*.tar.gz dist/SHA256SUMS + + image: + name: container image (ghcr.io) + needs: [build, publish] + if: startsWith(github.ref, 'refs/tags/v') + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - uses: actions/checkout@v4 + - uses: actions/download-artifact@v4 + with: + pattern: linux-* + path: dist + - name: Stage static binaries by architecture + shell: bash + run: | + set -euo pipefail + ver="${GITHUB_REF_NAME#v}" + for asset in linux-amd64 linux-arm64; do + arch="${asset#linux-}" + mkdir -p image-bin/"$arch" + tar xzf dist/"$asset"/openab-sb-"$ver"-"$asset".tar.gz -C image-bin/"$arch" --strip-components=1 openab-sb-"$ver"-"$asset"/openab-sb + chmod 0755 image-bin/"$arch"/openab-sb + done + image-bin/amd64/openab-sb --version + - uses: docker/setup-qemu-action@v3 + - name: Run the arm64 binary under emulation + run: | + set -euo pipefail + docker run --rm --platform linux/arm64 \ + -v "$PWD/image-bin/arm64/openab-sb:/tmp/openab-sb:ro" \ + debian:bookworm-slim /tmp/openab-sb --version + - uses: docker/setup-buildx-action@v3 + - uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - id: meta + uses: docker/metadata-action@v5 + with: + images: ghcr.io/${{ github.repository_owner }}/openab-sb + tags: | + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + - uses: docker/build-push-action@v6 + with: + context: . + file: ./Dockerfile + platforms: linux/amd64,linux/arm64 + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d56b8e1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,32 @@ +# +# Runtime image for openab-sb. It does not compile Rust. The release job in +# .github/workflows/release.yml unpacks the static musl binaries it already +# builds into image-bin//openab-sb (amd64, arm64) and runs buildx with +# this file as the Dockerfile. +# +# The config is not baked in. Mount it at /etc/openab-sb/openab-sb.toml. It +# must set listen = "127.0.0.1:8790" and an audit_path under /var/lib/openab-sb. +# The switchboard binds loopback, so only processes in the same pod (the +# tailscale sidecar) can reach it. +# +# The user is numeric (10001) so that kubelet runAsNonRoot can verify it. + +FROM debian:bookworm-slim + +ARG TARGETARCH + +# hadolint ignore=DL3008 +RUN apt-get update \ + && apt-get install -y --no-install-recommends ca-certificates curl \ + && rm -rf /var/lib/apt/lists/* + +RUN groupadd --system --gid 10001 openab-sb \ + && useradd --system --uid 10001 --gid 10001 --no-create-home --home-dir /var/lib/openab-sb --shell /usr/sbin/nologin openab-sb \ + && install -d -o 10001 -g 10001 -m 0750 /var/lib/openab-sb /etc/openab-sb + +COPY image-bin/${TARGETARCH}/openab-sb /usr/local/bin/openab-sb + +USER 10001:10001 +WORKDIR /var/lib/openab-sb + +ENTRYPOINT ["/usr/local/bin/openab-sb", "serve", "-c", "/etc/openab-sb/openab-sb.toml"] diff --git a/README.md b/README.md index 51425a6..57404a0 100644 --- a/README.md +++ b/README.md @@ -253,6 +253,29 @@ cp openab-sb.toml.example openab-sb.toml # paste the verifiers Adding a computer later is an operator action — generate a pair, add the verifier, `SIGHUP`. There is no self-registration. +### Container image + +Each `v*` tag publishes a multi-arch (amd64, arm64) image to GHCR. The image job runs only after +the GitHub Release for the tag has been created. A stable tag (no prerelease suffix) also moves +`:latest`. A prerelease tag does not. + +```bash +docker pull ghcr.io/openabdev/openab-sb:0.2.2 # also :0.2 and :latest +``` + +A new GHCR package starts private, so anonymous `docker pull` fails until someone sets it to +Public once: open the `openab-sb` package under the openabdev org, then Package settings, then +Change visibility to Public. Authenticated pulls work before that change. + +The image is `debian:bookworm-slim` with the release's static `openab-sb` binary, `curl` and +`ca-certificates`. It runs as the non-root user `openab-sb` (UID and GID 10001), and its entrypoint is +`openab-sb serve -c /etc/openab-sb/openab-sb.toml`. The config is not baked in: mount it at that +path. It must set `listen = "127.0.0.1:8790"` and an `audit_path` under `/var/lib/openab-sb`, +which the image creates and owns for the audit file. + +A pod can probe the switchboard with `curl -fsS --max-time 2 http://127.0.0.1:8790/healthz` from inside the +container. Keep the listener on loopback, and put TLS in a sidecar such as `tailscale serve`. + The switchboard binds loopback and refuses anything else unless you set `allow_insecure_bind = true`. Put TLS in front of it: