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

feat: Add functionality to use temporary session token for authentication to s3 #123

Merged
merged 4 commits into from
Dec 25, 2024

Conversation

saqijaan
Copy link
Contributor

@saqijaan saqijaan commented Dec 24, 2024

📑 Description

This merge request added functionality to support session tokens for authentication on S3, enabling it to work with temporary credentials, such as those used in an AWS Lambda environment.

Summary by CodeRabbit

  • New Features

    • Enhanced S3 client initialization with an optional token for improved credential management.
  • Bug Fixes

    • Improved error handling for file existence checks, including enhanced logging for better error visibility.

✅ Checks

  • Added test cases for my code

Copy link

coderabbitai bot commented Dec 24, 2024

Walkthrough

The changes modify the S3 filesystem implementation in the s3.go file. The primary modifications include introducing a new token variable during S3 client initialization, which is retrieved from the configuration using a dynamic key. The token is now passed to the NewStaticCredentialsProvider method, enhancing the credential configuration flexibility. Additionally, error handling in the Exists method has been improved by adding a log statement to capture and record any errors encountered during file existence checks.

Changes

File Change Summary
s3.go - Added token variable in NewS3 function retrieved from configuration
- Updated NewStaticCredentialsProvider to include token parameter
- Enhanced error logging in Exists method using log.Println

The changes are relatively straightforward, focusing on configuration flexibility and improved error visibility in the S3 filesystem implementation.


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.

@saqijaan
Copy link
Contributor Author

@hwbrzzl please review this mr and merge if possible.

@hwbrzzl hwbrzzl changed the title Add functionality to use temporary session token for authentication to s3 feat: Add functionality to use temporary session token for authentication to s3 Dec 24, 2024
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 0% with 6 lines in your changes missing coverage. Please review.

Project coverage is 5.32%. Comparing base (8a7fae9) to head (cf4203d).
Report is 72 commits behind head on master.

Files with missing lines Patch % Lines
s3.go 0.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##           master    #123      +/-   ##
=========================================
- Coverage    5.53%   5.32%   -0.21%     
=========================================
  Files           3       4       +1     
  Lines         307     319      +12     
=========================================
  Hits           17      17              
- Misses        289     301      +12     
  Partials        1       1              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -42,13 +43,14 @@ func NewS3(ctx context.Context, config config.Config, disk string) (*S3, error)
region := config.GetString(fmt.Sprintf("filesystems.disks.%s.region", disk))
bucket := config.GetString(fmt.Sprintf("filesystems.disks.%s.bucket", disk))
url := config.GetString(fmt.Sprintf("filesystems.disks.%s.url", disk))
token := config.GetString(fmt.Sprintf("filesystems.disks.%s.token", disk), "")
Copy link
Contributor

Choose a reason for hiding this comment

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

The token is not fixed data, right? In current logic, the token will be fixed when initiating S3, I wonder if it's expected.

Copy link
Contributor Author

@saqijaan saqijaan Dec 24, 2024

Choose a reason for hiding this comment

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

yes It will be inject via config like other variables. I'll send an MR for goravel config as well later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

most of the cases accesskeyId and accessKeySecret will be used. But on lambda those two does not work and lambda provide a temporary access token for the time span of lambda function. So it will be injected via environmet > goravel config > s3 driver.

As lambda instances are short term so it will be destroyed and recreated with new token after few minutes so no worry here.

Let me know if you mean something else.

Copy link
Contributor

Choose a reason for hiding this comment

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

So the token is fixed in the short term; it's safe to inject it via environment directly.

Copy link

@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.

Actionable comments posted: 0

🧹 Nitpick comments (2)
s3.go (2)

46-46: Consider validating or documenting the optional token usage.

You’re correctly retrieving the token from the config with a default "". However, it might be helpful to add a code comment or validation indicating that this is optional. This ensures developers using your code understand when and why the token is needed.


210-214: Fix the spelling of “existance” and consider providing more details in the log message.

There’s a minor spelling mistake in the log message: “existance” should be “existence.” If the error could relate to permissions or missing files, adding context can help with debugging.

Proposed fix:

-   log.Println("error while checking file existance:", err)
+   log.Println("error while checking file existence:", err)
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 313a63e and cf4203d.

📒 Files selected for processing (1)
  • s3.go (3 hunks)
🔇 Additional comments (1)
s3.go (1)

53-53: S3 client now supports session tokens.

Passing the token to credentials.NewStaticCredentialsProvider increases security for environments using temporary credentials. This change looks good!

Copy link
Contributor

@hwbrzzl hwbrzzl left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM

@hwbrzzl hwbrzzl merged commit 26198e2 into goravel:master Dec 25, 2024
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants