Skip to content

Commit 1f50821

Browse files
committed
Tweak JWT, expect account vs system in field
Signed-off-by: Neil Twigg <[email protected]>
1 parent 2f752ac commit 1f50821

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module github.com/nats-io/nats-server/v2
22

33
go 1.21.0
44

5-
replace github.com/nats-io/jwt/v2 => github.com/nats-io/jwt/v2 v2.5.9-0.20240730132529-79732145f9be
5+
replace github.com/nats-io/jwt/v2 => github.com/nats-io/jwt/v2 v2.5.9-0.20240801130136-270cc45c44ee
66

77
require (
88
github.com/google/go-tpm v0.9.0

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2
66
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
77
github.com/minio/highwayhash v1.0.3 h1:kbnuUMoHYyVl7szWjSxJnxw11k2U709jqFPPmIUyD6Q=
88
github.com/minio/highwayhash v1.0.3/go.mod h1:GGYsuwP/fPD6Y9hMiXuapVvlIUEhFhMTh0rxU3ik1LQ=
9-
github.com/nats-io/jwt/v2 v2.5.9-0.20240730132529-79732145f9be h1:0EpVNpiLRtjqTgsz8TFtVeNzOwpjC/Xu7yXDiqJSxyI=
10-
github.com/nats-io/jwt/v2 v2.5.9-0.20240730132529-79732145f9be/go.mod h1:ZdWS1nZa6WMZfFwwgpEaqBV8EPGVgOTDHN/wTbz0Y5A=
9+
github.com/nats-io/jwt/v2 v2.5.9-0.20240801130136-270cc45c44ee h1:kiTo11kMbk4UMNjdgXAFFSq8+p1RLI3XPcAukFaiw+g=
10+
github.com/nats-io/jwt/v2 v2.5.9-0.20240801130136-270cc45c44ee/go.mod h1:ZdWS1nZa6WMZfFwwgpEaqBV8EPGVgOTDHN/wTbz0Y5A=
1111
github.com/nats-io/nats.go v1.36.0 h1:suEUPuWzTSse/XhESwqLxXGuj8vGRuPRoG7MoRN/qyU=
1212
github.com/nats-io/nats.go v1.36.0/go.mod h1:Ubdu4Nh9exXdSz0RVWRFBbRfrbSxOYd26oF0wkWclB8=
1313
github.com/nats-io/nkeys v0.4.7 h1:RwNJbbIdYCoClSDNY7QVKZlyb/wfT6ugvFCiKy6vDvI=

server/accounts.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -3683,7 +3683,16 @@ func (s *Server) updateAccountClaimsWithRefresh(a *Account, ac *jwt.AccountClaim
36833683
if a.js != nil {
36843684
// Check whether the account NRG status changed. If it has then we need to notify the
36853685
// Raft groups running on the system so that they can move their subs if needed.
3686-
if wasAccountNRG := a.js.accountNRG.Swap(ac.AccountNRG); wasAccountNRG != ac.AccountNRG {
3686+
wantAccountNRG := a.js.accountNRG.Load()
3687+
switch strings.ToLower(ac.NRGAccount) {
3688+
case "account":
3689+
wantAccountNRG = true
3690+
case "system":
3691+
wantAccountNRG = false
3692+
default:
3693+
s.Errorf("Account claim for %q has invalid value %q for account NRG status", a.Name, ac.NRGAccount)
3694+
}
3695+
if wasAccountNRG := a.js.accountNRG.Swap(wantAccountNRG); wasAccountNRG != wantAccountNRG {
36873696
s.updateNRGAccountStatus()
36883697
}
36893698
}

server/jetstream_jwt_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -1571,8 +1571,8 @@ func TestJetStreamJWTClusterAccountNRG(t *testing.T) {
15711571

15721572
// We'll try flipping the state a few times and then do some sanity
15731573
// checks to check that it took effect.
1574-
for _, state := range []bool{true, false, true} {
1575-
accClaim.AccountNRG = state
1574+
for _, state := range []string{"account", "system", "account"} {
1575+
accClaim.NRGAccount = state
15761576
accJwt = encodeClaim(t, accClaim, aExpPub)
15771577

15781578
for _, s := range c.servers {
@@ -1586,7 +1586,7 @@ func TestJetStreamJWTClusterAccountNRG(t *testing.T) {
15861586
// Check that everything looks like it should.
15871587
require_True(t, acc != nil)
15881588
require_True(t, acc.js != nil)
1589-
require_Equal(t, acc.js.accountNRG.Load(), state)
1589+
require_Equal(t, acc.js.accountNRG.Load(), state == "account")
15901590

15911591
// Now get a list of all of the Raft nodes that should
15921592
// have been updated by now.
@@ -1608,7 +1608,7 @@ func TestJetStreamJWTClusterAccountNRG(t *testing.T) {
16081608
inAcc := rg.inAcc
16091609
rg.Unlock()
16101610

1611-
require_Equal(t, inAcc, state)
1611+
require_Equal(t, inAcc, state == "account")
16121612
}
16131613
}
16141614
}

0 commit comments

Comments
 (0)