Skip to content

Commit 3f22530

Browse files
Make jwt duration configurable. (#4870)
1 parent 9a4a960 commit 3f22530

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

server/util/claims/claims.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,14 @@ const (
2424
// Maximum number of entries in JWT -> Claims cache.
2525
claimsCacheSize = 10_00
2626

27-
// BuildBuddy JWT duration maximum.
28-
defaultBuildBuddyJWTDuration = 6 * time.Hour
29-
3027
// The key the Claims are stored under in the context.
3128
// If unset, the JWT can be used to reconstitute the claims.
3229
contextClaimsKey = "auth.claims"
3330
)
3431

3532
var (
36-
jwtKey = flag.String("auth.jwt_key", "set_the_jwt_in_config", "The key to use when signing JWT tokens.", flag.Secret)
33+
jwtKey = flag.String("auth.jwt_key", "set_the_jwt_in_config", "The key to use when signing JWT tokens.", flag.Secret)
34+
jwtDuration = flag.Duration("auth.jwt_duration", 6*time.Hour, "Maximum lifetime of the generated JWT.")
3735
)
3836

3937
type Claims struct {
@@ -204,7 +202,7 @@ func userClaims(u *tables.User, effectiveGroup string) *Claims {
204202
}
205203

206204
func assembleJWT(ctx context.Context, c *Claims) (string, error) {
207-
expirationTime := time.Now().Add(defaultBuildBuddyJWTDuration)
205+
expirationTime := time.Now().Add(*jwtDuration)
208206
expiresAt := expirationTime.Unix()
209207
// Round expiration times down to the nearest minute to improve stability
210208
// of JWTs for caching purposes.

0 commit comments

Comments
 (0)