mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(redshift): add ModifyClusterIamRoles, DescribeClusterVersions and DescribeOrderableClusterOptions (#3990)
ModifyClusterIamRoles adds and removes the IAM roles associated with a cluster. The change is pushed to the running auth proxy, so COPY and UNLOAD on new connections authorize against the updated role list. Cluster IamRoles now report ApplyStatus in-sync. DescribeClusterVersions and DescribeOrderableClusterOptions return static data so IaC providers can validate node types before creating a cluster.
This commit is contained in:
1 parent
992b80f8f7
commit
d227ef9195
13 files changed
+390
-9
No files matched your search
+49
@@ -15,6 +15,7 @@ import java.util.Optional;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
@@ -167,6 +168,54 @@ public class RedshiftOperationsTest {
|
||||
.statusCode(200)
|
||||
.body(containsString("<NodeType>ra3.xlplus</NodeType>"));
|
||||
|
||||
// 1d. ModifyClusterIamRoles adds a role, then removes it
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.formParam("Action", "ModifyClusterIamRoles")
|
||||
.formParam("ClusterIdentifier", "cluster-src")
|
||||
.formParam("AddIamRoles.IamRoleArn.1", "arn:aws:iam::000000000000:role/redshift-copy")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<IamRoleArn>arn:aws:iam::000000000000:role/redshift-copy</IamRoleArn>"))
|
||||
.body(containsString("<ApplyStatus>in-sync</ApplyStatus>"));
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.formParam("Action", "ModifyClusterIamRoles")
|
||||
.formParam("ClusterIdentifier", "cluster-src")
|
||||
.formParam("RemoveIamRoles.IamRoleArn.1", "arn:aws:iam::000000000000:role/redshift-copy")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(not(containsString("redshift-copy")));
|
||||
|
||||
// 1e. Static discovery APIs
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.formParam("Action", "DescribeClusterVersions")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<ClusterParameterGroupFamily>redshift-1.0</ClusterParameterGroupFamily>"));
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.formParam("Action", "DescribeOrderableClusterOptions")
|
||||
.formParam("NodeType", "ra3.xlplus")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<NodeType>ra3.xlplus</NodeType>"));
|
||||
|
||||
// 2. CreateClusterSnapshot
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
|
||||
+68
@@ -428,6 +428,74 @@ class RedshiftQueryHandlerTest {
|
||||
assertEquals("InvalidParameterValue", ex.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyClusterIamRolesAcceptsNamedMemberForm() {
|
||||
// Real Redshift SDK sends "AddIamRoles.IamRoleArn.N" and "RemoveIamRoles.IamRoleArn.N".
|
||||
MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
|
||||
params.putSingle("ClusterIdentifier", "c1");
|
||||
params.putSingle("AddIamRoles.IamRoleArn.1", "arn:aws:iam::111111111111:role/a");
|
||||
params.putSingle("RemoveIamRoles.IamRoleArn.1", "arn:aws:iam::111111111111:role/b");
|
||||
Cluster cluster = new Cluster();
|
||||
cluster.setClusterIdentifier("c1");
|
||||
cluster.setIamRoleArns(List.of("arn:aws:iam::111111111111:role/a"));
|
||||
when(service.modifyClusterIamRoles(eq("c1"), any(), any())).thenReturn(cluster);
|
||||
|
||||
Response response = handler.handle("ModifyClusterIamRoles", params);
|
||||
|
||||
assertEquals(200, response.getStatus());
|
||||
verify(service).modifyClusterIamRoles("c1",
|
||||
List.of("arn:aws:iam::111111111111:role/a"), List.of("arn:aws:iam::111111111111:role/b"));
|
||||
String body = response.getEntity().toString();
|
||||
assertTrue(body.contains("<ModifyClusterIamRolesResult>"));
|
||||
assertTrue(body.contains("<IamRoleArn>arn:aws:iam::111111111111:role/a</IamRoleArn>"));
|
||||
assertTrue(body.contains("<ApplyStatus>in-sync</ApplyStatus>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeClusterVersionsListsTheEmulatedVersion() {
|
||||
Response response = handler.handle("DescribeClusterVersions", new MultivaluedHashMap<>());
|
||||
|
||||
assertEquals(200, response.getStatus());
|
||||
String body = response.getEntity().toString();
|
||||
assertTrue(body.contains("<DescribeClusterVersionsResult>"));
|
||||
assertTrue(body.contains("<ClusterVersion>1.0</ClusterVersion>"));
|
||||
assertTrue(body.contains("<ClusterParameterGroupFamily>redshift-1.0</ClusterParameterGroupFamily>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeClusterVersionsFiltersByVersion() {
|
||||
MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
|
||||
params.putSingle("ClusterVersion", "9.9");
|
||||
|
||||
String body = handler.handle("DescribeClusterVersions", params).getEntity().toString();
|
||||
|
||||
assertFalse(body.contains("<ClusterVersion>1.0</ClusterVersion>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeOrderableClusterOptionsFiltersByNodeType() {
|
||||
MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
|
||||
params.putSingle("NodeType", "ra3.xlplus");
|
||||
when(regionResolver.resolveRegionFromAuth("auth")).thenReturn("eu-west-1");
|
||||
|
||||
Response response = handler.handle("DescribeOrderableClusterOptions", params, "auth");
|
||||
|
||||
assertEquals(200, response.getStatus());
|
||||
String body = response.getEntity().toString();
|
||||
assertTrue(body.contains("<Name>eu-west-1a</Name>"));
|
||||
assertTrue(body.contains("<DescribeOrderableClusterOptionsResult>"));
|
||||
assertTrue(body.contains("<NodeType>ra3.xlplus</NodeType>"));
|
||||
assertFalse(body.contains("<NodeType>dc2.large</NodeType>"));
|
||||
assertTrue(body.contains("<ClusterType>multi-node</ClusterType>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyClusterIamRolesRequiresClusterIdentifier() {
|
||||
AwsException ex = assertThrows(AwsException.class,
|
||||
() -> handler.handle("ModifyClusterIamRoles", new MultivaluedHashMap<>()));
|
||||
assertEquals("InvalidParameterValue", ex.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBuildClusterXmlIncludesParameterGroupAndTags() {
|
||||
MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
|
||||
|
||||
@@ -807,6 +807,62 @@ class RedshiftServiceTest {
|
||||
service.modifyCluster("missing", "ra3.xlplus", null, null, null, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyClusterIamRolesAddsAndRemovesRolesAndUpdatesTheProxy() {
|
||||
Cluster cluster = new Cluster();
|
||||
cluster.setClusterIdentifier("c1");
|
||||
cluster.setIamRoleArns(List.of("arn:aws:iam::111111111111:role/old", "arn:aws:iam::111111111111:role/keep"));
|
||||
when(clusterBackend.get("c1")).thenReturn(Optional.of(cluster));
|
||||
when(clusterBackend.accountId()).thenReturn("111111111111");
|
||||
|
||||
Cluster updated = service.modifyClusterIamRoles("c1",
|
||||
List.of("arn:aws:iam::111111111111:role/new", "arn:aws:iam::111111111111:role/keep"),
|
||||
List.of("arn:aws:iam::111111111111:role/old"));
|
||||
|
||||
assertEquals(List.of("arn:aws:iam::111111111111:role/keep", "arn:aws:iam::111111111111:role/new"),
|
||||
updated.getIamRoleArns());
|
||||
verify(proxyManager).updateIamRoles("111111111111:c1", updated.getIamRoleArns());
|
||||
verify(clusterBackend).put(eq("c1"), any(Cluster.class));
|
||||
verify(clusterBackend).flush();
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyClusterIamRolesRejectsMalformedRoleArnWithoutChangingTheCluster() {
|
||||
Cluster cluster = new Cluster();
|
||||
cluster.setClusterIdentifier("c1");
|
||||
cluster.setIamRoleArns(List.of("arn:aws:iam::111111111111:role/keep"));
|
||||
when(clusterBackend.get("c1")).thenReturn(Optional.of(cluster));
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class, () ->
|
||||
service.modifyClusterIamRoles("c1", List.of("not-an-arn"), List.of()));
|
||||
|
||||
assertEquals("InvalidParameterValue", ex.getErrorCode());
|
||||
assertEquals(List.of("arn:aws:iam::111111111111:role/keep"), cluster.getIamRoleArns());
|
||||
verify(proxyManager, never()).updateIamRoles(any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyClusterIamRolesRejectsNonRoleArn() {
|
||||
Cluster cluster = new Cluster();
|
||||
cluster.setClusterIdentifier("c1");
|
||||
when(clusterBackend.get("c1")).thenReturn(Optional.of(cluster));
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class, () ->
|
||||
service.modifyClusterIamRoles("c1", List.of("arn:aws:iam::111111111111:user/bob"), List.of()));
|
||||
|
||||
assertEquals("InvalidParameterValue", ex.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyClusterIamRolesNotFound() {
|
||||
when(clusterBackend.get("missing")).thenReturn(Optional.empty());
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class, () ->
|
||||
service.modifyClusterIamRoles("missing", List.of(), List.of()));
|
||||
|
||||
assertEquals("ClusterNotFound", ex.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDescribeSnapshots() {
|
||||
Snapshot s = new Snapshot("snap-1", "my-cluster", "available", 5439, "admin");
|
||||
|
||||
+28
@@ -12,6 +12,7 @@ import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.ServerSocket;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
@@ -99,6 +100,26 @@ class RedshiftProxyManagerTest {
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void updateIamRolesSwapsTheRunningSnapshotWithoutARestart() throws Exception {
|
||||
RedshiftProxyManager manager = newManager();
|
||||
int port = availablePort();
|
||||
try {
|
||||
start(manager, KEY, port);
|
||||
manager.updateIamRoles(KEY, List.of("arn:aws:iam::111111111111:role/copy"));
|
||||
assertEquals(List.of("arn:aws:iam::111111111111:role/copy"), iamRoleArns(registry(manager).get(KEY)));
|
||||
assertPortUnavailable(port);
|
||||
} finally {
|
||||
manager.stopAll();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateIamRolesForUnknownKeyIsANoOp() {
|
||||
RedshiftProxyManager manager = newManager();
|
||||
assertDoesNotThrow(() -> manager.updateIamRoles("missing", List.of()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateMasterPasswordForUnknownKeyIsANoOp() {
|
||||
RedshiftProxyManager manager = newManager();
|
||||
@@ -267,6 +288,13 @@ class RedshiftProxyManagerTest {
|
||||
return (String) field.get(proxy);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static List<String> iamRoleArns(RedshiftAuthProxy proxy) throws Exception {
|
||||
Field field = RedshiftAuthProxy.class.getDeclaredField("iamRoleArns");
|
||||
field.setAccessible(true);
|
||||
return (List<String>) field.get(proxy);
|
||||
}
|
||||
|
||||
private static int availablePort() throws IOException {
|
||||
try (ServerSocket socket = new ServerSocket(0)) {
|
||||
return socket.getLocalPort();
|
||||
|
||||
Reference in new issue
Block a user