Skip to content

Commit

Permalink
SNOW-837400: set S3 proxy default values to prevent reading from envi…
Browse files Browse the repository at this point in the history
…ronment variables (#1475)

set S3 proxy default values to prevent reading from environment variables
  • Loading branch information
sfc-gh-ext-simba-lb authored Jul 18, 2023
1 parent 9d625df commit 9b14674
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ private SnowflakeS3Client createS3Client(
clientConfig.setMaxErrorRetry(S3_TRANSFER_MAX_RETRIES);
clientConfig.setDisableSocketProxy(HttpUtil.isSocksProxyDisabled());

// If proxy is set via connection properties or JVM settings these will be overridden later.
// This is to prevent the aws client builder from reading proxy environment variables.
clientConfig.setProxyHost("");
clientConfig.setProxyPort(0);
clientConfig.setProxyUsername("");
clientConfig.setProxyPassword("");

logger.debug(
"s3 client configuration: maxConnection={}, connectionTimeout={}, "
+ "socketTimeout={}, maxErrorRetry={}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@

import com.amazonaws.ClientConfiguration;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import net.snowflake.client.ConditionalIgnoreRule;
import net.snowflake.client.RunningOnGithubAction;
import net.snowflake.client.core.SFSession;
import net.snowflake.client.core.SFStatement;
import net.snowflake.client.jdbc.*;
import net.snowflake.common.core.RemoteStoreFileEncryptionMaterial;
import org.junit.Ignore;
import org.junit.Test;

public class SnowflakeS3ClientLatestIT extends BaseJDBCTest {
Expand Down Expand Up @@ -47,4 +50,42 @@ public void testS3Client256Encryption() throws SQLException {
assertEquals(256, client.getEncryptionKeySize());
}
}

/**
* This is a manual test to confirm that the s3 client builder doesn't read from
* https_proxy/http_proxy environment variable.
*
* <p>Prerequisite: 1. Set HTTPS_PROXY/HTTP_PROXY to a proxy that won't connect i.e.
* HTTPS_PROXY=https://myproxy:8080
*
* <p>2. Connect to S3 host.
*
* @throws SQLException
*/
@Test
@Ignore
public void testS3ConnectionWithProxyEnvVariablesSet() throws SQLException {
Connection connection = null;
String testStageName = "s3TestStage";
try {
connection = getConnection();
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("select 1");
assertTrue(resultSet.next());
statement.execute("create or replace stage " + testStageName);
resultSet =
connection
.createStatement()
.executeQuery(
"PUT file://" + getFullPathFileInResource(TEST_DATA_FILE) + " @" + testStageName);
while (resultSet.next()) {
assertEquals("UPLOADED", resultSet.getString("status"));
}
} finally {
if (connection != null) {
connection.createStatement().execute("DROP STAGE if exists " + testStageName);
connection.close();
}
}
}
}

0 comments on commit 9b14674

Please sign in to comment.