

# Logging and monitoring agent and workload identity

**Preview release**  
Agent and workload identity is in preview release for AWS Identity and Access Management (IAM) and is subject to change.

AWS CloudTrail records every agent and workload identity API call, and the role session that carries each workload's identity. Use CloudTrail to audit configuration changes, to trace what a specific workload did, and to investigate failed issuance. Use Amazon EventBridge to alert on configuration changes.

IAM and AWS Security Token Service (AWS STS) CloudTrail logging works as described in Logging IAM and AWS STS API calls with AWS CloudTrail.

## Events that CloudTrail records
<a name="wi-lm-events"></a>


| Event | Logged when | What it shows | 
| --- | --- | --- | 
| CreateWorkloadIdentityProvider, DeleteWorkloadIdentityProvider, and other provider, template, policy, and signer actions | Someone changes your setup | Who made the change, and the request | 
| EnableOrganizationLevelResources, DisableOrganizationLevelResources | The management account turns organization-level resources on or off | Who made the change | 
| The service's own create or update event, such as CreatePodIdentityAssociation or CreateAgentRuntime | Someone assigns a template to a resource | The template ARN, in the request parameters | 
| IssueWorkloadIdentityContext | A service attests a workload | The attestation document, not redacted, so you can see what was checked; the resulting identifier; the template. CloudTrail redacts the signed context. The event has the same request ID as the AssumeRole event that follows it. | 
| AssumeRole with provided context | AWS STS creates a workload's role session | The workload's identifier (subject), provider (issuer), and template (workloadIdentityTemplateArn), in `userIdentity.onBehalfOf`. For an organization-level template, issuedFor names the member account. The source account and resource that the service sent, in `additionalEventData`. | 
| GetWebIdentityToken | A workload requests a JSON Web Token SPIFFE Verifiable Identity Document (JWT-SVID) | The calling session and the request | 
| GetCertificate | A workload requests an X.509 SPIFFE Verifiable Identity Document (X.509-SVID). AWS Private Certificate Authority (AWS Private CA) also records IssueCertificate and GetCertificate events (event source acm-pca.amazonaws.com), because AWS STS calls it with the workload's role session. | The workload's identifier, the certificate's serial number, the requested duration, and NotAfter | 
| Calls to other AWS services | A workload uses its session | The workload's identifier, provider, and template, in `userIdentity.onBehalfOf`. If an event doesn't have that field, match the session's access key ID to the AssumeRole event that created the session. | 

The attestation document describes where your workload runs, which version of it runs, and which instance or session it is. For example, a document from Amazon EKS names the cluster, namespace, service account, and pod. A document from AgentCore runtime names the runtime, its version, and the session. It holds no secrets. For complete example records, see Logging IAM and AWS STS API calls with AWS CloudTrail.

When an organization-level provider or template is created, changed, or deleted from a member account, for example by a delegated administrator, CloudTrail records the event in both the calling account and the organization's management account.

## Trace what a workload did
<a name="wi-lm-trace"></a>

Agent and workload identities aren't stored as records, so you can't list them in IAM. CloudTrail is how you find them.

### Find every action by one workload
<a name="wi-lm-trace-one"></a>

CloudTrail names the workload on the events that it causes. The AssumeRole event that creates a workload's role session has the workload in `userIdentity.onBehalfOf`. Events for the calls that the workload then makes with the session have the same field.

```json
{
  "userIdentity": {
      "type": "AssumedRole",
      "invokedBy": "pods.eks.amazonaws.com",
      "onBehalfOf": {
          "workloadIdentityTemplateArn": "arn:aws:iam::111122223333:workload-identity-template/eks-prod-1",
          "subject": "spiffe://111122223333.aws.internal/us-east-1/eks/prod-cluster-1/ns/payments/sa/checkout-sa",
          "subjectType": "workload",
          "issuer": "arn:aws:iam::111122223333:workload-identity-provider/payments-prod"
      }
  },
  "responseElements": {
      "credentials": {
          "accessKeyId": "ASIAIOSFODNN7EXAMPLE",
          "sessionToken": "<session-token>",
          "expiration": "2026-12-01T17:00:00Z"
      }
  },
  "additionalEventData": {
      "sourceAccount": "111122223333",
      "sourceArn": "arn:aws:eks:us-east-1:111122223333:cluster/prod-cluster-1"
  }
}
```

**To search by workload**

Send a trail to Amazon CloudWatch Logs, and run this query in CloudWatch Logs Insights. It returns the workload's events across every role session and refresh.

```text
fields eventTime, awsRegion, eventSource, eventName, errorCode
| filter userIdentity.onBehalfOf.subject = "spiffe://111122223333.aws.internal/us-east-1/eks/prod-cluster-1/ns/payments/sa/checkout-sa"
    and userIdentity.onBehalfOf.issuer = "arn:aws:iam::111122223333:workload-identity-provider/payments-prod"
| sort eventTime asc
```

Several pods can share one identity. To tell them apart, look at the role session ARN on each event. On Amazon EKS, it includes the pod name.

**To find a workload's role sessions in Event history**

CloudTrail Event history shows the management events from the last 90 days in the current Region, and needs no setup. It has no filter for onBehalfOf. Start from the AssumeRole event, which also returns the session's access key ID, and follow that key from one event to the next.

1. Open the CloudTrail console at [https://console.aws.amazon.com/cloudtrail/](https://console.aws.amazon.com/cloudtrail/).

1. Choose the Region where the workload runs. The service that runs the workload calls AWS STS in that Region.

1. In the navigation pane, choose **Event history**.

1. Set the time range to when the workload was running.

1. For **Lookup attributes**, choose **Event name**, and then enter AssumeRole.

1. Choose an event to view its event record. An event for your workload has the workload's identifier in `userIdentity.onBehalfOf.subject` and your provider's ARN in `userIdentity.onBehalfOf.issuer`.

1. Copy the access key ID from `responseElements.credentials.accessKeyId`.

**To find what a role session did**

1. For **Lookup attributes**, choose **Access key ID**, and then paste the access key ID.

1. Set the time range from the AssumeRole event's time to the session's expiration, in `responseElements.credentials.expiration`.

1. Review the events. Each one is a call that the session made.

1. Repeat in each Region where the workload calls AWS services. IAM events are recorded in US East (N. Virginia) us-east-1.

The service that runs a workload refreshes its role session regularly. Each refresh creates a new AssumeRole event with a new access key ID. To cover a workload's full activity, repeat these steps for each AssumeRole event in the time range.

**Note**  
Event history doesn't include data events, such as Amazon Simple Storage Service (Amazon S3) GetObject and PutObject calls. To trace data events, create a trail that logs them, and send the trail to Amazon CloudWatch Logs. Then query the log group with CloudWatch Logs Insights. For more information, see Working with CloudTrail Event history in the AWS CloudTrail User Guide and Analyzing log data with CloudWatch Logs Insights in the Amazon CloudWatch Logs User Guide.

### Find which workloads used a shared role
<a name="wi-lm-trace-shared"></a>

In Event history, look up AssumeRole events and compare `userIdentity.onBehalfOf.subject` across events with the same `requestParameters.roleArn`. To group them, send a trail to CloudWatch Logs and run this query in CloudWatch Logs Insights:

```text
fields userIdentity.onBehalfOf.subject
| filter eventName = "AssumeRole" and requestParameters.roleArn = "arn:aws:iam::111122223333:role/eks-pod-identity-role"
| stats count(*) by userIdentity.onBehalfOf.subject
```

### Follow a workload across accounts
<a name="wi-lm-trace-accounts"></a>

Event history shows one account at a time, so repeat the steps in each account the workload reaches. To search every account at once, send an organization trail to CloudWatch Logs and query it with CloudWatch Logs Insights for the AssumeRole events that name the workload.

### List the identities a template built
<a name="wi-lm-trace-list"></a>

In Event history, look up IssueWorkloadIdentityContext events and read the identifier in each event for that template. To list the distinct identifiers, query a trail's log group in CloudWatch Logs Insights.

## Investigate failed issuance
<a name="wi-lm-failed"></a>

When attestation fails, the service that runs the workload doesn't start it or doesn't give it credentials. CloudTrail records the failed IssueWorkloadIdentityContext event only in the account of the service that attested the workload, not in your account. To find the cause, check the errors that the service reports for the action that requested the identity, such as creating a pod or invoking an agent runtime. Failures after attestation, such as a trust policy that denies the role, aren't recorded in your account either. CloudTrail records a failed AssumeRole call only in the caller's account, and the caller is the AWS service that assumes the role for the workload, not the account of the workload's role.


| Error | Reason | What to do | 
| --- | --- | --- | 
| AccessDenied on IssueWorkloadIdentityContext | The attestation policy doesn't allow the service, account, resource, or facts. Or the template has no attestation policy, or the template doesn't exist. | Compare the attestation document in the event with the policy. | 
| InvalidAttestationDocument | unresolvedTemplateVariable: the template uses an attested value that the document doesn't contain. | Check that the attested facts include every key in the pattern. | 
| InvalidAttestationDocument | unexpectedAttestation: the document contains a key that the calling service can't attest. | Contact the service that runs the workload. | 
| InvalidAttestationDocument | providerNotFound, cannotParse, duplicateKey, invalidKey, or tooLarge | Contact the service that runs the workload. | 
| InvalidWorkloadIdentityConfiguration | identifierTooLarge: the identifier is longer than 256 characters. | Shorten the path prefix or pattern. | 
| InvalidWorkloadIdentityConfiguration | unrenderableTemplate: IAM can't build a valid identifier, for example because an attested value is . or .. or contains a slash. | Rename the resource, such as the namespace, or change the pattern. | 
| InvalidWorkloadIdentityConfiguration | caseOnlyDuplicateTagKeys, unsupportedTagKeyCharacters: a tag key on the template differs from another only in case, or contains a character that isn't supported. | Fix the template's tags. | 
| AccessDenied on AssumeRole | The role's trust policy doesn't let the service assume the role, or explicitly denies sts:SetContext. | Update the trust policy. See Role trust policies. | 
| AccessDenied on AssumeRole | "The provided context is not valid for this request." The context was presented for a different role than the one it was issued for. | Use the role that was named when the context was issued. | 
| AccessDenied on AssumeRole | "The provided context is not valid for this request." The template was deleted after the context was issued. | Expected after revocation. | 
| AccessDenied on AssumeRole | "The provided context is not valid for this request." The calling session already carries a different origin identity. | A session's origin identity can't be replaced. Start from a session that doesn't carry one. | 
| ValidationError | The provider ARN doesn't match the context, or isn't a valid workload identity provider ARN. | Contact the service that runs the workload. | 
| ValidationError | The context is malformed, was altered, or its signature didn't verify. | The service requests a new context. If this repeats, contact the service that runs the workload. | 
| ValidationError | The context expired. A context is valid for 60–300 seconds after issuance. | The service requests a new context. If this repeats, contact the service that runs the workload. | 
| InvalidContextAssertion | The role's account hasn't enabled AWS STS in the Region, or the role is in a different partition. | Enable the Region for that account, or use a role in the same partition. | 
| SessionDurationEscalation | A JWT-SVID was requested for longer than the remaining session. | Request a shorter duration. | 
| SignerNotConfigured, RegionalSignerUnavailable, MalformedCertificateSigningRequest | An X.509-SVID request failed. RegionalSignerUnavailable also means the signer isn't active yet, or the CA is disabled, expired, or not replicated to the Region. | See [Get an X.509-SVID](workload-identity-authenticate-external.md#wi-ae-get-x509). | 

## Monitor with EventBridge
<a name="wi-lm-eventbridge"></a>

### React to configuration changes
<a name="wi-lm-eventbridge-config"></a>

Create an Amazon EventBridge rule that matches changes to providers, templates, their policies, signers, and tags:

```json
{
  "source": ["aws.iam"],
  "detail-type": ["AWS API Call via CloudTrail"],
  "detail": {
    "eventSource": ["iam.amazonaws.com"],
    "eventName": [
      { "prefix": "CreateWorkloadIdentity" }, { "prefix": "UpdateWorkloadIdentity" }, { "prefix": "DeleteWorkloadIdentity" },
      { "prefix": "PutWorkloadIdentity" }, { "prefix": "EnableWorkloadIdentity" }, { "prefix": "DisableWorkloadIdentity" },
      { "prefix": "TagWorkloadIdentity" }, { "prefix": "UntagWorkloadIdentity" },
      "EnableOrganizationLevelResources", "DisableOrganizationLevelResources"
    ]
  }
}
```

IAM is a global service, so create this rule in US East (N. Virginia) us-east-1, where IAM events are delivered to Amazon EventBridge.

IAM doesn't publish CloudWatch metrics for agent and workload identity. To monitor configuration changes, use the CloudTrail events and the EventBridge rule on this page.