Repository navigation
Description
Bug
The IAM plugin uses iamJSONResponse() which returns Content-Type: application/x-amz-json-1.1. However, the AWS IAM service uses the Query protocol: requests are application/x-www-form-urlencoded and responses are XML.
The AWS Go SDK v2 IAM client expects XML. When it receives JSON, it returns HTTP 200 with no error but deserializes every field to its zero value (nil pointers, empty slices). The operation appears to "succeed" but no data is accessible.
Reproduction
ts := substrate.StartTestServer(t)
cfg := aws.Config{
Region: "us-east-1",
EndpointResolverWithOptions: aws.EndpointResolverWithOptionsFunc(
func(service, region string, _ ...interface{}) (aws.Endpoint, error) {
return aws.Endpoint{URL: ts.URL, HostnameImmutable: true, SigningRegion: "us-east-1"}, nil
},
),
Credentials: credentials.NewStaticCredentialsProvider("test", "test", ""),
}
iamClient := iam.NewFromConfig(cfg)
_, err := iamClient.CreateInstanceProfile(ctx, &iam.CreateInstanceProfileInput{
InstanceProfileName: aws.String("my-profile"),
})
// err == nil ✓
resp, err := iamClient.GetInstanceProfile(ctx, &iam.GetInstanceProfileInput{
InstanceProfileName: aws.String("my-profile"),
})
// err == nil ✓
// resp.InstanceProfile == nil ← should be populated, is nil
// Accessing resp.InstanceProfile.Roles causes nil pointer dereference panicRoot Cause
iamJSONResponse sets Content-Type: application/x-amz-json-1.1:
// iam_plugin.go
func iamJSONResponse(status int, v any) (*AWSResponse, error) {
body, err := json.Marshal(v)
...
return &AWSResponse{
StatusCode: status,
Headers: map[string]string{"Content-Type": "application/x-amz-json-1.1"},
Body: body,
}, nil
}IAM responses must be XML wrapped in the Query protocol envelope:
<GetInstanceProfileResponse xmlns="https://iam.amazonaws.com/doc/2010-05-08/">
<GetInstanceProfileResult>
<InstanceProfile>
<InstanceProfileName>my-profile</InstanceProfileName>
<InstanceProfileId>AIPA...</InstanceProfileId>
<Arn>arn:aws:iam::123456789012:instance-profile/my-profile</Arn>
<Path>/</Path>
<CreateDate>2026-04-02T00:00:00Z</CreateDate>
<Roles/>
</InstanceProfile>
</GetInstanceProfileResult>
<ResponseMetadata>
<RequestId>...</RequestId>
</ResponseMetadata>
</GetInstanceProfileResponse>Affected Operations
All IAM operations that return structs are silently broken when called from the Go SDK:
GetUser,CreateUser→Useris nilGetRole,CreateRole→Roleis nilGetInstanceProfile,CreateInstanceProfile→InstanceProfileis nilGetGroup,CreateGroup→Groupis nil- Any
List*operation → empty slice instead of populated list
Write-only operations (DeleteUser, AttachRolePolicy, etc.) appear to work because the SDK doesn't parse the response body.
Other Services Using Query Protocol
The same issue likely affects STS responses (GetCallerIdentity, AssumeRole). STS also uses the Query/XML protocol. Worth auditing whether sts_plugin.go has the same pattern.
Fix
Replace iamJSONResponse with an XML serializer that wraps results in the appropriate <*Response><*Result>...</*Result><ResponseMetadata>...</ResponseMetadata></*Response> envelope. The IAM API reference documents the exact XML structure for each operation.
Alternatively, register IAM under the application/x-amz-json-1.1 protocol content-type negotiation so the AWS SDK negotiates JSON — but this would require patching the SDK or using a custom HTTP client, which is not viable for end users.
Discovered Via
Integration testing Prism against Substrate in pkg/aws/substrate_integration_test.go. The TestSubstrateIAMInstanceProfile test panics with nil pointer dereference when accessing resp.InstanceProfile.Roles after a successful-appearing GetInstanceProfile call.
Activity
Release v0.45.7: IAM XML protocol + SSM timestamp fix (#260, #261, #262)