Skip to content

fix: spored installs and runs on EL8 and SELinux-enforcing AMIs (#1052, #1056) - #1174

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/1052-1056-spored-install-el
Oct 19, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/1052-1056-spored-install-el

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Two bugs that stopped spored from starting on Enterprise Linux. Each one left the instance running with no TTL, no cost limit and no --on-complete, so it billed until someone terminated it by hand.

Fixes #1052
Fixes #1056

#1056: EL8 (Rocky/RHEL 8), curl 7.61.1

Cause. All four downloads in the shared installer (pkg/sporedinstall) used curl ... --retry-all-errors. That flag was added in curl 7.71 (#462 added it so that a transient Empty reply from server would be retried). EL8 ships curl 7.61.1, which exits 2 on the unknown option. The installer hid curl's stderr, so every source was reported as Failed to download ... from any source, and the bootstrap aborted.

Fix. A spore_curl_retry <retries> <delay> <curl args...> shell function now does the retrying. It makes up to retries+1 attempts, sleeps a fixed delay between them, and retries on any error, which is the semantics of --retry N --retry-delay D --retry-all-errors. The call sites keep the same numbers as before: 3/1 for the .sig HEAD probe, 5/2 for the binary, .sha256 and .sig. Two changes:

  • Exit 2 (usage error) stops retrying, since repeating it cannot help.
  • The final attempt keeps stderr, so a usage error is no longer reported as a network failure. That is what hid this bug.

Plain curl --retry without --retry-all-errors was not an option. It does not retry exit 52, and the new transient-failure test fails against it (see below).

#1052: SELinux enforcing (Rocky 9)

Cause. The binary is downloaded to mktemp /tmp/spored.XXXXXX, which cloud-init labels cloud_init_tmp_t, and then mv'd into /usr/local/bin. mv keeps the source's label, and systemd (init_t) cannot exec a cloud_init_tmp_t file. The result was status=203/EXEC on every restart.

Fix. A spore_selinux_relabel <path...> function runs restorecon -Fv when restorecon exists and selinuxenabled does not say no. It warns rather than failing, because the binary is already verified and in place. It is called:

  • in the installer, after the rename, on /usr/local/bin/spored;
  • after every place that writes /etc/systemd/system/spored.service, before systemctl start: the boot bootstrap and both app user-data cores;
  • on the spawn upgrade-spored rollback, which also renames a /tmp backup into place.

The install still uses rename + relabel rather than install -m 0755. The rename is atomic, so it cannot hit ETXTBSY (#27) and there is never a moment with no binary, or a partial one, at the destination. GNU install unlinks the old file and then writes the new one in place.

Hosts without restorecon (Ubuntu), or with SELinux disabled, are unaffected. On AL2023 (SELinux permissive) restorecon runs and sets the default bin_t label, which does no harm.

Gates

Per CLAUDE.md "Writing a gate". Each one was watched failing against a revert that compiles.

Gate What it asserts Revert it failed against
internal/curlcompat (new) The curl 7.61.1 option set, parsed from the real curl --help of rockylinux:8 (committed, embedded), not written from memory. A test pins known members and known newer options so a broken parse can't pass vacuously. n/a (helper)
cmd/TestNoCurlOptionNewerThanEL8 Every curl command line (comment lines skipped) in (a) every non-test .go file in the module, nested lambda/ modules included, found by walking the tree, and (b) all 7 rendered Linux scripts uses only 7.61.1 options. Fails if it finds fewer than 20 invocations, or any rendered script has none. Old curl ... --retry-all-errors line restored: fails in the source sweep and in all 7 rendered scripts. --retry-all-errors passed through the wrapper (only visible after Sprintf): fails in the rendered sweep.
pkg/sporedinstall/TestInstallsWithEL8Curl Runs the real installer with a fake curl 7.61.1 on PATH. The fake accepts exactly the parsed option set, exits 2 like 7.61.1 does on anything else, and otherwise execs the real curl. TestEL8CurlShimRejectsANewerOption checks that the fake actually rejects a newer option. Old binary-download line: exit 1, nothing installed.
pkg/sporedinstall/TestRetriesATransientEmptyReplyOnEveryFetch The fixture drops the connection with no reply (curl 52) on the binary, .sha256, .sig HEAD and .sig GET; the install must still succeed (#462 kept). Loop disabled (single attempt): fails. Native curl --retry N --retry-delay D without --retry-all-errors: fails, so plain --retry does not cover this.
pkg/sporedinstall/TestRelabelsTheInstalledBinaryForSELinux A fake restorecon records its arguments and whether the target was already installed. Four cases: enforcing (-Fv <dest> after install), SELinux disabled (not called), restorecon failing (install exit 0 with a WARNING), no restorecon (no-op). Relabel line removed: fails. Relabel moved before the rename (relabels the temp file, which mv then carries over): fails.
cmd/TestEveryScriptRelabelsSporedForSELinux Every rendered script that installs spored defines the relabel function. Every script that writes the spored unit (heredoc found by an anchored regex, at least 3 expected) runs spore_selinux_relabel /etc/systemd/system/spored.service after the heredoc and before systemctl start spored. The upgrade rollback line relabels. Bootstrap unit relabel removed; the DCV core's relabel moved after systemctl start; rollback relabel removed. Each fails.

pkg/launcher's existing #462 retry assertions now match the wrapper calls instead of the flag string.

Validation

  • Real EL8 / EL9 containers, no network or AWS. The rendered installer was run in rockylinux:8 (curl 7.61.1, openssl installed for the signature step) and rockylinux:9 (curl 7.76.1), using file:// sources and a throwaway P-256 key. On both: a missing source is skipped, the checksum and signature are verified, the binary is installed and runs. On EL8, spore_curl_retry 3 1 --retry-all-errors ... prints curl: option --retry-all-errors: is unknown and returns 2, which shows the final-attempt stderr is visible. On rockylinux:9 with policycoreutils installed, selinuxenabled returns 1 inside the container and the install is the expected no-op.
  • shellcheck (-S warning): clean on all 7 rendered scripts. The standalone installer is clean at every severity.
  • Not verified: a real SELinux-enforcing boot. Containers cannot run enforcing, and this PR touches no AWS. The relabel behaviour is covered by the shim tests. The cause and the remedy (restorecon -F gives bin_t) come from the issue's on-instance evidence and the sclero workaround, which uses the same command.

Found while doing this and filed as #1173: the pipeline-orchestrator Lambda installs spored with its own inline curl, sha256 only, and the verified-installer gate does not walk lambda/.

@scttfrdmn scttfrdmn added this to the v0.135.2 milestone Oct 19, 2026
#1056)

EL8 (#1056): the shared installer used curl --retry-all-errors (curl 7.71+);
EL8's curl 7.61.1 exits 2 on it, every download "failed", and the bootstrap
aborted with no spored, so no TTL or cost limit. Retries now go through a
portable spore_curl_retry loop with the same semantics (#462), which stops on
a usage error and shows curl's stderr on the final attempt.

SELinux (#1052): spored was renamed into place from /tmp, keeping cloud-init's
cloud_init_tmp_t label, which systemd cannot exec on an enforcing host. The
installer now runs restorecon on the binary after the rename, and every script
that writes the spored unit, plus the upgrade rollback, relabels too. It is a
no-op without SELinux.

Gates: internal/curlcompat parses curl 7.61.1's real --help (captured from
rockylinux:8). Every curl command in the module's Go source and in every
rendered Linux script is checked against it. The installer runs under a fake
7.61.1 curl, survives empty-reply drops on every fetch, and is checked for the
relabel with a fake restorecon. Each gate was watched failing against a
compiling revert.

Fixes #1052
Fixes #1056
@scttfrdmn
scttfrdmn force-pushed the fix/1052-1056-spored-install-el branch from 889f755 to 0b8cf18 Compare October 19, 2026 04:39
@codecov

codecov Bot commented Oct 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.81443% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/curlcompat/curlcompat.go 87.23% 4 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit cfa8e5f into main Oct 19, 2026
8 checks passed
@scttfrdmn
scttfrdmn deleted the fix/1052-1056-spored-install-el branch October 19, 2026 04:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant