-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🎉 Integration Testing for SSH using a docker container | Postgres Sou…
…rce and Destination update integration tests using ssh bastion in docker container (#6312) * ssh-test * add authentification via ssh tunnel with bastion docker host and postgres testcontainer * created SshBastion class in base-java module * implement Postgres source basic ssh tunneling connection for integration tests * implement Postgres source ssh tunneling connection and refactoring SshBastion * generate keys inside a bastion container * remove throwing Exception from startTestContainers method * fix checkstyle * add documentation and changelog for Posthres source and destination * update documentation for ssh readme.md | update version fo Postgres source and destination to 0.3.12 * update version of Postgres source and destination to 0.3.12 * removed static variables, removed version bump, rename class to SshBastionContainer, removed ci credentials for ssh Postgres Source and Destination Co-authored-by: vmaltsev <vitalii.maltsev@globallogic.com>
- Loading branch information
1 parent
ff479de
commit ec3951b
Showing
11 changed files
with
219 additions
and
39 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
101 changes: 101 additions & 0 deletions
101
...s/bases/base-java/src/main/java/io/airbyte/integrations/base/ssh/SshBastionContainer.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,101 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2020 Airbyte | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package io.airbyte.integrations.base.ssh; | ||
|
||
import static io.airbyte.integrations.base.ssh.SshTunnel.TunnelMethod.SSH_KEY_AUTH; | ||
import static io.airbyte.integrations.base.ssh.SshTunnel.TunnelMethod.SSH_PASSWORD_AUTH; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.google.common.collect.ImmutableMap; | ||
import io.airbyte.commons.json.Jsons; | ||
import java.io.IOException; | ||
import java.util.Objects; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.containers.JdbcDatabaseContainer; | ||
import org.testcontainers.containers.Network; | ||
import org.testcontainers.images.builder.ImageFromDockerfile; | ||
|
||
public class SshBastionContainer { | ||
|
||
private static final String SSH_USER = "sshuser"; | ||
private static final String SSH_PASSWORD = "secret"; | ||
private Network network; | ||
private GenericContainer bastion; | ||
|
||
public void initAndStartBastion() { | ||
network = Network.newNetwork(); | ||
bastion = new GenericContainer( | ||
new ImageFromDockerfile("bastion-test") | ||
.withFileFromClasspath("Dockerfile", "bastion/Dockerfile")) | ||
.withNetwork(network) | ||
.withExposedPorts(22); | ||
bastion.start(); | ||
} | ||
|
||
public JsonNode getTunnelConfig(SshTunnel.TunnelMethod tunnelMethod, ImmutableMap.Builder<Object, Object> builderWithSchema) | ||
throws IOException, InterruptedException { | ||
|
||
return Jsons.jsonNode(builderWithSchema | ||
.put("tunnel_method", Jsons.jsonNode(ImmutableMap.builder() | ||
.put("tunnel_host", | ||
Objects.requireNonNull(bastion.getContainerInfo().getNetworkSettings() | ||
.getNetworks() | ||
.get(((Network.NetworkImpl) network).getName()) | ||
.getIpAddress())) | ||
.put("tunnel_method", tunnelMethod) | ||
.put("tunnel_port", bastion.getExposedPorts().get(0)) | ||
.put("tunnel_user", SSH_USER) | ||
.put("tunnel_user_password", tunnelMethod.equals(SSH_PASSWORD_AUTH) ? SSH_PASSWORD : "") | ||
.put("ssh_key", tunnelMethod.equals(SSH_KEY_AUTH) ? bastion.execInContainer("cat", "var/bastion/id_rsa").getStdout() : "") | ||
.build())) | ||
.build()); | ||
} | ||
|
||
public ImmutableMap.Builder<Object, Object> getBasicDbConfigBuider(JdbcDatabaseContainer<?> db) { | ||
return ImmutableMap.builder() | ||
.put("host", Objects.requireNonNull(db.getContainerInfo().getNetworkSettings() | ||
.getNetworks() | ||
.get(((Network.NetworkImpl) getNetWork()).getName()) | ||
.getIpAddress())) | ||
.put("username", db.getUsername()) | ||
.put("password", db.getPassword()) | ||
.put("port", db.getExposedPorts().get(0)) | ||
.put("database", db.getDatabaseName()) | ||
.put("ssl", false); | ||
} | ||
|
||
public Network getNetWork() { | ||
return this.network; | ||
} | ||
|
||
public void stopAndCloseContainers(JdbcDatabaseContainer<?> db) { | ||
db.stop(); | ||
db.close(); | ||
bastion.stop(); | ||
bastion.close(); | ||
network.close(); | ||
} | ||
|
||
} |
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
25 changes: 25 additions & 0 deletions
25
airbyte-integrations/bases/base-java/src/main/resources/bastion/Dockerfile
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,25 @@ | ||
FROM ubuntu:18.04 | ||
|
||
RUN apt-get update && apt-get install -y openssh-server | ||
RUN apt-get install -y apt-utils | ||
RUN mkdir /var/run/sshd | ||
RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config | ||
RUN sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config | ||
|
||
RUN useradd -m -s /bin/bash sshuser | ||
RUN echo "sshuser:secret" | chpasswd | ||
|
||
RUN mkdir /var/bastion | ||
RUN ssh-keygen -m PEM -t rsa -b 4096 -C "test-container-bastion" -P "" -f /var/bastion/id_rsa -q | ||
RUN install -D /var/bastion/id_rsa.pub /home/sshuser/.ssh/authorized_keys | ||
|
||
RUN chown -R sshuser:sshuser /home/sshuser/.ssh | ||
RUN chmod 600 /home/sshuser/.ssh/authorized_keys | ||
|
||
RUN mkdir /root/.ssh | ||
|
||
RUN apt-get clean && \ | ||
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* | ||
EXPOSE 22 | ||
|
||
CMD ["/usr/sbin/sshd", "-D"] |
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
Oops, something went wrong.