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

SNOW-1435508: Adding support for auth through SSH Agent #1947

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

sfc-gh-thardie
Copy link

@sfc-gh-thardie sfc-gh-thardie commented May 17, 2024

Please answer these questions before submitting your pull requests. Thanks!

  1. What GitHub issue is this PR addressing? Make sure that there is an accompanying issue to your PR.

    Fixes SNOW-1435508

  2. Fill out the following pre-review checklist:

    • I am adding a new automated test(s) to verify correctness of my new code
    • I am adding new logging messages
    • I am adding a new telemetry message
    • I am modifying authorization mechanisms
    • I am adding new credentials
    • I am modifying OCSP code
    • I am adding a new dependency
  3. Please describe how your code solves the related issue.

This adds support to be able to authenticate to a Snowflake deployment using a key stored in an SSH Agent. This means you can use local SSH Keys, a Yubikey with a non-exportable private key, or 1Password as your SSH Agent. On the Snowflake side, you need top convert the SSH Public key to a PKCS#1 public key and load that into the user as a RSA_PUBLIC_KEY.

To convert an SSH public key to a PKCS#1 public key, use the following command (assuming the ssh public key is in a file called pubkey): ssh-keygen -f pubkey -e -m pem | openssl rsa -RSAPublicKey_in -pubout

This also adds a dependency on paramiko to talk to the local ssh agent

This adds support to be able to authenticate to a Snowflake deployment using a key stored in an SSH Agent. This means you can use local SSH Keys, a Yubikey with a non-exportable private key, or 1Password as your SSH Agent. On the Snowflake side, you need top convert the SSH Public key to a PKCS#1 public key and load that into the user as a RSA_PUBLIC_KEY.

To convert an SSH public key to a PKCS#1 public key, use the following command (assuming the ssh public key is in a file called `pubkey`):
`ssh-keygen -f pubkey -e -m pem | openssl rsa -RSAPublicKey_in -pubout`
Copy link


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

@sfc-gh-thardie
Copy link
Author

I can't figure out the linting problems. Running the git command mentioned works fine from the command line.

When I try to run it locally, I get

[INFO] Initializing environment for https://github.com/pre-commit/pre-commit-hooks.
An unexpected error has occurred: CalledProcessError: command: ('/usr/bin/git', 'fetch', 'origin', '--tags')
return code: 128
stdout: (none)
stderr:
    [email protected]: Permission denied (publickey).
    fatal: Could not read from remote repository.

    Please make sure you have the correct access rights
    and the repository exists.
Check the log at /Users/thardie/.cache/pre-commit/pre-commit.log
fix_lint: exit 3 (1.44 seconds) /Users/thardie/git/snowflake-connector-python> pre-commit run --all-files pid=44128
  fix_lint: FAIL code 3 (1.45=setup[0.00]+cmd[1.44] seconds)
  evaluation failed :( (1.63 seconds)```

@sfc-gh-thardie sfc-gh-thardie marked this pull request as ready for review May 17, 2024 23:48
src/snowflake/connector/auth/sshagent.py Outdated Show resolved Hide resolved
DESCRIPTION.md Outdated Show resolved Hide resolved
@sfc-gh-yixie
Copy link
Collaborator

Please add test code.
This is worth python connector documentation change. We should create a JIRA for the document team.

@sfc-gh-thardie
Copy link
Author

sfc-gh-thardie commented May 21, 2024

As I mentioned above, I cannot get the test framework to go. I don't see how to fix the problem I mentioned, so I'm unable to get any tests to work.

Could I get some help in fixing this, so I can get the test framework working?

@@ -46,6 +46,7 @@ install_requires =
asn1crypto>0.24.0,<2.0.0
cffi>=1.9,<2.0.0
cryptography>=3.1.0,<43.0.0
paramiko
Copy link
Collaborator

Choose a reason for hiding this comment

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

@sfc-gh-jfan We added a new dependency to python connector. Does it need to be reviewed by your team, or a tool has checked it?

@sfc-gh-thardie
Copy link
Author

NOTE: DO NOT MERGE until this has gone through a security review

@sfc-gh-jdu
Copy link
Collaborator

I can't figure out the linting problems. Running the git command mentioned works fine from the command line.

When I try to run it locally, I get

[INFO] Initializing environment for https://github.com/pre-commit/pre-commit-hooks.
An unexpected error has occurred: CalledProcessError: command: ('/usr/bin/git', 'fetch', 'origin', '--tags')
return code: 128
stdout: (none)
stderr:
    [email protected]: Permission denied (publickey).
    fatal: Could not read from remote repository.

    Please make sure you have the correct access rights
    and the repository exists.
Check the log at /Users/thardie/.cache/pre-commit/pre-commit.log
fix_lint: exit 3 (1.44 seconds) /Users/thardie/git/snowflake-connector-python> pre-commit run --all-files pid=44128
  fix_lint: FAIL code 3 (1.45=setup[0.00]+cmd[1.44] seconds)
  evaluation failed :( (1.63 seconds)```

You may try tox -e fix_lint

@sfc-gh-thardie
Copy link
Author

tox -e fix_lint

That's the command that give me the above error...

@sfc-gh-thardie sfc-gh-thardie marked this pull request as draft May 22, 2024 21:15
@sfc-gh-thardie
Copy link
Author

I can't figure out the linting problems. Running the git command mentioned works fine from the command line.
When I try to run it locally, I get

[INFO] Initializing environment for https://github.com/pre-commit/pre-commit-hooks.
An unexpected error has occurred: CalledProcessError: command: ('/usr/bin/git', 'fetch', 'origin', '--tags')
return code: 128
stdout: (none)
stderr:
    [email protected]: Permission denied (publickey).
    fatal: Could not read from remote repository.

    Please make sure you have the correct access rights
    and the repository exists.
Check the log at /Users/thardie/.cache/pre-commit/pre-commit.log
fix_lint: exit 3 (1.44 seconds) /Users/thardie/git/snowflake-connector-python> pre-commit run --all-files pid=44128
  fix_lint: FAIL code 3 (1.45=setup[0.00]+cmd[1.44] seconds)
  evaluation failed :( (1.63 seconds)```

You may try tox -e fix_lint

I ran this command and was able to get it working: pre-commit run --all-files

There is something tox is doing to mess up the environment and it doesn't honor any of the environment settings for SSH Agent or .ssh/config settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants