How can I restrict S3 bucket access to allow only VPC Flow logs from within an organization?

0

Hello,

I have a landing zone created with Control Tower (Audit and Logging account and so on) In the logging account I have an S3 bucket in which I want to receive the VPC Flow logs from all current and future accounts from that organization. So, I want to create a bucket policy that only allows receiving VPC Flow logs as long as the source account is in the organization. The new accounts are created with Control Tower account factory by other teams in a self service fashion so I need to filter by organization, not account ids or specific ARNs.

According to the VPC Flow logs user guide, you have to add the following statement (and another similar one but let's simplify things) to the S3 bucket policy to the destination bucket:

{
            "Sid": "AWSLogDeliveryWrite",
            "Effect": "Allow",
            "Principal": {"Service": "delivery.logs.amazonaws.com"},
            "Action": "s3:PutObject",
            "Resource": "my-s3-arn",
            "Condition": {
                "StringEquals": {
                    "s3:x-amz-acl": "bucket-owner-full-control",
                    "aws:SourceAccount": account_id
                },
                "ArnLike": {
                    "aws:SourceArn": "arn:aws:logs:region:account_id:*"
                }
            }
        }

As I need to filter by organization and not by account, I tried using the aws:PrincipalOrgID condition key instead of the SourceAccount and SourceArn. However, I get an error saying that the aws:PrincipalOrgID does not support service principals and I cannot create the policy.

I also tried with the aws:PrincipalOrgPaths condition key. Then, it lets me create the policy but when I try to create the Flow log it says "Access Denied for LogDestination: bucket_name. Please check LogDestination permissions."

I have also tried keeping the principal as "*" and adding the "aws:PrincipalServiceName": "delivery.logs.amazonaws.com" to the condition but I get the same error when trying to create the Flow logs.

Does anyone have any idea on how can I do that?

Thanks in advance

6 Answers
1
Accepted Answer

You cannot use any conditions related with organization, because the service principal is not a member of your organization.

Just delete all conditions related to Account ID is a simple stupid solution. And keep S3 bucket name as secret. I believe that delivery.logs.amazonaws.com service is safe enough.

{
   "Sid":"AWSLogDeliveryWrite",
   "Effect":"Allow",
   "Principal":{
      "Service":"delivery.logs.amazonaws.com"
   },
   "Action":"s3:PutObject",
   "Resource":"my-s3-arn",
   "Condition":{
      "StringEquals":{
         "s3:x-amz-acl":"bucket-owner-full-control"
      }
   }
}

I know it is not best, but simple! :)

profile picture
EXPERT
answered 2 years ago
  • Thanks for your answer @posquit0. That was my concern, that the delivery service principal is not member of my organization. There should be a way to restrict access to service principals within an organization as you cannot keep a bucket name as secret from a malicious ex employee.

0

I am creating central S3 bucket to get all VPC flow logs from many accounts within my org.. I using the principal org ID as the condition, however ideally we'd prevent one account overwriting another account's data, how can i make more cahnges to the following policy to be able to follow principle of least privilege ?

S3BucketPolicy: Type: AWS::S3::BucketPolicy Properties: Bucket: !Ref S3Bucket PolicyDocument: Version: '2012-10-17' Statement:

Effect: Allow Principal: AWS: '*' Action:

  • s3:ListBucket
  • s3:PutObject
  • s3:GetBucketAcl Resource:
  • 'arn:aws:s3:::testpolicycfns3vpc'
  • 'arn:aws:s3:::testpolicycfns3vpc/*' Condition: StringEquals: aws:PrincipalOrgID: x-xxxxxxx

Refrence links : https://aws.amazon.com/blogs/security/control-access-to-aws-resources-by-using-the-aws-organization-of-iam-principals/

answered 2 years ago
0

Use below bucket Policy with aws:ResourceOrgID condition.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "AWSLogDeliveryWrite",
            "Effect": "Allow",
            "Principal": {
                "Service": "delivery.logs.amazonaws.com"
            },
            "Action": [
                "s3:PutObject",
                "s3:GetBucketAcl",
                "s3:ListBucket"
            ],
            "Resource": [
                "arn:aws:s3:::bucket_name/*”,
                "arn:aws:s3:::bucket_name"
            ],
            "Condition": {
                "StringEquals": {
                    "aws:ResourceOrgID": “o-xyzz"
                }
            }
        }
    ]
}
AWS
answered 8 months ago
  • Your policy locks down access to the bucket that exists in org o-xyzz not log delivery from org o-xyzz

    This does not work

0

F.Y.I. In Nov 13 2023 , aws:SourceOrgID and aws:SourceOrgPaths have been released. You can restrict specific organization accounts that are able to delivery flow logs to s3 bucket.

https://aws.amazon.com/about-aws/whats-new/2023/11/organization-wide-iam-condition-keys-restrict-aws-service-to-service-requests/?nc1=h_ls https://aws.amazon.com/jp/blogs/security/use-scalable-controls-for-aws-services-accessing-your-resources/

AWS
suzuki
answered 3 months ago
-1

Just get rid of the service principal:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Principal": "*",
            "Action": "s3:PutObject",
            "Resource": [
                "arn:aws:s3:::flow-logs-bucket/*"
            ],
            "Effect": "Allow",
            "Condition": {
                "StringEquals": {
                    "aws:PrincipalOrgID": "o-aaa123bbb456",
                    "s3:x-amz-acl":"bucket-owner-full-control"
                }
            }
        }
    ]
}
AWS
answered 2 years ago
  • I wouldnt use Principal * as this grants all users and accounts within your Organisiation PutObject to the bucket. Nor does it follow least privilege

-1

Hello,

You can use "aws:ResourceOrgID" condition statement with the same and that should be working with your usecase. This lets the service related principals to only do mentioned actions when the resource org equals to the org id of the organization. You can use a condition as this -> "aws:ResourceOrgID": "${aws:PrincipalOrgID}"

Here is the documentation -> https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-resourceorgid

AWS
answered a year ago
  • Service principals are not part of your org.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions