fix(aws): admin policy gaps found by the live OpenTofu run

- s3:TagResource with s3:CreateBucket: a create with tags authorizes it
  (same request-tag and in-account conditions).
- ec2:CreateSecurityGroup on the VPC: EC2 shows the VPC no request tags,
  so that side is unconditioned; the group itself still needs the tag.
- ec2:DisassociateAddress on the literal */* only (${*}/${*}): destroying
  the NAT gateway's address disassociates it after the association is
  gone. The evaluator learns ${*}.

Checks, MODULE_CALLS and aws/README.md (including the Environments
section and the phase-4 live results) change with them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shadowdaoandClaude Opus 5.5 committed 2026-11-14 23:31:49 -08:00
1 parent bc23fc2dee
commit 2f5305eeb1
6 files changed
+214 -57

No files matched your search

+49 -20
View File
@@ -190,6 +190,9 @@ const PROBE_ROUTE_TABLE: &str = "arn:aws:ec2:{region}:{account}:route-table/rtb-
const PROBE_ELASTIC_IP: &str =
"arn:aws:ec2:{region}:{account}:elastic-ip/eipalloc-00000000000000000";
const PROBE_NAT_GATEWAY: &str = "arn:aws:ec2:{region}:{account}:natgateway/nat-00000000000000000";
/// What EC2 names when a call's resources no longer exist (an address
/// association that went with its NAT gateway): a literal `*/*`.
const PROBE_GONE_ASSOCIATION: &str = "arn:aws:ec2:{region}:{account}:*/*";
const PROBE_NETWORK_INTERFACE: &str =
"arn:aws:ec2:{region}:{account}:network-interface/eni-00000000000000000";
const PROBE_SECURITY_GROUP_RULE: &str =
@@ -475,7 +478,9 @@ const ENVIRONMENT_ADMIN_CHECKS: &[Check] = &[
REQUESTED_IN_TRIPLE_C_PARENT,
),
// The one create that may name an untagged (existing-network) VPC.
write("ec2:CreateSecurityGroup", PROBE_VPC, COMPONENT_REQUESTED),
// The VPC side of the request carries no request tag (verified live),
// so only the group's side is tag-checked.
write("ec2:CreateSecurityGroup", PROBE_VPC, &[]),
write(
"ec2:CreateTags",
PROBE_SECURITY_GROUP,
@@ -533,6 +538,10 @@ const ENVIRONMENT_ADMIN_CHECKS: &[Check] = &[
),
write("ec2:DisassociateRouteTable", PROBE_SUBNET, COMPONENT_TAGGED),
write("ec2:ReleaseAddress", PROBE_ELASTIC_IP, COMPONENT_TAGGED),
// Destroying the NAT gateway's address disassociates it first; the NAT
// gateway is gone by then, so EC2 authorizes the call against the
// literal `*/*` (verified live), which is all the policy allows.
write("ec2:DisassociateAddress", PROBE_GONE_ASSOCIATION, &[]),
write("ec2:DeleteNatGateway", PROBE_NAT_GATEWAY, COMPONENT_TAGGED),
write(
"ec2:DeleteSecurityGroup",
@@ -715,6 +724,8 @@ const ENVIRONMENT_ADMIN_CHECKS: &[Check] = &[
// The state bucket (the app creates it; OpenTofu's S3 backend reads and
// writes the state and lock objects).
write("s3:CreateBucket", PROBE_STATE_BUCKET, STATE_REQUESTED),
// CreateBucket with tags also authorizes s3:TagResource (verified live).
write("s3:TagResource", PROBE_STATE_BUCKET, STATE_REQUESTED),
write("s3:PutBucketVersioning", PROBE_STATE_BUCKET, IN_MY_ACCOUNT),
write(
"s3:PutEncryptionConfiguration",
@@ -1765,21 +1776,21 @@ mod tests {
"{action} on {elsewhere}"
);
}
assert!(allowed(
tier,
&write("s3:CreateBucket", PROBE_STATE_BUCKET, STATE_REQUESTED),
ME,
ME
));
for (bucket, context) in [
(PROBE_STATE_BUCKET, IN_MY_ACCOUNT),
(PROBE_STATE_BUCKET, OTHER_ACCOUNT_REQUESTED),
(OTHER_BUCKET, STATE_REQUESTED),
] {
for action in ["s3:CreateBucket", "s3:TagResource"] {
assert!(
!allowed(tier, &write("s3:CreateBucket", bucket, context), ME, ME),
"s3:CreateBucket {bucket} with {context:?}"
allowed(tier, &write(action, PROBE_STATE_BUCKET, STATE_REQUESTED), ME, ME),
"{action}"
);
for (bucket, context) in [
(PROBE_STATE_BUCKET, IN_MY_ACCOUNT),
(PROBE_STATE_BUCKET, OTHER_ACCOUNT_REQUESTED),
(OTHER_BUCKET, STATE_REQUESTED),
] {
assert!(
!allowed(tier, &write(action, bucket, context), ME, ME),
"{action} {bucket} with {context:?}"
);
}
}
}
@@ -1824,18 +1835,36 @@ mod tests {
"{action} on an untagged {resource}"
);
}
// A group may be created in any VPC (EC2 shows the VPC no request
// tag), but the group itself must carry the component tag.
assert!(allowed(
tier,
&write("ec2:CreateSecurityGroup", PROBE_VPC, COMPONENT_REQUESTED),
ME,
ME
));
assert!(!allowed(
tier,
&write("ec2:CreateSecurityGroup", PROBE_VPC, &[]),
ME,
ME
));
assert!(!allowed(
tier,
&write("ec2:CreateSecurityGroup", PROBE_SECURITY_GROUP, &[]),
ME,
ME
));
// Only the literal `*/*` of an association that is already gone: a
// live address, Triple-C's or anyone's, is never disassociated.
assert!(allowed(
tier,
&write("ec2:DisassociateAddress", PROBE_GONE_ASSOCIATION, &[]),
ME,
ME
));
for resource in [PROBE_ELASTIC_IP, PROBE_NETWORK_INTERFACE] {
for context in [&[][..], COMPONENT_TAGGED] {
assert!(
!allowed(tier, &write("ec2:DisassociateAddress", resource, context), ME, ME),
"ec2:DisassociateAddress on {resource} with {context:?}"
);
}
}
// A VPC's main route table association names no subnet, so swapping
// it would re-route a VPC by its route table alone: never allowed.
assert!(!allowed(
+15 -3
View File
@@ -16,15 +16,21 @@ pub(crate) const AT: Placeholders = Placeholders {
pub(crate) const ME: &str = "AROAEXAMPLEME:alice@example.com";
pub(crate) const SOMEONE_ELSE: &str = "AROAEXAMPLEOTHER:bob@example.com";
/// What [`Request::resolve`] turns IAM's `${*}` into: a literal `*` in a
/// pattern, which [`glob`] matches only against a `*`.
const LITERAL_STAR: char = '\u{e000}';
/// IAM wildcard match: `*` is any run of characters (including `:` and
/// `/`), `?` is exactly one.
/// `/`), `?` is exactly one; [`LITERAL_STAR`] is a plain `*`.
pub(crate) fn glob(pattern: &str, text: &str) -> bool {
let p: Vec<char> = pattern.chars().collect();
let t: Vec<char> = text.chars().collect();
let (mut pi, mut ti) = (0, 0);
let (mut star, mut mark) = (None, 0);
while ti < t.len() {
if pi < p.len() && (p[pi] == '?' || p[pi] == t[ti]) {
if pi < p.len()
&& (p[pi] == '?' || p[pi] == t[ti] || (p[pi] == LITERAL_STAR && t[ti] == '*'))
{
pi += 1;
ti += 1;
} else if pi < p.len() && p[pi] == '*' {
@@ -126,7 +132,9 @@ impl Request<'_> {
out.push_str(&rest[..start]);
let end = rest[start..].find('}').expect("unterminated ${") + start;
let name = &rest[start + 2..end];
let value = if name == "aws:userid" {
let value = if name == "*" {
Some(LITERAL_STAR.to_string())
} else if name == "aws:userid" {
Some(self.caller.to_string())
} else {
self.context_value(name)
@@ -254,6 +262,10 @@ mod tests {
));
assert!(glob("a?c", "abc"));
assert!(!glob("a?c", "ac"));
// `${*}` (resolved to LITERAL_STAR) matches only a real `*`.
let literal = format!("arn:aws:ec2:*:*:{LITERAL_STAR}/{LITERAL_STAR}");
assert!(glob(&literal, "arn:aws:ec2:us-west-2:1:*/*"));
assert!(!glob(&literal, "arn:aws:ec2:us-west-2:1:elastic-ip/eipalloc-1"));
}
#[test]
+9 -2
View File
@@ -1374,6 +1374,7 @@ const EIP: &str = "arn:aws:ec2:{region}:{account}:elastic-ip/eipalloc-0000000000
const NAT: &str = "arn:aws:ec2:{region}:{account}:natgateway/nat-00000000000000000";
const SG: &str = "arn:aws:ec2:{region}:{account}:security-group/sg-00000000000000000";
const SG_RULE: &str = "arn:aws:ec2:{region}:{account}:security-group-rule/sgr-00000000000000000";
const GONE_ASSOCIATION: &str = "arn:aws:ec2:{region}:{account}:*/*";
const ENI: &str = "arn:aws:ec2:{region}:{account}:network-interface/eni-00000000000000000";
const FS: &str = "arn:aws:elasticfilesystem:{region}:{account}:file-system/fs-00000000";
const TASK_ROLE: &str = "arn:aws:iam::{account}:role/triple-c-probe-0123456789ab-task";
@@ -1480,8 +1481,9 @@ const MODULE_CALLS: &[(&str, &[Check])] = &[
&[
call("ec2:CreateSecurityGroup", SG, ENV_CREATE),
// The one create that may name an untagged VPC: an
// `existing`-network environment's is the user's own.
call("ec2:CreateSecurityGroup", VPC, ENV_CREATE),
// `existing`-network environment's is the user's own. EC2 shows
// the VPC no request tag (verified live).
call("ec2:CreateSecurityGroup", VPC, NONE),
call("ec2:CreateTags", SG, created_by!("CreateSecurityGroup")),
call("ec2:DescribeSecurityGroups", "*", NONE),
call("ec2:DescribeSecurityGroupRules", "*", NONE),
@@ -1654,6 +1656,10 @@ const MODULE_CALLS: &[(&str, &[Check])] = &[
call("ec2:DescribeAddresses", "*", NONE),
call("ec2:DescribeAddressesAttribute", "*", NONE),
call("ec2:CreateTags", EIP, ENV_TAGGED),
// Delete disassociates first. The NAT gateway that held the
// association is gone by then, so EC2 authorizes it against a
// literal `*/*` (verified live).
call("ec2:DisassociateAddress", GONE_ASSOCIATION, NONE),
call("ec2:ReleaseAddress", EIP, ENV_TAGGED),
],
),
@@ -1973,6 +1979,7 @@ fn every_onboarding_role_stays_inside_the_boundary() {
const APP_ONLY_WRITES: &[&str] = &[
// The state bucket's setup (the backend only reads and writes objects).
"s3:CreateBucket",
"s3:TagResource",
"s3:PutBucketVersioning",
"s3:PutEncryptionConfiguration",
"s3:PutBucketPublicAccessBlock",