diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 99090b56..932887dc 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -4,7 +4,7 @@ ## Linear Ticket -< Replace_with_Linear_Link > +< Linear_Link > ## Security diff --git a/kafkaclient/client_test.go b/kafkaclient/client_test.go index 217b6066..5d5fe8ff 100644 --- a/kafkaclient/client_test.go +++ b/kafkaclient/client_test.go @@ -21,6 +21,7 @@ import ( "github.com/rudderlabs/rudder-go-kit/kafkaclient/testutil" dockerKafka "github.com/rudderlabs/rudder-go-kit/testhelper/docker/resource/kafka" "github.com/rudderlabs/rudder-go-kit/testhelper/docker/resource/sshserver" + "github.com/rudderlabs/rudder-go-kit/testhelper/keygen" ) const ( @@ -838,8 +839,9 @@ func TestSSH(t *testing.T) { require.NoError(t, err) // Let's setup the SSH server - publicKeyPath, err := filepath.Abs("./testdata/ssh/test_key.pub") + privateKeyPath, publicKeyPath, err := keygen.NewRSAKeyPair(2048, keygen.SaveTo(t.TempDir())) require.NoError(t, err) + sshServer, err := sshserver.Setup(pool, t, sshserver.WithPublicKeyPath(publicKeyPath), sshserver.WithCredentials("linuxserver.io", ""), @@ -850,7 +852,7 @@ func TestSSH(t *testing.T) { t.Logf("SSH server is listening on %s", sshServerHost) // Read private key - privateKey, err := os.ReadFile("./testdata/ssh/test_key") + privateKey, err := os.ReadFile(privateKeyPath) require.NoError(t, err) // Setup client and ping diff --git a/kafkaclient/testdata/client.key.pem b/kafkaclient/testdata/client.key.pem deleted file mode 100644 index 8f32f597..00000000 --- a/kafkaclient/testdata/client.key.pem +++ /dev/null @@ -1,28 +0,0 @@ ------BEGIN PRIVATE KEY----- -MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCkiaQY9ftkjxeG -oUFKQ6lMXFQCn9XemxaHPcanXo0HfYgtk5zi8LLAXOA+G0Ze3rq+Wnky4tJzOw9U -3mKuUJGj8Ek4i8Pf2ebSbhr25trG3XvQ8Z1AL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/qSC7AJRXyDsWnbrz1iS/JujHYDz5tEv1FaPpAoGAcjET -gQc4OBwCWL7takgB7jMynbruSk5NlGSrWUiUDkyP70crth3Kataos/YcHmjIa/Wz -tUzNSHT2y6wd/vHMu5CZgXEsLCn7/Lj0+VcMUtvS+E2E4yUW7/IcrznODVg4gp99 -Jw6QGLKSdw1nJ53QwVF3G8oJ8r/aWnUskiVjiHECgYEAtt0twUlwt/wNHjc6ENox -OpasyprRf9MUnmVa84sxdHh5mupikC1c16AnNaVKUisMCwwAZLZyyvXHAHIN6ueW -lrJ2KvA4tj+rESNT7iUnIlp1JDKRAE+Bn55QEzhPWNPbyDe6EN7qDq2MSAcEcYvl -nFs6oP2amYMd0YclFk/cZRA= ------END PRIVATE KEY----- diff --git a/kafkaclient/testdata/ssh/test_key b/kafkaclient/testdata/ssh/test_key deleted file mode 100644 index c095f906..00000000 --- a/kafkaclient/testdata/ssh/test_key +++ /dev/null @@ -1,39 +0,0 @@ ------BEGIN OPENSSH PRIVATE KEY----- -b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABlwAAAAdzc2gtcn -NhAAAAAwEAAQAAAYEA0f/mqkkZ3c9qw8MTz5FoEO3PGecO/dtUFfJ4g1UBu9E7hi/pyVYY -fLfdsd5bqA2pXdU0ROymyVe683I1VzJcihUtwB1eQxP1mUhmoo0ixK0IUUGm4PRieCGv+r -0/gMvaYbVGUPCi5tAUVh02vZB7p2cTIaz872lvCnRhYbhGUHSbhNSSQOjnCtZfjuZZnE0l -PKjWV/wbJ7Pvoc/FZMlWOqL1AjAKuwFH5zs1RMrPDDv5PCZksq4a7DDxziEdq39jvA3sOm -pQXvzBBBLBOzu7rM3/MPJb6dvAGJcYxkptfL4YXTscIMINr0g24cn+Thvt9yqA93rkb9RB -kw6RIEwMlQKqserA+pfsaoW0SkvnlDKzS1DLwXioL4Uc1Jpr/9jTMEfR+W7v7gJPB1JDnV -gen5FBfiMqbsG1amUS+mjgNfC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HQPsG/wgBER8VOP4bLOEB6gzVO2GE9HTJTOh5C+eEfrl52wPfXj -TqjtWAnhssxtgmWjkS0ibi+u1KMVXKHfaiqJ7nH0jMx+eu1RpMvuR8JqkU8qdMMGChAAAA -wHkQMfpCnjNAo6sllEB5FwjEdTBBOt7gu6nLQ2O3uGv0KNEEZ/BWJLQ5fKOfBtDHO+kl+5 -Qoxc0cE7cg64CyBF3+VjzrEzuX5Tuh4NwrsjT4vTTHhCIbIynxEPmKzvIyCMuglqd/nhu9 -6CXhghuTg8NrC7lY+cImiBfhxE32zqNITlpHW7exr95Gz1sML2TRJqxDN93oUFfrEuInx8 -HpXXnvMQxPRhcp9nDMU9/ahUamMabQqVVMwKDi8n3sPPzTiAAAAMEA+/hm3X/yNotAtMAH -y11parKQwPgEF4HYkSE0bEe+2MPJmEk4M4PGmmt/MQC5N5dXdUGxiQeVMR+Sw0kN9qZjM6 -SIz0YHQFMsxVmUMKFpAh4UI0GlsW49jSpVXs34Fg95AfhZOYZmOcGcYosp0huCeRlpLeIH -7Vv2bkfQaic3uNaVPg7+cXg7zdY6tZlzwa/4Fj0udfTjGQJOPSzIihdMLHnV81rZ2cUOZq -MSk6b02aMpVB4TV0l1w4j2mlF2eGD9AAAAwQDVW6p2VXKuPR7SgGGQgHXpAQCFZPGLYd8K -duRaCbxKJXzUnZBn53OX5fuLlFhmRmAMXE6ztHPN1/5JjwILn+O49qel1uUvzU8TaWioq7 -Are3SJR2ZucR4AKUvzUHGP3GWW96xPN8lq+rgb0th1eOSU2aVkaIdeTJhV1iPfaUUf+15S -YcJlSHLGgeqkok+VfuudZ73f3RFFhjoe1oAjlPB4leeMsBD9UBLx2U3xAevnfkecF4Lm83 -4sVswWATSFAFsAAAAsYWJoaW1hbnl1YmFiYmFyQEFiaGltYW55dXMtTWFjQm9vay1Qcm8u -bG9jYWwBAgMEBQYH ------END OPENSSH PRIVATE KEY----- diff --git a/kafkaclient/testdata/ssh/test_key.pub b/kafkaclient/testdata/ssh/test_key.pub deleted file mode 100644 index d7cfb5fb..00000000 --- a/kafkaclient/testdata/ssh/test_key.pub +++ /dev/null @@ -1 +0,0 @@ -ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDR/+aqSRndz2rDwxPPkWgQ7c8Z5w7921QV8niDVQG70TuGL+nJVhh8t92x3luoDald1TRE7KbJV7rzcjVXMlyKFS3AHV5DE/WZSGaijSLErQhRQabg9GJ4Ia/6vT+Ay9phtUZQ8KLm0BRWHTa9kHunZxMhrPzvaW8KdGFhuEZQdJuE1JJA6OcK1l+O5lmcTSU8qNZX/Bsns++hz8VkyVY6ovUCMAq7AUfnOzVEys8MO/k8JmSyrhrsMPHOIR2rf2O8Dew6alBe/MEEEsE7O7uszf8w8lvp28AYlxjGSm18vhhdOxwgwg2vSDbhyf5OG+33KoD3euRv1EGTDpEgTAyVAqqx6sD6l+xqhbRKS+eUMrNLUMvBeKgvhRzUmmv/2NMwR9H5bu/uAk8HUkOdWB6fkUF+IypuwbVqZRL6aOA18LwjTS1H4JQfGmpRYA21xZOKeFKcsnaySP/ZCdyI8eQe6tEQrITAJV5yCf7FUrJGBUMIawn5CcB2fnX6L+Q7ee8= abhimanyubabbar@Abhimanyus-MacBook-Pro.local diff --git a/sftp/sftp_test.go b/sftp/sftp_test.go index 0bb88008..78c0f840 100644 --- a/sftp/sftp_test.go +++ b/sftp/sftp_test.go @@ -18,6 +18,7 @@ import ( "github.com/rudderlabs/rudder-go-kit/sftp/mock_sftp" "github.com/rudderlabs/rudder-go-kit/testhelper/docker/resource/sshserver" + "github.com/rudderlabs/rudder-go-kit/testhelper/keygen" ) type nopReadWriteCloser struct { @@ -30,7 +31,10 @@ func (nwc *nopReadWriteCloser) Close() error { func TestSSHClientConfig(t *testing.T) { // Read private key - privateKey, err := os.ReadFile("testdata/ssh/test_key") + privateKeyPath, _, err := keygen.NewRSAKeyPair(2048, keygen.SaveTo(t.TempDir())) + require.NoError(t, err) + + privateKey, err := os.ReadFile(privateKeyPath) require.NoError(t, err) type testCase struct { @@ -218,8 +222,9 @@ func TestSFTP(t *testing.T) { require.NoError(t, err) // Let's setup the SSH server - publicKeyPath, err := filepath.Abs("testdata/ssh/test_key.pub") + privateKeyPath, publicKeyPath, err := keygen.NewRSAKeyPair(2048, keygen.SaveTo(t.TempDir())) require.NoError(t, err) + sshServer, err := sshserver.Setup(pool, t, sshserver.WithPublicKeyPath(publicKeyPath), sshserver.WithCredentials("linuxserver.io", ""), @@ -229,7 +234,7 @@ func TestSFTP(t *testing.T) { t.Logf("SSH server is listening on %s", sshServerHost) // Read private key - privateKey, err := os.ReadFile("testdata/ssh/test_key") + privateKey, err := os.ReadFile(privateKeyPath) require.NoError(t, err) // Setup ssh client diff --git a/sftp/testdata/ssh/test_key b/sftp/testdata/ssh/test_key deleted file mode 100644 index c095f906..00000000 --- a/sftp/testdata/ssh/test_key +++ /dev/null @@ -1,39 +0,0 @@ ------BEGIN OPENSSH PRIVATE KEY----- -b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABlwAAAAdzc2gtcn -NhAAAAAwEAAQAAAYEA0f/mqkkZ3c9qw8MTz5FoEO3PGecO/dtUFfJ4g1UBu9E7hi/pyVYY -fLfdsd5bqA2pXdU0ROymyVe683I1VzJcihUtwB1eQxP1mUhmoo0ixK0IUUGm4PRieCGv+r -0/gMvaYbVGUPCi5tAUVh02vZB7p2cTIaz872lvCnRhYbhGUHSbhNSSQOjnCtZfjuZZnE0l -PKjWV/wbJ7Pvoc/FZMlWOqL1AjAKuwFH5zs1RMrPDDv5PCZksq4a7DDxziEdq39jvA3sOm -pQXvzBBBLBOzu7rM3/MPJb6dvAGJcYxkptfL4YXTscIMINr0g24cn+Thvt9yqA93rkb9RB -kw6RIEwMlQKqserA+pfsaoW0SkvnlDKzS1DLwXioL4Uc1Jpr/9jTMEfR+W7v7gJPB1JDnV -gen5FBfiMqbsG1amUS+mjgNfC8I00tR+CUHxpqUWANtcWTinhSnLJ2skj/2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JTOh5C+eEfrl52wPfXj -TqjtWAnhssxtgmWjkS0ibi+u1KMVXKHfaiqJ7nH0jMx+eu1RpMvuR8JqkU8qdMMGChAAAA -wHkQMfpCnjNAo6sllEB5FwjEdTBBOt7gu6nLQ2O3uGv0KNEEZ/BWJLQ5fKOfBtDHO+kl+5 -Qoxc0cE7cg64CyBF3+VjzrEzuX5Tuh4NwrsjT4vTTHhCIbIynxEPmKzvIyCMuglqd/nhu9 -6CXhghuTg8NrC7lY+cImiBfhxE32zqNITlpHW7exr95Gz1sML2TRJqxDN93oUFfrEuInx8 -HpXXnvMQxPRhcp9nDMU9/ahUamMabQqVVMwKDi8n3sPPzTiAAAAMEA+/hm3X/yNotAtMAH -y11parKQwPgEF4HYkSE0bEe+2MPJmEk4M4PGmmt/MQC5N5dXdUGxiQeVMR+Sw0kN9qZjM6 -SIz0YHQFMsxVmUMKFpAh4UI0GlsW49jSpVXs34Fg95AfhZOYZmOcGcYosp0huCeRlpLeIH -7Vv2bkfQaic3uNaVPg7+cXg7zdY6tZlzwa/4Fj0udfTjGQJOPSzIihdMLHnV81rZ2cUOZq -MSk6b02aMpVB4TV0l1w4j2mlF2eGD9AAAAwQDVW6p2VXKuPR7SgGGQgHXpAQCFZPGLYd8K -duRaCbxKJXzUnZBn53OX5fuLlFhmRmAMXE6ztHPN1/5JjwILn+O49qel1uUvzU8TaWioq7 -Are3SJR2ZucR4AKUvzUHGP3GWW96xPN8lq+rgb0th1eOSU2aVkaIdeTJhV1iPfaUUf+15S -YcJlSHLGgeqkok+VfuudZ73f3RFFhjoe1oAjlPB4leeMsBD9UBLx2U3xAevnfkecF4Lm83 -4sVswWATSFAFsAAAAsYWJoaW1hbnl1YmFiYmFyQEFiaGltYW55dXMtTWFjQm9vay1Qcm8u -bG9jYWwBAgMEBQYH ------END OPENSSH PRIVATE KEY----- diff --git a/sftp/testdata/ssh/test_key.pub b/sftp/testdata/ssh/test_key.pub deleted file mode 100644 index d7cfb5fb..00000000 --- a/sftp/testdata/ssh/test_key.pub +++ /dev/null @@ -1 +0,0 @@ -ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDR/+aqSRndz2rDwxPPkWgQ7c8Z5w7921QV8niDVQG70TuGL+nJVhh8t92x3luoDald1TRE7KbJV7rzcjVXMlyKFS3AHV5DE/WZSGaijSLErQhRQabg9GJ4Ia/6vT+Ay9phtUZQ8KLm0BRWHTa9kHunZxMhrPzvaW8KdGFhuEZQdJuE1JJA6OcK1l+O5lmcTSU8qNZX/Bsns++hz8VkyVY6ovUCMAq7AUfnOzVEys8MO/k8JmSyrhrsMPHOIR2rf2O8Dew6alBe/MEEEsE7O7uszf8w8lvp28AYlxjGSm18vhhdOxwgwg2vSDbhyf5OG+33KoD3euRv1EGTDpEgTAyVAqqx6sD6l+xqhbRKS+eUMrNLUMvBeKgvhRzUmmv/2NMwR9H5bu/uAk8HUkOdWB6fkUF+IypuwbVqZRL6aOA18LwjTS1H4JQfGmpRYA21xZOKeFKcsnaySP/ZCdyI8eQe6tEQrITAJV5yCf7FUrJGBUMIawn5CcB2fnX6L+Q7ee8= abhimanyubabbar@Abhimanyus-MacBook-Pro.local diff --git a/testhelper/docker/resource/kafka/kafka_test.go b/testhelper/docker/resource/kafka/kafka_test.go index 5fd172da..e5f4a0e0 100644 --- a/testhelper/docker/resource/kafka/kafka_test.go +++ b/testhelper/docker/resource/kafka/kafka_test.go @@ -28,6 +28,7 @@ import ( "golang.org/x/crypto/ssh" "github.com/rudderlabs/rudder-go-kit/testhelper/docker/resource/sshserver" + "github.com/rudderlabs/rudder-go-kit/testhelper/keygen" ) const ( @@ -266,8 +267,9 @@ func TestSSH(t *testing.T) { require.NoError(t, err) // Let's setup the SSH server - publicKeyPath, err := filepath.Abs("./testdata/ssh/test_key.pub") + privateKeyPath, publicKeyPath, err := keygen.NewRSAKeyPair(2048, keygen.SaveTo(t.TempDir())) require.NoError(t, err) + sshServer, err := sshserver.Setup(pool, t, sshserver.WithPublicKeyPath(publicKeyPath), sshserver.WithCredentials("linuxserver.io", ""), @@ -278,7 +280,7 @@ func TestSSH(t *testing.T) { t.Logf("SSH server is listening on %s", sshServerHost) // Prepare SSH configuration - privateKey, err := os.ReadFile("./testdata/ssh/test_key") + privateKey, err := os.ReadFile(privateKeyPath) require.NoError(t, err) signer, err := ssh.ParsePrivateKey(privateKey) diff --git a/testhelper/docker/resource/kafka/testdata/ssh/test_key b/testhelper/docker/resource/kafka/testdata/ssh/test_key deleted file mode 100644 index c095f906..00000000 --- a/testhelper/docker/resource/kafka/testdata/ssh/test_key +++ /dev/null @@ -1,39 +0,0 @@ ------BEGIN OPENSSH PRIVATE KEY----- -b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABlwAAAAdzc2gtcn -NhAAAAAwEAAQAAAYEA0f/mqkkZ3c9qw8MTz5FoEO3PGecO/dtUFfJ4g1UBu9E7hi/pyVYY -fLfdsd5bqA2pXdU0ROymyVe683I1VzJcihUtwB1eQxP1mUhmoo0ixK0IUUGm4PRieCGv+r -0/gMvaYbVGUPCi5tAUVh02vZB7p2cTIaz872lvCnRhYbhGUHSbhNSSQOjnCtZfjuZZnE0l -PKjWV/wbJ7Pvoc/FZMlWOqL1AjAKuwFH5zs1RMrPDDv5PCZksq4a7DDxziEdq39jvA3sOm -pQXvzBBBLBOzu7rM3/MPJb6dvAGJcYxkptfL4YXTscIMINr0g24cn+Thvt9yqA93rkb9RB -kw6RIEwMlQKqserA+pfsaoW0SkvnlDKzS1DLwXioL4Uc1Jpr/9jTMEfR+W7v7gJPB1JDnV -gen5FBfiMqbsG1amUS+mjgNfC8I00tR+CUHxpqUWANtcWTinhSnLJ2skj/2QnciPHkHurR -EKyEwCVecgn+xVKyRgVDCGsJ+QnAdn51+i/kO3nvAAAFqENNbN9DTWzfAAAAB3NzaC1yc2 -EAAAGBANH/5qpJGd3PasPDE8+RaBDtzxnnDv3bVBXyeINVAbvRO4Yv6clWGHy33bHeW6gN -qV3VNETspslXuv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l+5 -Qoxc0cE7cg64CyBF3+VjzrEzuX5Tuh4NwrsjT4vTTHhCIbIynxEPmKzvIyCMuglqd/nhu9 -6CXhghuTg8NrC7lY+cImiBfhxE32zqNITlpHW7exr95Gz1sML2TRJqxDN93oUFfrEuInx8 -HpXXnvMQxPRhcp9nDMU9/ahUamMabQqVVMwKDi8n3sPPzTiAAAAMEA+/hm3X/yNotAtMAH -y11parKQwPgEF4HYkSE0bEe+2MPJmEk4M4PGmmt/MQC5N5dXdUGxiQeVMR+Sw0kN9qZjM6 -SIz0YHQFMsxVmUMKFpAh4UI0GlsW49jSpVXs34Fg95AfhZOYZmOcGcYosp0huCeRlpLeIH -7Vv2bkfQaic3uNaVPg7+cXg7zdY6tZlzwa/4Fj0udfTjGQJOPSzIihdMLHnV81rZ2cUOZq -MSk6b02aMpVB4TV0l1w4j2mlF2eGD9AAAAwQDVW6p2VXKuPR7SgGGQgHXpAQCFZPGLYd8K -duRaCbxKJXzUnZBn53OX5fuLlFhmRmAMXE6ztHPN1/5JjwILn+O49qel1uUvzU8TaWioq7 -Are3SJR2ZucR4AKUvzUHGP3GWW96xPN8lq+rgb0th1eOSU2aVkaIdeTJhV1iPfaUUf+15S -YcJlSHLGgeqkok+VfuudZ73f3RFFhjoe1oAjlPB4leeMsBD9UBLx2U3xAevnfkecF4Lm83 -4sVswWATSFAFsAAAAsYWJoaW1hbnl1YmFiYmFyQEFiaGltYW55dXMtTWFjQm9vay1Qcm8u -bG9jYWwBAgMEBQYH ------END OPENSSH PRIVATE KEY----- diff --git a/testhelper/docker/resource/kafka/testdata/ssh/test_key.pub b/testhelper/docker/resource/kafka/testdata/ssh/test_key.pub deleted file mode 100644 index d7cfb5fb..00000000 --- a/testhelper/docker/resource/kafka/testdata/ssh/test_key.pub +++ /dev/null @@ -1 +0,0 @@ -ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDR/+aqSRndz2rDwxPPkWgQ7c8Z5w7921QV8niDVQG70TuGL+nJVhh8t92x3luoDald1TRE7KbJV7rzcjVXMlyKFS3AHV5DE/WZSGaijSLErQhRQabg9GJ4Ia/6vT+Ay9phtUZQ8KLm0BRWHTa9kHunZxMhrPzvaW8KdGFhuEZQdJuE1JJA6OcK1l+O5lmcTSU8qNZX/Bsns++hz8VkyVY6ovUCMAq7AUfnOzVEys8MO/k8JmSyrhrsMPHOIR2rf2O8Dew6alBe/MEEEsE7O7uszf8w8lvp28AYlxjGSm18vhhdOxwgwg2vSDbhyf5OG+33KoD3euRv1EGTDpEgTAyVAqqx6sD6l+xqhbRKS+eUMrNLUMvBeKgvhRzUmmv/2NMwR9H5bu/uAk8HUkOdWB6fkUF+IypuwbVqZRL6aOA18LwjTS1H4JQfGmpRYA21xZOKeFKcsnaySP/ZCdyI8eQe6tEQrITAJV5yCf7FUrJGBUMIawn5CcB2fnX6L+Q7ee8= abhimanyubabbar@Abhimanyus-MacBook-Pro.local diff --git a/testhelper/docker/resource/postgres/config.go b/testhelper/docker/resource/postgres/config.go index ea054918..56d16d73 100644 --- a/testhelper/docker/resource/postgres/config.go +++ b/testhelper/docker/resource/postgres/config.go @@ -1,5 +1,7 @@ package postgres +import "github.com/ory/dockertest/v3/docker" + type Opt func(*Config) func WithTag(tag string) Opt { @@ -38,6 +40,12 @@ func WithPrintLogsOnError(printLogsOnError bool) Opt { } } +func WithNetwork(network *docker.Network) Opt { + return func(c *Config) { + c.NetworkID = network.ID + } +} + type Config struct { Tag string Options []string @@ -45,4 +53,5 @@ type Config struct { Memory int64 OOMKillDisable bool PrintLogsOnError bool + NetworkID string } diff --git a/testhelper/docker/resource/postgres/postgres.go b/testhelper/docker/resource/postgres/postgres.go index bc16ead7..c47d9d1f 100644 --- a/testhelper/docker/resource/postgres/postgres.go +++ b/testhelper/docker/resource/postgres/postgres.go @@ -51,6 +51,7 @@ func Setup(pool *dockertest.Pool, d resource.Cleaner, opts ...func(*Config)) (*R postgresContainer, err := pool.RunWithOptions(&dockertest.RunOptions{ Repository: "postgres", Tag: c.Tag, + NetworkID: c.NetworkID, Env: []string{ "POSTGRES_PASSWORD=" + postgresDefaultPassword, "POSTGRES_DB=" + postgresDefaultDB, diff --git a/testhelper/docker/resource/sshserver/sshserver_test.go b/testhelper/docker/resource/sshserver/sshserver_test.go index 1cb0c4f1..489d07a9 100644 --- a/testhelper/docker/resource/sshserver/sshserver_test.go +++ b/testhelper/docker/resource/sshserver/sshserver_test.go @@ -1,9 +1,10 @@ package sshserver import ( - "path/filepath" "testing" + "github.com/rudderlabs/rudder-go-kit/testhelper/keygen" + "github.com/melbahja/goph" "github.com/ory/dockertest/v3" dc "github.com/ory/dockertest/v3/docker" @@ -50,8 +51,9 @@ func TestKeys(t *testing.T) { } }) - publicKeyPath, err := filepath.Abs("./testdata/test_key.pub") + privateKeyPath, publicKeyPath, err := keygen.NewRSAKeyPair(2048, keygen.SaveTo(t.TempDir())) require.NoError(t, err) + res, err := Setup(pool, t, WithPublicKeyPath(publicKeyPath), WithCredentials("linuxserver.io", ""), @@ -59,8 +61,6 @@ func TestKeys(t *testing.T) { ) require.NoError(t, err) - privateKeyPath, err := filepath.Abs("./testdata/test_key") - require.NoError(t, err) auth, err := goph.Key(privateKeyPath, "") require.NoError(t, err) diff --git a/testhelper/docker/resource/sshserver/testdata/test_key b/testhelper/docker/resource/sshserver/testdata/test_key deleted file mode 100644 index c095f906..00000000 --- a/testhelper/docker/resource/sshserver/testdata/test_key +++ /dev/null @@ -1,39 +0,0 @@ ------BEGIN OPENSSH PRIVATE KEY----- -b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABlwAAAAdzc2gtcn -NhAAAAAwEAAQAAAYEA0f/mqkkZ3c9qw8MTz5FoEO3PGecO/dtUFfJ4g1UBu9E7hi/pyVYY -fLfdsd5bqA2pXdU0ROymyVe683I1VzJcihUtwB1eQxP1mUhmoo0ixK0IUUGm4PRieCGv+r -0/gMvaYbVGUPCi5tAUVh02vZB7p2cTIaz872lvCnRhYbhGUHSbhN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0th1eOSU2aVkaIdeTJhV1iPfaUUf+15S -YcJlSHLGgeqkok+VfuudZ73f3RFFhjoe1oAjlPB4leeMsBD9UBLx2U3xAevnfkecF4Lm83 -4sVswWATSFAFsAAAAsYWJoaW1hbnl1YmFiYmFyQEFiaGltYW55dXMtTWFjQm9vay1Qcm8u -bG9jYWwBAgMEBQYH ------END OPENSSH PRIVATE KEY----- diff --git a/testhelper/docker/resource/sshserver/testdata/test_key.pub b/testhelper/docker/resource/sshserver/testdata/test_key.pub deleted file mode 100644 index d7cfb5fb..00000000 --- a/testhelper/docker/resource/sshserver/testdata/test_key.pub +++ /dev/null @@ -1 +0,0 @@ -ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDR/+aqSRndz2rDwxPPkWgQ7c8Z5w7921QV8niDVQG70TuGL+nJVhh8t92x3luoDald1TRE7KbJV7rzcjVXMlyKFS3AHV5DE/WZSGaijSLErQhRQabg9GJ4Ia/6vT+Ay9phtUZQ8KLm0BRWHTa9kHunZxMhrPzvaW8KdGFhuEZQdJuE1JJA6OcK1l+O5lmcTSU8qNZX/Bsns++hz8VkyVY6ovUCMAq7AUfnOzVEys8MO/k8JmSyrhrsMPHOIR2rf2O8Dew6alBe/MEEEsE7O7uszf8w8lvp28AYlxjGSm18vhhdOxwgwg2vSDbhyf5OG+33KoD3euRv1EGTDpEgTAyVAqqx6sD6l+xqhbRKS+eUMrNLUMvBeKgvhRzUmmv/2NMwR9H5bu/uAk8HUkOdWB6fkUF+IypuwbVqZRL6aOA18LwjTS1H4JQfGmpRYA21xZOKeFKcsnaySP/ZCdyI8eQe6tEQrITAJV5yCf7FUrJGBUMIawn5CcB2fnX6L+Q7ee8= abhimanyubabbar@Abhimanyus-MacBook-Pro.local diff --git a/testhelper/keygen/keygen.go b/testhelper/keygen/keygen.go new file mode 100644 index 00000000..74d3f228 --- /dev/null +++ b/testhelper/keygen/keygen.go @@ -0,0 +1,102 @@ +package keygen + +import ( + "crypto/rand" + "crypto/rsa" + "crypto/x509" + "encoding/pem" + "fmt" + "os" + "path/filepath" + + "golang.org/x/crypto/ssh" +) + +type Option func(*keygen) + +type keygen struct { + saveTo *string +} + +func SaveTo(saveTo string) Option { + return func(k *keygen) { + k.saveTo = &saveTo + } +} + +// NewRSAKeyPair generates a new private and public key pair +func NewRSAKeyPair(bitSize int, opts ...Option) (string, string, error) { + var k keygen + for _, opt := range opts { + opt(&k) + } + + privateKey, err := generatePrivateKey(bitSize) + if err != nil { + return "", "", fmt.Errorf("failed to generate private key: %w", err) + } + + publicKeyBytes, err := generatePublicKey(&privateKey.PublicKey) + if err != nil { + return "", "", fmt.Errorf("failed to generate public key: %w", err) + } + + privateKeyBytes := encodePrivateKeyToPEM(privateKey) + + if k.saveTo == nil { + return string(privateKeyBytes), string(publicKeyBytes), nil + } + + privateKeyPath := filepath.Join(*k.saveTo, "id_rsa") + if err := writeKeyToFile(privateKeyBytes, privateKeyPath); err != nil { + return "", "", fmt.Errorf("failed to write private key to %q: %w", privateKeyPath, err) + } + + publicKeyPath := filepath.Join(*k.saveTo, "id_rsa.pub") + if err := writeKeyToFile(publicKeyBytes, publicKeyPath); err != nil { + return "", "", fmt.Errorf("failed to write public key to %q: %w", publicKeyPath, err) + } + + return privateKeyPath, publicKeyPath, nil +} + +// generatePrivateKey creates an RSA Private Key of specified byte size +func generatePrivateKey(bitSize int) (*rsa.PrivateKey, error) { + // Private Key generation + privateKey, err := rsa.GenerateKey(rand.Reader, bitSize) + if err != nil { + return nil, err + } + + // Validate Private Key + err = privateKey.Validate() + if err != nil { + return nil, err + } + + return privateKey, nil +} + +// encodePrivateKeyToPEM encodes Private Key from RSA to PEM format +func encodePrivateKeyToPEM(privateKey *rsa.PrivateKey) []byte { + // Private key in PEM format + return pem.EncodeToMemory(&pem.Block{ + Type: "RSA PRIVATE KEY", + Bytes: x509.MarshalPKCS1PrivateKey(privateKey), + }) +} + +// generatePublicKey take a rsa.PublicKey and return bytes suitable for writing to .pub file +// returns in the format "ssh-rsa ..." +func generatePublicKey(privateKey *rsa.PublicKey) ([]byte, error) { + publicRsaKey, err := ssh.NewPublicKey(privateKey) + if err != nil { + return nil, err + } + return ssh.MarshalAuthorizedKey(publicRsaKey), nil +} + +// writePemToFile writes keys to a file +func writeKeyToFile(keyBytes []byte, saveFileTo string) error { + return os.WriteFile(saveFileTo, keyBytes, 0o600) +}