Skip to content

Commit 3e72c76

Browse files
authored
VAULT-8337 OSS changes (#19580)
1 parent e6427b2 commit 3e72c76

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

vault/request_handling.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -2206,8 +2206,9 @@ func (c *Core) PopulateTokenEntry(ctx context.Context, req *logical.Request) err
22062206
token := req.ClientToken
22072207
var err error
22082208
req.InboundSSCToken = token
2209+
decodedToken := token
22092210
if IsSSCToken(token) {
2210-
token, err = c.CheckSSCToken(ctx, token, c.isLoginRequest(ctx, req), c.perfStandby)
2211+
decodedToken, err = c.CheckSSCToken(ctx, token, c.isLoginRequest(ctx, req), c.perfStandby)
22112212
// If we receive an error from CheckSSCToken, we can assume the token is bad somehow, and the client
22122213
// should receive a 403 bad token error like they do for all other invalid tokens, unless the error
22132214
// specifies that we should forward the request or retry the request.
@@ -2218,12 +2219,18 @@ func (c *Core) PopulateTokenEntry(ctx context.Context, req *logical.Request) err
22182219
return logical.ErrPermissionDenied
22192220
}
22202221
}
2221-
req.ClientToken = token
2222+
req.ClientToken = decodedToken
2223+
// We ignore the token returned from CheckSSCToken here as Lookup also decodes the SSCT, and
2224+
// it may need the original SSCT to check state.
22222225
te, err := c.LookupToken(ctx, token)
22232226
if err != nil {
2227+
// If we're missing required state, return that error as-is to the client
2228+
if errors.Is(err, logical.ErrPerfStandbyPleaseForward) || errors.Is(err, logical.ErrMissingRequiredState) {
2229+
return err
2230+
}
22242231
// If we have two dots but the second char is a dot it's a vault
22252232
// token of the form s.SOMETHING.nsid, not a JWT
2226-
if !IsJWT(token) {
2233+
if !IsJWT(decodedToken) {
22272234
return fmt.Errorf("error performing token check: %w", err)
22282235
}
22292236
}

vault/token_store.go

+15
Original file line numberDiff line numberDiff line change
@@ -1560,6 +1560,10 @@ func (ts *TokenStore) lookupInternal(ctx context.Context, id string, salted, tai
15601560
return ts.lookupBatchToken(ctx, id)
15611561
}
15621562

1563+
// Before we check to see if this is an SSCT, keep the old value in case
1564+
// we need to check the full SSCT flow later.
1565+
originalToken := id
1566+
15631567
// lookupInternal is called internally with tokens that oftentimes come from request
15641568
// parameters that we cannot really guess. Most notably, these calls come from either
15651569
// validateWrappedToken and/or lookupTokenTainted, used in the wrapping token logic.
@@ -1703,6 +1707,17 @@ func (ts *TokenStore) lookupInternal(ctx context.Context, id string, salted, tai
17031707
// It's any kind of expiring token with no lease, immediately delete it
17041708
case le == nil:
17051709
if ts.core.perfStandby {
1710+
// If we're a perf standby with a token but without the lease entry, then
1711+
// we have the WALs for the token but not the lease entry. We should check
1712+
// the SSCToken again to validate our state. We will receive a 412 if we
1713+
// don't have the requisite state.
1714+
// We set unauth to 'false' here as we want to validate the full SSCT flow
1715+
// and if we're at this point in the method, we have reason to need the token.
1716+
_, err = ts.core.CheckSSCToken(ctx, originalToken, false, ts.core.perfStandby)
1717+
if err != nil {
1718+
return nil, err
1719+
}
1720+
// If we don't have a state error, and we're still here, return a 500.
17061721
return nil, fmt.Errorf("no lease entry found for token that ought to have one, possible eventual consistency issue")
17071722
}
17081723

0 commit comments

Comments
 (0)