Skip to content

Ship staging from the on-prem runner over its private address - #84

Merged
aterga merged 3 commits into
mainfrom
claude/staging-onprem-runner-d74205
Jul 27, 2026
Merged

aterga merged 3 commits into
mainfrom
claude/staging-onprem-runner-d74205

Conversation

@aterga

@aterga aterga commented Jul 27, 2026 •

Copy link
Copy Markdown
Collaborator

Replaces #83, which GitHub auto-closed as merged when a force-push made its head an ancestor of its then-base. Nothing reached main; this is the same change, now based directly on main and self-contained.

Correction, 2026-07-29. This body described 22/tcp as open to 0.0.0.0/0, which was true when written and is no longer. Internet-facing SSH is closed on both hosts: each has a public-facing network interface and a private one, security groups attach per-interface, and the public-facing ones now carry a group permitting 80/443 only. Verified from outside the VPN. The rule itself still exists in the shared group and still applies to the private interfaces, so SSH remains reachable from the VPN and on-prem estate — a residual that is knowingly accepted. The plan sketched at the bottom of this body (revoke and replace with a range-scoped group) was not what happened and should not be followed; see #91 for the current position, and #104 for the documentation.

Summary

Staging is the only reason any host in this VPC needs SSH open to the public internet. Its deploy runs on GitHub-hosted runners, which can reach it no other way, so at the time the shared security group carried 22/tcp from 0.0.0.0/0 and ::/0. Restricting that to GitHub's ranges isn't viable — Actions runners egress from Azure prefixes numbering in the thousands and rotating, well past the per-group rule limit. Reaching the host over the VPN instead removes the requirement rather than trying to narrow it.

That needs the deploy split in two. Building still wants Docker and a few minutes of Rust compile, which doesn't belong on an on-prem runner; shipping needs only ssh and tar. So the mechanics move into a reusable workflow with a build job on hosted infrastructure and a ship job wherever the target is reachable, and only the finished binary crosses into the private network. The ship runner's own architecture is irrelevant — it never executes the binary.

Two latent problems surfaced while wiring this up and are fixed here:

  • build.sh hardcoded linux/arm64 and deploy.sh always fetched an arm64 Caddy. Pointing either at an x86_64 host produced a unit that installed cleanly and then crash-looped on Exec format error — a failure that reads like an app bug rather than a build-target mistake.
  • Nothing verified the host actually picked up the new binary. A systemctl restart that silently kept the old one would have passed as a green deploy.

Related issues

None.

Changes

  • Add deploy-native.yml, a reusable workflow holding the deploy mechanics, split into build (hosted, needs Docker) and ship (reachability-constrained, needs only ssh + tar).
  • deploy.yml calls it, runs in a staging environment, and ships from the on-prem runner.
  • Teach build.sh an $ARCH knob (arm64 / amd64, accepting the uname -m spellings too) and thread it through the build container.
  • Have deploy.sh derive Caddy's download architecture from the host's uname -m, and compare the binary's ELF e_machine against the host before shipping anything — a mismatch aborts with the exact rebuild command instead of taking the service down.
  • Resolve the build commit from the checkout rather than github.sha, which points at the default branch on a workflow_dispatch run and would have mislabelled the binary.
  • Assert GET /version reports the just-built commit after each deploy, read over SSH from the host so it works when the domain isn't resolvable from the runner.
  • Document the deploy model, the build/ship split, and the dual-stack reachability traps.

Testing

  • All three workflow files parse as YAML; build.sh and deploy.sh pass bash -n.
  • Exercised deploy.sh end-to-end against a stubbed ssh, and confirmed the rendered remote script parses as bash and substitutes PUBLIC_URL, the Caddy domain, and the dashboard's allowlist correctly.
  • Confirmed the host-side $(uname -m) in the Caddy block survives heredoc escaping and evaluates on the host rather than locally.
  • Arch guard verified both ways, plus a non-ELF payload: matching arch proceeds, mismatch aborts with exit 1 and the correct rebuild hint before anything is shipped.
  • ELF e_machine probe verified against a real x86-64 binary and synthesized aarch64, LoongArch and big-endian headers.
  • Verified against src/main.rs that /version reports the field as commit.
  • The on-prem ship path can only be tested by merging. No runner other than the real one can exercise it.
  • Not verified: the real ARCH=amd64 container build — no Docker daemon in the authoring sandbox. The arm64 path is unchanged from what has been deploying green.
  • Not run: cargo build / cargo test / clippy — no Rust source changed.

Checklist

  • I have read the Contributing guidelines.
  • Docs (README / comments) updated for any user-visible change.
  • No secrets, credentials, or internal-only information are included.

Required before merge

Update the DEPLOY_HOST repository secret to staging's private address. The ship job runs inside the VPN, so the current public value is unreachable from there and the first run after merge fails at the SSH step.

(Retrospect: this was the right instruction and it did not stick. DEPLOY_HOST was later set to staging's public FQDN, so staging's deploys travelled over the internet rather than the VPN for some time — undetected until the public interface stopped permitting 22. The requirement is now stated on the secret's own description in deploy-native.yml, per #102.)

Once a deploy goes green from on-prem, 22/tcp can be revoked from 0.0.0.0/0 and ::/0 on imcp2-web and replaced with an SSH group scoped to the runner's range. Superseded — the ::/0 half was removed, and revoking the 0.0.0.0/0 half broke the deploy, because the runners present no stable range to scope a group to. What actually closed the internet path was separating the public-facing and deploy network interfaces onto different security groups. See #91.


Generated by Claude Code

Staging was the only reason any host in this VPC needed SSH open to the public
internet: its deploy ran on GitHub-hosted runners, which can reach it no other
way, so the shared security group carries 22/tcp from 0.0.0.0/0 and ::/0.
Restricting that to GitHub's ranges is not viable — Actions runners egress from
Azure prefixes numbering in the thousands and rotating, well past the
per-group rule limit. Reaching the host over the VPN instead removes the
requirement rather than trying to narrow it.

That needs the deploy split in two. Building still wants Docker and a few
minutes of Rust compile, which does not belong on an on-prem runner; shipping
needs only ssh and tar. So the mechanics move into a reusable workflow with a
`build` job on hosted infrastructure and a `ship` job wherever the target is
reachable, and only the finished binary crosses into the private network. The
ship runner's own architecture is irrelevant — it never executes the binary.

Make the build target-architecture aware while here. build.sh hardcoded
linux/arm64 and deploy.sh always fetched an arm64 Caddy, so pointing either at
an x86_64 host produced a unit that installed cleanly and then crash-looped on
"Exec format error" — a failure that reads like an app bug rather than a
build-target mistake. build.sh now honours $ARCH, deploy.sh derives Caddy's
architecture from the host's uname, and it compares the binary's ELF e_machine
against the host before shipping anything, so a mismatch aborts with the exact
rebuild command instead of taking the service down.

After each deploy the ship job reads GET /version on the host and asserts the
reported commit matches what was built, so a restart that silently kept the old
binary fails the run instead of passing quietly. It reads over SSH from the host
so this works even when the domain does not resolve from the runner.

DEPLOY_HOST must change to the host's private address before this lands, or the
ship job will try to reach the old public address from inside the VPN.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01R8ZshwKmjD5fZ4Hs9dS6zh
@aterga aterga mentioned this pull request Jul 27, 2026
6 of 9 tasks
@aterga
aterga requested a review from Copilot July 27, 2026 19:14
@aterga
aterga marked this pull request as ready for review July 27, 2026 19:15
@aterga
aterga requested a review from a team as a code owner July 27, 2026 19:15

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the native (Docker-free) staging deploy so the build happens on a GitHub-hosted runner while the “ship” step runs on a self-hosted on-prem runner that can reach the staging host over its private/VPN address, eliminating the need for public inbound SSH. It also hardens deploy correctness by adding architecture targeting/verification and post-deploy version verification.

Changes:

  • Introduces a reusable deploy-native.yml workflow split into build (hosted) and ship (reachability-constrained) jobs, and updates deploy.yml to call it for staging.
  • Adds ARCH support to deploy/native/build.sh, updates deploy/native/deploy.sh to download the correct Caddy arch and to validate the shipped binary’s arch vs the host.
  • Expands native deploy documentation, including dual-stack reachability caveats and the build/ship model.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
deploy/native/README.md Updates deploy docs to reflect build/ship split, arch support, and dual-stack reachability guidance.
deploy/native/deploy.sh Adds ELF/arch checks before shipping and downloads the correct Caddy binary for the host arch.
deploy/native/build.sh Adds ARCH selection/normalization and threads it through the container build platform.
.github/workflows/deploy.yml Switches staging deploy to call the reusable workflow and ships from the on-prem runner.
.github/workflows/deploy-native.yml New reusable workflow implementing the two-job build/ship deploy with post-deploy /version verification.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread deploy/native/deploy.sh Resolved
Comment thread .github/workflows/deploy-native.yml Resolved
Comment thread deploy/native/README.md Resolved
Comment thread .github/workflows/deploy-native.yml Resolved
Match all four ELF magic bytes in deploy.sh rather than the three that
follow the leading 0x7F. The old check skipped byte 0, so a payload whose
2nd-4th bytes spelled "ELF" passed it; verified end-to-end against a
stubbed ssh that such a file is now rejected before anything ships, while
a real binary still passes and a genuine arch mismatch still aborts with
the rebuild hint.

Two comments in deploy-native.yml overclaimed. The header said the build
job runs on a GitHub-hosted arm64 runner when it runs on whatever
inputs.build_runs_on names, which normally tracks inputs.arch. The
supply-chain note said third-party actions are pinned to a commit SHA
while setup-node, upload-artifact and download-artifact all float on a
major tag; the comment now describes what is actually pinned rather than
the intent. Pinning the remaining three needs SHAs not recorded anywhere
in this repository, so that stays a follow-up.

Also add the missing "that" in the per-arch assembly paragraph.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01R8ZshwKmjD5fZ4Hs9dS6zh

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Comment thread .github/workflows/deploy-native.yml Resolved
Comment thread .github/workflows/deploy.yml Resolved
Both workflow headers pointed at deploy-release.yml, which this branch does
not add — it arrives with the production release-tag workflow. Standing
alone the references dangle, and this branch is meant to merge first and
prove the on-prem ship path on staging before production follows, so the
window where they point at nothing is not necessarily short.

Describe what is actually here instead: deploy.yml is the one caller, and
the mechanics are parameterised by environment, runner and architecture so a
second caller can drive production without duplicating them. The comments
name deploy-release.yml again in the branch that adds it.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01R8ZshwKmjD5fZ4Hs9dS6zh
Copilot AI review requested due to automatic review settings July 27, 2026 19:28
@aterga
aterga merged commit b17d484 into main Jul 27, 2026
2 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Comment thread .github/workflows/deploy-native.yml Resolved
Comment thread deploy/native/README.md Resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants