Skip to content

fix(clp-package): Temporarily remove support for implicit AWS credentials. - #682

Merged
kirkrodrigues merged 5 commits into
y-scope:mainfrom
haiqi96:guard_s3_credentials
Jan 21, 2025
Merged

fix(clp-package): Temporarily remove support for implicit AWS credentials.#682
kirkrodrigues merged 5 commits into
y-scope:mainfrom
haiqi96:guard_s3_credentials

Conversation

@haiqi96

@haiqi96 haiqi96 commented Jan 20, 2025

Copy link
Copy Markdown
Contributor

Description

Our original plan was to support implicit AWS credentials that are associated with machine, such as IAM. However, we don't have session token support ready in CLP-S executable. Depending on how the aws identity is configured, some identities may return a temporary credentials with a session token so we don't have support for such cases.

As a temporary solution, we simply disable all implicit AWS credentials support until we can properly handle session tokens.

Validation performed

Manually tested for

  1. compressing without s3 credentials specified
  2. removing credential fields from clp-config.
    Verified that script returns error requiring credentials to be specified.

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Enhanced error handling for AWS S3 credentials validation.
    • Consolidated AWS credentials into a structured format for improved management.
  • Bug Fixes

    • Improved robustness of command generation and credential checks.
    • Added explicit validation for AWS credentials in S3 configuration.
  • Refactor

    • Updated method signatures to support more flexible error handling.
    • Stricter type requirements for S3 configuration credentials.

The changes focus on improving input validation and error management for S3-related operations, ensuring more reliable credential handling and command generation.

@coderabbitai

coderabbitai Bot commented Jan 20, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

This pull request enhances error handling and validation for AWS S3 credential management across multiple components. It introduces stricter validation for AWS credentials, ensuring that they are fully specified and validated during S3 operations. The changes encapsulate AWS credentials into a structured format, improving the organization and robustness of credential handling in the codebase.

Changes

File Change Summary
components/clp-package-utils/clp_package_utils/scripts/compress.py Introduced S3Credentials import and modified _generate_clp_io_config to use a single credentials parameter for AWS credentials.
components/clp-py-utils/clp_py_utils/clp_config.py Changed S3Config.credentials from optional to required type, updated get_credentials method to return non-optional values.
components/job-orchestration/job_orchestration/executor/compress/compression_task.py Modified return type of make_clp_s_command_and_env to allow None for the command list, updated AWS credentials access to use credentials object, added error handling for command generation.
components/job-orchestration/job_orchestration/scheduler/job_config.py Replaced aws_access_key_id and aws_secret_access_key with a single credentials attribute of type S3Credentials in S3InputConfig.
components/job-orchestration/job_orchestration/executor/query/extract_stream_task.py Removed error handling for AWS credentials in _make_clp_s_command_and_env_vars, allowing function to proceed without validation.
components/job-orchestration/job_orchestration/executor/query/fs_search_task.py Removed error handling for AWS credentials in _make_core_clp_s_command_and_env_vars, allowing function to proceed without validation.
components/clp-package-utils/clp_package_utils/scripts/start_clp.py Modified start_log_viewer_webui to unconditionally append AWS credentials to Docker command options.
components/clp-py-utils/clp_py_utils/s3_utils.py Updated s3_get_object_metadata to access AWS credentials from a nested credentials attribute.

Possibly Related PRs

Suggested Reviewers

  • haiqi96

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8ab90df and 2b4bb6a.

📒 Files selected for processing (1)
  • components/job-orchestration/job_orchestration/executor/compress/compression_task.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/job-orchestration/job_orchestration/executor/compress/compression_task.py
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: lint-check (ubuntu-latest)
  • GitHub Check: lint-check (macos-latest)
  • GitHub Check: build (macos-latest)

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>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • 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 testing code 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

if InputType.S3 == clp_config.input.type:
aws_access_key_id = clp_config.input.aws_access_key_id
aws_secret_access_key = clp_config.input.aws_secret_access_key
if aws_access_key_id is None or aws_secret_access_key is None:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

technically, we shouldn't run into this case. However, clp worker will return weird error message if we ever run into a None=aws_access_key_id here, since a env=None is invalid can cause error for subprocess.run.

Just to be safe, I decided to add the guard here.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
components/clp-py-utils/clp_py_utils/clp_config.py (1)

357-359: Enhance the TODO comment with specific requirements.

The TODO comment could be more specific about the requirements for supporting empty credentials, particularly regarding session token handling.

Consider updating the comment to:

-    # TODO: When we support empty credentials, this method should be used to return a tuple that's
-    # either (None, None) if empty, or the credentials otherwise.
+    # TODO: When implementing support for implicit AWS credentials:
+    # 1. Update this method to return Tuple[Optional[str], Optional[str]]
+    # 2. Add support for session tokens in S3Credentials
+    # 3. Update credential handling to work with temporary credentials from IAM roles
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c01b29d and 8ab90df.

📒 Files selected for processing (9)
  • components/clp-package-utils/clp_package_utils/scripts/compress.py (2 hunks)
  • components/clp-package-utils/clp_package_utils/scripts/native/compress.py (2 hunks)
  • components/clp-package-utils/clp_package_utils/scripts/start_clp.py (1 hunks)
  • components/clp-py-utils/clp_py_utils/clp_config.py (2 hunks)
  • components/clp-py-utils/clp_py_utils/s3_utils.py (1 hunks)
  • components/job-orchestration/job_orchestration/executor/compress/compression_task.py (3 hunks)
  • components/job-orchestration/job_orchestration/executor/query/extract_stream_task.py (0 hunks)
  • components/job-orchestration/job_orchestration/executor/query/fs_search_task.py (0 hunks)
  • components/job-orchestration/job_orchestration/scheduler/job_config.py (2 hunks)
💤 Files with no reviewable changes (2)
  • components/job-orchestration/job_orchestration/executor/query/fs_search_task.py
  • components/job-orchestration/job_orchestration/executor/query/extract_stream_task.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • components/clp-package-utils/clp_package_utils/scripts/compress.py
  • components/job-orchestration/job_orchestration/executor/compress/compression_task.py
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: lint-check (ubuntu-latest)
  • GitHub Check: build (macos-latest)
  • GitHub Check: lint-check (macos-latest)
🔇 Additional comments (2)
components/job-orchestration/job_orchestration/scheduler/job_config.py (1)

6-6: Verify the impact of making credentials mandatory.

The change from optional AWS credential fields to a mandatory credentials attribute effectively prevents the use of implicit credentials, which aligns with the PR objective. However, this is a breaking change that might affect existing configurations.

Consider adding a deprecation warning for any code still trying to use implicit credentials, to provide a better migration path.

Also applies to: 38-38

components/clp-py-utils/clp_py_utils/clp_config.py (1)

335-335: LGTM! Consider documenting the breaking change.

Making credentials non-optional effectively disables implicit AWS credentials as intended. This is a breaking change that requires all S3 configurations to provide explicit credentials.

Let's verify the impact on existing configurations:

✅ Verification successful

The breaking change is safe and well-contained.

The codebase only uses S3 operations when explicitly configured through storage type settings. Making credentials mandatory will fail early during configuration validation, preventing any runtime issues.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for S3Config usage to identify affected configurations
rg -A 5 "S3Config" 

Length of output: 5100

Comment on lines +151 to +154
credentials=S3Credentials(
access_key_id=parsed_args.aws_access_key_id,
secret_access_key=parsed_args.aws_secret_access_key,
),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance error handling for AWS credentials.

While the code now enforces explicit credentials, it should validate that both credentials are provided before creating the S3Credentials object.

Add validation before creating S3Credentials:

+            if not parsed_args.aws_access_key_id or not parsed_args.aws_secret_access_key:
+                raise ValueError("Both AWS access key ID and secret access key must be provided")
             credentials=S3Credentials(
                 access_key_id=parsed_args.aws_access_key_id,
                 secret_access_key=parsed_args.aws_secret_access_key,
             ),
📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
credentials=S3Credentials(
access_key_id=parsed_args.aws_access_key_id,
secret_access_key=parsed_args.aws_secret_access_key,
),
if not parsed_args.aws_access_key_id or not parsed_args.aws_secret_access_key:
raise ValueError("Both AWS access key ID and secret access key must be provided")
credentials=S3Credentials(
access_key_id=parsed_args.aws_access_key_id,
secret_access_key=parsed_args.aws_secret_access_key,
),

Comment on lines +946 to +953
container_cmd_extra_opts.extend(
(
"-e",
f"AWS_ACCESS_KEY_ID={access_key_id}",
"-e",
f"AWS_SECRET_ACCESS_KEY={secret_access_key}",
)
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add validation for AWS credentials.

The unconditional addition of AWS credentials to container environment variables could lead to issues if the credentials are None. This should be validated first.

Add validation before extending container options:

         access_key_id, secret_access_key = s3_config.get_credentials()
+        if not access_key_id or not secret_access_key:
+            raise ValueError("Both AWS access key ID and secret access key must be provided for S3 storage")
         container_cmd_extra_opts.extend(
             (
                 "-e",
                 f"AWS_ACCESS_KEY_ID={access_key_id}",
                 "-e",
                 f"AWS_SECRET_ACCESS_KEY={secret_access_key}",
             )
         )
📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
container_cmd_extra_opts.extend(
(
"-e",
f"AWS_ACCESS_KEY_ID={access_key_id}",
"-e",
f"AWS_SECRET_ACCESS_KEY={secret_access_key}",
)
)
if not access_key_id or not secret_access_key:
raise ValueError("Both AWS access key ID and secret access key must be provided for S3 storage")
container_cmd_extra_opts.extend(
(
"-e",
f"AWS_ACCESS_KEY_ID={access_key_id}",
"-e",
f"AWS_SECRET_ACCESS_KEY={secret_access_key}",
)
)

Comment on lines +80 to +81
aws_access_key_id=s3_input_config.credentials.access_key_id,
aws_secret_access_key=s3_input_config.credentials.secret_access_key,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling for missing credentials.

While the code now uses the structured credentials format, it should handle the case where credentials might be None.

Add validation before accessing credentials:

+    if not s3_input_config.credentials:
+        raise ValueError("AWS credentials are required")
     s3_client = boto3.client(
         "s3",
         region_name=s3_input_config.region_code,
         aws_access_key_id=s3_input_config.credentials.access_key_id,
         aws_secret_access_key=s3_input_config.credentials.secret_access_key,
     )

Committable suggestion skipped: line range outside the PR's diff.

db_config_file_path: pathlib.Path,
use_single_file_archive: bool,
) -> Tuple[List[str], Optional[Dict[str, str]]]:
) -> Tuple[Optional[List[str]], Optional[Dict[str, str]]]:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

With your change, we won't return optional.

logger.error(f"Unsupported storage engine {clp_storage_engine}")
return False, {"error_message": f"Unsupported storage engine {clp_storage_engine}"}

if compression_cmd is None:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

same comment as the one above. can't be None

@haiqi96 haiqi96 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Looks all good to me but I can't approve since it's my own PR.

@kirkrodrigues kirkrodrigues left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For the PR title, how about:

fix(clp-package): Temporarily remove support for implicit AWS credentials.

@kirkrodrigues kirkrodrigues changed the title fix(clp-package): Temporarily disable support for implicit AWS credentials. fix(clp-package): Temporarily remove support for implicit AWS credentials. Jan 21, 2025
@kirkrodrigues
kirkrodrigues merged commit a8551a0 into y-scope:main Jan 21, 2025
@haiqi96
haiqi96 deleted the guard_s3_credentials branch June 16, 2025 20:05
junhaoliao pushed a commit to junhaoliao/clp that referenced this pull request May 17, 2026
…ials. (y-scope#682)

Co-authored-by: Kirk Rodrigues <2454684+kirkrodrigues@users.noreply.github.com>
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.

2 participants