AWS resource policy review: external access
Brief
Identity policies say what a principal may do; resource-based policies say who may reach a resource, and they admit principals from other accounts and from the internet that no identity review will show. This page reads the policy on each S3 bucket, KMS key, Lambda function, SQS queue, SNS topic, secret, ECR repository and REST API, and turns the foreign principals into a table of the data they can reach.
On this page
- Situation
- A read-only review role in each account in scope with the
SecurityAuditmanaged policy, which includes Access Analyzer read, the client's list of their own account ids, their organization id and the accounts of vendors they have contracts with, and the regions the scope letter names. Every command here reads a policy, a finding, a tag or a metric; no object, message, secret value or image is read, and no policy is written. - Goal
- A reach table: each resource with a resource-based policy, every principal outside the account it admits, the condition that limits them if any, and the data class and size behind it.
- Outputs
- Representative examples on placeholder hosts, trimmed to the lines that matter. Not captured from a public fixture yet.
Check first
- The client's account ids, organization id and vendor account ids: the list every principal is compared to.
- Which regions are enabled; everything here but S3 is regional.
- Whether an analyzer exists in each region, and its zone of trust.
- Whether S3 Block Public Access is on at the account level.
- The rule: policies, findings, tags and metrics only, never an object.
Steps
AWS
What does Access Analyzer already know?
aws accessanalyzer list-analyzers --region us-east-1 --query 'analyzers[].[name,type,status]' --output text
an=$(aws accessanalyzer list-analyzers --region us-east-1 --query 'analyzers[?type==`ORGANIZATION`].arn | [0]' --output text)
aws accessanalyzer list-findings-v2 --region us-east-1 --analyzer-arn "$an" \
--filter '{"status":{"eq":["ACTIVE"]}}' \
--query 'findings[].[resourceType,resource,resourceOwnerAccount,status]' --output text
Expected output
org-external ORGANIZATION ACTIVE
AWS::S3::Bucket arn:aws:s3:::example-exports 111122223333 ACTIVE # <- a bucket reachable from outside the organization
AWS::KMS::Key arn:aws:kms:us-east-1:111122223333:key/1a2b3c4d-5e6f-4a5b-8c7d-9e0f1a2b3c4d 111122223333 ACTIVE
AWS::SQS::Queue arn:aws:sqs:us-east-1:111122223333:orders-inbound 111122223333 ACTIVE
Access Analyzer reports every resource a principal outside the zone of trust can reach. Analyzers are per region and exist only where created, and a finding is relative to its zone: with an account zone a grant to a sibling account is a finding. It covers buckets, roles, keys, functions, queues, topics, secrets, ECR repositories, EFS, snapshots and DynamoDB tables, not API Gateway. Archived findings are hidden by default, so we list ARCHIVED once and ask who archived each.
Negative result. An organization analyzer in every enabled region, active findings only for listed vendors, and archive rules by principal account rather than resource type.
Fix. Create an organization analyzer in every enabled region, send findings to Security Hub, and allow archive rules by principal account only.
Which S3 bucket policies admit other accounts or everyone?
aws s3control get-public-access-block --account-id 111122223333 --query PublicAccessBlockConfiguration
for b in $(aws s3api list-buckets --query 'Buckets[].Name' --output text); do
printf '%s\t' "$b"
aws s3api get-bucket-policy-status --bucket "$b" --query PolicyStatus.IsPublic --output text 2>/dev/null || echo none
done
aws s3api get-bucket-policy --bucket example-exports --query Policy --output text \
| jq -c '.Statement[] | {Sid, Principal, Action, Condition}'
Expected output
{
"BlockPublicAcls": true,
"IgnorePublicAcls": true,
"BlockPublicPolicy": true,
"RestrictPublicBuckets": true
}
example-assets False
example-exports False # <- not public, and still readable from a second account: the question Block Public Access does not answer
example-logs none
{"Sid":"PartnerRead","Principal":{"AWS":"arn:aws:iam::444455556666:root"},"Action":["s3:GetObject","s3:ListBucket"],"Condition":null}
{"Sid":"VpceOnly","Principal":"*","Action":"s3:GetObject","Condition":{"StringEquals":{"aws:SourceVpce":"vpce-0a1b2c3d4e5f67890"}}}
IsPublic answers one question, the policy text the other. A root principal from another account leaves which identities read the bucket to that account's administrators, and a * with an aws:SourceVpce condition is not public yet admits every identity in every account using that endpoint. Only principal and network condition keys narrow a *; aws:SecureTransport narrows nothing. A PrincipalOrgID that is not the client's grants to that vendor's whole organization.
Negative result. Every statement names a principal in the client's organization or a listed vendor, with a condition keeping any * to one network path or organization.
Fix. Keep Block Public Access on, replace root principals with named roles, add aws:PrincipalOrgID to statements that must stay open to the organization, and log access to buckets that admit another account.
Who can use each key, read each secret and pull each image?
aws kms get-key-policy --region us-east-1 --key-id 1a2b3c4d-5e6f-4a5b-8c7d-9e0f1a2b3c4d --policy-name default \
--query Policy --output text | jq -c '.Statement[] | select(.Effect=="Allow") | {Sid, Principal, Action}'
aws secretsmanager get-resource-policy --region us-east-1 --secret-id prod/partner/webhook \
--query ResourcePolicy --output text | jq -c '.Statement[] | {Principal, Action, Condition}'
aws ecr get-repository-policy --region us-east-1 --repository-name app-api \
--query policyText --output text | jq -c '.Statement[] | {Sid, Principal, Action}'
Expected output
{"Sid":"Enable IAM User Permissions","Principal":{"AWS":"arn:aws:iam::111122223333:root"},"Action":"kms:*"}
{"Sid":"PartnerDecrypt","Principal":{"AWS":"arn:aws:iam::444455556666:root"},"Action":["kms:Decrypt","kms:DescribeKey"]} # <- the vendor can decrypt any ciphertext under this key it can reach
{"Principal":{"AWS":"arn:aws:iam::444455556666:role/partner-sync"},"Action":"secretsmanager:GetSecretValue","Condition":null}
{"Sid":"PullFromCI","Principal":{"AWS":"arn:aws:iam::777788889999:root"},"Action":["ecr:BatchGetImage","ecr:GetDownloadUrlForLayer"]} # <- an account id on nobody's list
A key grant admits the account to every object, secret and snapshot under that key it can obtain, wider than any bucket grant; a secret's policy names one secret; an ECR pull grant hands over every layer of every image. Account 777788889999 is on neither list: unknown in the table, and to the client the same day. The secrets and KMS review carries on with grants and rotation.
Negative result. Keys admit only the client's accounts, secrets admit named roles in the organization, and ECR repositories admit the build accounts the client names.
Fix. Separate keys for data shared with a vendor from keys for everything else, aws:PrincipalOrgID on every secret policy, and ECR repositories shared through named role ARNs rather than account roots.
Which Lambda, SQS and SNS policies trust a service without a source?
aws lambda get-policy --region us-east-1 --function-name order-webhook --query Policy --output text \
| jq -c '.Statement[] | {Sid, Principal, Action, Condition}'
aws sqs get-queue-attributes --region us-east-1 --queue-url https://sqs.us-east-1.amazonaws.com/111122223333/orders-inbound \
--attribute-names Policy --query Attributes.Policy --output text | jq -c '.Statement[] | {Principal, Action, Condition}'
aws sns get-topic-attributes --region us-east-1 --topic-arn arn:aws:sns:us-east-1:111122223333:alerts \
--query Attributes.Policy --output text | jq -c '.Statement[] | {Sid, Principal, Action, Condition}'
Expected output
{"Sid":"FromApi","Principal":{"Service":"apigateway.amazonaws.com"},"Action":"lambda:InvokeFunction","Condition":{"ArnLike":{"AWS:SourceArn":"arn:aws:execute-api:us-east-1:111122223333:a1b2c3d4e5/*/POST/orders"}}}
{"Sid":"PublicUrl","Principal":"*","Action":"lambda:InvokeFunctionUrl","Condition":{"StringEquals":{"lambda:FunctionUrlAuthType":"NONE"}}} # <- anyone on the internet can run this function
{"Principal":{"Service":"sns.amazonaws.com"},"Action":"sqs:SendMessage","Condition":null} # <- any SNS topic in any account can write to this queue
{"Sid":"__default_statement_ID","Principal":{"AWS":"*"},"Action":["SNS:Publish","SNS:Subscribe","SNS:GetTopicAttributes"],"Condition":{"StringEquals":{"AWS:SourceOwner":"111122223333"}}}
A service principal is a * for that service unless a condition names the resource that may act. aws:SourceArn keeps the function to one API; the SQS statement with no condition lets any topic in any account send into the client's pipeline. The SNS default statement looks alarming and is not: AWS:SourceOwner pins it to the account. A NONE function URL is public whatever the identity policies say.
Negative result. Every service principal carries a source condition in the client's accounts, no * without an account or organization condition, and no NONE function URL on anything that touches data.
Fix. Add aws:SourceArn to every service principal statement, aws:PrincipalOrgID to queues and topics other accounts write to, and set function URLs to AWS_IAM or put them behind a gateway.
Which API Gateway resource policies exist, and what do they admit?
aws apigateway get-rest-apis --region us-east-1 \
--query "items[].[id,name,endpointConfiguration.types[0],length(policy || '')]" --output text
aws apigateway get-rest-api --region us-east-1 --rest-api-id a1b2c3d4e5 --query policy --output text \
| sed 's/\\"/"/g' | jq -c '.Statement[] | {Effect, Principal, Action, Condition}'
Expected output
a1b2c3d4e5 orders-api PRIVATE 312
f6g7h8i9j0 partner-api REGIONAL 0 # <- no policy on this one: open to any caller its authorizer accepts
{"Effect":"Allow","Principal":"*","Action":"execute-api:Invoke","Condition":{"StringEquals":{"aws:SourceVpce":"vpce-0a1b2c3d4e5f67890"}}}
Access Analyzer does not cover API Gateway, so every REST API is read by hand; the fourth column is the policy's length, 0 meaning none. The policy comes back as one escaped string, hence the sed. A private API's aws:SourceVpce condition does the work; a regional API with no policy is reachable by anyone its authorizer accepts, which is the Web and API track's question.
Negative result. Every private API has a policy naming its endpoint; every other API has a policy naming the client's accounts or an authorizer the client meant to expose.
Fix. A resource policy on every REST API, aws:SourceVpce for private APIs and aws:PrincipalOrgID or aws:SourceAccount for cross-account ones, and a Config rule on endpoint type.
What can each foreign principal reach?
aws s3api get-bucket-tagging --bucket example-exports --query 'TagSet[?Key==`DataClass`].Value' --output text
aws cloudwatch get-metric-statistics --region us-east-1 --namespace AWS/S3 --metric-name NumberOfObjects \
--dimensions Name=BucketName,Value=example-exports Name=StorageType,Value=AllStorageTypes \
--start-time 2026-10-27T00:00:00Z --end-time 2026-10-29T00:00:00Z --period 86400 --statistics Average \
--query 'sort_by(Datapoints,&Timestamp)[-1].Average' --output text
aws cloudwatch get-metric-statistics --region us-east-1 --namespace AWS/S3 --metric-name BucketSizeBytes \
--dimensions Name=BucketName,Value=example-exports Name=StorageType,Value=StandardStorage \
--start-time 2026-10-27T00:00:00Z --end-time 2026-10-29T00:00:00Z --period 86400 --statistics Average \
--query 'sort_by(Datapoints,&Timestamp)[-1].Average' --output text
Expected output
Confidential
48213.0 # <- objects the partner account can list and read
219482345472.0
For a bucket, the classification tag, object count and size from the daily storage metrics, sorted because datapoints come back unordered; for a key, the resources encrypted under it; for a queue, ApproximateNumberOfMessages; for a repository, describe-images. No object is read, and the row still says what the principal holds: 48,213 confidential objects, 204 GiB, readable from account 444455556666 by any identity its administrators choose, which the cloud finding write-up carries into the report.
Negative result. Every external grant lands on a resource tagged for sharing with that account, confirmed by the client in writing.
Fix. A data classification tag on every bucket and key, and a Config rule that flags an external grant on anything tagged above internal.
The defender sees
Our reads, under the review role: ListAnalyzers, ListFindingsV2, GetAccountPublicAccessBlock, ListBuckets, GetBucketPolicy, GetBucketPolicyStatus, GetBucketTagging, GetKeyPolicy, GetResourcePolicy, GetRepositoryPolicy, GetPolicy20150331v2, GetQueueAttributes, GetTopicAttributes, GetRestApis, GetRestApi and GetMetricStatistics. None is worth an alert; these are: PutBucketPolicy, DeleteBucketPolicy, PutKeyPolicy, PutResourcePolicy on a secret, SetRepositoryPolicy, AddPermission20150331v2 and CreateFunctionUrlConfig20211031 on Lambda, SetQueueAttributes with Policy, SetTopicAttributes, UpdateRestApi patching /policy, and PutAccountPublicAccessBlock. Each carries the identity that opened the resource. Access Analyzer turns those writes into a finding within about half an hour; Config rules such as s3-bucket-public-read-prohibited, s3-bucket-policy-grantee-check and lambda-function-public-access-prohibited flag the resource. Without these, the grants have been open since the write event, and once that is older than event history keeps, nobody can say who opened them: a finding beside the grant.
Done when
Every supported resource type in every in-scope region has had its policies read or its Access Analyzer findings listed, every external principal is marked as client account, vendor or unknown, and each unknown or public grant has a row with the data behind it.
Not covered
Identity policies (see the IAM escalation checks) and role trust (see the trust policy review), anonymous bucket tests from outside (see public bucket checks), and secret rotation and KMS grants in depth (see the secrets and KMS review); the outputs shown are representative examples on placeholder accounts, not captured runs.