Skip to content

Converge the HashiCorp APT key before apt_update (development) - #304

Merged
akuzminsky merged 2 commits into
mainfrom
hashicorp-keyring-converge
Oct 3, 2026
Merged

akuzminsky merged 2 commits into
mainfrom
hashicorp-keyring-converge

Conversation

@akuzminsky

Copy link
Copy Markdown
Member

Phase 1 of 3 for the HashiCorp signing-key rotation. Development environment only.

  1. This PR: puppet-code converges the HashiCorp key, in environments/development only.
  2. terraform-aws-terraformer drops its bundled DEB-GPG-KEY-hashicorp and the extra_repos entry. Its CI runs against environment = "development", so a green test proves this change.
  3. Promote to modules/ (production).

Why

HashiCorp rotated its Linux package signing key on 2026-09-09 (HCSEC-2026-33), AA16FCBCA621E701 to FC9CA96ACA026560. There was no notice, no overlap period, and the old key does not sign the new one. InRelease is now signed by the new key only.

terraform-aws-terraformer bundles the 2023 key and cloud-init seeds it, so every terraformer fails:

Error: /Stage[init]/Apt::Update/Exec[apt_update]: '/usr/bin/apt-get update' returned 100 instead of one of [0]
Warning: /Stage[main]/Profile::Infrahouse_repo/Exec[profile::infrahouse_repo::converge]: Skipping because of failed dependencies
...

apt_update runs in stage init on every run, and when it fails all of stage main is skipped, including anything there that could have fixed the key. A pinned key cannot survive an emergency rotation like this one, so trust has to move to TLS on the key URL. That is what HashiCorp's own install instructions do, and it is what profile::infrahouse_repo already does for our own key.

What changed

  • profile::hashicorp_repo (new), declared by profile::terraformer with stage => init and ordered before => Class['apt::update']:
    • converges /etc/apt/keyrings/hashicorp.gpg from https://apt.releases.hashicorp.com/gpg on every run
    • rewrites /etc/apt/sources.list.d/hashicorp.list. That is the file cloud-init's extra_repos seed writes (verified in cc_apt_configure.add_apt_sources) and the path HashiCorp's docs use. Rewriting it avoids a second line with a different signed-by, which apt rejects with "Conflicting values set for option Signed-By"
    • removes the stale /etc/apt/cloud-init.gpg.d/hashicorp.gpg
  • converge-apt-keyring.sh (new) works like converge-infrahouse-keyring.sh, but takes the URL and keyring path as arguments, with two behaviour differences:
    • A failed fetch keeps an installed keyring (warns, exits 0). This runs ahead of apt_update, so failing would skip the whole run over a HashiCorp outage the existing key may well survive. With no keyring installed it fails.
    • Fingerprints are logged on a key change (logoutput => true; check keeps steady state silent), so a rotation is visible in the Puppet log.
    • Also: --proto =https --proto-redir =https, since trust is anchored on TLS. The fetched key must parse as an OpenPGP public key.

Verification

puppet-lint --fail-on-warnings and shellcheck are clean.

The script was run through 12 cases in ubuntu:noble. All behaved as intended:

Case Exit
check / apply, no keyring 1 / 0 (installs D55C…6560)
check / apply, in sync 0 / 0 (silent)
check / apply, stale 2023 key 1 / 0 (replaces it)
404, keyring present apply 0 with WARNING, check 1
404 / HTML page / http://, no keyring 1
bad usage 2

Puppet 8.4.0 + puppetlabs-apt 9.4.0 in ubuntu:noble, with a wrapper shaped like profile::terraformer. The container was seeded with cloud-init's 3.x state (old key at /etc/apt/cloud-init.gpg.d/hashicorp.gpg), and apt-get update exited 100. One Puppet run then healed it:

/Stage[init]/Profile::Hashicorp_repo/Exec[profile::hashicorp_repo::converge]/returns: Installed /etc/apt/keyrings/hashicorp.gpg ... fingerprint(s):
/Stage[init]/Profile::Hashicorp_repo/Exec[profile::hashicorp_repo::converge]/returns: D55C0D1AC78A8D8126CB631CFC9CA96ACA026560
/Stage[init]/Profile::Hashicorp_repo/File[/etc/apt/sources.list.d/hashicorp.list]/content: content changed ...
/Stage[init]/Profile::Hashicorp_repo/File[/etc/apt/cloud-init.gpg.d/hashicorp.gpg]/ensure: removed
/Stage[init]/Apt::Update/Exec[apt_update]/returns: executed successfully
/Stage[main]/Test_terraformer/Package[terraform]/ensure: created

Afterwards apt-get update exited 0. A second run touched no HashiCorp resources. A fresh container with no seed (the phase 2 state) gave the same result.

The container used a wrapper, not the full role. The end-to-end proof is phase 2's CI run.

Not covered

  • Already-broken hosts. Their Puppet is stuck in stage init, so they need the key fixed by hand once (or replacement) before this can reach them.
  • profile::infrahouse_repo converges in stage main, so it has the same blind spot for our own key: an expired or non-overlapping rotation of the InfraHouse key would wedge the same way (see the skipped converge above). Separate follow-up.

🤖 Generated with Claude Code

HashiCorp rotated its package signing key on 2026-09-09 (HCSEC-2026-33) with
no overlap and no cross-signature. Terraformers seeded with the old key by
cloud-init fail apt_update in stage init, which skips all of stage main.

profile::hashicorp_repo re-fetches the key from apt.releases.hashicorp.com on
every run, in stage init and before Class['apt::update'], so a rotation heals
on the next Puppet run. Development environment only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@akuzminsky
akuzminsky merged commit ff5be29 into main Oct 3, 2026
2 checks passed
@akuzminsky
akuzminsky deleted the hashicorp-keyring-converge branch October 3, 2026 18:21
akuzminsky added a commit that referenced this pull request Oct 3, 2026
…oduction) (#305)

Straight promotion of #304, proven end to end by
infrahouse/terraform-aws-terraformer#42: with the module no longer seeding the
HashiCorp repository, a development-environment terraformer got Terraform from
apt.releases.hashicorp.com via profile::hashicorp_repo.

All three copies of hashicorp_repo.pp, converge-apt-keyring.sh and
terraformer.pp are now identical.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

2 participants