S3 GetObject 403 across accounts while HeadObject works: the KMS key policy
A partner account could list and HEAD our S3 objects but every GetObject returned Access Denied. The bucket policy was fine; the objects were SSE-KMS encrypted and the key policy never trusted the other account. How we proved it and fixed both sides.
A data partner reads daily export files from a bucket in our account. After we moved the bucket's default encryption from SSE-S3 to SSE-KMS with our own key, their job started failing the next morning. Listing still worked. Fetching metadata still worked. Downloading did not:
$ aws s3 cp s3://acme-partner-exports/daily/2027-01-27.parquet .
download failed: s3://acme-partner-exports/daily/2027-01-27.parquet to ./2027-01-27.parquet
An error occurred (AccessDenied) when calling the GetObject operation: Access Denied
Files written before the encryption change still downloaded fine. Only new files failed.
Reproducing it
From the partner account (444455556666), with the role their job uses:
aws s3api list-objects-v2 --bucket acme-partner-exports --prefix daily/ --max-items 3
aws s3api head-object --bucket acme-partner-exports --key daily/2027-01-27.parquet
aws s3api get-object --bucket acme-partner-exports --key daily/2027-01-27.parquet /tmp/out
The first two succeeded. The head-object output contained the clue:
{
"ContentLength": 48211022,
"ServerSideEncryption": "aws:kms",
"SSEKMSKeyId": "arn:aws:kms:eu-west-1:111122223333:key/1a2b3c4d-5e6f-7a8b-9c0d-ef1234567890",
"BucketKeyEnabled": true
}
The third call failed with AccessDenied.
What we ruled out
Bucket policy. It granted
s3:GetObjectonarn:aws:s3:::acme-partner-exports/daily/*to the partner's role. If that were missing,head-objectwould fail too, because HEAD needs the sames3:GetObjectpermission.Object ownership. The bucket uses the "bucket owner enforced" setting, so ACLs are disabled and we own every object. Ownership problems were not possible.
Block Public Access. It blocks public grants, not grants to a specific account principal.
Partner's identity policy for S3. They had
s3:GetObjecton our bucket ARN. Otherwise the HEAD call would have failed as well.
Root cause
HeadObject returns metadata without decrypting anything, so it only needs S3 permissions. A GetObject on an SSE-KMS object makes S3 call KMS Decrypt on behalf of the caller. For a cross-account caller, that KMS call is allowed only if both the key policy in our account trusts the partner account and the partner's own IAM policy allows kms:Decrypt on our key ARN. Neither existed. The key had the default key policy, which only trusts our own account.
What is happening under the hood
With SSE-KMS, S3 stores each object encrypted with a data key. On upload S3 asks KMS for a data key (GenerateDataKey); on download S3 sends the encrypted data key to KMS (Decrypt). KMS evaluates that request as if the original caller made it, with the condition kms:ViaService set to the S3 endpoint.
KMS keys are different from most AWS resources: the key policy is the primary access control. An IAM policy alone cannot grant access to a key unless the key policy delegates to IAM in that account. For cross-account use, AWS documents a two-sided setup:
The key policy in the key's account allows the external account (or a specific role in it).
An IAM policy in the external account allows its principal to use the key ARN.
S3 Bucket Keys, which we had enabled, reduce KMS calls by caching a bucket-level key. They change the encryption context to the bucket ARN, but they do not change who needs kms:Decrypt.
Another detail: objects encrypted with the AWS managed key aws/s3 cannot be shared across accounts at all, because you cannot edit that key's policy. Cross-account SSE-KMS always needs a customer managed key.
Cross-account access errors from S3 are deliberately generic ("Access Denied"), so the reason phrases you see for same-account requests do not appear here.
Environment
Component | Version / value |
|---|---|
Bucket account |
|
Reader account |
|
Encryption | SSE-KMS, customer managed key, S3 Bucket Keys on |
Object ownership | Bucket owner enforced (ACLs disabled) |
Client | AWS CLI 2.22, partner job uses boto3 1.35 |
Minimal reproduction
The default key policy created with the key, unchanged:
{
"Version": "2012-10-17",
"Statement": [{
"Sid": "EnableIAMPolicies",
"Effect": "Allow",
"Principal": { "AWS": "arn:aws:iam::111122223333:root" },
"Action": "kms:*",
"Resource": "*"
}]
}
Bucket default encryption pointing at that key, a bucket policy granting s3:GetObject to arn:aws:iam::444455556666:role/partner-ingest, and any new object. HEAD works, GET fails.
Who is affected
Anyone who shares SSE-KMS objects with another account, including:
data exchanges with partners or between business units,
central logging buckets read by a security account,
CI accounts that read artifacts from a shared artifact bucket.
The failure often appears right after a security improvement such as "switch all buckets to customer managed keys", which is why it feels unrelated to the change.
The fix
Two changes, one in each account.
Our account (key owner): add a statement to the key policy that allows the partner role to decrypt, and only through S3 in this region.
{
"Sid": "AllowPartnerDecryptViaS3",
"Effect": "Allow",
"Principal": { "AWS": "arn:aws:iam::444455556666:role/partner-ingest" },
"Action": "kms:Decrypt",
"Resource": "*",
"Condition": {
"StringEquals": {
"kms:ViaService": "s3.eu-west-1.amazonaws.com",
"kms:CallerAccount": "444455556666"
}
}
}
In a key policy, "Resource": "*" means "this key". We named the role instead of the account root because the partner only needs one reader. If they need to write objects too, add kms:GenerateDataKey to the action list.
Partner account (reader): add an IAM policy to the role that allows the key ARN.
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": "kms:Decrypt",
"Resource": "arn:aws:kms:eu-west-1:111122223333:key/1a2b3c4d-5e6f-7a8b-9c0d-ef1234567890",
"Condition": {
"StringEquals": { "kms:ViaService": "s3.eu-west-1.amazonaws.com" }
}
}]
}
Use the key ARN, not an alias ARN; cross-account aliases cannot be used in policies to identify another account's key.
Alternatives and trade-offs
Grant the account root in the key policy and let the partner's admins decide which roles get access through IAM. Simpler for us, less control.
KMS grants (
CreateGrant) for temporary or programmatic access. Useful for automation, but grants are harder to audit than a key policy.Keep SSE-S3 for the shared prefix. Removes the KMS step, but also removes the ability to revoke access by changing the key policy and the KMS audit trail.
Copy objects into a bucket the partner owns with their key. More moving parts, but each side controls its own encryption.
How to test the fix
From the partner account:
aws s3api get-object \
--bucket acme-partner-exports \
--key daily/2027-01-27.parquet /tmp/out \
--query '{enc:ServerSideEncryption,key:SSEKMSKeyId,size:ContentLength}'
It returned the object size and key ARN. We also checked that the role still cannot use the key outside S3, which proves the kms:ViaService condition works:
aws kms describe-key --key-id arn:aws:kms:eu-west-1:111122223333:key/1a2b3c4d-5e6f-7a8b-9c0d-ef1234567890
That call is denied, because the key policy only grants kms:Decrypt via S3.
Confirming in production
KMS logs cross-account calls in CloudTrail of the key owner's account. Before the fix our trail showed Decrypt events with errorCode: AccessDenied and userIdentity.accountId: 444455556666. After the fix, the same query returned successful Decrypt events from the partner role, one burst per daily job:
SELECT eventTime, errorCode, userIdentity.arn
FROM cloudtrail_logs
WHERE eventSource = 'kms.amazonaws.com'
AND eventName = 'Decrypt'
AND userIdentity.accountId = '444455556666'
ORDER BY eventTime DESC
LIMIT 20;
The partner confirmed their job loaded the files for the two missed days after a re-run.
Regression guard
The bucket module in Terraform now takes a list of reader principals and writes both the bucket policy and the key policy statement from the same variable, so they cannot drift apart.
A scheduled check runs IAM Access Analyzer on the account; any external access to the key that is not in the approved list raises a finding.
The runbook for "change bucket encryption" lists cross-account readers as a required check.
Security implications
The fix widens access to the key, so we kept it as narrow as possible: one role, one action, only via S3 in one region, plus the caller account condition. The partner cannot use the key to decrypt anything outside our bucket's S3 requests. Encrypting with a customer managed key is still worth it: we can now revoke the partner's access instantly by removing one key policy statement, and every decrypt is logged.
Prevention checklist
Before switching a bucket to SSE-KMS, list every principal that reads it from another account.
Use customer managed keys for anything shared across accounts;
aws/s3cannot be shared.Generate bucket policy and key policy from one source of truth.
Test with
head-objectandget-object; only the second proves KMS access.Watch the key owner's CloudTrail for
Decrypterrors from external accounts.
References
AWS: Allowing users in other accounts to use a KMS key — https://docs.aws.amazon.com/kms/latest/developerguide/key-policy-modifying-external-accounts.html
AWS: Using server-side encryption with AWS KMS keys (SSE-KMS) — https://docs.aws.amazon.com/AmazonS3/latest/userguide/UsingKMSEncryption.html
AWS: Reducing the cost of SSE-KMS with Amazon S3 Bucket Keys — https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucket-key.html
AWS: kms:ViaService condition key — https://docs.aws.amazon.com/kms/latest/developerguide/conditions-kms.html
AWS: Troubleshoot access denied (403 Forbidden) errors in Amazon S3 — https://docs.aws.amazon.com/AmazonS3/latest/userguide/troubleshoot-403-errors.html
Add a label
Embed this post
<iframe src="https://hibug.me/s3-403-cross-account-kms-key-policy" width="700" height="420" frameborder="0" loading="lazy"></iframe>
I work on performance and capacity for a marketplace with heavy read traffic and sharp daily peaks. My days are split between caches, Redis, document stores, connection pools and the load tests that tell us whether any of it will hold. Most of the problems I write about looked like scaling issues and turned out to be something smaller: a cache that refilled itself with stale data, a single command that froze Redis, a pool drained by one leaked connection, a load test that measured its own generator instead of the system. I try hard to measure before changing anything, so each post includes how we gathered numbers, what they showed and how we confirmed the fix under realistic load. I also include the optimisations that made things worse, because those taught me the most.
Comments
0No comments yet. Be the first to comment!
Sign In to post a comment.