When it is written
SetRepositoryPolicy applies the JSON document in policyText to the repository in repositoryName, replacing any earlier policy. registryId names the registry (an account ID) and defaults to the caller's. A policy that would stop the caller from setting another policy later is refused unless force is true. AWS's own API example sets a policy on a repository that lets every AWS account pull from it, which shows what a wildcard principal means here.
The response returns the policy, the registry and the repository. AWS publishes no example record for this call: the paths below follow the API's parameter names.
How to turn it on
AWS CloudTrail records SetRepositoryPolicy calls to ecr.amazonaws.com without any setup. Vendor documentation
Management events, which include the IAM, AWS STS and AWS Organizations calls that identity attacks leave behind, are recorded in every account without any setup and stay in Event history for 90 days, per Region. Event history is not a collection point: to keep the records longer, receive them from every Region and account, and send them to a SIEM, create a trail (or a CloudTrail Lake event data store).
- A trail created in the console is multi-Region; an organization trail created in the management account covers every member account.
- A trail records read and write management events by default. Data events (object-level Amazon S3, Lambda invocations and others) are not recorded unless you add them, and they cost extra.
- CloudTrail typically delivers records within an average of about 5 minutes of the API call; AWS does not guarantee the delay.
- Since November 22, 2021, events of global services such as IAM, AWS STS and CloudFront are recorded in US East (N. Virginia): a single-Region trail in another Region no longer receives them. Use a multi-Region trail.
aws cloudtrail describe-trails --include-shadow-trailsaws cloudtrail get-trail-status --name <trail-name>aws cloudtrail get-event-selectors --trail-name <trail-name>aws cloudtrail lookup-events --lookup-attributes AttributeKey=EventName,AttributeValue=SetRepositoryPolicy --max-results 5Fields
The operation’s own fields first, then the fields every AWS CloudTrail record has. Field names are the JSON paths of the record as the vendor documents it.
| Field | What it holds |
|---|---|
requestParameters. | Name of the repository that received the policy (from the API name repositoryName; not shown in an AWS example). |
requestParameters. | The registry that holds the repository, an account ID; absent when the caller's own registry was meant (from registryId; not shown in an AWS example). |
requestParameters.Read by 1 rule | The repository policy as JSON text (from policyText; not shown in an AWS example). |
requestParameters. | Whether the caller forced a policy that could lock it out of setting another one (from force; not shown in an AWS example). |
Fields every AWS CloudTrail record has (23)
| Field | What it holds |
|---|---|
eventVersion | Version of the record format, major and minor (for example 1.11). A new minor version only adds fields. |
eventTime | When the request was completed, in UTC, from the clock of the host that served the API endpoint. |
eventSourceRead by 2 rules | The service the request was made to, usually its short name plus .amazonaws.com (iam.amazonaws.com). |
eventNameRead by 2 rules | The API action that was requested. The operation this page is about. |
awsRegion | The Region the request was made to. Most global service events (IAM, for example) are logged as occurring in us-east-1. |
sourceIPAddress | The address the request came from. For a call made by an AWS service on your behalf it holds the service's DNS name, and AWS Internal for calls AWS makes. |
userAgent | The client that made the request (the console, an SDK, the AWS CLI, or the calling service), as the client reports it. |
userIdentity. | The kind of identity that made the request (Root, IAMUser, AssumedRole, FederatedUser, AWSService, IdentityCenterUser and others). |
userIdentity. | ARN of the identity that made the request; for an assumed role, the role session (assumed-role/<role>/<session>). |
userIdentity. | The account that owns the identity that made the request. |
userIdentity. | The access key that signed the request; an ASIA prefix marks temporary credentials, AKIA a long-term key. |
userIdentity. | For temporary credentials, the role (or user) that issued the session. |
errorCode | The AWS error when the request failed (AccessDenied, NoSuchEntity...); absent when it succeeded. |
errorMessage | The description of the error, including authorization failures. |
requestParameters | The parameters sent with the request, as the service's API reference documents them. |
responseElements | What the service returned for an action that changes something; null for read-only calls and for actions that return nothing. |
requestID | The identifier the service gave the request. |
eventID | A GUID CloudTrail gives each record, unique per event. |
readOnly | Whether the operation only reads (true) or changes something (false). |
eventType | How the record was produced, AwsApiCall for an API call. |
managementEvent | Whether the record is a management event. |
recipientAccountId | The account that received the record; differs from userIdentity.accountId when another account acted on your resource. |
eventCategory | The event category, Management for management events. |
Values to know
requestParameters.policyText
| Value | Meaning | Signal |
|---|---|---|
a wildcard principal | Every AWS account can perform the granted actionsReported by the second detection rule, unless a condition narrows the statement. | Attack signal |
an account ID outside your organization | Another account was given access to the repositoryThe case the hypothesis looks for. | Attack signal |
errorCode
| Value | Meaning | Signal |
|---|---|---|
RepositoryNotFoundException | The repository does not exist in that registry | Failure |
Volume and noise
Low to medium: repository policies are written when a repository is created by a template and when a new account or service needs its images. A wildcard principal, an account outside your organization, or a change by a principal that does not manage the registry is the record to read first.
Keeping it manageable
- Read the principals in
requestParameters.policyText: a wildcard ("Principal": "*"or"AWS": "*") is what the second detection rule reports, an account outside your organization is what the hypothesis looks for. Read the conditions of the statement too. - Check the actions granted: pull actions expose the images, push actions let the other side replace them.
- Allow the roles of your deployment pipelines and review calls by anyone else.
Sample event
A AWS CloudTrail record in the vendor’s format, with made-up values.
{
"eventVersion": "1.11",
"userIdentity": {
"type": "IAMUser",
"principalId": "AIDAEXAMPLEPRINCIPAL1",
"arn": "arn:aws:iam::111122223333:user/ops-admin",
"accountId": "111122223333",
"accessKeyId": "AKIAEXAMPLEOPSADMIN1",
"userName": "ops-admin"
},
"eventTime": "2026-11-18T09:30:12Z",
"eventSource": "ecr.amazonaws.com",
"eventName": "SetRepositoryPolicy",
"awsRegion": "us-east-1",
"sourceIPAddress": "203.0.113.24",
"userAgent": "aws-cli/2.17.0 Python/3.11.9 Linux/6.8 exe/x86_64",
"requestParameters": {
"repositoryName": "orders-api",
"registryId": "111122223333",
"policyText": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Sid\":\"AllowPull\",\"Effect\":\"Allow\",\"Principal\":\"*\",\"Action\":[\"ecr:BatchGetImage\",\"ecr:GetDownloadUrlForLayer\"]}]}",
"force": false
},
"responseElements": null,
"requestID": "6f1c2d3e-4a5b-4c6d-8e9f-0a1b2c3d4e5f",
"eventID": "0b9e8d7c-6a5f-4e3d-9c2b-1a0f9e8d7c6b",
"readOnly": false,
"eventType": "AwsApiCall",
"managementEvent": true,
"recipientAccountId": "111122223333",
"eventCategory": "Management"
}Attacks this event reveals
Detection rules that read this event: