mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(opensearch): round-trip VPC/security/encryption options and per-family instance type metadata (#1039)
Closes the follow-ups from #1025: domain option blocks now survive CreateDomain → DescribeDomain, and DescribeInstanceTypeLimits returns family-appropriate metadata instead of one canned EBS response. - VPCOptions, AdvancedSecurityOptions, EncryptionAtRestOptions, NodeToNodeEncryptionOptions, and DomainEndpointOptions now round-trip through the management API. Real SDK clients (Terraform / CDK / Pulumi) read these back to detect drift; previously they were silently dropped. - Master passwords are accepted but never echoed back, matching AWS. - AdvancedSecurityOptions.Enabled + InternalUserDatabaseEnabled without a master user is rejected with ValidationException, as is CustomEndpointEnabled without a CustomEndpoint value. - New OpenSearchInstanceTypes catalog drives DescribeInstanceTypeDetails and DescribeInstanceTypeLimits. or1.* now reports s3-backed storage with the larger 8-36 TiB ceiling AWS documents; i3.* reports instance-store; everything else stays EBS at 3584 GiB. Unknown types fall back to a generic EBS spec instead of 404'ing. - Floci still boots one Docker container per domain regardless of instance type, but the management metadata now matches AWS so introspection tools work correctly. Tests: 60 OpenSearch tests pass. New: 6 OpenSearchInstanceTypesTest unit tests + 6 OpenSearchDomainOptionsIntegrationTest end-to-end + 2 or1 / EBS instance-type-limit integration tests. Live Docker validation: VPC + Encryption + N2N + Endpoint round-trip on a real running domain; or1.2xlarge.search returns s3-backed/36864 GiB while m6g.large.search returns ebs/3584 GiB; FGAC validation fires correctly when MasterUserName is omitted.
This commit is contained in:
1 parent
9b436e6c67
commit
5a9c30eb58
13 files changed
+1130
-34
No files matched your search
+183
@@ -0,0 +1,183 @@
|
||||
package io.github.hectorvent.floci.services.opensearch;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
/**
|
||||
* Verifies that VPC, advanced security, encryption, and endpoint option
|
||||
* blocks round-trip from {@code CreateDomain} / {@code UpdateDomainConfig}
|
||||
* through {@code DescribeDomain} / {@code DescribeDomainConfig}.
|
||||
*
|
||||
* <p>Real SDK clients (Terraform / CDK / Pulumi) read these fields back to
|
||||
* detect drift; if they don't survive the round-trip, every plan re-applies
|
||||
* the same change forever.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class OpenSearchDomainOptionsIntegrationTest {
|
||||
|
||||
private static final String AUTH_HEADER =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/es/aws4_request";
|
||||
|
||||
@AfterEach
|
||||
void cleanup() {
|
||||
// Delete every domain we touch so test order is irrelevant.
|
||||
for (String name : new String[]{"opts-vpc", "opts-adv", "opts-enc", "opts-endpoint", "opts-update"}) {
|
||||
given().header("Authorization", AUTH_HEADER)
|
||||
.when().delete("/2021-01-01/opensearch/domain/" + name);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void vpcOptionsRoundTrip() {
|
||||
String body = "{"
|
||||
+ "\"DomainName\":\"opts-vpc\","
|
||||
+ "\"EngineVersion\":\"OpenSearch_2.19\","
|
||||
+ "\"VPCOptions\":{"
|
||||
+ " \"SubnetIds\":[\"subnet-aaa\",\"subnet-bbb\"],"
|
||||
+ " \"SecurityGroupIds\":[\"sg-111\"],"
|
||||
+ " \"VPCId\":\"vpc-zzz\""
|
||||
+ "}}";
|
||||
|
||||
given().contentType("application/json").header("Authorization", AUTH_HEADER).body(body)
|
||||
.when().post("/2021-01-01/opensearch/domain")
|
||||
.then().statusCode(200)
|
||||
.body("DomainStatus.VPCOptions.SubnetIds", contains("subnet-aaa", "subnet-bbb"))
|
||||
.body("DomainStatus.VPCOptions.SecurityGroupIds", contains("sg-111"))
|
||||
.body("DomainStatus.VPCOptions.VPCId", equalTo("vpc-zzz"));
|
||||
|
||||
given().header("Authorization", AUTH_HEADER)
|
||||
.when().get("/2021-01-01/opensearch/domain/opts-vpc")
|
||||
.then().statusCode(200)
|
||||
.body("DomainStatus.VPCOptions.SubnetIds", hasItem("subnet-aaa"))
|
||||
.body("DomainStatus.VPCOptions.VPCId", equalTo("vpc-zzz"));
|
||||
|
||||
given().header("Authorization", AUTH_HEADER)
|
||||
.when().get("/2021-01-01/opensearch/domain/opts-vpc/config")
|
||||
.then().statusCode(200)
|
||||
.body("DomainConfig.VPCOptions.Options.VPCId", equalTo("vpc-zzz"))
|
||||
.body("DomainConfig.VPCOptions.Status.State", equalTo("Active"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void advancedSecurityOptionsRoundTripsButNeverEchoesPassword() {
|
||||
String body = "{"
|
||||
+ "\"DomainName\":\"opts-adv\","
|
||||
+ "\"EngineVersion\":\"OpenSearch_2.19\","
|
||||
+ "\"AdvancedSecurityOptions\":{"
|
||||
+ " \"Enabled\":true,"
|
||||
+ " \"InternalUserDatabaseEnabled\":true,"
|
||||
+ " \"MasterUserOptions\":{"
|
||||
+ " \"MasterUserName\":\"admin\","
|
||||
+ " \"MasterUserPassword\":\"super-secret\""
|
||||
+ " }}"
|
||||
+ "}";
|
||||
|
||||
given().contentType("application/json").header("Authorization", AUTH_HEADER).body(body)
|
||||
.when().post("/2021-01-01/opensearch/domain")
|
||||
.then().statusCode(200)
|
||||
.body("DomainStatus.AdvancedSecurityOptions.Enabled", is(true))
|
||||
.body("DomainStatus.AdvancedSecurityOptions.InternalUserDatabaseEnabled", is(true))
|
||||
.body("DomainStatus.AdvancedSecurityOptions.MasterUserOptions.MasterUserName", equalTo("admin"))
|
||||
// Master password must not leak — AWS doesn't echo it back either.
|
||||
.body("DomainStatus.AdvancedSecurityOptions.MasterUserOptions.MasterUserPassword", nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
void advancedSecurityRequiresMasterUserWhenInternalDbEnabled() {
|
||||
// Reject the same combination AWS rejects so Terraform plans surface
|
||||
// the validation error here instead of waiting for prod.
|
||||
String body = "{"
|
||||
+ "\"DomainName\":\"opts-adv\","
|
||||
+ "\"EngineVersion\":\"OpenSearch_2.19\","
|
||||
+ "\"AdvancedSecurityOptions\":{"
|
||||
+ " \"Enabled\":true,"
|
||||
+ " \"InternalUserDatabaseEnabled\":true"
|
||||
+ "}}";
|
||||
|
||||
given().contentType("application/json").header("Authorization", AUTH_HEADER).body(body)
|
||||
.when().post("/2021-01-01/opensearch/domain")
|
||||
.then().statusCode(400);
|
||||
}
|
||||
|
||||
@Test
|
||||
void encryptionAndNodeToNodeOptionsRoundTrip() {
|
||||
String body = "{"
|
||||
+ "\"DomainName\":\"opts-enc\","
|
||||
+ "\"EngineVersion\":\"OpenSearch_2.19\","
|
||||
+ "\"EncryptionAtRestOptions\":{"
|
||||
+ " \"Enabled\":true,"
|
||||
+ " \"KmsKeyId\":\"arn:aws:kms:us-east-1:000000000000:key/my-key\""
|
||||
+ "},"
|
||||
+ "\"NodeToNodeEncryptionOptions\":{\"Enabled\":true}"
|
||||
+ "}";
|
||||
|
||||
given().contentType("application/json").header("Authorization", AUTH_HEADER).body(body)
|
||||
.when().post("/2021-01-01/opensearch/domain")
|
||||
.then().statusCode(200)
|
||||
.body("DomainStatus.EncryptionAtRestOptions.Enabled", is(true))
|
||||
.body("DomainStatus.EncryptionAtRestOptions.KmsKeyId",
|
||||
equalTo("arn:aws:kms:us-east-1:000000000000:key/my-key"))
|
||||
.body("DomainStatus.NodeToNodeEncryptionOptions.Enabled", is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
void domainEndpointOptionsRoundTripAndRejectMissingCustomEndpoint() {
|
||||
String okBody = "{"
|
||||
+ "\"DomainName\":\"opts-endpoint\","
|
||||
+ "\"EngineVersion\":\"OpenSearch_2.19\","
|
||||
+ "\"DomainEndpointOptions\":{"
|
||||
+ " \"EnforceHTTPS\":true,"
|
||||
+ " \"TLSSecurityPolicy\":\"Policy-Min-TLS-1-2-2019-07\""
|
||||
+ "}}";
|
||||
|
||||
given().contentType("application/json").header("Authorization", AUTH_HEADER).body(okBody)
|
||||
.when().post("/2021-01-01/opensearch/domain")
|
||||
.then().statusCode(200)
|
||||
.body("DomainStatus.DomainEndpointOptions.EnforceHTTPS", is(true))
|
||||
.body("DomainStatus.DomainEndpointOptions.TLSSecurityPolicy",
|
||||
equalTo("Policy-Min-TLS-1-2-2019-07"));
|
||||
|
||||
// Custom endpoint without a value set is malformed — match AWS behavior.
|
||||
String badBody = "{"
|
||||
+ "\"DomainName\":\"opts-endpoint-bad\","
|
||||
+ "\"EngineVersion\":\"OpenSearch_2.19\","
|
||||
+ "\"DomainEndpointOptions\":{"
|
||||
+ " \"CustomEndpointEnabled\":true"
|
||||
+ "}}";
|
||||
|
||||
given().contentType("application/json").header("Authorization", AUTH_HEADER).body(badBody)
|
||||
.when().post("/2021-01-01/opensearch/domain")
|
||||
.then().statusCode(400);
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateDomainConfigPersistsNewVpcOptions() {
|
||||
// Create with one set of subnets; update to a different set.
|
||||
given().contentType("application/json").header("Authorization", AUTH_HEADER)
|
||||
.body("{\"DomainName\":\"opts-update\",\"EngineVersion\":\"OpenSearch_2.19\","
|
||||
+ "\"VPCOptions\":{\"SubnetIds\":[\"subnet-old\"]}}")
|
||||
.when().post("/2021-01-01/opensearch/domain")
|
||||
.then().statusCode(200);
|
||||
|
||||
given().contentType("application/json").header("Authorization", AUTH_HEADER)
|
||||
.body("{\"VPCOptions\":{\"SubnetIds\":[\"subnet-new\"],\"SecurityGroupIds\":[\"sg-new\"]}}")
|
||||
.when().post("/2021-01-01/opensearch/domain/opts-update/config")
|
||||
.then().statusCode(200)
|
||||
.body("DomainConfig.VPCOptions.Options.SubnetIds", contains("subnet-new"));
|
||||
|
||||
given().header("Authorization", AUTH_HEADER)
|
||||
.when().get("/2021-01-01/opensearch/domain/opts-update")
|
||||
.then().statusCode(200)
|
||||
.body("DomainStatus.VPCOptions.SubnetIds", contains("subnet-new"))
|
||||
.body("DomainStatus.VPCOptions.SubnetIds", not(hasItem("subnet-old")));
|
||||
}
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
package io.github.hectorvent.floci.services.opensearch;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.hasItems;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
class OpenSearchInstanceTypesTest {
|
||||
|
||||
@Test
|
||||
void listAllIncludesEbsAndOr1Families() {
|
||||
assertThat(OpenSearchInstanceTypes.listAll(),
|
||||
hasItems("m5.large.search", "m6g.large.search", "m7g.large.search",
|
||||
"or1.medium.search", "or1.2xlarge.search",
|
||||
"i3.large.search"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void or1FamilyIsS3BackedAndNotEbsAttachable() {
|
||||
OpenSearchInstanceTypes.InstanceTypeSpec spec = OpenSearchInstanceTypes.specOf("or1.2xlarge.search");
|
||||
assertThat(spec, notNullValue());
|
||||
// or1 backs storage by S3 — not EBS. Real fidelity here matters for
|
||||
// SDK clients (Terraform, CDK) that reject EBS config on or1.
|
||||
assertThat(spec.storageType(), equalTo("s3-backed"));
|
||||
assertThat(spec.ebsAttachable(), is(false));
|
||||
assertThat(spec.maxVolumeSizeGib(), greaterThan(8000));
|
||||
}
|
||||
|
||||
@Test
|
||||
void ebsFamilyHas3584GibCeiling() {
|
||||
// 3584 GiB ceiling matches AWS's published gp2/gp3 limit; regression
|
||||
// here would mislead cost calculators into allowing impossible volume
|
||||
// sizes.
|
||||
OpenSearchInstanceTypes.InstanceTypeSpec spec = OpenSearchInstanceTypes.specOf("m6g.2xlarge.search");
|
||||
assertThat(spec.storageType(), equalTo("ebs"));
|
||||
assertThat(spec.ebsAttachable(), is(true));
|
||||
assertThat(spec.maxVolumeSizeGib(), equalTo(3584));
|
||||
}
|
||||
|
||||
@Test
|
||||
void i3FamilyHasInstanceStoreNotEbs() {
|
||||
OpenSearchInstanceTypes.InstanceTypeSpec spec = OpenSearchInstanceTypes.specOf("i3.4xlarge.search");
|
||||
assertThat(spec.storageType(), equalTo("instance-store"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void specOfReturnsNullForUnknownType() {
|
||||
assertThat(OpenSearchInstanceTypes.specOf("imaginary.10xlarge.search"), nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
void genericFallbackIsEbsWithStandardLimits() {
|
||||
OpenSearchInstanceTypes.InstanceTypeSpec spec = OpenSearchInstanceTypes.genericFallback("future.99xlarge.search");
|
||||
assertThat(spec.storageType(), equalTo("ebs"));
|
||||
assertThat(spec.maxVolumeSizeGib(), equalTo(3584));
|
||||
assertThat(spec.ebsAttachable(), is(true));
|
||||
}
|
||||
}
|
||||
+22
-3
@@ -272,19 +272,38 @@ class OpenSearchIntegrationTest {
|
||||
.get("/2021-01-01/opensearch/instanceTypeDetails/OpenSearch_2.11")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("InstanceTypeDetails", not(empty()));
|
||||
.body("InstanceTypeDetails", not(empty()))
|
||||
// or1 family must show up in the catalog; SDK clients filter on it.
|
||||
.body("InstanceTypeDetails.InstanceType", hasItem("or1.2xlarge.search"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(16)
|
||||
void describeInstanceTypeLimits() {
|
||||
void describeInstanceTypeLimitsForEbsFamily() {
|
||||
given()
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.get("/2021-01-01/opensearch/instanceTypeLimits/OpenSearch_2.11/m5.large.search")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("LimitsByRole", notNullValue());
|
||||
.body("LimitsByRole.data.StorageTypes[0].StorageTypeName", equalTo("ebs"))
|
||||
.body("LimitsByRole.data.StorageTypes[0].StorageTypeLimits[1].LimitValues[0]", equalTo("3584"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(16)
|
||||
void describeInstanceTypeLimitsForOr1FamilyExposesS3Backed() {
|
||||
// or1 differs from the ebs-only families AWS used to ship — Floci
|
||||
// needs to report s3-backed storage and the larger volume ceiling.
|
||||
given()
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.get("/2021-01-01/opensearch/instanceTypeLimits/OpenSearch_2.11/or1.2xlarge.search")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("LimitsByRole.data.StorageTypes[0].StorageTypeName", equalTo("s3-backed"))
|
||||
.body("LimitsByRole.data.StorageTypes[0].StorageTypeLimits[1].LimitValues[0]",
|
||||
equalTo("36864"));
|
||||
}
|
||||
|
||||
// ── Stubs ─────────────────────────────────────────────────────────────────
|
||||
|
||||
Reference in new issue
Block a user