Harden STS calls with VPC endpoints#275
Draft
starfolkai[bot] wants to merge 1 commit into
Draft
Conversation
2bc8494 to
c84269b
Compare
Add configurable interface VPC endpoints (STS, EC2, CloudWatch Logs) to the shared vpc module, each gated by its own variable and defined as an individual count-based resource. The quarantine VPC always creates all three so its traffic stays on the AWS network; the main VPC leaves them disabled for now. The shared vpc_endpoints_tls security group is always created. Lock down the quarantine function role: - Replace the AWS-managed AWSLambdaVPCAccessExecutionRole with a tightened self-managed execution policy: the EC2 ENI actions are authorized for the Lambda service only (lambda:SourceFunctionArn absent); CloudWatch Logs is granted to both the service and the function code. - Deny any call that does not originate from inside the quarantine VPC (aws:SourceVpc), excluding the Lambda-service ENI/Logs actions (which carry no aws:SourceVpc) so VPC networking and logging keep working. - Restrict the function's own code (lambda:SourceFunctionArn present) to the three CloudWatch Logs actions and require its calls originate from inside the quarantine VPC. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
c84269b to
99d67eb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds configurable interface VPC endpoints (STS, EC2, CloudWatch Logs) and locks the quarantine function role down so that the function code is confined to the VPC and to CloudWatch Logs, while the Lambda service retains exactly the access it needs.
1. Configurable interface VPC endpoints (
modules/vpc)vpcmodule creates interface endpoints for STS, EC2, and CloudWatch Logs, each gated by its own variable (enable_sts_vpc_endpoint,enable_ec2_vpc_endpoint,enable_logs_vpc_endpoint, defaultfalse) and defined as an individualcount-gatedaws_vpc_endpointresource (Interface type,private_dns_enabled = true, all three private subnets).truefrom the root).falsefrom the root).vpc_endpoints_tlssecurity group is always created.sts_vpc_endpoint_id,ec2_vpc_endpoint_id,logs_vpc_endpoint_id(null when not created).2. Quarantine function role lockdown (
modules/services-common)The
quarantine_function_role(used by user-defined quarantine Lambdas) is governed by three policies that separate the two callers of the role — the Lambda service (lambda:SourceFunctionArnabsent) and the function code (lambda:SourceFunctionArnpresent):QuarantineFunctionExecution— a tightened, self-managed replacement for the AWS-managedAWSLambdaVPCAccessExecutionRole. The EC2 ENI actions (CreateNetworkInterface,DescribeNetworkInterfaces,DescribeSubnets,DeleteNetworkInterface,Assign/UnassignPrivateIpAddresses) are granted only to the Lambda service, viaNull: { "lambda:SourceFunctionArn": "true" }. CloudWatch Logs is granted to both the service (log delivery) and the function code.QuarantineFunctionVpcLockdown— denies any call whoseaws:SourceVpcis not the quarantine VPC. The service's ENI/Logs actions carry noaws:SourceVpc, so they are excluded viaNotAction(a blanket*deny would break VPC attachment and logging).QuarantineFunctionCodeLogsOnly— denies the function's own code anything other than the three CloudWatch Logs actions, and additionally denies any function-code call that does not originate from inside the quarantine VPC.Net effect: the function code can do nothing but write CloudWatch Logs from inside the quarantine VPC; the Lambda service retains exactly the ENI + log-delivery access it needs and nothing more.
Notes / caveats
lambda:SourceFunctionArn(present only for function-code calls). There is no positive "principal == Lambda service" key for the ENI calls, andaws:ViaAWSServiceis not a documented/reliable lever for Hyperplane ENI management, so it is intentionally not used.sts.<region>.amazonaws.com; the legacy globalsts.amazonaws.comwould bypass the endpoint. Modern AWS SDKs default to regional STS.Testing
terraform fmt,terraform validate, andtflint --recursivepass.examples/braintrust-data-plane) validates against the local module.terraform plan/applyrun (no AWS credentials).🤖 Generated with Claude Code
Created by mike
Slack thread