Skip to content

spored-baseline-policy omits ec2:DescribeVolumes, so LookupAndTagEBSCost can never succeed under the policy spawn itself provisions — and its 0.003 fallback is logged as if measured #517

Closed

Description

@scttfrdmn

Summary

sporedSelfManagementStatements() grants ec2:DescribeTags and ec2:DescribeInstances but not ec2:DescribeVolumes. LookupAndTagEBSCost needs both: DescribeInstances for the block device mappings (allowed, succeeds), then DescribeVolumes for sizes and types (denied, 403).

So on every EC2 instance whose role carries spored-baseline-policy — which #502 now makes every spawn-launched instance — the EBS cost lookup fails on its second call, the spawn:ebs-hourly-cost tag is never written, and spored status's storage-cost line is permanently not yet available. This isn't an edge case: the feature cannot work in the default configuration, because the policy spawn writes and the API calls spored makes are two independently-maintained lists that disagree by one entry.

Separately, and harder to diagnose than the missing permission: the denied path returns 0.003 and the caller logs it through a line indistinguishable from a measurement.

Found while verifying the #502 fix on a live 13-node fleet. That fix works — evidence below — which is how this surfaced.

Measured

spored v0.100.2, us-east-2, 13 × c8g.48xlarge, instance role spawn-instance-d1029e0a. From /var/log/spored.log on shard 0:

2026/08/18 23:05:12 spored v0.100.2 starting...
2026/08/18 23:05:12 Config: TTL=8h0m0s, IdleTimeout=0s, Hibernate=false
2026/08/18 23:05:12 Warning: could not describe volumes for EBS cost lookup: operation error EC2:
  DescribeVolumes, https response error StatusCode: 403, RequestID: d3d28de4-bcee-4368-a48f-ee58b4cf9bde,
  api error UnauthorizedOperation: You are not authorized to perform this operation. User:
  arn:aws:sts::…:assumed-role/spawn-instance-d1029e0a/i-09bbd2b961ebaf78d is not authorized to
  perform: ec2:DescribeVolumes because no identity-based policy allows the ec2:DescribeVolumes action
2026/08/18 23:05:12 EBS hourly cost: $0.0030/hr

Note the last two lines together. The 403 is a Warning:; the next line states a rate to four decimal places.

The policy actually on the role, read back from IAM — DescribeInstances is there, DescribeVolumes is not:

$ aws iam get-role-policy --role-name spawn-instance-d1029e0a --policy-name spored-baseline-policy
{"Action": ["ec2:DescribeTags", "ec2:DescribeInstances"], "Effect": "Allow", "Resource": "*"}
{"Action": ["ec2:CreateTags", "ec2:DeleteTags"],  … Condition spawn:managed=true}
{"Action": ["ec2:TerminateInstances", "ec2:StopInstances"], … Condition spawn:managed=true}
{"Action": ["lambda:InvokeFunctionUrl"], … spawn-dns-updater}
{"Action": ["fsx:DescribeFileSystems", "fsx:CreateDataRepositoryAssociation",
            "fsx:DescribeDataRepositoryAssociations"], "Effect": "Allow", "Resource": "*"}

And what the answer would have been, from the same account with a profile that can call it:

$ aws ec2 describe-volumes --region us-east-2 --filters Name=tag:RunId,Values=… \
    --query 'Volumes[].[Size,VolumeType]' --output text | sort | uniq -c
  13   20  gp3

Using spawn's own table (ebsPricePerGBMonth("gp3") = 0.08, hoursPerMonth = 730):

$/hr
measured, had the call been permitted 20 × 0.08 / 730 = $0.002192
what the fallback reports $0.003000

37% high, and the sign is not the interesting part — $0.0008/hr × 13 nodes is nothing. What matters is that the number's provenance is unrecoverable from the log.

Defect 1 — the policy can't satisfy the code it exists for

pkg/aws/iam.go:754-771. The doc comment describes the list as the statements every spored-running instance role MUST carry, and says the two policy paths are shared "so the two paths can never drift":

// sporedSelfManagementStatements returns the policy statements every
// spored-running instance role MUST carry, regardless of any additional
// user/scoped policy: read its own tags …
sporedReadPermissions := map[string]interface{}{
	"Effect": "Allow",
	"Action": []interface{}{
		"ec2:DescribeTags",
		"ec2:DescribeInstances",
	},
	"Resource": "*",
}

The two policy paths indeed can't drift from each other — but neither is derived from the set of AWS calls spored actually makes, and that's the drift that happened. LookupAndTagEBSCost (pkg/provider/ec2.go:384-442) calls DescribeInstances, DescribeVolumes and CreateTags; only the first and third are granted. A hand-maintained restatement of what the code needs has no producer to rot from, so nothing caught it.

Both Describe* calls are read-only and already on Resource: "*" for the documented reason (Describe APIs don't support resource-level scoping), so adding ec2:DescribeVolumes to the same statement widens nothing that isn't already wide.

Defect 2 — 0.003 is a legal value standing in for "unmeasured"

pkg/provider/ec2.go has three returns of the bare constant:

return 0.003 // safe fallback      // DescribeInstances failed
return 0.003                       // no volume ids
return 0.003                       // DescribeVolumes failed  <-- our case

The measured path logs its own distinct line and writes the tag:

log.Printf("EBS volumes: %d vol(s), hourly cost = $%.4f/hr", len(volOut.Volumes), totalHourlyCost)
// … CreateTags spawn:ebs-hourly-cost …
p.config.EBSHourlyCost = totalHourlyCost

while the fallback reaches the reader only through the caller's generic line (pkg/agent/agent.go:174-179):

if identity.Provider == "ec2" && config.EBSHourlyCost == 0 {
	go func() {
		if ebsCost := prov.LookupAndTagEBSCost(context.Background()); ebsCost > 0 {
			log.Printf("EBS hourly cost: $%.4f/hr", ebsCost)
		}
	}()
}

0.003 > 0, so the guard passes and a figure that was never measured is printed in the same shape as one that was.

Worth being precise about the blast radius, because it's smaller than it looks and the reason is to your credit. The fallback bypasses both the CreateTags and the p.config.EBSHourlyCost = … write, and the only consumer reads the value back from the tag. So config.EBSHourlyCost stays 0, and cmd/spored/main.go:489-508 does the right thing:

// If not yet available, skip the storage line rather than showing a guess.
ebsHourlyCost := config.EBSHourlyCost
ebsCostKnown := ebsHourlyCost > 0
…
fmt.Printf("  Storage cost:     not yet available  (%s stopped)\n", formatDuration(stoppedTime))

That's the correct handling of an unknown, and it means no cost arithmetic is wrong anywhere. The consequence is narrower and purely diagnostic: the constant's sole observable effect in the entire program is a log line that contradicts what spored status will say about the same instance minutes later — the log asserts $0.0030/hr, the status output says not yet available. A reader trying to work out whether cost tracking is functioning gets opposite answers from two parts of the same daemon.

So: defect 1 is the functional bug, defect 2 is why it took reading three files to find.

Suggested fix

  1. Add ec2:DescribeVolumes to sporedReadPermissions in sporedSelfManagementStatements(). One line, same statement, already Resource: "*". This alone restores the feature.
  2. Make the fallback un-mistakable for a measurement. Return (float64, error) or (float64, bool) rather than a bare sentinel, and have the caller log the two cases differently — EBS hourly cost: unknown (DescribeVolumes denied); storage cost will not be reported versus the measured line. A value that is indistinguishable from a real one is the part that costs debugging time.
  3. Derive the policy from the call sites, don't restate them. The existing iam_test.go check asserts a hand-written want list against a hand-written policy — two copies of the same assumption, so it passes while the policy is missing a grant the code needs. Something closer to the real invariant: enumerate the EC2 API calls spored can make (or list them in one place both the policy builder and the callers read) and assert the policy covers that set. Test-only, but it's the check that would have caught this.
  4. Optional: if a DescribeVolumes denial is expected on pre-CRITICAL: launch --iam-policy-file omits the spored baseline policy — TTL, --on-complete and --pre-stop all silently dead (the #406 fix covers 2 of 3 role paths) #502 roles that haven't relaunched, one line at WARN naming the missing permission would point straight at the fix rather than at AWS.

(1) is the whole functional fix; (3) is the one that stops it recurring.

Incidental — #502 verified working on this fleet

Since this was found while checking that: the role gained spored-baseline-policy with DescribeTags/CreateTags/TerminateInstances, and shard 0 logs Config: TTL=8h0m0s against the TTL=0s that the same launch profile produced before the fix, with spawn:on-complete=terminate and spawn:ttl-deadline=2026-08-19T07:04:36Z on the instance. TTL and on-complete are live. Thank you — that one mattered.

Also still true on this fleet, per #515: the instances carry spawn:version=0.1.0 from the hard-coded literal while spored correctly self-reports 0.100.2.

Environment

  • spawn/spored 0.100.2, commit 8086471e597f6957388c1cd3cd54bccd516dec05, us-east-2
  • 13 × c8g.48xlarge, each with a single 20 GB gp3 root volume, launched 2026-08-18 23:04Z
  • instance role spawn-instance-d1029e0a, policies: spored-baseline-policy, spawn-custom-policy, AmazonSSMManagedInstanceCore
  • code paths: pkg/aws/iam.go:748-771 (the statement list), pkg/provider/ec2.go:384-442 (LookupAndTagEBSCost, three 0.003 returns), pkg/agent/agent.go:174-179 (the log line), cmd/spored/main.go:487-508 (the careful consumer)

Activity

  1. added
    bug
    on Aug 18, 2026
  2. added a commit that references this issue on Aug 19, 2026
    5cb1a7c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions