Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
brandonluong-lgtm wants to merge22 commits intoGoogleCloudPlatform:main
base:main
Choose a base branch
Loading
frombrandonluong-lgtm:brandonluong-sthi

Conversation

brandonluong-lgtm
Copy link

@brandonluong-lgtmbrandonluong-lgtm commentedMay 5, 2025
edited
Loading

Description

Fixes #

Note: Before submitting a pull request, please open an issue for discussion if you are not associated with Google.

Checklist

@brandonluong-lgtmbrandonluong-lgtm requested review froma team ascode ownersMay 5, 2025 18:56
@product-auto-labelproduct-auto-labelbot added samplesIssues that are directly related to samples. api: cloudkmsIssues related to the Cloud Key Management Service API. labelsMay 5, 2025
Copy link
Contributor

@gemini-code-assistgemini-code-assistbot left a 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 asetup.py script for building a custom gcloud CLI and generating RSA keys on YubiKeys, and anapprove_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 asetup.py script that builds a custom gcloud CLI tailored for Single Tenant HSM, streamlining the setup process.
  • HSM Proposal Approval: The pull request implementsapprove_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 usingpytest 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 forapprove_proposal.py, mocking gcloud commands and YubiKey interactions to ensure proper functionality.
    • Includes tests for fetching challenges, signing them, and verifying the signatures.
  • 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 forgcloud_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.
  • kms/singletenanthsm/requirements.txt
    • Added dependencies required for the scripts, includingyubikey-manager,cryptography, and testing libraries.
  • 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 forykman_utils.py, mocking YubiKey interactions to ensure proper functionality.
    • Includes tests for signing challenges, verifying signatures, and handling errors.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on ourdocumentation 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.

FeatureCommandDescription
Code Review/gemini reviewPerforms a code review for the current pull request in its current state.
Pull Request Summary/gemini summaryProvides a summary of the current pull request in its current state.
Comment@gemini-code-assistResponds in comments when explicitly tagged, both in issue comments and review comments.
Help/gemini helpDisplays 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 foundhere.

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 theGemini Code Assist IDE Extension.


A key's born of challenge,
Signed by Yubi's embrace,
HSM's gate swings.

Footnotes

  1. Review thePrivacy Notices,Generative AI Prohibited Use Policy,Terms of Service, and learn how to configure Gemini Code Assist in GitHubhere. Gemini can make mistakes, so double check it anduse code with caution.

Copy link
Contributor

@gemini-code-assistgemini-code-assistbot left a 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 inparse_challenges_into_files andsigned_challenges_to_files is basic. Consider logging the full exception with a traceback for better debugging.
  • Security: Hardcoded Credentials: Theykman_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 inparse_challenges_into_files andsigned_challenges_to_files. Consider refactoring this into a reusable function.
  • Test Coverage: The test coverage forapprove_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 inykman_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.

@brandonluong-lgtm
Copy link
Author

brandonluong-lgtm commentedMay 5, 2025
edited
Loading

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 commandsudo apt install libpcsclite-dev

@iennaeiennae changed the titleBrandonluong Add single tenant hsm scriptsfeat(cloudkms): Add single tenant hsm scriptsMay 6, 2025
@iennaeiennae assigneddavidcavazos and unassignedSita04May 6, 2025
@brandonluong-lgtmbrandonluong-lgtm requested review froma team ascode ownersMay 6, 2025 15:47
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@gemini-code-assistgemini-code-assist[bot]gemini-code-assist[bot] requested changes

At least 1 approving review is required to merge this pull request.

Assignees

@davidcavazosdavidcavazos

Labels
api: cloudkmsIssues related to the Cloud Key Management Service API.samplesIssues that are directly related to samples.
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@brandonluong-lgtm@davidcavazos@Sita04

[8]ページ先頭

©2009-2025 Movatter.jp