-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Fixed weed mount reads with jwt.signing.read.key #7061
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
Conversation
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.
Summary of Changes
Hello @maxkost, 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!
I've addressed an issue where weed mount operations failed with "Input/output error" and "401 Unauthorized" when the jwt.signing.read.key was configured. This fix integrates JWT token authorization into the RetriedFetchChunkData function, ensuring that file reads from weed mount proceed correctly under these security settings.
Highlights
- Enhanced RetriedFetchChunkData Signature: I've updated the RetriedFetchChunkData function signature across filechunk_manifest.go, reader_cache.go, and stream.go to accept a fileId parameter. This fileId is crucial for generating authenticated requests.
- JWT Authorization for Chunk Data Fetching: In http_global_client_util.go, I've integrated JWT token authorization into RetriedFetchChunkData. This involves importing the security package, retrieving JWT signing configuration, generating a JWT for the volume server using the provided fileId, and then using this JWT to make authenticated requests via ReadUrlAsStreamAuthenticated.
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 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 or fill out our survey 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.
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
This pull request correctly adds JWT authentication for chunk reads from weed mount
when jwt.signing.read.key
is configured. The changes involve passing the fileId
down to RetriedFetchChunkData
where the JWT is generated and used for authenticated requests. The fix appears to solve the described problem. I've included one suggestion to improve performance by caching the JWT configuration, as it's currently being read on every chunk fetch, which could be a bottleneck.
v := util.GetViper() | ||
signingKey := v.GetString("jwt.signing.read.key") | ||
var jwt security.EncodedJwt | ||
|
||
if signingKey != "" { | ||
expiresAfterSec := v.GetInt("jwt.signing.expires_after_seconds") | ||
jwt = security.GenJwtForVolumeServer(security.SigningKey(signingKey), expiresAfterSec, fileId) | ||
} |
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.
This implementation fetches JWT configuration on every call to RetriedFetchChunkData
. Since this function is on a hot path for chunk reads, and util.GetViper()
uses a global lock, this could become a performance bottleneck due to lock contention.
Consider reading the JWT configuration once and caching it at the package level using sync.Once
to avoid repeated lookups and locking. This will improve performance for concurrent chunk reads.
You can add the following at the package level:
var (
jwtSigningReadKey security.SigningKey
jwtExpiresAfterSec int
loadJwtConfigOnce sync.Once
)
func loadJwtConfig() {
v := util.GetViper()
jwtSigningReadKey = security.SigningKey(v.GetString("jwt.signing.read.key"))
jwtExpiresAfterSec = v.GetInt("jwt.signing.expires_after_seconds")
}
Then, you can replace the current configuration loading logic with this.
v := util.GetViper() | |
signingKey := v.GetString("jwt.signing.read.key") | |
var jwt security.EncodedJwt | |
if signingKey != "" { | |
expiresAfterSec := v.GetInt("jwt.signing.expires_after_seconds") | |
jwt = security.GenJwtForVolumeServer(security.SigningKey(signingKey), expiresAfterSec, fileId) | |
} | |
loadJwtConfigOnce.Do(loadJwtConfig) | |
var jwt security.EncodedJwt | |
if len(jwtSigningReadKey) > 0 { | |
jwt = security.GenJwtForVolumeServer( | |
jwtSigningReadKey, | |
jwtExpiresAfterSec, | |
fileId, | |
) | |
} |
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.
this is a good comment! I did experience performance problem with viper.
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.
Addressed it.
What problem are we solving?
If you set the
jwt.signing.read.key
parameter in security.toml, you will encounter an “Input/output error” when trying to read a file from weed mount.weed mount
logs:Mb fix for #6740.
How are we solving the problem?
Added JWT token authorization usage to
RetriedFetchChunkData
.How is the PR tested?
After making the changes, files from
weed mount
are read without errors. No side effects on other functions were observed.Checks