Skip to content

github_runner: register through ih-github runner register, over SSM or from the secret (SEC-46 slice 3, PR 3 of 5) - #307

Merged
infrahouse8 merged 3 commits into
mainfrom
aleks/sec-46-slice-3-1-puppet-code
Nov 30, 2026
Merged

infrahouse8 merged 3 commits into
mainfrom
aleks/sec-46-slice-3-1-puppet-code

Conversation

@akuzminsky

@akuzminsky akuzminsky commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

SEC-46, slice 3, PR 3 of 5 (puppet-code). Design: the note, the answers and the approval, unchanged.

PR Repository Change State
1 infrahouse-core The delivery protocol, both halves infrahouse-core#163, released as 1.5.0
2 infrahouse-toolkit ih-github runner register --registration-token-delivery ssm|secret|github infrahouse-toolkit#277, released as 2.70.0
3 puppet-code One exec per path that calls the toolkit this PR
4 terraform-aws-actions-runner The Lambda delivers over SSM; the instance role loses the secret grants after this PR is published
5 aws-control-303467602807, then -493370826424 The pools on the new module version after the module release

Why

Today any job on a runner can read the pool's pending registration tokens, because the instance role reads <registration_token_secret_prefix>-<instance id> from Secrets Manager. In slice 3 the registration Lambda delivers the token over SSM instead, and the role loses both Secrets Manager grants (PR 4).

This PR first added the instance's side as a bash script, gha-register-runner.sh, copied into the three trees and not unit-tested (approved at 549b618). Aleks then decided that the protocol lives in infrahouse-core and that the instance's half runs through the toolkit (SEC-46, "Where the code lives", step 3). Both are released: infrahouse-core 1.5.0 and infrahouse-toolkit 2.70.0, which is in release-noble.infrahouse.com for amd64 and arm64. So Puppet now only calls the toolkit.

What changes

profile::github_runner::register has one exec { 'register_runner': } per path. The fact registration_token_delivery chooses the path: profile::github_runner reads it with pick_default(…, 'secret'), and the class takes Enum['ssm', 'secret'] $token_delivery. Both are unchanged from the first round, so a pool on terraform-aws-actions-runner 6.1.0 or older, which doesn't set the fact, keeps the secret path.

  • ssm. The exec runs as root, because only root can read the delivery key:

    /usr/local/bin/ih-github runner register --registration-token-delivery ssm \
        --registration-token-wait 300 --runner-user github-runner \
        --actions-runner-code-path /tmp/actions-runner-linux --label … <url>
    

    The toolkit waits for the ciphertext, decrypts it in memory, runs config.sh as github-runner with the token only in ACTIONS_RUNNER_INPUT_TOKEN, and deletes the key and the ciphertext whatever happens. A runner that already registered with a delivered token (the marker) exits 0. Any failure exits non-zero: Puppet fails, and the bootstrap lifecycle hook abandons the instance. creates => <dir>/.credentials, as in the first round. timeout => 420: the 300 s wait plus config.sh, inside the hook's 1200 s.

  • secret. The exec runs as github-runner, as today:

    /usr/local/bin/ih-github runner --registration-token-secret <prefix>-<instance id> --org <org> register \
        --registration-token-delivery secret --actions-runner-code-path /tmp/actions-runner-linux --label … <url>
    

    The toolkit reads the secret, runs config.sh with the token in ACTIONS_RUNNER_INPUT_TOKEN (before 2.70.0 it was in argv), and deletes the secret after a successful registration. A failed delete only warns. A failed registration leaves the secret for the next run.

On both paths no token is on the exec's command line.

Removed: gha-register-runner.sh (all three copies), the file resource that installed it as /usr/local/sbin/gha-register-runner, and the delete_registration_token exec. The toolkit deletes the secret itself. No Puppet run ever installed the script, because no module version sets the fact yet. So no host has a copy to remove.

The toolkit version. Both execs require => Package['infrahouse-toolkit']. profile::infrahouse_toolkit declares that package with ensure => latest. profile::repos runs apt-get update in stage init on every run. The release repository keeps every version, and Puppet never downgrades. So once the package resource is in sync, the toolkit is the repository's latest, 2.70.0 or later. If the package resource fails, Puppet skips the exec. The register class includes profile::infrahouse_toolkit itself, so the reference resolves even where a role doesn't include profile::base. role::github_runner includes both today. Without the require, only Puppet's default manifest ordering put the package first: profile::base comes before profile::github_runner in the role.

path. The command is /usr/local/bin/ih-github, where the toolkit's .deb links it (packaging/nfpm.yaml at v2.70.0: /opt/infrahouse-toolkit/embedded/bin/ih-github → /usr/local/bin/ih-github). path => '/usr/local/bin:/usr/bin:/bin'. config.sh gets its own PATH from the toolkit (CONFIG_PATH). The runner directory is no longer on the secret exec's path: nothing runs from there by its bare name.

Labels. One --label per label, the form the toolkit's --label takes (multiple=True): the Hiera labels, instance_id:<id> and the fact labels. Empty labels are dropped. This fixes a bug in today's code: '' is true in Puppet, so if $label kept it, and the command got a bare --label, which takes the next word as its value. undef was already dropped, and still is.

Docs. The class's header and @params describe the two paths as above. The script isn't mentioned.

The trees. modules/profile and both environments' copies differ only where they differed on main before this PR: apt_lock_timeout.pp exists only in the environments, and repos.pp differs (diff -rq).

debian/changelog: one new entry, 0.1.0-1build338, after the first round's build337. I wrote it by hand in dch -R's format, because hooks/pre-commit runs make bumpversion in Docker, which isn't available where this was written.

Checks

  • puppet-lint --fail-on-warnings on the four paths in hooks/pre-commit (modules/profile, modules/role, environments/development/modules/profile, environments/sandbox/modules/profile):
    • 2.5.2: clean.
    • 4.3.0 and 5.1.1: they report space_before_arrow only in base.pp, elastic/prometheus.pp and teleport/packages.pp and their copies. This PR doesn't touch those files, and the reports are the same on main.
    • 5.1.1 on the three changed register.pp: clean.
  • puppet parser validate (Puppet 8.10.0) on the three changed manifests: clean.
  • A scratch catalog (Puppet 8.10.0) of profile::github_runner::register, with the real profile::infrahouse_toolkit, a stub Exec[extract_runner_package] and stub facts (instance i-0123456789abcdef0, fact labels [noble, "", awesome]):
    • registration_token_delivery: ssm:
      Exec[register_runner]
        user: (none, so root)
        path: /usr/local/bin:/usr/bin:/bin
        cwd: /tmp/actions-runner-linux
        command: /usr/local/bin/ih-github runner register --registration-token-delivery ssm --registration-token-wait 300 --runner-user github-runner --actions-runner-code-path /tmp/actions-runner-linux --label self-hosted --label Linux --label instance_id:i-0123456789abcdef0 --label noble --label awesome https://github.com/infrahouse
        creates: /tmp/actions-runner-linux/.credentials
        timeout: 420
        require: ["Exec[extract_runner_package]", "Package[infrahouse-toolkit]"]
      
    • the fact absent (the same with secret):
      Exec[register_runner]
        user: github-runner
        path: /usr/local/bin:/usr/bin:/bin
        cwd: /tmp/actions-runner-linux
        command: /usr/local/bin/ih-github runner --registration-token-secret registration-token-i-0123456789abcdef0 --org infrahouse register --registration-token-delivery secret --actions-runner-code-path /tmp/actions-runner-linux --label self-hosted --label Linux --label instance_id:i-0123456789abcdef0 --label noble --label awesome https://github.com/infrahouse
        creates: /tmp/actions-runner-linux/.credentials
        require: ["Exec[extract_runner_package]", "Package[infrahouse-toolkit]"]
      
    • In both, no Exec[delete_registration_token] and no File[/usr/local/sbin/gha-register-runner].
    • puppet apply --noop of the same code applies Exec[extract_runner_package], then Package[infrahouse-toolkit], then Exec[register_runner], with either fact.
  • The commands against the toolkit. I ran both rendered commands with infrahouse-toolkit 2.70.0 from PyPI, as root, on a scratch host with no runner user and no AWS access. The ssm command ran with --registration-token-wait 0 instead of 300. Both parse and reach the registration, which fails as it should there, with exit 1: "There is no user github-runner to run config.sh as." and an invalid-credentials GetSecretValue error. Neither got exit 2, the usage error. With 2.69.0 both exit 2, No such option '--registration-token-delivery', before any secret or delivery is read. So a host with an old toolkit fails closed and the instance is abandoned. No token is exposed.
  • CI (CI.yml) builds the .deb for noble. Its result on the head commit is in the Ready for review comment.

After merge

CD (CD.yml, on push to main) builds the package and publishes it to infrahouse-release-noble. To check that the published package has the change:

curl -s https://release-noble.infrahouse.com/dists/noble/main/binary-amd64/Packages \
  | grep -A3 '^Package: puppet-code$' | grep '^Version:'
# expect Version: 0.1.0-1build338 among them; then download that package and:
dpkg-deb -c puppet-code_0.1.0-1build338_all.deb | grep -c gha-register-runner   # expect 0

Nothing changes on the running pools. No module version sets the fact yet, so new runners take the secret path through the toolkit until PR 4 ships. Runners that are already registered have .credentials, so the exec doesn't run on them.

Next step

Aleks: merge, and check that CD published 0.1.0-1build338. Then PR 4 (terraform-aws-actions-runner) sets the fact registration_token_delivery to ssm and takes the secret grants off the instance role. Its CI must run after this package is published.

decided

  • decided: --registration-token-wait 300 is passed explicitly. It's the toolkit's default too. Passing it puts the number next to the timeout => 420 that must cover it, and a later change of the toolkit's default can't push the wait past the timeout.
  • decided: the toolkit version is guaranteed with require => Package['infrahouse-toolkit'], and the register class includes profile::infrahouse_toolkit. There's no Depends: infrahouse-toolkit (>= 2.70.0) in debian/control and no separate version-check exec. With ensure => latest, the require already means "the repository's latest", and 2.70.0 is in the repository. An older toolkit fails the exec with a usage error (exit 2) before it reads a token, so it fails closed. A package dependency would change every host's packaging for one role.
  • decided: the command is the absolute /usr/local/bin/ih-github, and path is set too, with /usr/local/bin first. An ih-github from an older pip install elsewhere on PATH can't be the one that runs.
  • decided: the secret exec keeps --org <org>, which the toolkit ignores on that path. The command stays today's plus --registration-token-delivery secret. The ssm exec doesn't pass --org.
  • decided: the options come before the URL on both paths. Click accepts either order. One --label per label, as the toolkit takes them.
  • decided: an empty label is dropped explicitly ($label =~ NotUndef and $label != ''). Today's if $label didn't drop it.
  • decided (from the first round, unchanged): the fact chooses the path, defaulting to secret. Aleks owns removing the secret path, with the module's 7.0.0. (design)

https://claude.ai/code/session_01GsX4weCxwCX7Lncqv3YhBB


Generated by Claude Code

…M (SEC-46)

SEC-46 slice 3 takes the registration-token secrets away from the runner's
instance role, which every job on the runner can use. In the new design the
pool's registration Lambda delivers the token over SSM instead: it is
encrypted to an RSA key that the instance makes for this delivery, in a
ramfs at /run/gha-registration.

profile::github_runner::register now has two paths, chosen by the fact
registration_token_delivery:

- "ssm", set by terraform-aws-actions-runner versions that deliver over
  SSM: /usr/local/sbin/gha-register-runner (root, 0700) waits for the
  ciphertext and decrypts it in memory (RSA-OAEP, SHA-256). It runs
  config.sh as github-runner with the token in ACTIONS_RUNNER_INPUT_TOKEN,
  not in argv. It deletes the key and the ciphertext on every exit, and on
  success leaves a marker that makes the Lambda's commands refuse to
  deliver again.
- otherwise: unchanged. ih-github reads the secret
  <registration_token_secret_prefix>-<instance id>, and Puppet deletes it.
  This is how module 6.1.0 and older deliver the token.

The same change is in the sandbox and development environments' copies.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GsX4weCxwCX7Lncqv3YhBB

Copy link
Copy Markdown
Member Author

Ready for review: 549b618

First round. CI on this commit is green:

  • test (noble) built puppet-code_0.1.0-1build337_all.deb.
  • vulnerability-check / osv-scan passed.

Lintian's dir-or-file-in-opt (E) and script-not-executable (W) on gha-register-runner.sh are the same messages it gives for every file under /opt/puppet-code: 634 and 30 hits, gha_prerun.sh included. They don't fail the build, and Puppet sets the installed script's mode to 0700.

What to look at:

  • modules/profile/manifests/github_runner.pp: the fact, defaulting to secret;
  • modules/profile/manifests/github_runner/register.pp: both paths, and the secret path's code is unchanged;
  • modules/profile/files/github_runner/gha-register-runner.sh: the lock, the ramfs check, the EXIT trap, rsa_mgf1_md:sha256, the token in the environment only, and the marker;
  • both environments' copies, identical by diff -r;
  • debian/changelog → 0.1.0-1build337.

Generated by Claude Code

Copy link
Copy Markdown
Member Author

Approved 549b618

What I checked:

  • Puppet. The fact defaults to secret, and that path's commands are byte-for-byte today's. Enum['ssm', 'secret'] fails closed on any other value. The modules/ change and both environments' copies are identical (diff -r). puppet-lint --fail-on-warnings (5.1.1) and puppet parser validate pass on the changed manifests. The ssm exec's command renders with no token in it. shellcheck is clean, the changelog moves to 0.1.0-1build337, and CI's test (noble) built the package on this sha.
  • The script, run on a real ramfs with a ciphertext made by cryptography's OAEP(SHA-256, MGF1 SHA-256) and a stub config.sh running as an unprivileged user. The stub got the token in its environment only: neither its argv nor runuser's held it. key.pem and token.enc were gone afterwards, with only the marker left. A corrupt ciphertext exits 1 and deletes both files.

non-blocking: the EXIT trap is set after the wait, so when no delivery arrives in time, the script exits with key.pem still in place. The instance is abandoned and nothing untrusted runs on it, but setting the trap before the wait would make "every exit path" literally true.


Generated by Claude Code

infrahouse8 and others added 2 commits November 29, 2026 11:50
…hs (SEC-46)

SEC-46 slice 3, PR 3 of 5. The instance's half of the SSM delivery now
lives in infrahouse-core 1.5.0 and runs through infrahouse-toolkit 2.70.0's
`ih-github runner register`, so Puppet is one exec per path:

* ssm: as root (only root can read the delivery key), `ih-github runner
  register --registration-token-delivery ssm --registration-token-wait 300
  --runner-user github-runner ...`, timeout 420 s, creates .credentials.
* secret (the default, no fact): as github-runner, today's command plus
  `--registration-token-delivery secret`. The toolkit deletes the secret
  after a successful registration.

Removed: gha-register-runner.sh (all three copies), the file resource that
installed it, and the delete_registration_token exec.

Both execs call /usr/local/bin/ih-github, where the toolkit's .deb links
it, and require Package['infrahouse-toolkit'] (ensure => latest; the
register class includes profile::infrahouse_toolkit), so they run only
after Puppet brought the toolkit to the repository's latest, 2.70.0 or
later. Empty labels are dropped: '' is true in Puppet, so `if $label` kept
it and the command got a bare "--label".

Same change in modules/ and both environments' copies. debian/changelog
moves to 0.1.0-1build338, by hand (no Docker for `make bumpversion`).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GsX4weCxwCX7Lncqv3YhBB
@akuzminsky akuzminsky changed the title github_runner: register with the registration token delivered over SSM (SEC-46 slice 3, PR 1) github_runner: register through ih-github runner register, over SSM or from the secret (SEC-46 slice 3, PR 3 of 5) Nov 29, 2026

Copy link
Copy Markdown
Member Author

Ready for review: 509268d

The rework into PR 3 of 5 (SEC-46 slice 3). The approval of 549b618 doesn't cover this head. The description is rewritten for what the PR does now.

What changed since 549b618 (one commit, 509268d, on top of Aleks's merge of main at 80cf0fb):

  • gha-register-runner.sh is gone from all three trees, with its file resource. The delete_registration_token exec is gone too: the toolkit deletes the secret after a successful registration.
  • ssm: an exec as root, /usr/local/bin/ih-github runner register --registration-token-delivery ssm --registration-token-wait 300 --runner-user github-runner --actions-runner-code-path … --label … <url>, creates .credentials, timeout => 420.
  • secret (the default, no fact): as github-runner, today's command plus --registration-token-delivery secret.
  • Both execs require => Package['infrahouse-toolkit'] (ensure => latest). The class includes profile::infrahouse_toolkit.
  • Empty labels are now really dropped: '' is true in Puppet, so today's if $label kept it.
  • @param docs for every parameter. debian/changelog → 0.1.0-1build338, written by hand because there's no Docker here.

Your non-blocking point on 549b618 (the EXIT trap set after the wait): the script is gone. The toolkit's receiver (infrahouse-core 1.5.0) now does the cleanup. infrahouse-toolkit#277 records the one gap that's left: a SIGTERM during the wait leaves the root-only key on the ramfs for the next run.

CI on 509268d is green:

  • test (noble) built puppet-code_0.1.0-1build338_all.deb.
  • vulnerability-check / osv-scan passed.
  • Lintian lists no gha-register-runner.sh now. Its warnings are the same kind as before: script-not-executable on every other script under /opt/puppet-code, and syntax-error-in-debian-changelog on the build32–build34 entries from the jammy era.

What to look at:

  • modules/profile/manifests/github_runner/register.pp (the copies are identical). The rendered commands, users and requires from a scratch catalog are in the description, under "Checks".
  • Both rendered commands parse with toolkit 2.70.0. With 2.69.0 they fail with exit 2 before any token is read.
  • diff -rq between modules/profile and the environments shows only what main already differed in: apt_lock_timeout.pp and repos.pp.

https://claude.ai/code/session_01GsX4weCxwCX7Lncqv3YhBB


Generated by Claude Code

Copy link
Copy Markdown
Member Author

Approved 509268d

What I checked. I read the full diff against main and 80cf0fb..509268d. Both rendered commands parse against infrahouse-toolkit v2.70.0's Click options: the ssm exec has no user (root), passes --runner-user github-runner, --registration-token-wait 300 and no token; the secret exec runs as github-runner with the group's --registration-token-secret and --org before register. In my own scratch catalog (Puppet 8.10.0) both come out as described, including with the labels fact absent, and empty labels are dropped. The timeout => 420 covers the 300 s wait inside the 1200 s hook, and creates is .credentials. /usr/local/bin/ih-github matches packaging/nfpm.yaml, and both execs require Package['infrahouse-toolkit']. profile::repos runs apt update in the init stage, and the release repo has 2.70.0.

The fact still defaults to secret. puppet parser validate is clean on all six changed manifests. puppet-lint --fail-on-warnings reports only the space_before_arrow warnings in the untouched base.pp, elastic/prometheus.pp and teleport/packages.pp (and their copies), as on main. diff -rq between the trees shows only apt_lock_timeout.pp and repos.pp, as before. The three github_runner directories are identical, the script and its file resource are gone, and no other manifest references delete_registration_token. CI on this sha is green.

non-blocking: .claude/plans/actions-runner-scale-in-race.md still describes the removed delete_registration_token exec. It is a historical plan, so it can stay.
non-blocking: the toolkit's secret delete only warns on failure, where the old exec failed the Puppet run. A leftover secret then lives until its token expires, which the toolkit PR already decided.


Generated by Claude Code

@infrahouse8
infrahouse8 merged commit cf7c065 into main Nov 30, 2026
2 checks passed
@infrahouse8
infrahouse8 deleted the aleks/sec-46-slice-3-1-puppet-code branch November 30, 2026 00:52
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