Skip to content

fix: add ec2:DescribeVolumes to spored's self-management baseline policy - #519

Merged
scttfrdmn merged 2 commits into
mainfrom
fix/517-ebs-describevolumes-permission
Aug 19, 2026
Merged

scttfrdmn merged 2 commits into
mainfrom
fix/517-ebs-describevolumes-permission

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Summary

  • sporedSelfManagementStatements() granted ec2:DescribeTags + ec2:DescribeInstances but not ec2:DescribeVolumes. LookupAndTagEBSCost (pkg/provider/ec2.go) needs both DescribeInstances (block-device mappings) and DescribeVolumes (actual sizes/types) to price EBS storage — the second call always 403'd. Since 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 made spored-baseline-policy apply to every spawn-launched instance, the EBS cost lookup could never succeed in the default configuration, spawn:ebs-hourly-cost was never written, and spored status's storage-cost line stayed permanently "not yet available".
  • Added ec2:DescribeVolumes to the same statement (already Resource: "*" — Describe APIs don't support resource-level scoping, so this widens nothing that wasn't already wide).
  • Also fixed defect 2 from the issue: the unmeasured 0.003 fallback constant was logged in the exact same shape as a real measurement (EBS hourly cost: $0.0030/hr), so a reader comparing that log line against spored status's "not yet available" storage line for the same instance got contradictory answers. Provider.LookupAndTagEBSCost now returns (cost float64, measured bool) instead of a bare float64; the caller in pkg/agent/agent.go only logs a rate when measured is true, otherwise logs an explicit "unknown (lookup failed or denied)" line.
  • Did not implement the issue's optional item 3 (deriving the policy from the actual EC2 API call set instead of hand-maintained lists) — that's a larger structural change (a shared call-site registry) out of scope for this fix; noted as a good follow-up in the issue.

Test plan

  • go build ./...
  • go vet ./...
  • go test ./pkg/provider/... ./pkg/agent/... ./pkg/aws/...
    • New: TestEC2Provider_LookupAndTagEBSCost_CachedTagIsMeasured, TestEC2Provider_LookupAndTagEBSCost_NoVolumesIsNotMeasured
    • Updated TestSporedBaselinePolicyDoc to assert ec2:DescribeVolumes is present — verified it fails without the iam.go change and passes with it.
  • golangci-lint run ./pkg/provider/... ./pkg/agent/... ./pkg/aws/... — no new findings on touched lines (pre-existing findings elsewhere in these packages are unchanged)
  • CHANGELOG.md updated under [Unreleased]

Fixes #517

@codecov

codecov Bot commented Aug 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 30.76923% with 9 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/agent/agent.go 0.00% 4 Missing ⚠️
pkg/provider/ec2.go 50.00% 3 Missing ⚠️
pkg/provider/local.go 0.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

LookupAndTagEBSCost needs DescribeInstances (block-device mappings) and
DescribeVolumes (actual sizes/types) to price EBS storage, but the baseline
policy spored#502 attaches to every instance only granted the first. The
EBS cost lookup always 403'd, spawn:ebs-hourly-cost was never written, and
spored status's storage line stayed "not yet available" forever.

Also make the un-measured 0.003 fallback distinguishable from a real
measurement: LookupAndTagEBSCost now returns (cost float64, measured bool)
instead of a bare float64, so the caller's log line no longer states an
unmeasured constant as if it were data.

Fixes #517
@scttfrdmn
scttfrdmn force-pushed the fix/517-ebs-describevolumes-permission branch from 737f067 to 5d63edb Compare August 19, 2026 05:01
@scttfrdmn
scttfrdmn merged commit 61cfae4 into main Aug 19, 2026
7 checks passed
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