Skip to content

Conversation

maxkost
Copy link
Contributor

@maxkost maxkost commented Jul 31, 2025

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:

E0731 21:32:40.395505 reader_at.go:163 fetching chunk &{FileId:1,ceea99843c5c OffsetInChunk:0 ViewSize:13 ViewOffset:0 ChunkSize:13 CipherKey:[] IsGzipped:true ModifiedTsNs:1753984005346050238}: http://192.168.2.41:8080/1,ceea99843c5c?readDeleted=true: 401 Unauthorized
E0731 21:32:40.395534 filehandle_read.go:66 file handle read /shared/test.txt: http://192.168.2.41:8080/1,ceea99843c5c?readDeleted=true: 401 Unauthorized
W0731 21:32:40.395548 weedfs_file_read.go:51 file handle read /shared/test.txt 0: http://192.168.2.41:8080/1,ceea99843c5c?readDeleted=true: 401 Unauthorized

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

  • I have added unit tests if possible.
  • I will add related wiki document changes and link to this PR after merging.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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

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

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot 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

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.

Comment on lines 459 to 466
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)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

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.

Suggested change
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,
)
}

Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed it.

@chrislusf chrislusf merged commit 9fadd9d into seaweedfs:master Jul 31, 2025
22 checks passed
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