Skip to content

EC2: UserData is not observable through any operation (no DescribeInstanceAttribute) #473

Closed

Description

@scttfrdmn

Discovered while implementing #453.

The gap

RunInstances records UserData, and #453 added the launch-template fallback for it, so an instance launched from a template now carries the template's user data. Nothing can read it back. DescribeInstanceAttribute is not implemented, and no other operation exposes the field, so:

DescribeInstanceAttribute is the operation AWS provides for this (Attribute=userData returns it base64-encoded), and it covers a family of other attributes on the same surface: instanceType, kernel, ramdisk, disableApiTermination, instanceInitiatedShutdownBehavior, rootDeviceName, blockDeviceMapping, sourceDestCheck, groupSet, ebsOptimized, sriovNetSupport, enaSupport, enclaveOptions, disableApiStop.

Its companion ModifyInstanceAttribute is what a consumer uses to change user data on a stopped instance, and is absent too.

Scope note

Per CLAUDE.md's boundary: this is about making the recorded input observable through an API call, not about executing it. Substrate does not run user data or cloud-init and should not — the value is recorded intent, and reporting it back is exactly the observable half.

Acceptance criteria

  • DescribeInstanceAttribute with Attribute=userData returns the recorded value, base64-encoded, in the documented { InstanceId, UserData: { Value } } shape
  • The response shape for an attribute that was never set matches AWS (an empty <value/> element rather than an omitted one, verified against the reference)
  • An unsupported or missing Attribute returns the documented error, not a 200
  • Attribute=instanceType, groupSet and disableApiTermination are covered as well, since they read state substrate already holds
  • A RunInstances that took its UserData from a launch template reports the template's value — the EC2: a launch template is ignored entirely when ImageId is also passed #453 assertion this issue exists to make possible
  • ModifyInstanceAttribute for userData on a stopped instance, and the IncorrectInstanceState error on a running one, or a note deferring it with a reason
  • docs/services.md coverage matrix updated

Activity

  1. added this to the v0.86.0 milestone on Aug 2, 2026
  2. scttfrdmn commented on Aug 2, 2026

    @scttfrdmn
    OwnerAuthor

    Shipped in v0.86.0 (#486). Three notes, one of them a criterion this issue asked to have
    verified and which cannot be from the reference.

    The empty-attribute shape has weaker provenance than the rest. This issue asked that
    an unset attribute's shape be checked against the reference. All three of the reference's
    worked examples show an attribute that has a value, so the reference does not settle it.
    The shape ships from moto's test_describe_instance_attribute, which asserts
    response["UserData"] == {} — an empty mapping, i.e. a present element with no children,
    so <userData></userData> on the wire rather than an omitted element. That is a
    reimplementation's test rather than a capture, and it is labelled as such in both the code
    comment and docs/services.md. The distinction is not cosmetic: an SDK maps a
    present-but-empty element to an empty struct and an omitted one to nil, so
    resp.UserData.Value panics under one and not the other.

    The unknown-attribute error, by contrast, has the strongest provenance in the release.
    Value (enaSupport) for parameter attribute is invalid. Unknown attribute. is captured
    from real AWS in aws/aws-cli#4273 and is byte-identical to moto's string — a capture and an
    independent reimplementation agreeing. The reference could not have supplied it; its Errors
    section is empty. enaSupport is the case that makes the boundary concrete: it is in AWS's
    own valid-values list while the same page says the attribute "is not supported", and #4273
    captures exactly that rejection. So substrate refusing the twelve unmodelled attributes is
    fidelity, not a shortfall — answering sourceDestCheck with a default false would be
    indistinguishable from a real instance that has it disabled.

    One finding changed the plan. The stopped-state gate on ModifyInstanceAttribute
    covers userData and instanceType — the latter a behaviour change, since substrate
    previously changed a running instance's type — but not disableApiTermination.
    RunInstances' reference says protection can be enabled "when you launch an instance,
    while the instance is running, or while the instance is stopped", so gating it would refuse
    a call real EC2 accepts. That is the same class of defect as accepting one real EC2
    refuses, just in the other direction and harder to notice, because it looks like extra
    rigor. There is a test pinning the exemption.

    Also worth recording: writing the wire-shape test caught a bug no struct decoder could
    see. Go's encoding/xml emits the parent element of an a>b path even for an empty
    slice, so a groupSet>item field put <groupSet></groupSet> in every response — a
    caller asking for userData was told the instance had no security groups. Fixed with a
    nil-able wrapper and pinned from both directions.

    Termination protection is now recorded and reported but still not acted on:
    TerminateInstances terminates a protected instance, where real EC2 refuses with
    OperationNotPermitted. That is #489.

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

    area: ec2fidelitytype: feature

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions