Skip to content
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

Add key authentication option #11180

Merged
merged 13 commits into from
Jan 25, 2022
Merged

Add key authentication option #11180

merged 13 commits into from
Jan 25, 2022

Conversation

coignetp
Copy link
Contributor

@coignetp coignetp commented Jan 20, 2022

What does this PR do?

Add private_key_path and private_key_password options so users can connect to snowflake using key pair authentication (see https://docs.snowflake.com/en/user-guide/python-connector-example.html#using-key-pair-authentication-key-pair-rotation)

Motivation

Feature request

Additional Notes

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • PR title must be written as a CHANGELOG entry (see why)
  • Files changes must correspond to the primary purpose of the PR as described in the title (small unrelated changes should have their own PR)
  • PR must have changelog/ and integration/ labels attached

@coignetp coignetp changed the title Add kay authentication option Add key authentication option Jan 20, 2022
@coignetp coignetp mentioned this pull request Jan 21, 2022
4 tasks
@@ -0,0 +1,28 @@
-----BEGIN PRIVATE KEY-----
MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCXeqIH2MXr6E7p
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used example key in voltdb

-----BEGIN PRIVATE KEY-----
MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCXeqIH2MXr6E7p
utpe+ZC/31oMMgXi7EPqjeNdbEMkM5c1hCLSyy762mlafkvxqEaL+OIEamZXDtOq
/cenVogdu5gvP/mMkijxWnMg7CNOtg6ulME2UqOPiMRQRJm9iXFoqx1xLSVSUh08
0ydbh2k8+yav/eRqaAJyREOE0IvafyeG1ocHTL/D6eHos3epB9T4OLXS6UjOvLoJ
9eu4GLj7R6GuMB1X15RlmYP+XLWWO2pKjlfBdY8KxQ48Q5GQHpKV10ytuH36VO0q
UvGRy5svz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fh6eHWRqsmBp+2GH/x5ta
ecVipLfnR6gspmzDkbpZ12G55hDgCnDQcFykBW0CgYBeYRRfvZuJVDbA7M3DygfI
DCNPpgcjaECt5Uz/3N0udBNsoXY9vRakRlhKANLYesMUd76mUjVWu6Kc+EJtyEcC
q2plTc4gowD/hhxT1Fw95p6yxz8m+eHFc8BWAaHtoGMMgK1/wm1UXYe/hQDu39g9
ojckZpT64MHda9CvnF814g==
-----END PRIVATE KEY-----

@coignetp coignetp marked this pull request as ready for review January 21, 2022 14:56
@coignetp coignetp requested review from a team as code owners January 21, 2022 14:56
sarina-dd
sarina-dd previously approved these changes Jan 21, 2022
@@ -8,4 +8,10 @@ def initialize_instance(values, **kwargs):
if 'username' not in values and 'user' in values:
values['username'] = values['user']

if 'private_key_password' in values and 'private_key_path' not in values:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can these values be used along username and password?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These values shouldn't be used alongside password
I'll open a new PR after this one is merged to refactor the whole config validation ; since I'm adding other authentication methods at the same time

@hithwen
Copy link
Contributor

hithwen commented Jan 24, 2022

Is it feasible to add an integration test that uses this authentication mechanism?

@coignetp
Copy link
Contributor Author

Is it feasible to add an integration test that uses this authentication mechanism?

Since there is no way to spin up a snowflake env with dd_environment, we can't really do that ; I improved the test and documented how to manually try the private key authentication

snowflake/datadog_checks/snowflake/data/conf.yaml.example Outdated Show resolved Hide resolved
snowflake/datadog_checks/snowflake/data/conf.yaml.example Outdated Show resolved Hide resolved
snowflake/tests/test_unit.py Show resolved Hide resolved
snowflake/tests/test_unit.py Outdated Show resolved Hide resolved
snowflake/assets/configuration/spec.yaml Outdated Show resolved Hide resolved
@@ -82,6 +84,25 @@ def renew_token(self):
with open(self._config.token_path, 'rb', encoding="UTF-8") as f:
self._config.token = f.read()

def read_key(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The token function is named renew_token and this is named read_key, could we harmonize these names? Additionally, why do we read the token before the connection, and read the key file while making it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to not store the key in the integration ; I'll do a bit of refactor in a next PR to do the same with the token alongside updating the validators

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good!

@github-actions
Copy link

The validations job has failed; please review the Files changed tab for possible suggestions to resolve.

@coignetp coignetp merged commit 73e8e38 into master Jan 25, 2022
@coignetp coignetp deleted the paul/sf-key-auth branch January 25, 2022 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants