fix(init): replace GetBucketLocation with HeadBucket for cross-account S3 support - #1079
fix(init): replace GetBucketLocation with HeadBucket for cross-account S3 support#1079bensi94 wants to merge 2 commits into
Conversation
…t S3 support GetBucketLocation requires bucket ownership, causing AccessDenied errors when the Fluent Bit init process retrieves config from S3 buckets owned by a different AWS account. HeadBucket returns the bucket region via BucketRegion regardless of ownership, and returns canonical region strings directly, eliminating the need for special-case mapping of empty string to us-east-1 and EU to eu-west-1.
|
The hard part here is that if we immediately deprecate |
Instead of fully replacing GetBucketLocation with HeadBucket, try HeadBucket first and fall back to GetBucketLocation with the existing LocationConstraint mapping. This avoids breaking users who only have s3:GetBucketLocation in their IAM policies.
@ShelbyZ Yes that's a very good point. I've added a fallback now. Is that suitable? |
|
@bensi94 - had some time to test out both APIs via CLI and there is no strong requirement to use s3:HeadBucket when dealing with cross-account buckets. The bucket needs to enable calling head-bucket get-bucket-location Let me know if there is something more to the current setup that is preventing the cross-account access |
|
Thank you @ShelbyZ, that is correct if they are in the same region. But if they're in different regions GetBucketLocation will not work. See this one from the AWS Docs:
|
Description
parseS3ARNAndGetBucketInfousess3:GetBucketLocationto discover the region of an S3 bucket during the Fluent Bit init process. This API requires the caller to be the bucket owner, which causesAccessDeniederrors in cross-account scenarios (e.g., an ECS task pulling Fluent Bit config from an S3 bucket owned by a different AWS account).This PR adds
HeadBucketas the primary region discovery method with a fallback toGetBucketLocationfor backward compatibility. This avoids breaking users who only haves3:GetBucketLocationin their IAM policies.Behavior
HeadBucketfirst — works cross-account, returns canonical region strings directlyHeadBucketfails (e.g., missings3:ListBucketpermission), fall back toGetBucketLocationwith the existingLocationConstraintmapping (empty →us-east-1,"EU"→eu-west-1)Changes
HeadBucketto theS3Clientinterface alongside existingGetBucketLocationparseS3ARNAndGetBucketInfoto tryHeadBucketfirst, fall back toGetBucketLocationHeadBucketMockS3Clientto support both methods with configurableHeadBucketErrorfor testing the fallback pathTestParseS3ARNAndGetBucketInfo_Fallbackcovering theGetBucketLocationfallback pathTesting
All existing tests pass alongside the new tests. No regressions.
References