-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛Destination-dynamodb: enforce ssl connection (#18672)
* [16283] Destination-dynamodb: Added strict-encrypt version and enforced ssl connection on cloud
- Loading branch information
Showing
10 changed files
with
138 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...src/main/java/io/airbyte/integrations/destination/dynamodb/DynamodbDestinationRunner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright (c) 2022 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.integrations.destination.dynamodb; | ||
|
||
import io.airbyte.integrations.base.adaptive.AdaptiveDestinationRunner; | ||
|
||
public class DynamodbDestinationRunner { | ||
|
||
public static void main(final String[] args) throws Exception { | ||
AdaptiveDestinationRunner.baseOnEnv() | ||
.withOssDestination(DynamodbDestination::new) | ||
.withCloudDestination(DynamodbDestinationStrictEncrypt::new) | ||
.run(args); | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
...n/java/io/airbyte/integrations/destination/dynamodb/DynamodbDestinationStrictEncrypt.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright (c) 2022 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.integrations.destination.dynamodb; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import io.airbyte.protocol.models.AirbyteConnectionStatus; | ||
|
||
public class DynamodbDestinationStrictEncrypt extends DynamodbDestination { | ||
|
||
protected static final String NON_SECURE_URL_ERR_MSG = "Server Endpoint requires HTTPS"; | ||
|
||
public DynamodbDestinationStrictEncrypt() { | ||
super(); | ||
} | ||
|
||
@Override | ||
public AirbyteConnectionStatus check(final JsonNode config) { | ||
final DynamodbDestinationConfig dynamodbDestinationConfig = | ||
DynamodbDestinationConfig.getDynamodbDestinationConfig(config); | ||
|
||
// enforce ssl connection | ||
if (!DynamodbChecker.testCustomEndpointSecured(dynamodbDestinationConfig.getEndpoint())) { | ||
return new AirbyteConnectionStatus() | ||
.withStatus(AirbyteConnectionStatus.Status.FAILED) | ||
.withMessage(NON_SECURE_URL_ERR_MSG); | ||
} | ||
|
||
return super.check(config); | ||
} | ||
|
||
} |
63 changes: 63 additions & 0 deletions
63
...va/io/airbyte/integrations/destination/dynamodb/DynamodbDestinationStrictEncryptTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright (c) 2022 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.integrations.destination.dynamodb; | ||
|
||
import static io.airbyte.integrations.destination.dynamodb.DynamodbDestinationStrictEncrypt.NON_SECURE_URL_ERR_MSG; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.google.common.collect.ImmutableMap; | ||
import io.airbyte.commons.io.IOs; | ||
import io.airbyte.commons.json.Jsons; | ||
import io.airbyte.protocol.models.AirbyteConnectionStatus; | ||
import io.airbyte.protocol.models.AirbyteConnectionStatus.Status; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class DynamodbDestinationStrictEncryptTest { | ||
|
||
protected static final Path secretFilePath = Path.of("secrets/config.json"); | ||
|
||
/** | ||
* Test that check passes if user is using HTTPS connection | ||
*/ | ||
@Test | ||
public void checkPassCustomEndpointIsHttpsOnly() { | ||
final DynamodbDestination destinationWithHttpsOnlyEndpoint = new DynamodbDestinationStrictEncrypt(); | ||
final AirbyteConnectionStatus status = destinationWithHttpsOnlyEndpoint.check(getBaseConfigJson()); | ||
assertEquals(Status.SUCCEEDED, status.getStatus()); | ||
} | ||
|
||
/** | ||
* Test that check fails if user is using a non-secure (http) connection | ||
*/ | ||
@Test | ||
public void checkFailCustomEndpointIsHttpsOnly() { | ||
final DynamodbDestination destinationWithHttpsOnlyEndpoint = new DynamodbDestinationStrictEncrypt(); | ||
final AirbyteConnectionStatus status = destinationWithHttpsOnlyEndpoint.check(getUnsecureConfig()); | ||
assertEquals(AirbyteConnectionStatus.Status.FAILED, status.getStatus()); | ||
assertEquals(NON_SECURE_URL_ERR_MSG, status.getMessage()); | ||
} | ||
|
||
protected JsonNode getBaseConfigJson() { | ||
if (!Files.exists(secretFilePath)) { | ||
throw new IllegalStateException("Secret config file doesn't exist. Get a valid secret (for airbyter: " | ||
+ "get secret from GSM) and put to ../destination-dynamodb/secrets/secret.json file"); | ||
} | ||
return Jsons.deserialize(IOs.readFile(secretFilePath)); | ||
} | ||
|
||
protected JsonNode getUnsecureConfig() { | ||
return Jsons.jsonNode(ImmutableMap.builder() | ||
.put("dynamodb_endpoint", "http://testurl.com:9000") | ||
.put("dynamodb_table_name_prefix", "integration-test") | ||
.put("dynamodb_region", "us-east-2") | ||
.put("access_key_id", "dummy_access_key_id") | ||
.put("secret_access_key", "dummy_secret_access_key") | ||
.build()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters