Skip to content

CreateOrGetInstanceProfile does not re-add the role to an existing empty instance profile #1318

Closed

Description

@scttfrdmn

Found while implementing #1300 (reaping unused per-task spawn-instance-* roles).

pkg/aws.CreateOrGetInstanceProfile (pkg/aws/iam.go) calls AddRoleToInstanceProfile only inside if !profileExists { ... }. When the profile already exists it is returned as-is, without checking that GetInstanceProfile().InstanceProfile.Roles contains the role.

So a profile that exists with no role attached is handed to RunInstances and the instance boots with no credentials: spored cannot read its own tags, flush its task or terminate itself (the reaper's TTL backstop still applies).

How a profile ends up empty:

Proposed fix: in the profileExists branch, read the profile's Roles; if the role is absent, AddRoleToInstanceProfile (LimitExceeded = another role already attached → error naming it) and waitForInstanceProfile. Also consider handling NoSuchEntity from GetInstanceProfile right after the existence check (profile deleted mid-launch) by retrying the create path once.

Evidence: code reading only (no AWS run); see the if !profileExists { block in CreateOrGetInstanceProfile.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions