A resource-based policy decides who can reach a bucket, key, function or queue from outside your IAM roles, and one wildcard principal in it can open that resource to every AWS account in the world. Resource-based policies are attached to the resource itself, name the principals allowed to use it, and are evaluated alongside the caller's identity-based policies. This guide is for cloud security engineers, platform teams and reviewers who write or approve these policies for Amazon S3, AWS KMS, AWS Lambda and Amazon SQS. It covers how evaluation works, the service-specific rules that catch teams out, safe condition keys, guardrails at organisation level and how to detect drift. For the choice between sharing through a resource policy and through a cross-account role, see Cross-Account Roles vs Resource-Based Policies; this page assumes you have chosen a resource policy and need to write it well.
This is an independent guide from NHI Mgmt Group, based on AWS's public documentation as of December 2026. It is not sponsored or reviewed by AWS. Product features change, so confirm settings against AWS's current documentation.
Key takeaways
- Same account, either policy can allow: AWS checks for a Deny, then allows the request if any identity-based or resource-based policy allows it; cross-account, both sides must allow.
- Every service has its own rules: a KMS key policy must enable IAM policies, an S3 bucket policy is judged public unless it uses fixed values, a Lambda function URL with auth type NONE needs a public resource policy, and SQS refuses some actions across accounts.
- Pin service principals to a source: whenever a policy grants an AWS service principal, add aws:SourceArn, aws:SourceAccount, aws:SourceOrgID or aws:SourceOrgPaths to prevent the cross-service confused deputy.
- Principal "*" must always carry a fixed condition: aws:PrincipalOrgID or a specific aws:SourceVpce turns a public statement into a bounded one.
- Guardrails sit above the policy: S3 Block Public Access, resource control policies (RCPs) and IAM Access Analyzer external access findings catch the mistakes a single policy review misses.
How resource-based policies are evaluated
AWS describes identity-based and resource-based policies as both being permissions policies that are evaluated together. For a request in the same account, AWS first looks for an explicit Deny anywhere; if none exists, at least one Allow in either policy is enough. AWS states that it does not matter whether the Allow sits in the identity-based policy or the resource-based policy. For a request from one account to another, the caller needs an identity-based policy allowing the action and the resource policy in the other account must allow that caller. If either is missing, the request fails.
Two consequences shape every review:
- A resource policy can grant access on its own inside the account. A bucket policy naming a role gives that role access even if its IAM policy does not mention S3. Reviewing IAM policies alone understates who can reach the data.
- Cross-account access is a two-key system. The resource owner controls who can have access; the caller's account controls who does. AWS KMS documentation puts it exactly that way for keys.
Guardrails cap both. Service control policies limit what principals in member accounts can do; resource control policies limit what can be done to resources in member accounts. Permission boundaries cap identity-based permissions on a role but do not cap every resource-based grant (see the AWS IAM Permissions Boundaries Guide), which is one more reason to get the resource policy right. How the three guardrails differ is set out in Permission Boundaries vs SCPs.
Service-specific rules at a glance
| Service | Policy name | Rule that catches teams out | Safe pattern |
|---|---|---|---|
| Amazon S3 | Bucket policy (plus access point policies) | S3 assumes a bucket policy is public until it grants access only to fixed values | Keep Block Public Access on at account level; ACLs disabled (Bucket owner enforced); name principals or use aws:PrincipalOrgID |
| AWS KMS | Key policy | Without the account statement in the key policy, IAM policies that allow use of the key have no effect | Separate key administrators from key users; cross-account callers use the full key ARN |
| AWS Lambda | Function resource-based policy | put-resource-policy replaces the whole policy; add-permission supports only aws:SourceArn, aws:SourceAccount and aws:PrincipalOrgID | Manage the full JSON policy in code; scope service principals to a source ARN |
| Amazon SQS | Queue access policy | Some actions (for example CreateQueue, DeleteQueue, SetQueueAttributes, AddPermission) cannot be granted across accounts | Grant only send or receive actions to named principals or a pinned service principal |
Amazon S3 bucket policies
Disable ACLs first. AWS documents that Object Ownership defaults to Bucket owner enforced, with all ACLs disabled, and recommends keeping ACLs disabled for most modern use cases, sharing data through the bucket policy instead. With ACLs disabled, the bucket policy is the single place to review access.
Understand what "public" means to S3. AWS states that S3 begins by assuming a bucket policy is public and then checks whether it qualifies as non-public. It is non-public only if it grants access to fixed values (no wildcard, no policy variable) for at least one of: a named AWS principal or service principal, aws:PrincipalOrgID, aws:SourceIp CIDR blocks, aws:SourceArn, aws:SourceVpc, aws:SourceVpce, aws:SourceOwner, aws:SourceAccount, aws:userid (outside the pattern AROLEID:*), s3:DataAccessPointArn or s3:DataAccessPointAccount. AWS gives the example that "aws:SourceVpc": "vpc-*" with StringLike is public, while a specific VPC ID with StringEquals is not. Very broad aws:SourceIp ranges (wider than /8 for IPv4 or /32 for IPv6, excluding RFC 1918 ranges) also count as public.
Use Block Public Access as the backstop. The four settings are BlockPublicAcls, IgnorePublicAcls, BlockPublicPolicy and RestrictPublicBuckets. They can be set at organisation, account and bucket or access point level, and S3 applies the most restrictive combination. AWS recommends applying BlockPublicPolicy at account level. Note that the settings do not rewrite existing policies: removing them makes a bucket with a public policy public again.
Typical non-public patterns:
- Organisation sharing: Principal "*" with
"StringEquals": {"aws:PrincipalOrgID": "o-exampleorgid"}. - Private network only: a Deny for requests where aws:SourceVpce is not your endpoint ID, combined with named Allow statements.
- Service delivery (for example logs): the service principal plus aws:SourceAccount and aws:SourceArn fixed to your trail, distribution or load balancer.
Leaked keys and over-broad buckets remain a recurring pairing in incidents. In the Sisense Breach, a credential in a GitLab repository reportedly opened S3 buckets full of customer tokens; resource policies limited to expected network paths and principals reduce what a single stolen credential can reach. To audit an existing estate, follow How to Audit Cloud Resource Policies for Public Access.
AWS KMS key policies
Every KMS key must have a key policy, and AWS states that no principal, including the account root user or key creator, has any permission to a key unless a key policy, IAM policy or grant explicitly allows it. The default policy created through the API contains a single statement that gives the owning account full access and allows IAM policies to grant access to the key. AWS warns that without this statement, IAM policies that allow access to the key are ineffective, although IAM policies that deny access still work. If the only principal with access is deleted, the key becomes unmanageable and AWS Support must be contacted.
- Separate administrators from users: the console default policy has a key administrators statement (Create*, Describe*, Enable*, Put*, Update*, Revoke*, Disable*, Delete*, ScheduleKeyDeletion and others) and a key users statement (Decrypt, Encrypt, GenerateDataKey*, ReEncrypt*, DescribeKey). AWS notes that key administrators can change the key policy and create grants, so they can give themselves cryptographic access; treat that role as privileged.
- Constrain grants: the default key user statement allows CreateGrant, ListGrants and RevokeGrant only when
kms:GrantIsForAWSResourceis true, so the user cannot create grants directly, only through integrated services. - Cross-account use needs both policies: the key policy in the owning account and an IAM policy in the external account. AWS lists the operations that work across accounts (cryptographic operations, CreateGrant, DescribeKey, GetKeyRotationStatus, GetPublicKey, ListGrants, RetireGrant, RevokeGrant); others such as ScheduleKeyDeletion have no effect. Callers must use the key ARN or alias ARN, or AWS assumes the key is in their own account.
- Never bypass the lockout check casually: a policy that would lock the account out is rejected unless BypassPolicyLockoutSafetyCheck is set to true. Keep that flag out of pipelines.
The AWS KMS Security Guide covers rotation, multi-Region keys and monitoring.
AWS Lambda function policies
Lambda resource-based policies grant other accounts, organisations and AWS services permission to invoke or manage a function, version or alias. AWS recommends managing the full JSON policy. Two operations behave differently: add-permission adds a single Allow statement without overwriting, but supports only aws:SourceArn, aws:SourceAccount and aws:PrincipalOrgID as conditions; put-resource-policy replaces the whole existing policy. Pass --revision-id so a stale update fails instead of overwriting a newer policy. The maximum policy size is 20 KB.
- Service triggers: when S3, SNS or EventBridge invokes a function, grant the service principal
lambda:InvokeFunctionwith aws:SourceAccount and, where possible, aws:SourceArn fixed to the bucket, topic or rule. - Organisation callers: use aws:PrincipalOrgID or aws:PrincipalOrgPaths rather than listing accounts.
- Function URLs: with auth type AWS_IAM, Lambda authenticates callers through IAM and the resource policy. With auth type NONE, AWS states that Lambda performs no authentication and the resource policy must grant public access. The console default statement grants Principal "*" lambda:InvokeFunctionUrl with the condition
lambda:FunctionUrlAuthType= NONE, and lambda:InvokeFunction withlambda:InvokedViaFunctionUrl= true. AWS states that starting in October 2025, new function URLs require both permissions. Treat any function URL with auth type NONE as an internet-facing API that must do its own authentication.
More on runtime roles and secrets is in the AWS Lambda Security Guide.
Amazon SQS queue policies
SQS access policies grant send, receive and related actions on a queue. AWS documents that cross-account permissions do not apply to a set of actions including AddPermission, CreateQueue, DeleteQueue, SetQueueAttributes, TagQueue and UntagQueue, so those stay with the owning account. AWS examples use Principal "*" for anonymous access, bounded in one example by an aws:SourceIp range; in production, avoid anonymous statements entirely.
- SNS to SQS fan-out: grant
sqs:SendMessageto the SNS service principal with aws:SourceArn fixed to the topic ARN, in line with AWS's confused deputy guidance. - Cross-account producers: name the producing role ARN and grant only sqs:SendMessage; consumers get sqs:ReceiveMessage, sqs:DeleteMessage and sqs:GetQueueAttributes.
- Transport: a Deny statement on requests where aws:SecureTransport is false is a common hardening pattern for queues and buckets alike.
See the Amazon EventBridge, SNS and SQS Security Guide for encryption and dead-letter queue controls.
Condition keys that make policies safe
| Condition key | Use it when | Example value |
|---|---|---|
| aws:PrincipalOrgID | Sharing with every principal in your organisation | o-exampleorgid |
| aws:PrincipalOrgPaths | Sharing with one organisational unit path | o-exampleorgid/r-ab12/ou-ab12-11111111/* |
| aws:SourceArn | A service principal acts for one specific resource | arn:aws:sns:eu-west-2:111122223333:orders |
| aws:SourceAccount | A service principal acts for one account | 111122223333 |
| aws:SourceOrgID / aws:SourceOrgPaths | A service principal acts for resources anywhere in your organisation | o-exampleorgid |
| aws:SourceVpce | Access only through your VPC endpoint | vpce-0abc1234def567890 |
| lambda:FunctionUrlAuthType | Tie a function URL statement to its auth type | AWS_IAM |
| kms:GrantIsForAWSResource | Allow grants only via integrated services | true |
AWS recommends the four source keys wherever a resource policy grants access to an AWS service principal, because a service principal acts on behalf of many customers and could otherwise be steered to your resource from another account. Always use StringEquals with fixed values: wildcards defeat the purpose and, for S3, make the policy public. Full definitions are in the AWS IAM Global Condition Keys Reference.
Where identity fits
Resource policies are where non-human identities meet data. Each principal ARN in a policy is a role used by a pipeline, a function or a partner integration, and the policy outlives the project unless someone removes it. Record which workload each principal represents, prefer roles over IAM users in Principal elements, and remove grants when the role is retired. Unknown external account IDs in a policy deserve the same urgency as an unknown access key. The AWS Resource-Based Policies for Beginners page explains these ideas for newcomers.
Guardrails and a phased rollout
Resource control policies set the maximum available permissions for resources in member accounts across supported services including S3, KMS, SQS, Secrets Manager and STS. AWS stresses that RCPs grant nothing, do not affect resources in the management account and do not change the effective permissions of service-linked roles. They let you enforce aws:SourceOrgID or aws:PrincipalOrgID once, centrally, instead of in every policy.
- Baseline: enable an IAM Access Analyzer external access analyzer with the organisation as the zone of trust, in every Region you use (it only analyses resources in its own Region). Export all findings.
- Triage: mark each finding as intended (archive with a reason) or unintended (owner and fix date). Start with public findings, then unknown external accounts.
- Turn on the backstops: S3 Block Public Access at account and organisation level; Object Ownership set to Bucket owner enforced.
- Policy as code: move bucket, key, function and queue policies into infrastructure code with Access Analyzer policy validation and custom policy checks (for example, check that a change grants no new access) in the pipeline.
- RCP pilot: attach an RCP that denies access from outside the organisation to one test OU, watch CloudTrail for denied calls from legitimate partners, add explicit exceptions, then widen. Rollback is detaching the RCP, which takes effect without touching resource policies.
- Steady state: new external grants require a ticket; Access Analyzer findings route to the resource owner automatically.
Decision guidance
- Resource policy versus cross-account role: use a resource policy when the caller should keep its own identity and audit trail and the service supports one; use a role when you need to cap the caller's permissions centrally or the service has no resource policy. The comparison is in Cross-Account Roles vs Resource-Based Policies.
- Named principals versus organisation conditions: name principals for a handful of known callers; use aws:PrincipalOrgID or aws:PrincipalOrgPaths when the set changes often.
- Per-resource conditions versus RCPs: small estates can enforce conditions in each policy; organisations with many accounts should add RCPs so a single missed policy is not a data exposure.
- Function URL versus API Gateway: keep function URLs on AWS_IAM for service-to-service calls; front public endpoints with a layer that authenticates callers if the function itself does not.
Detection and measurement
CloudTrail management events record policy changes: PutBucketPolicy, DeleteBucketPublicAccessBlock and PutBucketOwnershipControls for S3; PutKeyPolicy and CreateGrant for KMS; AddPermission (logged as AddPermission20150331v2) and CreateFunctionUrlConfig for Lambda; SetQueueAttributes and AddPermission for SQS. Alert on any of these outside a pipeline role, and on new Access Analyzer external access findings. The IAM Access Analyzer Guide explains finding workflows.
Metrics:
- Active Access Analyzer external access findings not marked as intended (target zero), and median age.
- Percentage of accounts with account-level S3 Block Public Access fully enabled.
- Percentage of resource policies granting a service principal that carry a source condition key.
- Number of Lambda function URLs with auth type NONE, each with a documented owner.
- Percentage of resource policy changes made by the deployment pipeline rather than by people.
Common failure patterns
- Wildcard with a soft condition: Principal "*" with StringLike on aws:SourceVpc "vpc-*", which S3 treats as public.
- Removed account statement: a KMS key policy rewritten without the account statement, so IAM-based access breaks and only the named principals remain, risking an unmanageable key.
- Overwritten function policy: put-resource-policy run from a script replaces grants that other teams added with add-permission.
- Unpinned service principal: an SQS or S3 policy granting sns.amazonaws.com or a logging service without aws:SourceArn or aws:SourceAccount, open to the cross-service confused deputy.
- Turning off Block Public Access to "test": existing public policies become live immediately.
- Stale external accounts: a former vendor's account ID left in bucket and key policies years after the contract ended.
Framework mapping
| Control area | NIST SP 800-53 Rev 5 | NIST CSF 2.0 | MITRE ATT&CK |
|---|---|---|---|
| Least privilege resource policies and conditions | AC-3, AC-6 | PR.AA-05 | T1530 |
| Public access prevention (Block Public Access, RCPs) | AC-3, CM-7 | PR.DS-01 | T1530 |
| KMS key policy and grant management | SC-12 | PR.DS-01 | None mapped |
| Policy change logging and analyzer findings | AU-12, AU-6 | DE.CM-03 | T1098.003 |
Practitioner checklist
- Enable IAM Access Analyzer external access with the organisation as zone of trust in every Region in use.
- Turn on S3 Block Public Access at account and organisation level and keep ACLs disabled.
- Pair every Principal "*" with a fixed aws:PrincipalOrgID, aws:SourceVpce or similar condition.
- Add aws:SourceArn or aws:SourceAccount to every statement granting an AWS service principal.
- Keep the account statement in KMS key policies and separate key administrators from key users.
- Manage Lambda function policies as full JSON in code with revision IDs; review every function URL with auth type NONE.
- Grant SQS producers and consumers only the send or receive actions they need.
- Pilot an RCP that blocks access from outside the organisation, then roll it out by OU.
- Alert on policy change events made outside the deployment pipeline.
Standards and references
- AWS: Identity-based policies and resource-based policies
- AWS: The confused deputy problem
- AWS: Blocking public access to your Amazon S3 storage
- AWS: Controlling ownership of objects and disabling ACLs for your bucket
- AWS: Default key policy (AWS KMS)
- AWS: Allowing users in other accounts to use a KMS key
- AWS: Viewing resource-based IAM policies in Lambda
- AWS: Resource control policies (RCPs)
Related NHI Mgmt Group resources: Cross-Account Roles vs Resource-Based Policies, Permission Boundaries vs SCPs, IAM Access Analyzer Guide, AWS Organizations and SCPs Guide.