mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(iam): return a SAML provider's metadata document as uploaded (#7270)
This commit is contained in:
1 parent
6c0336b251
commit
cc0cb5a3a3
4 files changed
+63
-1
No files matched your search
@@ -689,7 +689,10 @@ public class IamQueryHandler {
|
||||
private Response handleGetSAMLProvider(MultivaluedMap<String, String> params, String authorization) {
|
||||
String accountId = accountResolver.resolve(authorization);
|
||||
SAMLProvider provider = samlProviderService.getForAccount(accountId, getParam(params, "SAMLProviderArn"));
|
||||
String metadata = "<md:EntityDescriptor xmlns:md=\"urn:oasis:names:tc:SAML:2.0:metadata\" entityID=\""
|
||||
// AWS returns the document as uploaded. Providers stored before it was kept fall back to
|
||||
// a minimal document rebuilt from the entity ID and certificate.
|
||||
String metadata = provider.getMetadataDocument() != null ? provider.getMetadataDocument()
|
||||
: "<md:EntityDescriptor xmlns:md=\"urn:oasis:names:tc:SAML:2.0:metadata\" entityID=\""
|
||||
+ provider.getEntityId() + "\"><md:KeyDescriptor use=\"signing\"><ds:KeyInfo xmlns:ds=\"http://www.w3.org/2000/09/xmldsig#\"><ds:X509Data><ds:X509Certificate>"
|
||||
+ provider.getCertificate() + "</ds:X509Certificate></ds:X509Data></ds:KeyInfo></md:KeyDescriptor></md:EntityDescriptor>";
|
||||
return Response.ok(AwsQueryResponse.envelope("GetSAMLProvider", AwsNamespaces.IAM,
|
||||
|
||||
@@ -66,6 +66,7 @@ public class SAMLProviderService {
|
||||
provider.setArn(arn);
|
||||
provider.setEntityId(parsed.entityId());
|
||||
provider.setCertificate(parsed.certificateBase64());
|
||||
provider.setMetadataDocument(metadata);
|
||||
provider.setTags(tags);
|
||||
synchronized (providerLock) {
|
||||
if (findForAccount(accountId, arn).isPresent()) {
|
||||
@@ -146,6 +147,7 @@ public class SAMLProviderService {
|
||||
updated.setTags(existing.getTags());
|
||||
updated.setEntityId(parsed.entityId());
|
||||
updated.setCertificate(parsed.certificateBase64());
|
||||
updated.setMetadataDocument(metadata);
|
||||
putBack(accountId, arn, updated);
|
||||
return updated;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@ public class SAMLProvider {
|
||||
private String arn;
|
||||
private String entityId;
|
||||
private String certificate;
|
||||
/** The SAMLMetadataDocument exactly as uploaded; null for providers stored before it was kept. */
|
||||
private String metadataDocument;
|
||||
private Instant createDate = Instant.now();
|
||||
private Map<String, String> tags = new ConcurrentHashMap<>();
|
||||
|
||||
@@ -24,6 +26,8 @@ public class SAMLProvider {
|
||||
public void setEntityId(String entityId) { this.entityId = entityId; }
|
||||
public String getCertificate() { return certificate; }
|
||||
public void setCertificate(String certificate) { this.certificate = certificate; }
|
||||
public String getMetadataDocument() { return metadataDocument; }
|
||||
public void setMetadataDocument(String metadataDocument) { this.metadataDocument = metadataDocument; }
|
||||
public Instant getCreateDate() { return createDate; }
|
||||
public void setCreateDate(Instant createDate) { this.createDate = createDate; }
|
||||
public Map<String, String> getTags() { return tags; }
|
||||
|
||||
+53
@@ -9,6 +9,7 @@ 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.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
@@ -57,6 +58,58 @@ class SAMLProviderLifecycleIntegrationTest {
|
||||
.body(not(containsString("https://idp.example.test/original")));
|
||||
}
|
||||
|
||||
/**
|
||||
* An IdP's own metadata as uploaded: a default namespace rather than an {@code md:} prefix,
|
||||
* an IDPSSODescriptor with SingleSignOnService endpoints, whitespace, and a {@code &} in
|
||||
* a URL. AWS returns the document as uploaded, so it must read back character for character.
|
||||
*/
|
||||
private static String idpMetadata(String entityId, String certBase64) {
|
||||
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
||||
+ "<EntityDescriptor xmlns=\"urn:oasis:names:tc:SAML:2.0:metadata\" entityID=\"" + entityId + "\">\n"
|
||||
+ " <IDPSSODescriptor WantAuthnRequestsSigned=\"false\""
|
||||
+ " protocolSupportEnumeration=\"urn:oasis:names:tc:SAML:2.0:protocol\">\n"
|
||||
+ " <KeyDescriptor use=\"signing\">\n"
|
||||
+ " <ds:KeyInfo xmlns:ds=\"http://www.w3.org/2000/09/xmldsig#\"><ds:X509Data>"
|
||||
+ "<ds:X509Certificate>" + certBase64 + "</ds:X509Certificate></ds:X509Data></ds:KeyInfo>\n"
|
||||
+ " </KeyDescriptor>\n"
|
||||
+ " <NameIDFormat>urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress</NameIDFormat>\n"
|
||||
+ " <SingleSignOnService Binding=\"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect\""
|
||||
+ " Location=\"https://idp.example.test/sso?app=aws&mode=redirect\"/>\n"
|
||||
+ " <SingleSignOnService Binding=\"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST\""
|
||||
+ " Location=\"https://idp.example.test/sso?app=aws&mode=post\"/>\n"
|
||||
+ " </IDPSSODescriptor>\n"
|
||||
+ " <!-- " + "x".repeat(SamlMetadata.MINIMUM_LENGTH) + " -->\n"
|
||||
+ "</EntityDescriptor>\n";
|
||||
}
|
||||
|
||||
private static String getMetadataDocument(String arn) {
|
||||
return iam("GetSAMLProvider").formParam("SAMLProviderArn", arn)
|
||||
.when().post("/").then().statusCode(200)
|
||||
.extract().xmlPath()
|
||||
.getString("GetSAMLProviderResponse.GetSAMLProviderResult.SAMLMetadataDocument");
|
||||
}
|
||||
|
||||
@Test
|
||||
void getSamlProviderReturnsTheMetadataDocumentAsUploadedAfterCreateAndUpdate() {
|
||||
String name = "verbatim-saml-" + System.nanoTime();
|
||||
String arn = "arn:aws:iam::000000000000:saml-provider/" + name;
|
||||
String original = idpMetadata("https://idp.example.test/verbatim", "b3JpZ2luYWw=");
|
||||
iam("CreateSAMLProvider")
|
||||
.formParam("Name", name)
|
||||
.formParam("SAMLMetadataDocument", original)
|
||||
.when().post("/").then().statusCode(200);
|
||||
|
||||
assertEquals(original, getMetadataDocument(arn));
|
||||
|
||||
String updated = idpMetadata("https://idp.example.test/verbatim-updated", "dXBkYXRlZA==");
|
||||
iam("UpdateSAMLProvider")
|
||||
.formParam("SAMLProviderArn", arn)
|
||||
.formParam("SAMLMetadataDocument", updated)
|
||||
.when().post("/").then().statusCode(200);
|
||||
|
||||
assertEquals(updated, getMetadataDocument(arn));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateSamlProviderWithNoMetadataLeavesTheExistingDocumentUnchanged() {
|
||||
String name = "update-noop-saml-" + System.nanoTime();
|
||||
|
||||
Reference in new issue
Block a user