Skip to content
This repository was archived by the owner on Jun 20, 2025. It is now read-only.

Commit 43e5094

Browse files
markslivafacebook-github-bot
authored andcommitted
limit the PCE's full s3 access to the deployed data bucket (#1743)
Summary: Pull Request resolved: #1743 For partner side deployments. For other usages it will still default to the current AmazonS3FullAccess arn for now. Reviewed By: ankushksingh, ajaybhargavb, anthonyzhang25 Differential Revision: D40406015 fbshipit-source-id: c9f91369fc9cd2e00b53667e4eb3927c756ade18
1 parent da413e4 commit 43e5094

4 files changed

Lines changed: 73 additions & 1 deletion

File tree

fbpcs/infra/cloud_bridge/deploy.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ undeploy_aws_resources() {
8686
-var "aws_region=$region" \
8787
-var "tag_postfix=$tag_postfix" \
8888
-var "aws_account_id=$aws_account_id" \
89+
-var "s3_access_arn=$data_bucket_policy_arn" \
8990
-var "pce_id=$pce_id"
9091
echo "Finished undeploying AWS resources under PCE_shared."
9192
echo "Start undeploying AWS resource under PCE..."
@@ -181,10 +182,16 @@ undeploy_aws_resources() {
181182
fi
182183
echo "######################## Undeploy resources policy ########################"
183184
log_streaming_data "Undeploying resources policies..."
185+
echo "Deleting policy: $policy_name"
184186
cd /terraform_deployment
185187
python3 cli.py destroy aws \
186188
--delete_iam_policy \
187189
--policy_name "$policy_name"
190+
191+
echo "Deleting data bucket policy: $data_bucket_policy_name"
192+
python3 cli.py destroy aws \
193+
--delete_iam_policy \
194+
--policy_name "$data_bucket_policy_name"
188195
echo "######################## Finished undeploy resources policy ########################"
189196

190197
log_streaming_data "finished undeploying all AWS resources "
@@ -211,6 +218,18 @@ deploy_aws_resources() {
211218
# Create the S3 data bucket if it doesn't exist
212219
log_streaming_data "creating s3 data bucket, if it does not exist"
213220
validate_or_create_s3_bucket "$s3_bucket_data_pipeline" "$region" "$aws_account_id"
221+
222+
# Create data bucket policy
223+
echo "########################Create data bucket policy########################"
224+
cd /terraform_deployment
225+
python3 cli.py create aws \
226+
--add_iam_policy \
227+
--policy_name "$data_bucket_policy_name" \
228+
--template_path "$fb_pc_data_bucket_policy" \
229+
--region "$region" \
230+
--data_bucket_name "$s3_bucket_data_pipeline"
231+
echo "########################Done creating data bucket policy########################"
232+
214233
# Deploy PCE Terraform scripts
215234
onedocker_ecs_container_image='539290649537.dkr.ecr.us-west-2.amazonaws.com/one-docker-prod:latest'
216235
publisher_vpc_cidr='10.0.0.0/16'
@@ -229,6 +248,7 @@ deploy_aws_resources() {
229248
-var "tag_postfix=$tag_postfix" \
230249
-var "aws_account_id=$aws_account_id" \
231250
-var "onedocker_ecs_container_image=$onedocker_ecs_container_image" \
251+
-var "s3_access_arn=$data_bucket_policy_arn" \
232252
-var "pce_id=$pce_id"
233253
echo "######################## Deploy PCE SHARED Terraform scripts completed ########################"
234254
# Store the outputs into variables
@@ -427,6 +447,9 @@ data_upload_key_path="semi-automated-data-ingestion"
427447
query_results_key_path="query-results"
428448
data_ingestion_lambda_name="cb-data-ingestion-stream-processor${tag_postfix}"
429449
fb_pc_iam_policy="/terraform_deployment/fbpcs/infra/cloud_bridge/deployment_helper/aws/iam_policies/fb_pc_iam_policy.json"
450+
fb_pc_data_bucket_policy="/terraform_deployment/fbpcs/infra/cloud_bridge/deployment_helper/aws/iam_policies/fb_pc_data_bucket_policy.json"
451+
data_bucket_policy_name="fb-pc-data-bucket-policy${tag_postfix}"
452+
data_bucket_policy_arn="arn:aws:iam::${aws_account_id}:policy/${data_bucket_policy_name}"
430453

431454
if "$undeploy"
432455
then
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"Version": "2012-10-17",
3+
"Statement": [
4+
{
5+
"Effect": "Allow",
6+
"Action": [
7+
"s3:*"
8+
],
9+
"Resource": [
10+
"arn:aws:s3:::${DATA_BUCKET_NAME}",
11+
"arn:aws:s3:::${DATA_BUCKET_NAME}/*"
12+
]
13+
},
14+
{
15+
"Effect": "Allow",
16+
"Action": [
17+
"s3:Describe*",
18+
"s3:Get*",
19+
"s3:List*"
20+
],
21+
"Resource": [
22+
"*"
23+
]
24+
},
25+
{
26+
"Effect": "Deny",
27+
"Action": [
28+
"s3:*"
29+
],
30+
"NotResource": [
31+
"arn:aws:s3:::${DATA_BUCKET_NAME}",
32+
"arn:aws:s3:::${DATA_BUCKET_NAME}/*"
33+
],
34+
"Condition": {
35+
"StringEquals": {
36+
"s3:ResourceAccount": [
37+
"${ACCOUNT_ID}"
38+
]
39+
}
40+
}
41+
}
42+
]
43+
}

fbpcs/infra/pce/aws_terraform_template/common/pce_shared/iam.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@ resource "aws_iam_role_policy_attachment" "ecs-task-execution-role-policy-attach
5151

5252
resource "aws_iam_role_policy_attachment" "task_s3" {
5353
role = aws_iam_role.onedocker_ecs_task_role.name
54-
policy_arn = "arn:aws:iam::aws:policy/AmazonS3FullAccess"
54+
policy_arn = var.s3_access_arn
5555
}

fbpcs/infra/pce/aws_terraform_template/common/pce_shared/variable.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,9 @@ variable "pce_id" {
2222
type = string
2323
description = "The identifier for marking the cloud resources are in PCE"
2424
}
25+
26+
variable "s3_access_arn" {
27+
type = string
28+
description = "The s3 arn that the PCE can access"
29+
default = "arn:aws:iam::aws:policy/AmazonS3FullAccess"
30+
}

0 commit comments

Comments
 (0)