carlos / platform Public

region HA P3b: install floor must be stated by the operator (census F1)

Bind the explicit SSM boot floor choice into the protected group marker.
Refuse absent floors unless the operator expects absence; always verify
published floors. Cover boot parsing, install behavior and the bypass mutation.
Co-Authored-By: GPT-6 Astra (codex) <noreply@openai.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev fe9693950030ac9a761eb871f324f42667b9b1e9 parent b68411f
9 files changed, +150 −39
  • docs/site/cli.md +1 −1
  • infra/modules/region-host/group-init.sh.tftpl +7 −2
  • internal/host/group_boot_budget_test.go +40 −11
  • internal/host/group_config_test.go +22 −1
  • internal/host/group_hairpin_rootrunner_linux_test.go +1 −1
  • internal/host/installchannel.go +10 −2
  • internal/host/installchannel_test.go +63 −19
  • internal/hostenv/group.go +5 −1
  • internal/hostenv/group_test.go +1 −1

Intent

Human

<task-notification> <task-id>bq9as4roe</task-id> <tool-use-id>toolu_01PufP5QzX6d8e4QwneutHMU</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/05c816f1-0a2d-43e3-9285-de8352549786/tasks/bq9as4roe.output</output-file> <status>completed</status> <summary>Background command "D=/home/paulca/amadan.net/carlos/platform/.claude/worktrees/region-ha-p3b-build/.superpowers/sdd/2026-11-04-region-ha-p3b-group; $D/wait-astra.sh cif $D/ci-fix-report.md" completed (exit code 0)</summary> </task-notification>

Human

<task-notification> <task-id>b75710xy5</task-id> <tool-use-id>toolu_01FDnq9fUwW9zQY7SQsArgdp</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/05c816f1-0a2d-43e3-9285-de8352549786/tasks/b75710xy5.output</output-file> <status>completed</status> <summary>Background command "D=.superpowers/sdd/2026-11-04-region-ha-p3b-group &amp;&amp; rm -rf $TMPDIR/rrwt &amp;&amp; git worktree add --detach $TMPDIR/rrwt b68411f2 &gt;/dev/null 2&gt;&amp;1 &amp;&amp; timeout 3000 nice -n 19 python3 -u $D/root-runner-nft.py --worktree $TMPDIR/rrwt --pkg ./internal/host --run '^TestHairpinKernelAgentTenantSidecar$' --tags rootrunner &gt; $D/rootrunner-cif.log 2&gt;&amp;1; echo "exit $?" &gt;&gt; $D/rootrunner-cif.log; git worktree remove --force $TMPDIR/rrwt; grep -E -- '--- (FAIL|PASS)|_test.go:|terminated|LEAKED|^exit' $D/rootrunner-cif.log | head -20" completed (exit code 0)</summary> </task-notification>

Human

<task-notification> <task-id>a9a4eff0de71f580b</task-id> <tool-use-id>toolu_01EX9ouFWYGpqV7ZKZvtJtr1</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/05c816f1-0a2d-43e3-9285-de8352549786/tasks/a9a4eff0de71f580b.output</output-file> <status>completed</status> <summary>Agent "Scoped check of CI fix diff" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>I found no P1 or P2 problems in the CI-fix diff (6c365b15..04ae3dfb). I ran one test, `go test ./internal/edge -run '^TestHairpinOriginalDestination$' -count=1`, and it passed. The full write-up is in `/home/paulca/amadan.net/carlos/platform/.claude/worktrees/region-ha-p3b-build/.superpowers/sdd/2026-11-04-region-ha-p3b-group/ci-fix-check.md`. **1. `internal/edge/hairpin.go`: OK.** - **Narrower peer set:** accepted peers are now loopback, `PrimaryIPv4` and `PublicIPs`. That is a strict subset of the old set (every interface address). The destination check (an ingress EIP on 80/443) is unchanged. - **No non-local peer can be marked:** - Off-box traffic never reaches the kernel with an EIP as its destination. AWS translates EIP traffic to the private IP, and source/dest check drops the rest. - A packet arriving from outside with a local or 127/8 source is dropped by the kernel as a martian. That holds because nothing in the tree sets `accept_local` or `route_localnet`. - IPv4-mapped IPv6 addresses are unmapped on both sides before comparison. - **Legitimate local callers still match:** root installs `local &lt;eip&gt;/32 dev carlos-hairpin src &lt;PrimaryIPv4&gt;` (`internal/hairpin/native_linux.go:293`). So any unbound socket in the host netns uses the primary as its source, whatever the ENI or secondary-address layout. If that route rewrite were lost, the source would be the EIP itself, which is also accepted. - **P3, behaviour change:** a caller that explicitly binds another source (a secondary IP, Tailscale, docker0) is now closed at accept. Before, it was marked. This fails closed, and no platform code binds that way. - **P3, removed boot assertion:** the edge no longer checks at boot that the primary IPv4 is assigned locally. The kernel still enforces it, because `ip route ... src &lt;primary&gt;` is refused when the primary is not local, so activation fails closed. - Nothing here falls in the A1/N1 family, so no rule-2 label is needed. The egress fence is untouched. **2. `internal/host/group_install.go`: OK.** - The region pin and the single SDK attempt (`RetryMaxAttempts = 1`) are unchanged. - `EnableChangeIndex` only takes effect on Put, Delete and similar writes. Every user of the group store only reads: `guardtransaction.go:194` and `:552`, `systemapply.go:2271`, and `fetchTo`. So boot still makes no index calls. - The classifier entry's count of 1 matches the one call. **3. `ReadGroupFileAt`: OK.** - `ReadGroupFile` still anchors at "/" (`internal/hostenv/group_linux.go:15-17`), and every check inside `readGroupFileAt` is unchanged. - Only tests call the exported variant, and the non-Linux version refuses. - **P3:** it is exported and does not check the anchor's own parent directories, and nothing stops a future root caller from using it. A guard allowing only test callers would close that off. **4. `plan14_generation_boot_test.go`: OK.** It is test-only and no production file in `internal/release` changed. The fixture now builds a consistent private-mount proof and adds three refusal cases (same namespace, missing lineage, substituted source). **Out of scope:** - The census refresh commit (b68411f2) changes only census docs and testdata. I didn't re-verify it. - The two console failures from the full gate are still open. - The host suite still depends on this machine's `carlos-devbox.service`. - No kernel-level test of hairpin source selection exists, so that conclusion rests on reading the code.</result> <usage><subagent_tokens>89260</subagent_tokens><tool_uses>16</tool_uses><duration_ms>195837</duration_ms></usage> </task-notification>

diff --git a/docs/site/cli.md b/docs/site/cli.md
index 0ac074954..20646aa0c 100644
--- a/docs/site/cli.md
+++ b/docs/site/cli.md
@@ -3023,7 +3023,7 @@ carlos system host-env write builds /etc/carlos/host.env from the deployment's p
For claim-free group boot, `host-env write --group --install` checks the root-owned group configuration, leaves out host-claim variables, writes the environment, then runs bootstrap and install-channel. The boot queue overrides a queue copied from a fixed box. Pools must be explicit and match the group configuration. `--install` requires `--group`.
-carlos system install-channel installs the release the box's channel names, as both carlos and carlos.prev, once it passes the published host floor. A box that already runs a release is refused: carlos system update moves it. A claim-free group can install when both the floor and its authorization are absent. A missing half or a failed read stops installation.
+carlos system install-channel installs the release the box's channel names, as both carlos and carlos.prev, once it passes the published host floor. A box that already runs a release is refused: carlos system update moves it. A claim-free group can install without a floor only when the operator sets `floor` to `absent-expected` in SSM `boot/bootstrap-object` and both the floor and its authorization are absent. The boot object requires `floor` to be `absent-expected` or `required`; root copies it into `/etc/carlos/group.json` and includes it in `config_digest`. A published floor is always verified. A missing half or a failed read stops installation.
With --policy FILE, the armed policy carlos system claims run sign-policy wrote, it installs before the host floor is published. The policy's floor stands in for the published one, and once a floor is published the two must be the same. It also arms a box that carlos system update has already moved to the channel's release: carlos is left as it is, and carlos.prev, the release before, is replaced by it, so guard-arm finds the release in both. A box on another release, or with an armed guard, is still refused.
diff --git a/infra/modules/region-host/group-init.sh.tftpl b/infra/modules/region-host/group-init.sh.tftpl
index 33281c1ef..df4abd22c 100644
--- a/infra/modules/region-host/group-init.sh.tftpl
+++ b/infra/modules/region-host/group-init.sh.tftpl
@@ -123,6 +123,11 @@ chronyc waitsync 20 2
# fetch verified bootstrap
# The three boot values are read once; ordinary SSM enumeration is separate.
+# Operator-seeded boot/bootstrap-object has exactly key, version, known_readers,
+# deployment_aws_region and floor. Terraform names this parameter but does not
+# write it. Set floor to required, or absent-expected only for a deployment with
+# no published floor. Root binds this choice in group.json's config_digest;
+# a published floor is always verified. Box roles cannot write this SSM value.
python3 - <<'PY'
import base64, datetime, hashlib, ipaddress, json, os, re, subprocess, time, urllib.request
E = os.environ
@@ -146,7 +151,7 @@ values = {p['Name']: p['Value'] for p in params}
if values[names[2]] != E['CARLOS_TERMINATION_QUEUE_URL']:
raise SystemExit('group_boot_queue')
obj = json.loads(values[names[0]])
-if set(obj) != {'key', 'version', 'known_readers', 'deployment_aws_region'} or not isinstance(obj['known_readers'], list) or len(obj['known_readers']) > 1000:
+if set(obj) != {'key', 'version', 'known_readers', 'deployment_aws_region', 'floor'} or obj['floor'] not in ('absent-expected', 'required') or not isinstance(obj['known_readers'], list) or len(obj['known_readers']) > 1000:
raise SystemExit('group_boot_object')
if not obj['key'].startswith('bootstrap/' + E['CARLOS_DEPLOYMENT'] + '/' + E['CARLOS_REGION'] + '/') or not obj['version'] or obj['version'] == 'null':
raise SystemExit('group_boot_object')
@@ -218,7 +223,7 @@ for ip in ips:
address = ipaddress.ip_address(ip)
if not public_v4(ip) or ip == public_ip:
raise SystemExit('group_boot_ingress')
-marker = dict(v=1, data_bucket=E['CARLOS_GROUP_DATA_BUCKET'], deployment_aws_region=obj['deployment_aws_region'], account=identity['accountId'], aws_region=E['AWS_REGION'], region=E['CARLOS_REGION'], deployment=E['CARLOS_DEPLOYMENT'], bucket=E['CARLOS_DEPLOYMENT_BUCKET'], group=E['CARLOS_GROUP_NAME'], hook=E['CARLOS_LAUNCH_HOOK_NAME'], placement=E['CARLOS_PLACEMENT_REGION'], pools=E['CARLOS_POOLS'].split(','), known_readers=obj['known_readers'], release=E['CARLOS_RELEASE'], instance_id=iid, boot_id=boot_id, deadline=deadline, queue_url=values[names[2]])
+marker = dict(v=1, floor=obj['floor'], data_bucket=E['CARLOS_GROUP_DATA_BUCKET'], deployment_aws_region=obj['deployment_aws_region'], account=identity['accountId'], aws_region=E['AWS_REGION'], region=E['CARLOS_REGION'], deployment=E['CARLOS_DEPLOYMENT'], bucket=E['CARLOS_DEPLOYMENT_BUCKET'], group=E['CARLOS_GROUP_NAME'], hook=E['CARLOS_LAUNCH_HOOK_NAME'], placement=E['CARLOS_PLACEMENT_REGION'], pools=E['CARLOS_POOLS'].split(','), known_readers=obj['known_readers'], release=E['CARLOS_RELEASE'], instance_id=iid, boot_id=boot_id, deadline=deadline, queue_url=values[names[2]])
marker['config_digest'] = hashlib.sha256(json.dumps(marker, sort_keys=True, separators=(',', ':')).encode()).hexdigest()
write('/etc/carlos/group.json', json.dumps(marker, separators=(',', ':')).encode())
# Verify the signed document against the root marker before publishing the
diff --git a/internal/host/group_boot_budget_test.go b/internal/host/group_boot_budget_test.go
index e02ee3dc9..ed6567e27 100644
--- a/internal/host/group_boot_budget_test.go
+++ b/internal/host/group_boot_budget_test.go
@@ -139,7 +139,7 @@ func groupInstallBudget(t *testing.T) {
for _, floor := range []string{"", "v1.2.0"} {
t.Run(floor, func(t *testing.T) {
f := newChannelFixture(t, floor)
- f.in.group = true
+ groupChannelMarker(t, f, "absent-expected")
s := &coldBudgetStore{Store: f.store}
f.a.openStore = func(context.Context) (release.Store, ed25519.PublicKey, error) { return s, f.pub, nil }
if _, err := f.in.run(t.Context()); err != nil {
@@ -278,6 +278,7 @@ func groupBootstrapBudget(t *testing.T) {
program := `
import ast, builtins, io, json, os, subprocess, hashlib, urllib.request, datetime
source = SOURCE
+floor = FLOOR
root='/carlos/dev/ie/boot/'
os.environ.update(dict(CARLOS_DEPLOYMENT='dev',CARLOS_REGION='ie',AWS_REGION='eu-west-1',CARLOS_BOOTSTRAP_OBJECT_KEY=root+'bootstrap-object',CARLOS_BOOTSTRAP_HASH_KEY=root+'bootstrap-sha256',CARLOS_TERMINATION_QUEUE_URL='queue',CARLOS_DEPLOYMENT_BUCKET='deploy',CARLOS_GROUP_ACCOUNT='123456789012',CARLOS_PLACEMENT_REGION='ie',CARLOS_INGRESS_KEY=root+'ingress',CARLOS_GROUP_DATA_BUCKET='data',CARLOS_GROUP_NAME='dev-ie',CARLOS_LAUNCH_HOOK_NAME='carlos-initial-launch',CARLOS_POOLS='hapair',CARLOS_RELEASE='v1.2.3'))
calls=[];decryptions=0;metadata=[]
@@ -287,7 +288,9 @@ def run(args,timeout):
calls.append(args)
if 'get-parameters' in args:
names=args[args.index('--names')+1:args.index('--with-decryption')]
- vals=[json.dumps(dict(key='bootstrap/dev/ie/one',version='1',known_readers=[],deployment_aws_region='eu-west-1')),hashlib.sha256(b'bootstrap').hexdigest(),'queue']
+ obj=dict(key='bootstrap/dev/ie/one',version='1',known_readers=[],deployment_aws_region='eu-west-1')
+ if floor is not None: obj['floor']=floor
+ vals=[json.dumps(obj),hashlib.sha256(b'bootstrap').hexdigest(),'queue']
assert len(names)==3
decryptions+=3
return json.dumps(dict(Parameters=[dict(Name=n,Value=v) for n,v in zip(names,vals)])).encode()
@@ -323,8 +326,14 @@ def fakeopen(path,*args,**kwargs):
raise AssertionError('unexpected file '+path)
builtins.open=fakeopen
os.chmod=lambda *args:None
-writes=[]
+writes=[];marker=None
def write(path,body,mode=0o644):
+ global marker
+ if path=='/etc/carlos/group.json':
+ marker=json.loads(body)
+ assert marker['floor']==floor
+ unsigned=dict(marker);unsigned.pop('config_digest')
+ assert marker['config_digest']==hashlib.sha256(json.dumps(unsigned,sort_keys=True,separators=(',', ':')).encode()).hexdigest()
if path=='/etc/carlos/group-ingress.json':
assert verified_identity, 'snapshot published before signed identity verification'
snapshot=json.loads(body)
@@ -332,20 +341,40 @@ def write(path,body,mode=0o644):
writes.append(path)
tree=ast.parse(source)
tree.body=[n for n in tree.body if not isinstance(n,ast.FunctionDef) or n.name!='write']
-exec(compile(tree,'group-init.sh.tftpl','exec'))
+try:
+ exec(compile(tree,'group-init.sh.tftpl','exec'))
+except SystemExit as err:
+ assert floor not in ('required','absent-expected') and str(err)=='group_boot_object',err
+ assert len(calls)==1 and not metadata and not writes,(calls,metadata,writes)
+ print('invalid floor refused before bootstrap fetch')
+ raise SystemExit(0)
+assert floor in ('required','absent-expected'), 'invalid floor accepted'
assert len(calls)==3 and decryptions==4 and len(metadata)==7,(calls,decryptions,metadata)
assert len(writes)==4,writes
-print('boot: 2 SSM calls, 4 decrypted values, 1 versioned S3 GET, 7 IMDS requests')
+print(json.dumps(marker))
`
source, _ := json.Marshal(string(raw)[start : start+end])
program = strings.Replace(program, "SOURCE", string(source), 1)
- cmd := exec.Command("python3", "-c", program)
- cmd.Dir = t.TempDir()
- out, err := cmd.CombinedOutput()
- if err != nil {
- t.Fatalf("boot budget: %v %s", err, out)
+ for _, floor := range []string{"absent-expected", "required", "", "none", "missing"} {
+ t.Run(floor, func(t *testing.T) {
+ value := fmt.Sprintf("%q", floor)
+ if floor == "missing" {
+ value = "None"
+ }
+ cmd := exec.Command("python3", "-c", strings.Replace(program, "FLOOR", value, 1))
+ cmd.Dir = t.TempDir()
+ out, err := cmd.CombinedOutput()
+ if err != nil {
+ t.Fatalf("boot budget: %v %s", err, out)
+ }
+ if floor == "absent-expected" || floor == "required" {
+ c, err := hostenv.ParseGroupConfig(out)
+ if err != nil || c.Floor != floor {
+ t.Fatalf("boot marker does not parse in Go: %v %s", err, out)
+ }
+ }
+ })
}
- t.Log(strings.TrimSpace(string(out)))
}
func groupRuntimeS3Budget(t *testing.T) {
diff --git a/internal/host/group_config_test.go b/internal/host/group_config_test.go
index f78bccd3b..a0e777741 100644
--- a/internal/host/group_config_test.go
+++ b/internal/host/group_config_test.go
@@ -9,7 +9,7 @@ import (
func groupConfigFixture() (hostenv.GroupConfig, map[string]string) {
p := ""
- c := hostenv.GroupConfig{V: 1, Account: "123456789012", AWSRegion: "eu-west-1", DeploymentAWSRegion: "us-east-1", Region: "ie", Deployment: "dev", Bucket: "deploy", DataBucket: "data", Group: "dev-ie", Hook: "carlos-initial-launch", Placement: &p, Pools: []string{"hapair"}, KnownReaders: []string{"fixed"}, Release: "v1.2.3", InstanceID: "i-0123456789abcdef0", BootID: "boot", Deadline: time.Now().Add(time.Minute).Unix(), QueueURL: "https://sqs.eu-west-1.amazonaws.com/123456789012/group-queue"}
+ c := hostenv.GroupConfig{V: 1, Account: "123456789012", AWSRegion: "eu-west-1", DeploymentAWSRegion: "us-east-1", Region: "ie", Deployment: "dev", Bucket: "deploy", DataBucket: "data", Group: "dev-ie", Hook: "carlos-initial-launch", Placement: &p, Pools: []string{"hapair"}, KnownReaders: []string{"fixed"}, Release: "v1.2.3", Floor: "absent-expected", InstanceID: "i-0123456789abcdef0", BootID: "boot", Deadline: time.Now().Add(time.Minute).Unix(), QueueURL: "https://sqs.eu-west-1.amazonaws.com/123456789012/group-queue"}
c.ConfigDigest = c.Digest()
env := map[string]string{}
for _, k := range hostenv.Required {
@@ -62,3 +62,24 @@ func TestGroupConfiguration(t *testing.T) {
t.Fatal("inventory not bound by digest")
}
}
+
+func TestGroupConfigurationFloor(t *testing.T) {
+ for _, floor := range []string{"absent-expected", "required", "", "none"} {
+ t.Run(floor, func(t *testing.T) {
+ c, _ := groupConfigFixture()
+ c.Floor = floor
+ c.ConfigDigest = c.Digest()
+ raw, _ := json.Marshal(c)
+ _, err := hostenv.ParseGroupConfig(raw)
+ if (err == nil) != (floor == "absent-expected" || floor == "required") {
+ t.Fatalf("floor %q: %v", floor, err)
+ }
+ })
+ }
+ c, _ := groupConfigFixture()
+ c.Floor = "required"
+ raw, _ := json.Marshal(c)
+ if _, err := hostenv.ParseGroupConfig(raw); err == nil {
+ t.Fatal("floor change accepted without updating config_digest")
+ }
+}
diff --git a/internal/host/group_hairpin_rootrunner_linux_test.go b/internal/host/group_hairpin_rootrunner_linux_test.go
index 633164794..f30e4d5ac 100644
--- a/internal/host/group_hairpin_rootrunner_linux_test.go
+++ b/internal/host/group_hairpin_rootrunner_linux_test.go
@@ -459,7 +459,7 @@ func hairpinRunnerSnapshot(t *testing.T) *hairpin.Config {
t.Fatal("metadata address fixture unavailable")
}
placement := "ie"
- marker := hostenv.GroupConfig{V: 1, Account: doc.Account, AWSRegion: doc.Region, DeploymentAWSRegion: doc.Region, Region: "ie", Deployment: "dev", Bucket: "fixture-deploy", DataBucket: "fixture-data", Group: "fixture-group", Hook: "carlos-initial-launch", Placement: &placement, Pools: []string{"hapair"}, KnownReaders: []string{}, Release: "v1.2.3", InstanceID: doc.IID, BootID: readBootID(bootIDPath), Deadline: time.Now().Add(time.Hour).Unix(), QueueURL: "https://sqs." + doc.Region + ".amazonaws.com/" + doc.Account + "/fixture"}
+ marker := hostenv.GroupConfig{V: 1, Account: doc.Account, AWSRegion: doc.Region, DeploymentAWSRegion: doc.Region, Region: "ie", Deployment: "dev", Bucket: "fixture-deploy", DataBucket: "fixture-data", Group: "fixture-group", Hook: "carlos-initial-launch", Placement: &placement, Pools: []string{"hapair"}, KnownReaders: []string{}, Release: "v1.2.3", Floor: "absent-expected", InstanceID: doc.IID, BootID: readBootID(bootIDPath), Deadline: time.Now().Add(time.Hour).Unix(), QueueURL: "https://sqs." + doc.Region + ".amazonaws.com/" + doc.Account + "/fixture"}
marker.ConfigDigest = marker.Digest()
hairpinWriteJSON(t, hostenv.GroupConfigPath, marker)
hairpinWriteJSON(t, groupIdentityPath, record)
diff --git a/internal/host/installchannel.go b/internal/host/installchannel.go
index 3ec91595b..288317288 100644
--- a/internal/host/installchannel.go
+++ b/internal/host/installchannel.go
@@ -718,12 +718,20 @@ func (in channelInstall) cacheDir(version string) error {
return nil
}
-// Both halves are observed once. Only two genuine absences permit no-floor
-// installation; an unreadable half or a torn publication cannot downgrade it.
+// Both halves are observed once. No-floor installation also requires the
+// operator's absent-expected setting in the protected root marker. A published
+// floor always wins; an unreadable half or torn publication cannot downgrade it.
func (in channelInstall) checkGroupInstallFloor(ctx context.Context, p *release.SystemPointer, art release.SystemArtifact, pub ed25519.PublicKey) ([]byte, string, error) {
raw, _, fe := in.a.store.Get(ctx, hostfloor.Key)
auth, _, ae := in.a.store.Get(ctx, hostfloor.AuthKey)
if errors.Is(fe, os.ErrNotExist) && errors.Is(ae, os.ErrNotExist) {
+ c, err := in.a.maintenanceConfig()
+ if err != nil {
+ return nil, "", err
+ }
+ if c == nil || c.Floor != "absent-expected" {
+ return nil, "", errors.New("no host floor is published, so this box could not arm its guard and nothing was installed")
+ }
return nil, p.Current.ReleaseTag, nil
}
if fe != nil || ae != nil {
diff --git a/internal/host/installchannel_test.go b/internal/host/installchannel_test.go
index f34ac0b73..ec906d135 100644
--- a/internal/host/installchannel_test.go
+++ b/internal/host/installchannel_test.go
@@ -13,6 +13,7 @@ import (
"reflect"
"strings"
"testing"
+ "time"
"github.com/carlosframework/platform/internal/hostfloor"
"github.com/carlosframework/platform/internal/release"
@@ -472,27 +473,70 @@ func TestInstallChannelRefusesASymlinkedSlot(t *testing.T) {
}
}
-func TestGroupInstallFloor(t *testing.T) {
- for _, floor := range []string{"", "v1.2.0", "v9.0.0"} {
- t.Run(floor, func(t *testing.T) {
- f := newChannelFixture(t, floor)
- f.in.group = true
- _, err := f.in.run(t.Context())
- if (err != nil) != (floor == "v9.0.0") {
- t.Fatal(err)
- }
- })
+func groupChannelMarker(t *testing.T, f *channelFixture, floor string) {
+ t.Helper()
+ m, _ := maintenanceFixture(t)
+ f.a.etcDir = m.a.etcDir
+ f.a.groupMaintenance = m.a.groupMaintenance
+ f.edgeStartedThisBoot = false
+ f.in.group = true
+ c, _ := groupConfigFixture()
+ c.Floor = floor
+ c.Deadline = f.now.Add(time.Minute).Unix()
+ c.ConfigDigest = c.Digest()
+ b, err := json.Marshal(c)
+ if err != nil {
+ t.Fatal(err)
}
- for _, key := range []string{hostfloor.Key, hostfloor.AuthKey} {
- f := newChannelFixture(t, "v1.2.0")
- f.in.group = true
- if err := f.store.Delete(t.Context(), key); err != nil {
- t.Fatal(err)
+ if err := os.WriteFile(filepath.Join(f.a.etcDir, "carlos", "group.json"), b, 0644); err != nil {
+ t.Fatal(err)
+ }
+}
+
+func TestGroupInstallFloor(t *testing.T) {
+ for _, expected := range []string{"absent-expected", "required"} {
+ for _, floor := range []string{"", "v1.2.0", "v9.0.0"} {
+ t.Run(expected+"/"+floor, func(t *testing.T) {
+ f := newChannelFixture(t, floor)
+ groupChannelMarker(t, f, expected)
+ _, err := f.in.run(t.Context())
+ refuse := floor == "v9.0.0" || floor == "" && expected == "required"
+ if (err != nil) != refuse {
+ t.Fatalf("floor %q marker %q: %v", floor, expected, err)
+ }
+ if refuse && f.fetches != 0 || !refuse && f.fetches != 1 {
+ t.Fatalf("artifact fetches = %d", f.fetches)
+ }
+ if floor == "" && expected == "required" && !strings.Contains(err.Error(), "no host floor is published") {
+ t.Fatal(err)
+ }
+ if !refuse && floor != "" {
+ if _, err := os.Stat(channelIdentityPath(f.a.optDir)); err != nil {
+ t.Fatal("published floor identity not saved", err)
+ }
+ }
+ })
}
- if _, err := f.in.run(t.Context()); err == nil {
- t.Fatal("half floor accepted", key)
+ for _, key := range []string{hostfloor.Key, hostfloor.AuthKey} {
+ t.Run(expected+"/missing-"+key, func(t *testing.T) {
+ f := newChannelFixture(t, "v1.2.0")
+ groupChannelMarker(t, f, expected)
+ if err := f.store.Delete(t.Context(), key); err != nil {
+ t.Fatal(err)
+ }
+ if _, err := f.in.run(t.Context()); err == nil || f.fetches != 0 {
+ t.Fatal("half floor accepted", key, err)
+ }
+ })
}
}
+ t.Run("missing-marker", func(t *testing.T) {
+ f := newChannelFixture(t, "")
+ f.in.group = true
+ if _, err := f.in.run(t.Context()); err == nil || f.fetches != 0 {
+ t.Fatal("no-floor install without marker", err)
+ }
+ })
}
type groupFloorObservationStore struct {
@@ -511,7 +555,7 @@ func (s *groupFloorObservationStore) Get(ctx context.Context, key string) ([]byt
func TestGroupInstallFloorObservation(t *testing.T) {
for _, fail := range []string{"", hostfloor.Key, hostfloor.AuthKey} {
f := newChannelFixture(t, "")
- f.in.group = true
+ groupChannelMarker(t, f, "absent-expected")
store := &groupFloorObservationStore{Store: f.store, fail: fail, counts: map[string]int{}}
f.a.openStore = func(context.Context) (release.Store, ed25519.PublicKey, error) { return store, f.pub, nil }
_, err := f.in.run(t.Context())
@@ -527,7 +571,7 @@ func TestGroupInstallFloorObservation(t *testing.T) {
}
for _, kind := range []string{"required", "unreadable"} {
f := newChannelFixture(t, "")
- f.in.group = true
+ groupChannelMarker(t, f, "absent-expected")
f.a.rootMoves = func() (rootFloorIdentity, bool, error) {
if kind == "unreadable" {
return rootFloorIdentity{}, false, os.ErrPermission
diff --git a/internal/hostenv/group.go b/internal/hostenv/group.go
index 6007a4d9f..b421a2384 100644
--- a/internal/hostenv/group.go
+++ b/internal/hostenv/group.go
@@ -20,6 +20,9 @@ const GroupConfigPath = "/etc/carlos/group.json"
// GroupConfig is installed by root before bootstrap. Placement may be the
// empty home placement; Region is always the canonical deployment region.
+// Floor comes from the operator-seeded SSM boot/bootstrap-object. It is required
+// and digest-bound: only absent-expected permits both floor objects to be absent;
+// required refuses absence. A published floor is always verified.
type GroupConfig struct {
DataBucket string `json:"data_bucket"`
DeploymentAWSRegion string `json:"deployment_aws_region"`
@@ -35,6 +38,7 @@ type GroupConfig struct {
Placement *string `json:"placement"`
Pools []string `json:"pools"`
KnownReaders []string `json:"known_readers"`
+ Floor string `json:"floor"`
Release string `json:"release"`
InstanceID string `json:"instance_id"`
BootID string `json:"boot_id"`
@@ -45,7 +49,7 @@ type GroupConfig struct {
var ErrGroupConfig = errors.New("group_config_invalid")
func (c GroupConfig) Validate() error {
- if c.V != 1 || len(c.Account) != 12 || strings.Trim(c.Account, "0123456789") != "" || !scopeName.MatchString(c.DeploymentAWSRegion) || !scopeName.MatchString(c.AWSRegion) || !scopeName.MatchString(c.Region) || c.Region == SharedScope || !scopeName.MatchString(c.Deployment) || c.Bucket == "" || c.DataBucket == "" || !scopeName.MatchString(c.Group) || c.Hook != "carlos-initial-launch" || c.Placement == nil || (*c.Placement != "" && *c.Placement != c.Region) || c.Release == "" || len(c.Pools) == 0 || c.KnownReaders == nil {
+ if (c.Floor != "absent-expected" && c.Floor != "required") || c.V != 1 || len(c.Account) != 12 || strings.Trim(c.Account, "0123456789") != "" || !scopeName.MatchString(c.DeploymentAWSRegion) || !scopeName.MatchString(c.AWSRegion) || !scopeName.MatchString(c.Region) || c.Region == SharedScope || !scopeName.MatchString(c.Deployment) || c.Bucket == "" || c.DataBucket == "" || !scopeName.MatchString(c.Group) || c.Hook != "carlos-initial-launch" || c.Placement == nil || (*c.Placement != "" && *c.Placement != c.Region) || c.Release == "" || len(c.Pools) == 0 || c.KnownReaders == nil {
return ErrGroupConfig
}
for _, list := range [][]string{c.Pools, c.KnownReaders} {
diff --git a/internal/hostenv/group_test.go b/internal/hostenv/group_test.go
index 3e2442e14..ec48b2690 100644
--- a/internal/hostenv/group_test.go
+++ b/internal/hostenv/group_test.go
@@ -12,7 +12,7 @@ import (
func groupEnvFixture() (GroupConfig, map[string]string) {
placement := ""
- c := GroupConfig{V: 1, Account: "123456789012", AWSRegion: "eu-west-1", DeploymentAWSRegion: "us-east-1", Region: "ie", Deployment: "dev", Bucket: "deploy", DataBucket: "data", Group: "dev-ie", Hook: "carlos-initial-launch", Placement: &placement, Pools: []string{"hapair"}, KnownReaders: []string{"fixed"}, Release: "v1.2.3"}
+ c := GroupConfig{V: 1, Account: "123456789012", AWSRegion: "eu-west-1", DeploymentAWSRegion: "us-east-1", Region: "ie", Deployment: "dev", Bucket: "deploy", DataBucket: "data", Group: "dev-ie", Hook: "carlos-initial-launch", Placement: &placement, Pools: []string{"hapair"}, KnownReaders: []string{"fixed"}, Release: "v1.2.3", Floor: "absent-expected"}
env := map[string]string{}
for _, k := range Required {
env[k] = "value"