mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-11-19 02:15:02 +01:00
* operation: reassign an upload after a proven-expired volume JWT * seaweed-volume: mark an expired write JWT refused before append Mirror the Go volume server: a multipart POST whose write JWT is signed with the current key, names this fid and fails only on exp gets X-Seaweed-Write-Outcome: expired-jwt-before-append on its 401, so the uploader reassigns instead of failing. Both checks use one guard snapshot, so a key rotation between them cannot drop the marker. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * operation: keep same-FID retry for filer-proxy expiries, snapshot the write signing key, and make the RetryForever budget test fail fast * operation: re-mint the filer credential before a proxy same-FID expiry retry * operation: make a proxy marked-expiry terminal in the outer retry too, not only the inner same-FID loop --------- Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
33 lines
1.3 KiB
Go
33 lines
1.3 KiB
Go
package security
|
|
|
|
import (
|
|
"errors"
|
|
jwt "github.com/golang-jwt/jwt/v5"
|
|
"time"
|
|
)
|
|
|
|
// IsExpiredVolumeJwt reports a signed, FID-bound credential whose only failure
|
|
// is expiration. It never authorizes a request; it classifies an existing denial
|
|
// so an assignment-owning caller can obtain a fresh credential with a new FID.
|
|
func IsExpiredVolumeJwt(key SigningKey, encoded EncodedJwt, expectedFid string) bool {
|
|
return isExpiredVolumeJwtAt(key, encoded, expectedFid, time.Now())
|
|
}
|
|
|
|
func isExpiredVolumeJwtAt(key SigningKey, encoded EncodedJwt, expectedFid string, now time.Time) bool {
|
|
if len(key) == 0 || encoded == "" {
|
|
return false
|
|
}
|
|
claims := &SeaweedFileIdClaims{}
|
|
parsed, err := decodeJwt(key, encoded, claims, jwt.WithTimeFunc(func() time.Time { return now }))
|
|
// ParseWithClaims verifies the HMAC signature before validating any claims.
|
|
if parsed == nil || !errors.Is(err, jwt.ErrTokenExpired) || claims.Fid != expectedFid {
|
|
return false
|
|
}
|
|
otherClaims := *claims
|
|
otherClaims.ExpiresAt = nil
|
|
// Do not mistake expired+not-before/issued-at errors for expiry alone. This
|
|
// extra issued-at restriction applies only to classification, never normal
|
|
// authorization. Keep future volume claim policies aligned here.
|
|
return jwt.NewValidator(jwt.WithTimeFunc(func() time.Time { return now }), jwt.WithIssuedAt()).Validate(&otherClaims) == nil
|
|
}
|