This is an automated email from the ASF dual-hosted git repository.
bbotella pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra-sidecar.git
The following commit(s) were added to refs/heads/trunk by this push:
new 4e5378b6b CASSSIDECAR-501: Introduce server-side configuration to
enforce allowed credential modes for restore jobs (#386)
4e5378b6b is described below
commit 4e5378b6b8b23d1795200055e0028748e87e00cf
Author: Bernardo Botella <[email protected]>
AuthorDate: Fri Oct 23 16:33:33 2026 +0200
CASSSIDECAR-501: Introduce server-side configuration to enforce allowed
credential modes for restore jobs (#386)
Adding configuration options for allowed credentials.
Patch by Bernardo Botella; Reviewed by Bohdan Siryk, Yifan Cai for
CASSSIDECAR-501
---
CHANGES.txt | 1 +
conf/sidecar.yaml | 4 +
docs/src/user.adoc | 1 +
.../sidecar/config/RestoreJobConfiguration.java | 9 ++
.../config/yaml/RestoreJobConfigurationImpl.java | 44 +++++++
.../handlers/restore/CreateRestoreJobHandler.java | 20 ++-
.../org/apache/cassandra/sidecar/TestModule.java | 21 ++-
.../yaml/RestoreJobConfigurationImplTest.java | 99 ++++++++++++++
...reateRestoreJobHandlerCredentialPolicyTest.java | 146 +++++++++++++++++++++
9 files changed, 338 insertions(+), 7 deletions(-)
diff --git a/CHANGES.txt b/CHANGES.txt
index bd948e332..26d92c8a3 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,5 +1,6 @@
0.5.0
-----
+ * Introduce server-side configuration to enforce allowed credential modes for
restore jobs (CASSSIDECAR-501)
* Sanitize/Nullify Cloud Credentials on RestoreJob Completion
(CASSSIDECAR-500)
* CDC fails to deserialize nested UDT columns (CASSSIDECAR-507)
* CDC log_only mode should not require Kafka producer configuration
(CASSSIDECAR-492)
diff --git a/conf/sidecar.yaml b/conf/sidecar.yaml
index fea8ad3e1..3c9d8b94b 100644
--- a/conf/sidecar.yaml
+++ b/conf/sidecar.yaml
@@ -459,6 +459,10 @@ blob_restore:
slow_task_threshold: 10m
slow_task_report_delay: 1m
ring_topology_refresh_delay: 1m
+ # Restricts which credential modes restore jobs may use. A restore job whose
credentialType is not in
+ # this list is rejected at creation time with an HTTP 400. Useful in
multi-tenant IAM-only environments
+ # to prevent clients from supplying long-lived static credentials. By
default, both are allowed.
+ allowed_credential_types: [STATIC, IAM]
s3_client:
concurrency: 4
diff --git a/docs/src/user.adoc b/docs/src/user.adoc
index e417251ea..f90f6d0e7 100644
--- a/docs/src/user.adoc
+++ b/docs/src/user.adoc
@@ -434,6 +434,7 @@ This section defines input validations for Cassandra
keyspace and directory name
* `slow_task_threshold`: The threshold to consider a restore task as slow. By
default, `10m`.
* `slow_task_report_delay`: The delay between each report of the same slow
task. By default, `1m`.
* `ring_topology_refresh_delay`: This defines how often to periodically
refresh the Cassandra ring. By default, `1m`.
+* `allowed_credential_types`: The list of credential types (`STATIC`, `IAM`)
that restore jobs are allowed to use. A restore job creation request declaring
a `credentialType` not in this list is rejected with an HTTP 400. Operators
running multi-tenant, IAM-only environments can set this to `[IAM]` to prevent
clients from supplying long-lived static credentials. By default, both `STATIC`
and `IAM` are allowed.
[[s3-client]]
### s3_client
diff --git
a/server/src/main/java/org/apache/cassandra/sidecar/config/RestoreJobConfiguration.java
b/server/src/main/java/org/apache/cassandra/sidecar/config/RestoreJobConfiguration.java
index e80a45e72..ddc201696 100644
---
a/server/src/main/java/org/apache/cassandra/sidecar/config/RestoreJobConfiguration.java
+++
b/server/src/main/java/org/apache/cassandra/sidecar/config/RestoreJobConfiguration.java
@@ -18,6 +18,9 @@
package org.apache.cassandra.sidecar.config;
+import java.util.Set;
+
+import org.apache.cassandra.sidecar.common.data.CredentialType;
import
org.apache.cassandra.sidecar.common.server.utils.MillisecondBoundConfiguration;
import
org.apache.cassandra.sidecar.common.server.utils.SecondBoundConfiguration;
@@ -73,4 +76,10 @@ public interface RestoreJobConfiguration
* @return the delay for {@link
org.apache.cassandra.sidecar.restore.RingTopologyRefresher}
*/
MillisecondBoundConfiguration ringTopologyRefreshDelay();
+
+ /**
+ * @return the set of {@link CredentialType}s that the operator allows
restore jobs to use;
+ * a request declaring any other credential type must be rejected at job
creation time
+ */
+ Set<CredentialType> allowedCredentialTypes();
}
diff --git
a/server/src/main/java/org/apache/cassandra/sidecar/config/yaml/RestoreJobConfigurationImpl.java
b/server/src/main/java/org/apache/cassandra/sidecar/config/yaml/RestoreJobConfigurationImpl.java
index d4e97f8a2..8c4ae9254 100644
---
a/server/src/main/java/org/apache/cassandra/sidecar/config/yaml/RestoreJobConfigurationImpl.java
+++
b/server/src/main/java/org/apache/cassandra/sidecar/config/yaml/RestoreJobConfigurationImpl.java
@@ -18,6 +18,8 @@
package org.apache.cassandra.sidecar.config.yaml;
+import java.util.EnumSet;
+import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
@@ -25,8 +27,10 @@ import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.cassandra.sidecar.common.DataObjectBuilder;
+import org.apache.cassandra.sidecar.common.data.CredentialType;
import
org.apache.cassandra.sidecar.common.server.utils.MillisecondBoundConfiguration;
import
org.apache.cassandra.sidecar.common.server.utils.SecondBoundConfiguration;
+import org.apache.cassandra.sidecar.common.utils.Preconditions;
import org.apache.cassandra.sidecar.config.RestoreJobConfiguration;
/**
@@ -56,6 +60,8 @@ public class RestoreJobConfigurationImpl implements
RestoreJobConfiguration
// report once a minute
private static final SecondBoundConfiguration
DEFAULT_RESTORE_JOB_SLOW_TASK_REPORT_DELAY =
SecondBoundConfiguration.parse("1m");
public static final MillisecondBoundConfiguration
DEFAULT_RING_TOPOLOGY_REFRESH_DELAY = MillisecondBoundConfiguration.parse("1m");
+ // No restriction by default, preserving pre-existing behavior where the
client's declared credentialType is trusted as-is.
+ private static final Set<CredentialType> DEFAULT_ALLOWED_CREDENTIAL_TYPES
= EnumSet.allOf(CredentialType.class);
protected MillisecondBoundConfiguration jobDiscoveryActiveLoopDelay;
@@ -77,6 +83,8 @@ public class RestoreJobConfigurationImpl implements
RestoreJobConfiguration
private MillisecondBoundConfiguration ringTopologyRefreshDelay;
+ protected Set<CredentialType> allowedCredentialTypes;
+
protected RestoreJobConfigurationImpl()
{
this(builder());
@@ -93,6 +101,7 @@ public class RestoreJobConfigurationImpl implements
RestoreJobConfiguration
this.slowTaskThreshold = builder.slowTaskThreshold;
this.slowTaskReportDelay = builder.slowTaskReportDelay;
this.ringTopologyRefreshDelay = builder.ringTopologyRefreshDelay;
+ this.allowedCredentialTypes = builder.allowedCredentialTypes;
validate();
}
@@ -109,6 +118,10 @@ public class RestoreJobConfigurationImpl implements
RestoreJobConfiguration
throw new IllegalArgumentException("JobDiscoveryMinimumRecencyDays
(in seconds) cannot be greater than "
+ ttl);
}
+ if (allowedCredentialTypes == null || allowedCredentialTypes.isEmpty())
+ {
+ throw new IllegalArgumentException("allowedCredentialTypes must
not be empty");
+ }
}
/**
@@ -324,6 +337,24 @@ public class RestoreJobConfigurationImpl implements
RestoreJobConfiguration
setRingTopologyRefreshDelay(new
MillisecondBoundConfiguration(ringTopologyRefreshDelayMillis,
TimeUnit.MILLISECONDS));
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ @JsonProperty(value = "allowed_credential_types")
+ public Set<CredentialType> allowedCredentialTypes()
+ {
+ return allowedCredentialTypes;
+ }
+
+ @JsonProperty(value = "allowed_credential_types")
+ public void setAllowedCredentialTypes(Set<CredentialType>
allowedCredentialTypes)
+ {
+ Preconditions.checkArgument(allowedCredentialTypes != null &&
allowedCredentialTypes.size() > 0,
+ () -> "Invalid allowed_credential_types
value: " + allowedCredentialTypes);
+ this.allowedCredentialTypes = allowedCredentialTypes;
+ }
+
public static Builder builder()
{
return new Builder();
@@ -343,6 +374,7 @@ public class RestoreJobConfigurationImpl implements
RestoreJobConfiguration
private int processMaxConcurrency = DEFAULT_PROCESS_MAX_CONCURRENCY;
private SecondBoundConfiguration restoreJobTablesTtl =
DEFAULT_RESTORE_JOB_TABLES_TTL;
private MillisecondBoundConfiguration ringTopologyRefreshDelay =
DEFAULT_RING_TOPOLOGY_REFRESH_DELAY;
+ private Set<CredentialType> allowedCredentialTypes =
DEFAULT_ALLOWED_CREDENTIAL_TYPES;
protected Builder()
{
@@ -462,6 +494,18 @@ public class RestoreJobConfigurationImpl implements
RestoreJobConfiguration
return update(b -> b.ringTopologyRefreshDelay =
ringTopologyRefreshDelay);
}
+ /**
+ * Sets the {@code allowedCredentialTypes} and returns a reference to
this Builder enabling
+ * method chaining.
+ *
+ * @param allowedCredentialTypes the {@code allowedCredentialTypes} to
set
+ * @return a reference to this Builder
+ */
+ public Builder allowedCredentialTypes(Set<CredentialType>
allowedCredentialTypes)
+ {
+ return update(b -> b.allowedCredentialTypes =
allowedCredentialTypes);
+ }
+
@Override
public RestoreJobConfigurationImpl build()
{
diff --git
a/server/src/main/java/org/apache/cassandra/sidecar/handlers/restore/CreateRestoreJobHandler.java
b/server/src/main/java/org/apache/cassandra/sidecar/handlers/restore/CreateRestoreJobHandler.java
index 4db848a4f..e1f0bd4dd 100644
---
a/server/src/main/java/org/apache/cassandra/sidecar/handlers/restore/CreateRestoreJobHandler.java
+++
b/server/src/main/java/org/apache/cassandra/sidecar/handlers/restore/CreateRestoreJobHandler.java
@@ -33,9 +33,12 @@ import io.vertx.core.net.SocketAddress;
import io.vertx.ext.auth.authorization.Authorization;
import io.vertx.ext.web.RoutingContext;
import org.apache.cassandra.sidecar.acl.authorization.BasicPermissions;
+import org.apache.cassandra.sidecar.common.data.CredentialType;
import
org.apache.cassandra.sidecar.common.request.data.CreateRestoreJobRequestPayload;
import
org.apache.cassandra.sidecar.common.response.data.CreateRestoreJobResponsePayload;
import org.apache.cassandra.sidecar.concurrent.ExecutorPools;
+import org.apache.cassandra.sidecar.config.RestoreJobConfiguration;
+import org.apache.cassandra.sidecar.config.SidecarConfiguration;
import org.apache.cassandra.sidecar.db.RestoreJob;
import org.apache.cassandra.sidecar.db.RestoreJobDatabaseAccessor;
import org.apache.cassandra.sidecar.handlers.AbstractHandler;
@@ -55,15 +58,18 @@ import static
org.apache.cassandra.sidecar.utils.HttpExceptions.wrapHttpExceptio
public class CreateRestoreJobHandler extends
AbstractHandler<CreateRestoreJobRequestPayload> implements AccessProtected
{
private final RestoreJobDatabaseAccessor restoreJobDatabaseAccessor;
+ private final RestoreJobConfiguration restoreJobConfiguration;
@Inject
public CreateRestoreJobHandler(ExecutorPools executorPools,
InstanceMetadataFetcher
instanceMetadataFetcher,
RestoreJobDatabaseAccessor
restoreJobDatabaseAccessor,
- CassandraInputValidator validator)
+ CassandraInputValidator validator,
+ SidecarConfiguration sidecarConfiguration)
{
super(instanceMetadataFetcher, executorPools, validator);
this.restoreJobDatabaseAccessor = restoreJobDatabaseAccessor;
+ this.restoreJobConfiguration =
sidecarConfiguration.restoreJobConfiguration();
}
@Override
@@ -116,6 +122,18 @@ public class CreateRestoreJobHandler extends
AbstractHandler<CreateRestoreJobReq
private Future<CreateRestoreJobRequestPayload>
validatePayload(CreateRestoreJobRequestPayload createRestoreJobRequestPayload)
{
+ CredentialType credentialType =
createRestoreJobRequestPayload.credentialType();
+ Set<CredentialType> allowedCredentialTypes =
restoreJobConfiguration.allowedCredentialTypes();
+ if (allowedCredentialTypes != null &&
!allowedCredentialTypes.contains(credentialType))
+ {
+ logger.warn("Rejected restore job request using disallowed
credentialType. credentialType={} allowed={}",
+ credentialType, allowedCredentialTypes);
+ return Future.failedFuture(
+ wrapHttpException(HttpResponseStatus.BAD_REQUEST,
+ "credentialType '" + credentialType + "' is not
allowed by server policy. Allowed types: "
+ + allowedCredentialTypes));
+ }
+
UUID jobId = createRestoreJobRequestPayload.jobId();
if (jobId == null)
{
diff --git a/server/src/test/java/org/apache/cassandra/sidecar/TestModule.java
b/server/src/test/java/org/apache/cassandra/sidecar/TestModule.java
index 5e5d308e5..f2629483e 100644
--- a/server/src/test/java/org/apache/cassandra/sidecar/TestModule.java
+++ b/server/src/test/java/org/apache/cassandra/sidecar/TestModule.java
@@ -82,6 +82,13 @@ public class TestModule extends AbstractModule
public TestCassandraAdapterDelegate delegate;
+ private RestoreJobConfiguration restoreJobConfigurationOverride;
+
+ public void restoreJobConfiguration(RestoreJobConfiguration
restoreJobConfiguration)
+ {
+ this.restoreJobConfigurationOverride = restoreJobConfiguration;
+ }
+
@Singleton
@Provides
public CassandraAdapterDelegate delegate(Vertx vertx)
@@ -128,12 +135,14 @@ public class TestModule extends AbstractModule
.cdcConfiguration(cdcConfiguration)
.build();
RestoreJobConfiguration restoreJobConfiguration =
- RestoreJobConfigurationImpl.builder()
-
.restoreJobTablesTtl(SecondBoundConfiguration.parse((TimeUnit.DAYS.toSeconds(14)
+ 1) + "s"))
-
.processMaxConcurrency(RESTORE_MAX_CONCURRENCY)
-
.slowTaskThreshold(SecondBoundConfiguration.parse("10s"))
-
.slowTaskReportDelay(SecondBoundConfiguration.parse("2m"))
- .build();
+ restoreJobConfigurationOverride != null
+ ? restoreJobConfigurationOverride
+ : RestoreJobConfigurationImpl.builder()
+
.restoreJobTablesTtl(SecondBoundConfiguration.parse((TimeUnit.DAYS.toSeconds(14)
+ 1) + "s"))
+
.processMaxConcurrency(RESTORE_MAX_CONCURRENCY)
+
.slowTaskThreshold(SecondBoundConfiguration.parse("10s"))
+
.slowTaskReportDelay(SecondBoundConfiguration.parse("2m"))
+ .build();
PeriodicTaskConfiguration healthCheckConfiguration
= new PeriodicTaskConfigurationImpl(true,
MillisecondBoundConfiguration.parse("200ms"),
diff --git
a/server/src/test/java/org/apache/cassandra/sidecar/config/yaml/RestoreJobConfigurationImplTest.java
b/server/src/test/java/org/apache/cassandra/sidecar/config/yaml/RestoreJobConfigurationImplTest.java
new file mode 100644
index 000000000..3ae073830
--- /dev/null
+++
b/server/src/test/java/org/apache/cassandra/sidecar/config/yaml/RestoreJobConfigurationImplTest.java
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.sidecar.config.yaml;
+
+import java.io.IOException;
+import java.util.EnumSet;
+
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+import com.fasterxml.jackson.databind.JsonMappingException;
+
+import org.apache.cassandra.sidecar.common.data.CredentialType;
+import org.apache.cassandra.sidecar.config.RestoreJobConfiguration;
+import org.apache.cassandra.sidecar.config.SidecarConfiguration;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
+import static
org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
+
+/**
+ * Tests for the {@code allowed_credential_types} field of the {@code
blob_restore} configuration.
+ */
+class RestoreJobConfigurationImplTest
+{
+ @DisplayName("Defaults to allowing both STATIC and IAM credential types")
+ @Test
+ void testDefaultAllowsBothCredentialTypes()
+ {
+ RestoreJobConfiguration restoreJobConfig =
RestoreJobConfigurationImpl.builder().build();
+ assertThat(restoreJobConfig.allowedCredentialTypes())
+ .containsExactlyInAnyOrder(CredentialType.STATIC, CredentialType.IAM);
+ }
+
+ @DisplayName("Parses 'allowed_credential_types' from the 'blob_restore'
configuration")
+ @Test
+ void testParsesAllowedCredentialTypesFromYaml() throws IOException
+ {
+ String yaml = "blob_restore:\n" +
+ " allowed_credential_types: [IAM]";
+
+ SidecarConfiguration config =
SidecarConfigurationImpl.fromYamlString(yaml);
+ RestoreJobConfiguration restoreJobConfig =
config.restoreJobConfiguration();
+ assertThat(restoreJobConfig).isNotNull();
+
assertThat(restoreJobConfig.allowedCredentialTypes()).containsExactly(CredentialType.IAM);
+ }
+
+ @DisplayName("Parses 'allowed_credential_types' from the 'blob_restore'
configuration")
+ @Test
+ void testParsesInvalidAllowedCredentialTypesFromYaml() throws IOException
+ {
+ String yaml = "blob_restore:\n" +
+ " allowed_credential_types: []";
+
+ assertThatExceptionOfType(JsonMappingException.class)
+ .isThrownBy(() ->
SidecarConfigurationImpl.fromYamlString(yaml))
+ .withMessageContaining("Invalid allowed_credential_types
value: []");
+
+ }
+
+ @DisplayName("Rejects an empty 'allowed_credential_types' set")
+ @Test
+ void testRejectsEmptyAllowedCredentialTypes()
+ {
+ assertThatIllegalArgumentException()
+ .isThrownBy(() -> RestoreJobConfigurationImpl.builder()
+
.allowedCredentialTypes(EnumSet.noneOf(CredentialType.class))
+ .build())
+ .withMessageContaining("allowedCredentialTypes must not be empty");
+ }
+
+ @DisplayName("Rejects an empty 'allowed_credential_types' set once built")
+ @Test
+ void testRejectsEmptyAllowedCredentialTypes2()
+ {
+ RestoreJobConfigurationImpl config =
RestoreJobConfigurationImpl.builder()
+ .build();
+
+ assertThatIllegalArgumentException()
+ .isThrownBy(() ->
config.setAllowedCredentialTypes(EnumSet.noneOf(CredentialType.class)))
+ .withMessageContaining("Invalid allowed_credential_types
value");
+ }
+
+}
diff --git
a/server/src/test/java/org/apache/cassandra/sidecar/handlers/restore/CreateRestoreJobHandlerCredentialPolicyTest.java
b/server/src/test/java/org/apache/cassandra/sidecar/handlers/restore/CreateRestoreJobHandlerCredentialPolicyTest.java
new file mode 100644
index 000000000..7adec7eca
--- /dev/null
+++
b/server/src/test/java/org/apache/cassandra/sidecar/handlers/restore/CreateRestoreJobHandlerCredentialPolicyTest.java
@@ -0,0 +1,146 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.sidecar.handlers.restore;
+
+import java.util.EnumSet;
+import java.util.UUID;
+
+import org.junit.jupiter.api.Nested;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+import io.netty.handler.codec.http.HttpResponseStatus;
+import io.vertx.core.json.JsonObject;
+import io.vertx.ext.web.client.HttpResponse;
+import io.vertx.junit5.VertxExtension;
+import io.vertx.junit5.VertxTestContext;
+import org.apache.cassandra.sidecar.TestModule;
+import org.apache.cassandra.sidecar.common.data.CredentialType;
+import org.apache.cassandra.sidecar.config.yaml.RestoreJobConfigurationImpl;
+import org.apache.cassandra.sidecar.db.RestoreJobTest;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Tests that {@link CreateRestoreJobHandler} enforces the server-side {@code
allowed_credential_types}
+ * policy (see {@link RestoreJobConfigurationImpl#allowedCredentialTypes()}),
rejecting a restore job
+ * creation request whose {@code credentialType} is not permitted by the
operator's configuration.
+ */
+@ExtendWith(VertxExtension.class)
+class CreateRestoreJobHandlerCredentialPolicyTest
+{
+ private static final String CREATE_RESTORE_JOB_ENDPOINT =
"/api/v1/keyspaces/%s/tables/%s/restore-jobs";
+ private static final String JOB_ID =
"8e5799a4-d277-11ed-8d85-6916bb9b8056";
+
+ @Nested
+ class IamOnlyPolicy extends BaseRestoreJobTests
+ {
+ @Override
+ protected void configureTestModule(TestModule testModule)
+ {
+
testModule.restoreJobConfiguration(RestoreJobConfigurationImpl.builder()
+
.allowedCredentialTypes(EnumSet.of(CredentialType.IAM))
+
.build());
+ }
+
+ @Test
+ void rejectsStaticCredentialsRequest(VertxTestContext context) throws
Throwable
+ {
+ mockLookupRestoreJob(id -> null);
+ JsonObject payload = new JsonObject();
+ payload.put("jobId", JOB_ID);
+ payload.put("secrets", SECRETS); // defaults to STATIC
credentialType
+ payload.put("expireAt", System.currentTimeMillis() + 10000L);
+ postThenComplete(context,
String.format(CREATE_RESTORE_JOB_ENDPOINT, "ks", "table"), payload, asyncResult
-> {
+ HttpResponse<?> resp = asyncResult.result();
+ assertThat(resp).isNotNull();
+
assertThat(resp.statusCode()).isEqualTo(HttpResponseStatus.BAD_REQUEST.code());
+ });
+ }
+
+ @Test
+ void allowsIamCredentialsRequest(VertxTestContext context) throws
Throwable
+ {
+ mockCreateRestoreJob(x ->
RestoreJobTest.createNewTestingJob(UUID.fromString(JOB_ID)));
+ mockLookupRestoreJob(id -> null);
+ JsonObject regionOnlyCredentials = new JsonObject().put("region",
"us-east-1");
+ JsonObject secrets = new JsonObject()
+ .put("readCredentials", regionOnlyCredentials)
+ .put("writeCredentials",
regionOnlyCredentials);
+ JsonObject payload = new JsonObject();
+ payload.put("jobId", JOB_ID);
+ payload.put("credentialType", "IAM");
+ payload.put("secrets", secrets);
+ payload.put("expireAt", System.currentTimeMillis() + 10000L);
+ postThenComplete(context,
String.format(CREATE_RESTORE_JOB_ENDPOINT, "ks", "table"), payload, asyncResult
-> {
+ HttpResponse<?> resp = asyncResult.result();
+ assertThat(resp).isNotNull();
+
assertThat(resp.statusCode()).isEqualTo(HttpResponseStatus.OK.code());
+ });
+ }
+ }
+
+ @Nested
+ class StaticOnlyPolicy extends BaseRestoreJobTests
+ {
+ @Override
+ protected void configureTestModule(TestModule testModule)
+ {
+
testModule.restoreJobConfiguration(RestoreJobConfigurationImpl.builder()
+
.allowedCredentialTypes(EnumSet.of(CredentialType.STATIC))
+
.build());
+ }
+
+ @Test
+ void rejectsIamCredentialsRequest(VertxTestContext context) throws
Throwable
+ {
+ mockLookupRestoreJob(id -> null);
+ JsonObject regionOnlyCredentials = new JsonObject().put("region",
"us-east-1");
+ JsonObject secrets = new JsonObject()
+ .put("readCredentials", regionOnlyCredentials)
+ .put("writeCredentials",
regionOnlyCredentials);
+ JsonObject payload = new JsonObject();
+ payload.put("jobId", JOB_ID);
+ payload.put("credentialType", "IAM");
+ payload.put("secrets", secrets);
+ payload.put("expireAt", System.currentTimeMillis() + 10000L);
+ postThenComplete(context,
String.format(CREATE_RESTORE_JOB_ENDPOINT, "ks", "table"), payload, asyncResult
-> {
+ HttpResponse<?> resp = asyncResult.result();
+ assertThat(resp).isNotNull();
+
assertThat(resp.statusCode()).isEqualTo(HttpResponseStatus.BAD_REQUEST.code());
+ });
+ }
+
+ @Test
+ void allowsStaticCredentialsRequest(VertxTestContext context) throws
Throwable
+ {
+ mockCreateRestoreJob(x ->
RestoreJobTest.createNewTestingJob(UUID.fromString(JOB_ID)));
+ mockLookupRestoreJob(id -> null);
+ JsonObject payload = new JsonObject();
+ payload.put("jobId", JOB_ID);
+ payload.put("secrets", SECRETS); // defaults to STATIC
credentialType
+ payload.put("expireAt", System.currentTimeMillis() + 10000L);
+ postThenComplete(context,
String.format(CREATE_RESTORE_JOB_ENDPOINT, "ks", "table"), payload, asyncResult
-> {
+ HttpResponse<?> resp = asyncResult.result();
+ assertThat(resp).isNotNull();
+
assertThat(resp.statusCode()).isEqualTo(HttpResponseStatus.OK.code());
+ });
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]