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

Fix zenml deploy secret stores #2454

Merged
merged 3 commits into from
Feb 28, 2024

Conversation

safoinme
Copy link
Contributor

@safoinme safoinme commented Feb 20, 2024

Describe changes

I implemented/fixed _ to achieve _.

Pre-requisites

Please ensure you have done the following:

  • I have read the CONTRIBUTING.md document.
  • If my change requires a change to docs, I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • I have based my new branch on develop and the open PR is targeting develop. If your branch wasn't based on develop read Contribution guide on rebasing branch to develop.
  • If my changes require changes to the dashboard, these changes are communicated/requested.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Other (add details above)

Summary by CodeRabbit

  • Refactor
    • Improved handling of AWS and GCP secrets in the configuration. Now supports implicit authentication methods and issues deprecation warnings for old authentication attributes.

Copy link
Contributor

coderabbitai bot commented Feb 20, 2024

Important

Auto Review Skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository.

To trigger a single review, invoke the @coderabbitai review command.

Walkthrough

The recent changes involve refactoring the logic for handling authentication in both AWS and GCP secrets stores. The updates focus on improving how region_name, aws_access_key_id, and aws_secret_access_key are used for AWS, and how project_id and GOOGLE_APPLICATION_CREDENTIALS are handled for GCP. The modifications introduce implicit authentication methods and issue deprecation warnings for old attributes, streamlining the configuration process based on the presence of specific credentials.

Changes

File Path Change Summary
.../aws_secrets_store.py Refactored authentication logic to support implicit methods and issue deprecation warnings for old attributes. Adjusts handling of region_name, aws_access_key_id, and aws_secret_access_key.
.../gcp_secrets_store.py Revised authentication logic to prefer implicit methods. Issues deprecation warnings and adjusts handling of project_id and GOOGLE_APPLICATION_CREDENTIALS.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@github-actions github-actions bot added the internal To filter out internal PRs and issues label Feb 20, 2024
@safoinme safoinme added run-slow-ci and removed internal To filter out internal PRs and issues labels Feb 20, 2024
@safoinme
Copy link
Contributor Author

@coderabbitai review

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 2

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 5ab2c47 and dd65e81.
Files selected for processing (2)
  • src/zenml/zen_stores/secrets_stores/aws_secrets_store.py (1 hunks)
  • src/zenml/zen_stores/secrets_stores/gcp_secrets_store.py (1 hunks)

Comment on lines 94 to 121
if values.get("project_id"):
if not os.environ.get("GOOGLE_APPLICATION_CREDENTIALS"):
logger.warning(
"The `GOOGLE_APPLICATION_CREDENTIALS` environment variable "
"is not set. using an implicit GCP authentication to access "
"the GCP Secrets Manager API."
)
values["auth_method"] = GCPAuthenticationMethods.IMPLICIT
values["auth_config"] = dict(
project_id=values.get("project_id"),
)
else:
logger.warning(
"The `project_id` GCP secrets store attribute and the "
"`GOOGLE_APPLICATION_CREDENTIALS` environment variable are "
"deprecated and will be removed in a future version of ZenML. "
"Please use the `auth_method` and `auth_config` attributes "
"instead."
)
values[
"auth_method"
] = GCPAuthenticationMethods.SERVICE_ACCOUNT
values["auth_config"] = dict(
project_id=values.get("project_id"),
)
# Load the service account credentials from the file
with open(os.environ["GOOGLE_APPLICATION_CREDENTIALS"]) as f:
values["auth_config"]["service_account_json"] = f.read()
Copy link
Contributor

Choose a reason for hiding this comment

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

The implementation of the conditional logic for handling project_id and GOOGLE_APPLICATION_CREDENTIALS in the populate_config method introduces a clear and understandable approach to defaulting to implicit GCP authentication when necessary. However, there are a few areas that could be refined:

  1. Deprecation Warning Clarity: The deprecation warning message could be more specific about what is deprecated and provide a clear action for users to migrate to the new method. It's good practice to include a version number when mentioning deprecation to give users a timeline.

  2. Error Handling for File Reading: When reading the GOOGLE_APPLICATION_CREDENTIALS file, there's no explicit error handling for potential issues like file not found or permission errors. Wrapping this in a try-except block could improve robustness.

  3. Security Consideration: Loading and storing the entire service account JSON file in auth_config could potentially expose sensitive information. Ensure that this information is handled securely throughout its lifecycle and consider if there are ways to minimize the exposure of sensitive data.

  4. Performance and Efficiency: The current implementation is straightforward and should not introduce significant performance concerns. However, always consider the implications of file I/O operations and environmental variable access in terms of performance, especially in high-throughput environments.

- "The `project_id` GCP secrets store attribute and the "
- "`GOOGLE_APPLICATION_CREDENTIALS` environment variable are "
- "deprecated and will be removed in a future version of ZenML. "
+ "Using `project_id` directly with `GOOGLE_APPLICATION_CREDENTIALS` is deprecated and will be removed in ZenML version X.Y.Z. "
+ "Migrate to using `auth_method` and `auth_config` for future compatibility."

Consider adding error handling for reading the GOOGLE_APPLICATION_CREDENTIALS file to gracefully handle potential issues.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if values.get("project_id"):
if not os.environ.get("GOOGLE_APPLICATION_CREDENTIALS"):
logger.warning(
"The `GOOGLE_APPLICATION_CREDENTIALS` environment variable "
"is not set. using an implicit GCP authentication to access "
"the GCP Secrets Manager API."
)
values["auth_method"] = GCPAuthenticationMethods.IMPLICIT
values["auth_config"] = dict(
project_id=values.get("project_id"),
)
else:
logger.warning(
"The `project_id` GCP secrets store attribute and the "
"`GOOGLE_APPLICATION_CREDENTIALS` environment variable are "
"deprecated and will be removed in a future version of ZenML. "
"Please use the `auth_method` and `auth_config` attributes "
"instead."
)
values[
"auth_method"
] = GCPAuthenticationMethods.SERVICE_ACCOUNT
values["auth_config"] = dict(
project_id=values.get("project_id"),
)
# Load the service account credentials from the file
with open(os.environ["GOOGLE_APPLICATION_CREDENTIALS"]) as f:
values["auth_config"]["service_account_json"] = f.read()
if values.get("project_id"):
if not os.environ.get("GOOGLE_APPLICATION_CREDENTIALS"):
logger.warning(
"The `GOOGLE_APPLICATION_CREDENTIALS` environment variable "
"is not set. using an implicit GCP authentication to access "
"the GCP Secrets Manager API."
)
values["auth_method"] = GCPAuthenticationMethods.IMPLICIT
values["auth_config"] = dict(
project_id=values.get("project_id"),
)
else:
logger.warning(
"Using `project_id` directly with `GOOGLE_APPLICATION_CREDENTIALS` is deprecated and will be removed in ZenML version X.Y.Z. "
"Migrate to using `auth_method` and `auth_config` for future compatibility."
)
values[
"auth_method"
] = GCPAuthenticationMethods.SERVICE_ACCOUNT
values["auth_config"] = dict(
project_id=values.get("project_id"),
)
# Load the service account credentials from the file
with open(os.environ["GOOGLE_APPLICATION_CREDENTIALS"]) as f:
values["auth_config"]["service_account_json"] = f.read()

Comment on lines 89 to 113
if values.get("region_name"):
if not values.get("aws_access_key_id") or not values.get(
"aws_secret_access_key"
):
logger.warning(
"The `aws_access_key_id` and `aws_secret_access_key` is not "
"set. Using an implicit authentication method for AWS Secrets "
)
values["auth_method"] = AWSAuthenticationMethods.IMPLICIT
values["auth_config"] = dict(
region=values.get("region_name"),
)
else:
logger.warning(
"The `aws_access_key_id`, `aws_secret_access_key` and "
"`region_name` AWS secrets store attributes are deprecated and "
"will be removed in a future version of ZenML. Please use the "
"`auth_method` and `auth_config` attributes instead."
)
values["auth_method"] = AWSAuthenticationMethods.SECRET_KEY
values["auth_config"] = dict(
aws_access_key_id=values.get("aws_access_key_id"),
aws_secret_access_key=values.get("aws_secret_access_key"),
region=values.get("region_name"),
)
Copy link
Contributor

Choose a reason for hiding this comment

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

The implementation of the conditional logic for handling AWS secrets store attributes in the populate_config method introduces a clear approach to defaulting to implicit AWS authentication when necessary. Similar to the GCP secrets store, there are areas that could be refined:

  1. Deprecation Warning Clarity: As with the GCP implementation, the deprecation warning could benefit from being more specific about the deprecated features and providing a clear migration path for users, including a version number for the deprecation timeline.

  2. Security Consideration: The handling of AWS credentials (aws_access_key_id and aws_secret_access_key) should always be done with security in mind. Ensure that these credentials are not logged or exposed inappropriately within the application.

  3. Best Practices for Configuration Handling: The method of dynamically adjusting the auth_config based on the presence of certain keys is practical. However, ensure that this dynamic configuration does not lead to confusion or misconfiguration by clearly documenting how these settings are intended to be used.

- "The `aws_access_key_id`, `aws_secret_access_key` and "
- "`region_name` AWS secrets store attributes are deprecated and "
- "will be removed in a future version of ZenML. "
+ "Using `aws_access_key_id`, `aws_secret_access_key`, and `region_name` directly is deprecated and will be removed in ZenML version X.Y.Z. "
+ "Migrate to using `auth_method` and `auth_config` for future compatibility."

Ensure that AWS credentials are handled securely throughout their lifecycle, avoiding logging or exposing them inappropriately.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if values.get("region_name"):
if not values.get("aws_access_key_id") or not values.get(
"aws_secret_access_key"
):
logger.warning(
"The `aws_access_key_id` and `aws_secret_access_key` is not "
"set. Using an implicit authentication method for AWS Secrets "
)
values["auth_method"] = AWSAuthenticationMethods.IMPLICIT
values["auth_config"] = dict(
region=values.get("region_name"),
)
else:
logger.warning(
"The `aws_access_key_id`, `aws_secret_access_key` and "
"`region_name` AWS secrets store attributes are deprecated and "
"will be removed in a future version of ZenML. Please use the "
"`auth_method` and `auth_config` attributes instead."
)
values["auth_method"] = AWSAuthenticationMethods.SECRET_KEY
values["auth_config"] = dict(
aws_access_key_id=values.get("aws_access_key_id"),
aws_secret_access_key=values.get("aws_secret_access_key"),
region=values.get("region_name"),
)
if values.get("region_name"):
if not values.get("aws_access_key_id") or not values.get(
"aws_secret_access_key"
):
logger.warning(
"The `aws_access_key_id` and `aws_secret_access_key` is not "
"set. Using an implicit authentication method for AWS Secrets "
)
values["auth_method"] = AWSAuthenticationMethods.IMPLICIT
values["auth_config"] = dict(
region=values.get("region_name"),
)
else:
logger.warning(
"Using `aws_access_key_id`, `aws_secret_access_key`, and `region_name` directly is deprecated and will be removed in ZenML version X.Y.Z. "
"Migrate to using `auth_method` and `auth_config` for future compatibility."
)
values["auth_method"] = AWSAuthenticationMethods.SECRET_KEY
values["auth_config"] = dict(
aws_access_key_id=values.get("aws_access_key_id"),
aws_secret_access_key=values.get("aws_secret_access_key"),
region=values.get("region_name"),
)

Copy link
Contributor

@stefannica stefannica left a comment

Choose a reason for hiding this comment

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

Looks good, thanks for fixing this.

src/zenml/zen_stores/secrets_stores/aws_secrets_store.py Outdated Show resolved Hide resolved
src/zenml/zen_stores/secrets_stores/gcp_secrets_store.py Outdated Show resolved Hide resolved
@stefannica stefannica added the bug Something isn't working label Feb 28, 2024
@stefannica stefannica merged commit 3d7b839 into develop Feb 28, 2024
55 checks passed
@stefannica stefannica deleted the fix/OSSK-432-zenml-deploy-secret-stores branch February 28, 2024 17:12
adtygan pushed a commit to adtygan/zenml that referenced this pull request Mar 21, 2024
* Refactor AWS and GCP secrets store configuration

* Apply suggestions from code review

Co-authored-by: Stefan Nica <[email protected]>

---------

Co-authored-by: Stefan Nica <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working run-slow-ci
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants