-
Notifications
You must be signed in to change notification settings - Fork 6.5k
feat(cloudkms): Add single tenant hsm scripts #13339
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
base: main
Are you sure you want to change the base?
feat(cloudkms): Add single tenant hsm scripts #13339
Conversation
…gtm/python-docs-samples into brandonluong-sthi Updated the README.rst file on github. The changes need to be merged.
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.
Hello @brandonluong-lgtm, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
Summary of Changes
This pull request adds scripts and documentation for setting up and approving Single Tenant HSM instances in Google Cloud KMS. It includes a setup.py
script for building a custom gcloud CLI and generating RSA keys on YubiKeys, and an approve_proposal.py
script for fetching, signing, and submitting HSM instance proposal challenges. Additionally, it introduces supporting modules for interacting with gcloud and YubiKeys, along with comprehensive testing and a README for usage instructions.
Highlights
- Custom gcloud Build: The pull request introduces a
setup.py
script that builds a custom gcloud CLI tailored for Single Tenant HSM, streamlining the setup process. - HSM Proposal Approval: The pull request implements
approve_proposal.py
, a script designed to automate the approval of Single Tenant HSM instance proposals by fetching challenges, signing them using a YubiKey, and submitting the signed challenges back to gcloud. - YubiKey Integration: The pull request integrates with YubiKeys for secure signing of HSM proposal challenges, enhancing the security posture of the approval process.
- Testing and Mocking: The pull request includes comprehensive testing using
pytest
andpytest-mock
, with mocking of subprocess calls and YubiKey interactions to ensure the reliability of the scripts.
Changelog
Click here to see the changelog
- kms/singletenanthsm/README.rst
- Added a README file providing instructions on how to use the setup and approval scripts for Single Tenant HSM instances.
- kms/singletenanthsm/approve_proposal.py
- Created a script to fetch challenges from a Single Tenant HSM instance proposal, sign them using a YubiKey, and send the signed challenges back to gcloud for approval.
- Implements functions to parse challenges from gcloud output, sign them using ykman-utils, and submit the signed challenges.
- Includes argument parsing for specifying the proposal resource.
- kms/singletenanthsm/approve_proposal_test.py
- Added tests for
approve_proposal.py
, mocking gcloud commands and YubiKey interactions to ensure proper functionality. - Includes tests for fetching challenges, signing them, and verifying the signatures.
- Added tests for
- kms/singletenanthsm/challenges/challenge1.txt
- Added a challenge file for testing purposes.
- kms/singletenanthsm/challenges/challenge2.txt
- Added a challenge file for testing purposes.
- kms/singletenanthsm/challenges/challenge3.txt
- Added a challenge file for testing purposes.
- kms/singletenanthsm/challenges/public_key1.pem
- Added a public key file for testing purposes.
- kms/singletenanthsm/challenges/public_key2.pem
- Added a public key file for testing purposes.
- kms/singletenanthsm/challenges/public_key3.pem
- Added a public key file for testing purposes.
- kms/singletenanthsm/gcloud_commands.py
- Created a module to encapsulate gcloud commands for building a custom gcloud CLI and interacting with Single Tenant HSM proposals.
- Implements functions to build the custom gcloud CLI, fetch challenges, and send signed challenges.
- kms/singletenanthsm/gcloud_commands_test.py
- Added tests for
gcloud_commands.py
, mocking subprocess calls to ensure proper command execution and error handling. - Includes tests for building the custom gcloud CLI, fetching challenges, and sending signed challenges.
- Added tests for
- kms/singletenanthsm/requirements.txt
- Added dependencies required for the scripts, including
yubikey-manager
,cryptography
, and testing libraries.
- Added dependencies required for the scripts, including
- kms/singletenanthsm/setup.py
- Created a script to build a custom gcloud CLI and generate RSA keys on YubiKeys.
- Implements argument parsing for specifying the operation type (build custom gcloud, generate RSA keys, or both).
- kms/singletenanthsm/signed_challenges/public_key_1.pem
- Added a public key file for testing purposes.
- kms/singletenanthsm/signed_challenges/public_key_2.pem
- Added a public key file for testing purposes.
- kms/singletenanthsm/signed_challenges/public_key_3.pem
- Added a public key file for testing purposes.
- kms/singletenanthsm/signed_challenges/signed_challenge1.bin
- Added a signed challenge file for testing purposes.
- kms/singletenanthsm/ykman_fake.py
- Created a fake ykman module to mock yubikey interactions for testing purposes.
- kms/singletenanthsm/ykman_utils.py
- Created a module to provide utility functions for interacting with YubiKeys, including generating private keys, signing challenges, and verifying signatures.
- Implements functions to populate challenges from files, sign them using a YubiKey, and verify the signatures.
- kms/singletenanthsm/ykman_utils_test.py
- Added tests for
ykman_utils.py
, mocking YubiKey interactions to ensure proper functionality. - Includes tests for signing challenges, verifying signatures, and handling errors.
- Added tests for
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
A key's born of challenge,
Signed by Yubi's embrace,
HSM's gate swings.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
The pull request introduces scripts for managing Single Tenant HSM instances, including building a custom gcloud environment and approving proposals. The code appears well-structured and includes tests. However, there are several areas where improvements can be made to enhance clarity, maintainability, and security.
Summary of Findings
- Error Handling: The error handling in
parse_challenges_into_files
andsigned_challenges_to_files
is basic. Consider logging the full exception with a traceback for better debugging. - Security: Hardcoded Credentials: The
ykman_utils.py
script contains hardcoded default management key and PIN. These should be removed and instead be passed in as arguments, or retrieved from environment variables. - Code Duplication: There is duplicated code for directory creation in
parse_challenges_into_files
andsigned_challenges_to_files
. Consider refactoring this into a reusable function. - Test Coverage: The test coverage for
approve_proposal.py
is limited. More comprehensive tests are needed, especially around failure scenarios.
Merge Readiness
The pull request is not yet ready for merging. The hardcoded credentials in ykman_utils.py
pose a significant security risk and must be addressed. Additionally, the error handling and code duplication issues should be resolved to improve maintainability. I am unable to approve this pull request, and recommend that it not be merged until the critical and high severity issues are addressed, and that others review and approve this code before merging.
The kokoro presubmits are failing as libpcsclite-dev is not installed. This is needed to communicate with smartcards. Is there a way to ensure that the machines running the test have it installed? In the read me the users would install it using the command |
Description
Fixes #
Note: Before submitting a pull request, please open an issue for discussion if you are not associated with Google.
Checklist
nox -s py-3.9
(see Test Environment Setup)nox -s lint
(see Test Environment Setup)