8000 implement S3 cross account across all operations (#9121) · codeperl/localstack@6c91207 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6c91207

Browse files
authored
implement S3 cross account across all operations (localstack#9121)
1 parent d0836e8 commit 6c91207

File tree

6 files changed

+301
-370
lines changed

6 files changed

+301
-370
lines changed

localstack/services/s3/notifications.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from localstack.aws.api.events import PutEventsRequestEntry
1414
from localstack.aws.api.lambda_ import InvocationType
1515
from localstack.aws.api.s3 import (
16+
AccountId,
1617
BucketName,
1718
BucketRegion,
1819
Event,
@@ -97,6 +98,8 @@ class S3EventNotificationContext:
9798
key_name: ObjectKey
9899
xray: str
99100
bucket_location: BucketRegion
101+
bucket_account_id: AccountId
102+
caller: AccountId
100103
key_size: int
101104
key_etag: str
102105
key_version_id: str
@@ -154,8 +157,10 @@ def from_request_context(
154157
event_type=EVENT_OPERATION_MAP.get(request_context.operation.wire_name, ""),
155158
event_time=datetime.datetime.now(),
156159
region=request_context.region,
160+
caller=request_context.account_id, # TODO: use it for `userIdentity`
157161
bucket_name=bucket_name,
158162
bucket_location=bucket.location,
163+
bucket_account_id=bucket.account_id, # TODO: use it for bucket owner identity
159164
key_name=quote(key.name),
160165
key_etag=etag,
161166
key_size=key_size,
@@ -201,8 +206,10 @@ def from_request_context_native(
201206
event_type=EVENT_OPERATION_MAP.get(request_context.operation.wire_name, ""),
202207
event_time=datetime.datetime.now(),
203208
region=request_context.region,
209+
caller=request_context.account_id, # TODO: use it for `userIdentity`
204210
bucket_name=bucket_name,
205211
bucket_location=s3_bucket.bucket_region,
212+
bucket_account_id=s3_bucket.bucket_account_id, # TODO: use it for bucket owner identity
206213
key_name=quote(s3_object.key),
207214
key_etag=etag,
208215
key_size=key_size,
@@ -375,7 +382,7 @@ def _get_event_payload(
375382
awsRegion=ctx.region,
376383
eventTime=timestamp_millis(ctx.event_time),
377384
eventName=ctx.event_type.removeprefix("s3:"),
378-
userIdentity={"principalId": "AIDAJDPLRKLG7UEXAMPLE"},
385+
userIdentity={"principalId": "AIDAJDPLRKLG7UEXAMPLE"}, # TODO: use the real one?
379386
requestParameters={
380387
"sourceIPAddress": "127.0.0.1"
381388
}, # TODO sourceIPAddress was previously extracted from headers ("X-Forwarded-For")

0 commit comments

Comments
 (0)
0