fix(iam): refuse an unsigned management call under enforcement (#4489)

A request carrying no Authorization header returned before any policy check, so with enforcement on an unauthenticated caller reached every emulated API by simply omitting the header.

Refuse one whose wire shape names a management operation: a JSON, CBOR or Query claim exists only for a request carrying X-Amz-Target, an rpcv2 path or an Action parameter. AWS answers a credential-less request with MissingAuthenticationToken at 403, returned here in the encoding the request used.

Operations AWS itself serves without credentials stay allowed, taken from the authtype: none trait in its service models: the Cognito user-pool and identity flows and the two web-identity and SAML AssumeRole calls. The list is keyed by service because GetUser needs no credentials on cognito-idp and requires them on iam.

REST is left alone. This filter also sees the API Gateway execute path, Lambda function URLs, CloudFront serving and the Cognito OIDC endpoints, which are unsigned by design, and a REST claim does not say which service will serve the request.

The CBOR error shape moves into CborErrorResponses, shared with the rpcv2 controller so the two cannot drift into answering the same failure differently.

EksIrsaDockerIntegrationTest set up its IAM fixtures over unsigned Query calls and so began failing: CreateRole is not an operation AWS serves without credentials. Its fixture calls now carry the root stand-in credential, which is what every other test does under enforcement. The AssumeRoleWithWebIdentity calls it actually tests stay unsigned, as AWS serves those without credentials.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-09-27 22:59:34 -05:00
1 parent c55ff5362b
commit c26f782ea8
7 files changed
+338 -14

No files matched your search

@@ -44,6 +44,16 @@ class EksIrsaDockerIntegrationTest {
private static final Logger LOG = Logger.getLogger(EksIrsaDockerIntegrationTest.class);
private static final String FORM = "application/x-www-form-urlencoded";
/**
* The root stand-in credential, for the IAM fixtures this test sets up. Those are ordinary
* management calls that AWS signs, and this test runs with enforcement on, so they carry a
* credential. The AssumeRoleWithWebIdentity calls under test stay unsigned on purpose: AWS
* serves that operation without credentials, which is the whole point of web identity.
*/
private static final String SETUP_AUTH =
"AWS4-HMAC-SHA256 Credential=test/20260101/us-east-1/iam/aws4_request, "
+ "SignedHeaders=host, Signature=setup";
private static final String ACCOUNT = "000000000000";
public static final class Profile implements QuarkusTestProfile {
@@ -317,6 +327,7 @@ class EksIrsaDockerIntegrationTest {
private String createRole(String name, String trustPolicy) {
return given()
.contentType(FORM)
.header("Authorization", SETUP_AUTH)
.formParam("Action", "CreateRole")
.formParam("Version", "2010-05-08")
.formParam("RoleName", name)
@@ -332,6 +343,7 @@ class EksIrsaDockerIntegrationTest {
try {
given()
.contentType(FORM)
.header("Authorization", SETUP_AUTH)
.formParam("Action", "DeleteRole")
.formParam("Version", "2010-05-08")
.formParam("RoleName", name)
@@ -1,12 +1,21 @@
package io.github.hectorvent.floci.services.iam;
import io.github.hectorvent.floci.testing.IamEnforcementProfile;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import java.nio.charset.StandardCharsets;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* With enforcement on, an access key that exists nowhere must be rejected rather than waved
@@ -16,6 +25,11 @@ import static org.hamcrest.Matchers.containsString;
@TestProfile(IamEnforcementProfile.class)
class UnknownAccessKeyEnforcementIntegrationTest {
@BeforeAll
static void configureRestAssured() {
RestAssuredJsonUtils.configureAwsContentTypes();
}
private static final String UNKNOWN_KEY_AUTH =
"AWS4-HMAC-SHA256 Credential=AKIADOESNOTEXIST0000/20260101/us-east-1/%s/aws4_request, "
+ "SignedHeaders=host, Signature=not-a-real-signature";
@@ -43,6 +57,102 @@ class UnknownAccessKeyEnforcementIntegrationTest {
.body(containsString("InvalidAccessKeyId"));
}
@Test
void anUnsignedJsonServiceCallIsRefused() {
given()
.contentType("application/x-amz-json-1.0")
.header("X-Amz-Target", "DynamoDB_20120810.ListTables")
.body("{}")
.when()
.post("/")
.then()
.statusCode(403)
.body(containsString("MissingAuthenticationToken"));
}
@Test
void anUnsignedQueryCallIsRefused() {
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "CreateUser")
.formParam("UserName", "unsigned-user")
.formParam("Version", "2010-05-08")
.when()
.post("/")
.then()
.statusCode(403)
.body(containsString("MissingAuthenticationToken"));
}
@Test
void anUnsignedCborCallIsRefusedInCbor() {
byte[] body = given()
.contentType("application/x-amz-cbor-1.1")
.header("X-Amz-Target", "Kinesis_20131202.ListStreams")
.body(new byte[] {(byte) 0xa0})
.when()
.post("/")
.then()
.statusCode(403)
.header("smithy-protocol", "rpc-v2-cbor")
.contentType("application/x-amz-cbor-1.1")
.extract().asByteArray();
// CBOR text strings carry their content literally, so the type is readable in the bytes
// without decoding. A JSON body would have been unreadable to the client that sent this.
assertTrue(new String(body, StandardCharsets.ISO_8859_1).contains("MissingAuthenticationToken"),
"the rejection must arrive CBOR-encoded, not as JSON");
}
@ParameterizedTest
@ValueSource(strings = {"InitiateAuth", "SignUp", "ForgotPassword", "ConfirmSignUp", "GetUser"})
void anUnsignedCognitoFlowAwsServesWithoutCredentialsIsNotRefused(String operation) {
// AWS marks these noAuth: the user has no AWS credentials yet, which is the point of them.
// They must reach the service and fail on their own merits, not on a missing signature.
given()
.contentType("application/x-amz-json-1.1")
.header("X-Amz-Target", "AWSCognitoIdentityProviderService." + operation)
.body("{}")
.when()
.post("/")
.then()
.body("__type", not(equalTo("MissingAuthenticationTokenException")));
}
@Test
void anUnsignedAssumeRoleWithWebIdentityIsNotRefused() {
// Also noAuth: the web identity token is the credential, so AWS requires no signature.
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "AssumeRoleWithWebIdentity")
.formParam("Version", "2011-06-15")
.formParam("RoleArn", "arn:aws:iam::000000000000:role/web-identity-role")
.formParam("RoleSessionName", "unsigned-session")
.formParam("WebIdentityToken", "dummy-token")
.when()
.post("/")
.then()
.body(not(containsString("MissingAuthenticationToken")));
}
@Test
void aQueryManagementCallSignedWithTheRootStandInIsAllowed() {
// What a test fixture does when it sets up IAM state under enforcement, and what
// EksIrsaDockerIntegrationTest relies on now that an unsigned CreateRole is refused.
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", "AWS4-HMAC-SHA256 Credential=test/20260101/us-east-1/iam/aws4_request, "
+ "SignedHeaders=host, Signature=setup")
.formParam("Action", "CreateRole")
.formParam("Version", "2010-05-08")
.formParam("RoleName", "root-stand-in-created-role")
.formParam("AssumeRolePolicyDocument", "{\"Version\":\"2012-10-17\",\"Statement\":[]}")
.when()
.post("/")
.then()
.statusCode(200);
}
@Test
void theRootStandInKeyStillWorks() {
given()