mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(elbv2): round-trip the authenticate-oidc and authenticate-cognito configs (#3664)
* fix(elbv2): round-trip the authenticate-oidc and authenticate-cognito configs Action carried no fields for either authentication action, so CreateListener, CreateRule, ModifyListener and ModifyRule accepted an AuthenticateOidcConfig or an AuthenticateCognitoConfig and kept only Type and Order. DescribeListeners and DescribeRules then echoed an action with no Issuer, no UserPoolArn and no other sub-field, and a client that read its own configuration back saw the listener as changed on every read. Both configs are now parsed on all four write operations, stored on the action and written into the Describe response. SessionCookieName, Scope and SessionTimeout take the defaults their shapes document, since AWS reports the resolved value rather than the caller's gap, and the members each shape marks required are rejected with ValidationError when absent. ClientSecret is stored but never reported. Real AWS omits it from every Describe call, which is why Terraform's provider carries it forward from local state instead of reading it back. * fix(elbv2): require the OIDC client secret on create and keep it on modify Review feedback on #3664. parseAuthenticateOidc accepted a missing ClientSecret on every write and never read UseExistingClientSecret. AuthenticateOidcActionConfig requires the secret when creating and lets a modify omit it only when UseExistingClientSecret is true, so a create without one was accepted where AWS refuses it. The sharper half is the modify path pgermosen described. Both modify operations replace the action list wholesale through this same parser, so the documented way to keep a secret, sending UseExistingClientSecret with no ClientSecret, blanked the secret instead of preserving it. parseActions now knows create from modify. A create without the secret is rejected. A modify may drop it only by asking for the stored one, and applyExistingClientSecrets puts that secret back before the action list replaces the old one. A modify that drops the secret without the flag is rejected. Three tests cover create-without-secret rejection, the modify that preserves and can then preserve again, and the modify that drops it with no flag. Also imports RequestSpecification rather than spelling it inline, per the review nit.
This commit is contained in:
1 parent
7da4ee0b6b
commit
026abe4878
3 files changed
+562
-2
No files matched your search
+264
@@ -0,0 +1,264 @@
|
||||
package io.github.hectorvent.floci.services.elbv2;
|
||||
|
||||
import io.github.hectorvent.floci.services.ec2.Ec2Service;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.path.xml.XmlPath;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
||||
/**
|
||||
* DescribeListeners and DescribeRules have to echo back the authenticate-oidc and
|
||||
* authenticate-cognito configurations a listener or rule was created with. Without them a client
|
||||
* that reads its own configuration back sees every sub-field missing and treats the listener as
|
||||
* changed on every plan.
|
||||
*
|
||||
* <p>ClientSecret is the exception. Real AWS never returns it, so neither does floci.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class ElbV2AuthenticateActionIntegrationTest {
|
||||
|
||||
private static final String AUTH =
|
||||
"AWS4-HMAC-SHA256 Credential=test/20260427/us-east-1/elasticloadbalancing/aws4_request";
|
||||
|
||||
private static String lbArn;
|
||||
private static String tgArn;
|
||||
private static String listenerArn;
|
||||
|
||||
private static String xml(RequestSpecification spec) {
|
||||
return spec.header("Authorization", AUTH).when().post("/").then().statusCode(200)
|
||||
.extract().asString();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void seedLoadBalancerAndTargetGroup() {
|
||||
lbArn = XmlPath.from(xml(given()
|
||||
.formParam("Action", "CreateLoadBalancer")
|
||||
.formParam("Name", "auth-action-lb")
|
||||
.formParam("Type", "application")
|
||||
.formParam("Subnets.member.1", Ec2Service.defaultSubnetId("us-east-1", "a"))
|
||||
.formParam("Subnets.member.2", Ec2Service.defaultSubnetId("us-east-1", "b"))))
|
||||
.getString("CreateLoadBalancerResponse.CreateLoadBalancerResult"
|
||||
+ ".LoadBalancers.member.LoadBalancerArn");
|
||||
|
||||
tgArn = XmlPath.from(xml(given()
|
||||
.formParam("Action", "CreateTargetGroup")
|
||||
.formParam("Name", "auth-action-tg")
|
||||
.formParam("Protocol", "HTTP")
|
||||
.formParam("Port", "80")
|
||||
.formParam("VpcId", Ec2Service.defaultVpcId("us-east-1"))))
|
||||
.getString("CreateTargetGroupResponse.CreateTargetGroupResult"
|
||||
+ ".TargetGroups.member.TargetGroupArn");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void createListener_withAuthenticateOidc_roundTripsEverySubFieldExceptTheSecret() {
|
||||
String base = "DefaultActions.member.1.AuthenticateOidcConfig.";
|
||||
listenerArn = XmlPath.from(xml(given()
|
||||
.formParam("Action", "CreateListener")
|
||||
.formParam("LoadBalancerArn", lbArn)
|
||||
.formParam("Protocol", "HTTPS")
|
||||
.formParam("Port", "443")
|
||||
.formParam("DefaultActions.member.1.Type", "authenticate-oidc")
|
||||
.formParam("DefaultActions.member.1.Order", "1")
|
||||
.formParam(base + "Issuer", "https://idp.example.com")
|
||||
.formParam(base + "AuthorizationEndpoint", "https://idp.example.com/authorize")
|
||||
.formParam(base + "TokenEndpoint", "https://idp.example.com/token")
|
||||
.formParam(base + "UserInfoEndpoint", "https://idp.example.com/userinfo")
|
||||
.formParam(base + "ClientId", "client-abc")
|
||||
.formParam(base + "ClientSecret", "shhh")
|
||||
.formParam(base + "OnUnauthenticatedRequest", "authenticate")
|
||||
.formParam(base + "AuthenticationRequestExtraParams.entry.1.key", "prompt")
|
||||
.formParam(base + "AuthenticationRequestExtraParams.entry.1.value", "login")
|
||||
.formParam("DefaultActions.member.2.Type", "forward")
|
||||
.formParam("DefaultActions.member.2.Order", "2")
|
||||
.formParam("DefaultActions.member.2.TargetGroupArn", tgArn)))
|
||||
.getString("CreateListenerResponse.CreateListenerResult"
|
||||
+ ".Listeners.member.ListenerArn");
|
||||
|
||||
String raw = xml(given()
|
||||
.formParam("Action", "DescribeListeners")
|
||||
.formParam("ListenerArns.member.1", listenerArn));
|
||||
XmlPath described = XmlPath.from(raw);
|
||||
|
||||
String action = "DescribeListenersResponse.DescribeListenersResult.Listeners.member"
|
||||
+ ".DefaultActions.member[0].AuthenticateOidcConfig.";
|
||||
assertEquals("https://idp.example.com", described.getString(action + "Issuer"));
|
||||
assertEquals("https://idp.example.com/authorize",
|
||||
described.getString(action + "AuthorizationEndpoint"));
|
||||
assertEquals("https://idp.example.com/token", described.getString(action + "TokenEndpoint"));
|
||||
assertEquals("https://idp.example.com/userinfo",
|
||||
described.getString(action + "UserInfoEndpoint"));
|
||||
assertEquals("client-abc", described.getString(action + "ClientId"));
|
||||
assertEquals("authenticate", described.getString(action + "OnUnauthenticatedRequest"));
|
||||
assertEquals("prompt",
|
||||
described.getString(action + "AuthenticationRequestExtraParams.entry.key"));
|
||||
assertEquals("login",
|
||||
described.getString(action + "AuthenticationRequestExtraParams.entry.value"));
|
||||
|
||||
// The model documents all three defaults, and AWS reports the resolved value.
|
||||
assertEquals("AWSELBAuthSessionCookie", described.getString(action + "SessionCookieName"));
|
||||
assertEquals("openid", described.getString(action + "Scope"));
|
||||
assertEquals("604800", described.getString(action + "SessionTimeout"));
|
||||
|
||||
assertFalse(raw.contains("ClientSecret"),
|
||||
"real AWS never returns ClientSecret from a Describe call");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void createRule_withAuthenticateCognito_roundTripsItsConfig() {
|
||||
String base = "Actions.member.1.AuthenticateCognitoConfig.";
|
||||
given()
|
||||
.formParam("Action", "CreateRule")
|
||||
.formParam("ListenerArn", listenerArn)
|
||||
.formParam("Priority", "10")
|
||||
.formParam("Conditions.member.1.Field", "path-pattern")
|
||||
.formParam("Conditions.member.1.Values.member.1", "/private/*")
|
||||
.formParam("Actions.member.1.Type", "authenticate-cognito")
|
||||
.formParam("Actions.member.1.Order", "1")
|
||||
.formParam(base + "UserPoolArn",
|
||||
"arn:aws:cognito-idp:us-east-1:000000000000:userpool/us-east-1_abc")
|
||||
.formParam(base + "UserPoolClientId", "pool-client")
|
||||
.formParam(base + "UserPoolDomain", "auth.example.com")
|
||||
.formParam(base + "Scope", "openid profile")
|
||||
.formParam(base + "SessionTimeout", "3600")
|
||||
.formParam("Actions.member.2.Type", "forward")
|
||||
.formParam("Actions.member.2.Order", "2")
|
||||
.formParam("Actions.member.2.TargetGroupArn", tgArn)
|
||||
.header("Authorization", AUTH)
|
||||
.when().post("/").then().statusCode(200);
|
||||
|
||||
XmlPath described = XmlPath.from(xml(given()
|
||||
.formParam("Action", "DescribeRules")
|
||||
.formParam("ListenerArn", listenerArn)));
|
||||
|
||||
String action = "DescribeRulesResponse.DescribeRulesResult.Rules.member"
|
||||
+ ".findAll { it.Priority.text() == '10' }.Actions.member[0]"
|
||||
+ ".AuthenticateCognitoConfig.";
|
||||
assertEquals("arn:aws:cognito-idp:us-east-1:000000000000:userpool/us-east-1_abc",
|
||||
described.getString(action + "UserPoolArn"));
|
||||
assertEquals("pool-client", described.getString(action + "UserPoolClientId"));
|
||||
assertEquals("auth.example.com", described.getString(action + "UserPoolDomain"));
|
||||
assertEquals("openid profile", described.getString(action + "Scope"));
|
||||
assertEquals("3600", described.getString(action + "SessionTimeout"));
|
||||
assertEquals("AWSELBAuthSessionCookie", described.getString(action + "SessionCookieName"));
|
||||
}
|
||||
|
||||
// ClientSecret is required on a create and may be omitted on a modify only by asking for the
|
||||
// stored one. Both modify operations replace the action list wholesale, so without carrying the
|
||||
// stored secret forward the documented keep-the-secret flow would blank it instead.
|
||||
@Test
|
||||
@Order(4)
|
||||
void createListener_withoutClientSecret_isRejected() {
|
||||
String base = "DefaultActions.member.1.AuthenticateOidcConfig.";
|
||||
given()
|
||||
.formParam("Action", "CreateListener")
|
||||
.formParam("LoadBalancerArn", lbArn)
|
||||
.formParam("Protocol", "HTTPS")
|
||||
.formParam("Port", "9443")
|
||||
.formParam("DefaultActions.member.1.Type", "authenticate-oidc")
|
||||
.formParam(base + "Issuer", "https://idp.example.com")
|
||||
.formParam(base + "AuthorizationEndpoint", "https://idp.example.com/authorize")
|
||||
.formParam(base + "TokenEndpoint", "https://idp.example.com/token")
|
||||
.formParam(base + "UserInfoEndpoint", "https://idp.example.com/userinfo")
|
||||
.formParam(base + "ClientId", "client-abc")
|
||||
.header("Authorization", AUTH)
|
||||
.when().post("/")
|
||||
.then().statusCode(400)
|
||||
.body("ErrorResponse.Error.Code", equalTo("ValidationError"))
|
||||
.body("ErrorResponse.Error.Message", equalTo("ClientSecret is required."));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void modifyListener_withUseExistingClientSecret_keepsTheStoredSecret() {
|
||||
String base = "DefaultActions.member.1.AuthenticateOidcConfig.";
|
||||
xml(given()
|
||||
.formParam("Action", "ModifyListener")
|
||||
.formParam("ListenerArn", listenerArn)
|
||||
.formParam("DefaultActions.member.1.Type", "authenticate-oidc")
|
||||
.formParam("DefaultActions.member.1.Order", "1")
|
||||
.formParam(base + "Issuer", "https://idp.example.com")
|
||||
.formParam(base + "AuthorizationEndpoint", "https://idp.example.com/authorize")
|
||||
.formParam(base + "TokenEndpoint", "https://idp.example.com/token")
|
||||
.formParam(base + "UserInfoEndpoint", "https://idp.example.com/userinfo")
|
||||
.formParam(base + "ClientId", "client-abc")
|
||||
.formParam(base + "UseExistingClientSecret", "true")
|
||||
.formParam(base + "Scope", "openid email")
|
||||
.formParam("DefaultActions.member.2.Type", "forward")
|
||||
.formParam("DefaultActions.member.2.Order", "2")
|
||||
.formParam("DefaultActions.member.2.TargetGroupArn", tgArn));
|
||||
|
||||
// The modify took effect, and the secret the create supplied is still the stored one.
|
||||
XmlPath described = XmlPath.from(xml(given()
|
||||
.formParam("Action", "DescribeListeners")
|
||||
.formParam("ListenerArns.member.1", listenerArn)));
|
||||
String action = "DescribeListenersResponse.DescribeListenersResult.Listeners.member"
|
||||
+ ".DefaultActions.member[0].AuthenticateOidcConfig.";
|
||||
assertEquals("openid email", described.getString(action + "Scope"));
|
||||
|
||||
// A later modify that keeps the secret again still works, which it cannot do once the
|
||||
// stored secret has been blanked.
|
||||
given()
|
||||
.formParam("Action", "ModifyListener")
|
||||
.formParam("ListenerArn", listenerArn)
|
||||
.formParam("DefaultActions.member.1.Type", "authenticate-oidc")
|
||||
.formParam(base + "Issuer", "https://idp.example.com")
|
||||
.formParam(base + "AuthorizationEndpoint", "https://idp.example.com/authorize")
|
||||
.formParam(base + "TokenEndpoint", "https://idp.example.com/token")
|
||||
.formParam(base + "UserInfoEndpoint", "https://idp.example.com/userinfo")
|
||||
.formParam(base + "ClientId", "client-abc")
|
||||
.formParam(base + "UseExistingClientSecret", "true")
|
||||
.header("Authorization", AUTH)
|
||||
.when().post("/").then().statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void modifyListener_withoutSecretAndWithoutTheFlag_isRejected() {
|
||||
String base = "DefaultActions.member.1.AuthenticateOidcConfig.";
|
||||
given()
|
||||
.formParam("Action", "ModifyListener")
|
||||
.formParam("ListenerArn", listenerArn)
|
||||
.formParam("DefaultActions.member.1.Type", "authenticate-oidc")
|
||||
.formParam(base + "Issuer", "https://idp.example.com")
|
||||
.formParam(base + "AuthorizationEndpoint", "https://idp.example.com/authorize")
|
||||
.formParam(base + "TokenEndpoint", "https://idp.example.com/token")
|
||||
.formParam(base + "UserInfoEndpoint", "https://idp.example.com/userinfo")
|
||||
.formParam(base + "ClientId", "client-abc")
|
||||
.header("Authorization", AUTH)
|
||||
.when().post("/")
|
||||
.then().statusCode(400)
|
||||
.body("ErrorResponse.Error.Code", equalTo("ValidationError"))
|
||||
.body("ErrorResponse.Error.Message",
|
||||
equalTo("ClientSecret is required unless UseExistingClientSecret is true."));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
void createListener_missingRequiredOidcMember_isRejected() {
|
||||
given()
|
||||
.formParam("Action", "CreateListener")
|
||||
.formParam("LoadBalancerArn", lbArn)
|
||||
.formParam("Protocol", "HTTPS")
|
||||
.formParam("Port", "8443")
|
||||
.formParam("DefaultActions.member.1.Type", "authenticate-oidc")
|
||||
.formParam("DefaultActions.member.1.AuthenticateOidcConfig.Issuer",
|
||||
"https://idp.example.com")
|
||||
.header("Authorization", AUTH)
|
||||
.when().post("/")
|
||||
.then().statusCode(400)
|
||||
.body("ErrorResponse.Error.Code", equalTo("ValidationError"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user