Fix volume.fsck 401 Unauthorized by adding JWT to HTTP delete requests (#8306)
* Fix volume.fsck 401 Unauthorized by adding JWT to HTTP delete requests * Additionally, for performance, consider fetching the jwt.filer_signing.key once before any loops that call httpDelete, rather than inside httpDelete itself, to avoid repeated configuration lookups.
This commit is contained in:
@@ -25,6 +25,7 @@ import (
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/volume_server_pb"
|
||||
"github.com/seaweedfs/seaweedfs/weed/security"
|
||||
"github.com/seaweedfs/seaweedfs/weed/storage"
|
||||
"github.com/seaweedfs/seaweedfs/weed/storage/needle"
|
||||
"github.com/seaweedfs/seaweedfs/weed/storage/needle_map"
|
||||
@@ -39,7 +40,8 @@ func init() {
|
||||
}
|
||||
|
||||
const (
|
||||
readbufferSize = 16
|
||||
readbufferSize = 16
|
||||
jwtFilerTokenExpirationSeconds = 300
|
||||
)
|
||||
|
||||
type commandVolumeFsck struct {
|
||||
@@ -53,6 +55,7 @@ type commandVolumeFsck struct {
|
||||
forcePurging *bool
|
||||
findMissingChunksInFiler *bool
|
||||
verifyNeedle *bool
|
||||
filerSigningKey string
|
||||
}
|
||||
|
||||
func (c *commandVolumeFsck) Name() string {
|
||||
@@ -139,6 +142,8 @@ func (c *commandVolumeFsck) Do(args []string, commandEnv *CommandEnv, writer io.
|
||||
}
|
||||
defer os.RemoveAll(c.tempFolder)
|
||||
|
||||
c.filerSigningKey = util.GetViper().GetString("jwt.filer_signing.key")
|
||||
|
||||
// collect all volume id locations
|
||||
dataNodeVolumeIdToVInfo, err := c.collectVolumeIds()
|
||||
if err != nil {
|
||||
@@ -556,6 +561,12 @@ func (c *commandVolumeFsck) httpDelete(path util.FullPath) {
|
||||
Host: c.env.option.FilerAddress.ToHttpAddress(),
|
||||
Path: string(path),
|
||||
}
|
||||
|
||||
if c.filerSigningKey != "" {
|
||||
encodedJwt := security.GenJwtForFilerServer(security.SigningKey(c.filerSigningKey), jwtFilerTokenExpirationSeconds)
|
||||
req.Header.Set("Authorization", "BEARER "+string(encodedJwt))
|
||||
}
|
||||
|
||||
if *c.verbose {
|
||||
fmt.Fprintf(c.writer, "full HTTP delete request to be sent: %v\n", req)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user