-
Notifications
You must be signed in to change notification settings - Fork 2
DMD-189 Support private key #211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,14 @@ Keboola high level storage backend driver for Snowflake. | |
| ### Snowflake | ||
|
|
||
| Prepare credentials for Snowflake access | ||
| Create RSA key pair for Snowflake user, you can use the following command to generate it: | ||
|
|
||
| ```bash | ||
| openssl genrsa 2048 | openssl pkcs8 -topk8 -inform PEM -out rsa_key.p8 -nocrypt | ||
| openssl rsa -in rsa_key.p8 -pubout -out rsa_key.pub | ||
| ``` | ||
|
|
||
| Then you can use the public key in the Snowflake user creation script below. | ||
|
|
||
| ```snowflake | ||
| CREATE ROLE "KEBOOLA_CI_PHP_STORAGE_DRIVER_SNOWFLAKE"; | ||
|
|
@@ -19,8 +27,10 @@ GRANT ALL PRIVILEGES ON DATABASE "KEBOOLA_CI_PHP_STORAGE_DRIVER_SNOWFLAKE" TO RO | |
| GRANT USAGE ON WAREHOUSE "DEV" TO ROLE "KEBOOLA_CI_PHP_STORAGE_DRIVER_SNOWFLAKE"; | ||
|
|
||
| CREATE USER "KEBOOLA_CI_PHP_STORAGE_DRIVER_SNOWFLAKE" | ||
| PASSWORD = 'ewC@B3.6UyWVLxe*MZMdN7xYEnX6ZV_P' | ||
| DEFAULT_ROLE = "KEBOOLA_CI_PHP_STORAGE_DRIVER_SNOWFLAKE"; | ||
| PASSWORD = '' | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nechavam tady password a neresim TYPE, protoze to se odstrani az s https://github.com/keboola/storage-backend/pull/212/files |
||
| DEFAULT_ROLE = "KEBOOLA_CI_PHP_STORAGE_DRIVER_SNOWFLAKE" | ||
| RSA_PUBLIC_KEY = '<your_public_key>' | ||
| ; | ||
|
|
||
| GRANT ROLE "KEBOOLA_CI_PHP_STORAGE_DRIVER_SNOWFLAKE" TO USER "KEBOOLA_CI_PHP_STORAGE_DRIVER_SNOWFLAKE"; | ||
| ``` | ||
|
|
@@ -32,6 +42,7 @@ SNOWFLAKE_HOST: keboolaconnectiondev.us-east-1.snowflakecomputing.com | |
| SNOWFLAKE_PORT: 443 | ||
| SNOWFLAKE_USER: KEBOOLA_CI_PHP_STORAGE_DRIVER_SNOWFLAKE | ||
| SNOWFLAKE_PASSWORD: ${{ secrets.SNOWFLAKE_PASSWORD }} | ||
| SNOWFLAKE_PRIVATE_KEY: ${{ secrets.SNOWFLAKE_PRIVATE_KEY }} # note: it has to be full private key in PEM format, including the header and footer | ||
| SNOWFLAKE_DATABASE: KEBOOLA_CI_PHP_STORAGE_DRIVER_SNOWFLAKE | ||
| SNOWFLAKE_WAREHOUSE: DEV | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,10 +18,10 @@ abstract class BaseCase extends TestCase | |
|
|
||
| protected function getSnowflakeConnection(): Connection | ||
| { | ||
| $this->connection = SnowflakeConnectionFactory::getConnection( | ||
| $this->connection = SnowflakeConnectionFactory::getConnectionWithCert( | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. defaultne se k tomu uz chovam jako ke keypairu. BC pro heslo je tady jen docasna, opet odstranena pak v #212 |
||
| (string) getenv('SNOWFLAKE_HOST'), | ||
| (string) getenv('SNOWFLAKE_USER'), | ||
| (string) getenv('SNOWFLAKE_PASSWORD'), | ||
| (string) getenv('SNOWFLAKE_PRIVATE_KEY'), | ||
| [ | ||
| 'port' => (string) getenv('SNOWFLAKE_PORT'), | ||
| 'warehouse' => (string) getenv('SNOWFLAKE_WAREHOUSE'), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Keboola\StorageDriver\Snowflake\Tests\Functional; | ||
|
|
||
| use Google\Protobuf\Any; | ||
| use Keboola\StorageDriver\Credentials\GenericBackendCredentials; | ||
| use Keboola\StorageDriver\Credentials\GenericBackendCredentials\SnowflakeCredentialsMeta; | ||
| use Keboola\StorageDriver\Snowflake\ConnectionFactory; | ||
| use PHPUnit\Framework\TestCase; | ||
|
|
||
| class ConnectionFactoryTest extends TestCase | ||
| { | ||
| public function testCreateFromCredentialsWithPassword(): void | ||
| { | ||
| // Create credentials with a password | ||
| $credentials = new GenericBackendCredentials(); | ||
| $credentials->setHost((string) getenv('SNOWFLAKE_HOST')); | ||
| $credentials->setPrincipal((string) getenv('SNOWFLAKE_USER')); | ||
| $credentials->setSecret((string) getenv('SNOWFLAKE_PASSWORD')); | ||
| $credentials->setPort((int) getenv('SNOWFLAKE_PORT')); | ||
|
|
||
| $meta = new Any(); | ||
| $meta->pack( | ||
| (new SnowflakeCredentialsMeta()) | ||
| ->setWarehouse((string) getenv('SNOWFLAKE_WAREHOUSE')) | ||
| ->setDatabase((string) getenv('SNOWFLAKE_DATABASE')), | ||
| ); | ||
| $credentials->setMeta($meta); | ||
|
|
||
| // Create connection | ||
| $connection = ConnectionFactory::createFromCredentials($credentials); | ||
|
|
||
| // Test connection works | ||
| $result = $connection->executeQuery('SELECT 1 as TEST'); | ||
| $this->assertEquals(1, $result->fetchOne()); | ||
| } | ||
|
|
||
| public function testCreateFromCredentialsWithPrivateKey(): void | ||
| { | ||
| // Create credentials with a key | ||
| $credentials = new GenericBackendCredentials(); | ||
| $credentials->setHost((string) getenv('SNOWFLAKE_HOST')); | ||
| $credentials->setPrincipal((string) getenv('SNOWFLAKE_USER')); | ||
| $credentials->setSecret((string) getenv('SNOWFLAKE_PRIVATE_KEY')); | ||
| $credentials->setPort((int) getenv('SNOWFLAKE_PORT')); | ||
|
|
||
| $meta = new Any(); | ||
| $meta->pack( | ||
| (new SnowflakeCredentialsMeta()) | ||
| ->setWarehouse((string) getenv('SNOWFLAKE_WAREHOUSE')) | ||
| ->setDatabase((string) getenv('SNOWFLAKE_DATABASE')), | ||
| ); | ||
| $credentials->setMeta($meta); | ||
|
|
||
| // Create connection | ||
| $connection = ConnectionFactory::createFromCredentials($credentials); | ||
|
|
||
| // Test connection works | ||
| $result = $connection->executeQuery('SELECT 1 as TEST'); | ||
| $this->assertEquals(1, $result->fetchOne()); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Keboola\StorageDriver\Snowflake\Tests\Functional; | ||
|
|
||
| use Doctrine\DBAL\Connection; | ||
| use Keboola\TableBackendUtils\Connection\Snowflake\SnowflakeConnectionFactory; | ||
|
|
||
| class ConnectionTestWithPassword extends BaseCase | ||
| { | ||
| /** | ||
| * @doesNotPerformAssertions | ||
| */ | ||
| public function testQuery(): void | ||
| { | ||
| $connection = $this->getSnowflakeConnection(); | ||
| $connection->executeQuery('SELECT 1'); | ||
| } | ||
|
|
||
| protected function getSnowflakeConnection(): Connection | ||
| { | ||
| $this->connection = SnowflakeConnectionFactory::getConnection( | ||
| (string) getenv('SNOWFLAKE_HOST'), | ||
| (string) getenv('SNOWFLAKE_USER'), | ||
| (string) getenv('SNOWFLAKE_PASSWORD'), | ||
| [ | ||
| 'port' => (string) getenv('SNOWFLAKE_PORT'), | ||
| 'warehouse' => (string) getenv('SNOWFLAKE_WAREHOUSE'), | ||
| 'database' => (string) getenv('SNOWFLAKE_DATABASE'), | ||
| ], | ||
| ); | ||
|
|
||
| return $this->connection; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
protoze to tady chybelo z initu repa