8000 implement S3 cross account across all operations by bentsku · Pull Request #9121 · localstack/localstack · GitHub
[go: up one dir, main page]

Skip to content

implement S3 cross account across all operations #9121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 13, 2023
Merged

Conversation

bentsku
Copy link
Contributor
@bentsku bentsku commented Sep 12, 2023

Motivation

Issues with S3 Website were found from #9017, which showed a deeper issue in our S3 cross/multi account implementation.
GetBucketWebsite would return NoSuchBucket if a request from account A was done to a bucket in account B, even though you could get an object from account B.

We need to implement proper cross-account access for S3.

Changes

Make all S3 access cross-account

For the current provider:

Before, if we tried to access a bucket existing in account A from account B, we would get some weird issue, as we got the bucket from moto but we would then access the store from account B, which wouldn't have the bucket properties. We now use the found moto bucket account id and region to fetch the store.

For the v3 provider:

We now use the cross account access for every S3 operation, which will allow us to have some implementation of ACL if not using bucket policies, instead of returning NoSuchBucket if the bucket didn't exist in the caller account. This will need multi account setup in our test suite at some point?

Misc

Added a quick cross region test to verify it, and we didn't have one earlier for bucket operations.

Also sneaked in a little change for the request, I would get a big logging error that the account_id and region were not passed to the logging format string, following #9084 @whummer. This might just return None/None, not sure if that would still be helping or if we should refactor the format string? deleted as it's now part of another PR.

@bentsku bentsku added aws:s3 Amazon Simple Storage Service area: multi-account Multi-tenancy in LocalStack semver: minor Non-breaking changes which can be included in minor releases, but not in patch releases labels Sep 12, 2023
@bentsku bentsku self-assigned this Sep 12, 2023
if not context:
return s3_stores[get_aws_account_id()][aws_stack.get_region()]
def get_store(account_id: Optional[str] = None, region: Optional[str] = None) -> S3Store:
return s3_stores[account_id or DEFAULT_AWS_ACCOUNT_ID][region or AWS_REGION_US_EAST_1]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: not sure this is needed, but as it was optional before and I didn't check for all usages, better be safe than sorry for now. The new provider doesn't allow optional values.

@coveralls
Copy link
coveralls commented Sep 12, 2023

Coverage Status

coverage: 80.116% (+0.2%) from 79.92% when pulling 6658e77 on s3-cross-account into d0836e8 on master.

@github-actions
Copy link
github-actions bot commented Sep 12, 2023

LocalStack Community integration with Pro

       2 files         2 suites   1h 17m 34s ⏱️
2 200 tests 1 706 ✔️ 494 💤 0
2 201 runs  1 706 ✔️ 495 💤 0

Results for commit 6658e77.

♻️ This comment has been updated with latest results.

@bentsku bentsku removed the request for review from thrau September 13, 2023 12:53
@viren-nadkarni
Copy link
Member

We will have some conflicts with #9023 where I also introduce the account ID in S3EventNotificationContext.

Could we wait until that one is merged? I'm happy to take this PR over the line after that.

@bentsku
Copy link
Contributor Author
bentsku commented Sep 13, 2023

@viren-nadkarni sure, no problem. I'd like to keep the difference in name between caller_account_id and the bucket account id though. I can rebase once your PR is merged, no problem. 😄

@viren-nadkarni
Copy link
Member

@bentsku: my PR will take a bit more work before it is merged. You can go ahead and merge this one, I'll fix any conflicts on my end 👍

@bentsku bentsku merged commit 6c91207 into master Sep 13, 2023
@bentsku bentsku deleted the s3-cross-account branch September 13, 2023 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: multi-account Multi-tenancy in LocalStack aws:s3 Amazon Simple Storage Service semver: minor Non-breaking changes which can be included in minor releases, but not in patch releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0