refactor(iam): share what a public-access condition must say across S3, Lambda and DSQL (#6134)

* refactor(iam): share what a public-access condition must say across S3, Lambda and DSQL

S3's Block Public Access, Lambda's function URL and resource policies, and
Aurora DSQL's cluster policies each decide whether a condition keeps an Allow
to everyone from being public, and each carried its own copy of the same
reads: a value that names one thing (no wildcard, no policy variable), an
aws:SourceIp range of /8 or narrower for IPv4 and /32 for IPv6, an ARN whose
account has no wildcard, and the trusted condition keys Lambda and DSQL both
accept. Those now live in services.iam.PublicAccessConditions.

Each service keeps what it was measured to do differently: S3 its own key list
(aws:SourceOwner and the s3: access point keys) and operators, Lambda the extra
lambda:SourceFunctionArn and exact-case keys, DSQL aws:SourceIp, case-insensitive
keys and its operator rules. No answer changes; every existing test of the three
services passes unchanged. Asked for on #6048, as its own PR.

* refactor(iam): keep the shared-keys-plus-one helper on PublicAccessConditions

DsqlClusterPolicies and LambdaWebService each added a private with(keys, key)
to extend the shared trusted keys by the one key each accepts on its own; the
review asked for one copy, so it lives on PublicAccessConditions.
This commit is contained in:
Alessandro Lattao authored and GitHub committed 2026-10-21 13:26:56 -04:00
1 parent 9a7c62b8f1
commit f4a9b15ced
5 files changed
+152 -89

No files matched your search

@@ -0,0 +1,48 @@
package io.github.hectorvent.floci.services.iam;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import static org.junit.jupiter.api.Assertions.assertEquals;
class PublicAccessConditionsTest {
@ParameterizedTest
@CsvSource(delimiter = '|', value = {
"123456789012|true",
"o-abc|true",
"''|false",
"1234*|false",
"12?4|false",
"${aws:PrincipalAccount}|false",
})
void aFixedValueNamesOneThing(String value, boolean fixed) {
assertEquals(fixed, PublicAccessConditions.isFixedValue(value));
}
@ParameterizedTest
@CsvSource(delimiter = '|', value = {
"arn:aws:iam::123456789012:role/app|true",
"arn:aws:iam::123456789012:role/*|true",
"arn:aws:iam::*:role/app|false",
"arn:aws:iam::12345678901?:root|false",
"arn:aws:iam::123456789012|false",
})
void anArnPinsItsAccountWhenTheAccountHasNoWildcard(String arn, boolean pins) {
assertEquals(pins, PublicAccessConditions.pinsAccount(arn));
}
@ParameterizedTest
@CsvSource(delimiter = '|', value = {
"203.0.113.7|true",
"10.0.0.0/8|true",
"10.0.0.0/7|false",
"2001:db8::/32|true",
"2001:db8::/31|false",
"10.0.0.0/x|false",
"10.*.0.0/16|false",
})
void aSourceIpRangeIsNarrowFromSlash8ForIpv4AndSlash32ForIpv6(String cidr, boolean narrow) {
assertEquals(narrow, PublicAccessConditions.isNarrowSourceIp(cidr));
}
}