Add new API endpoint to revoke STS tokens (#21072)

This commit is contained in:
Taran Pelkey
2025-03-31 14:51:24 -04:00
committed by GitHub
parent e88d494775
commit 53d40e41bc
11 changed files with 555 additions and 205 deletions

View File

@@ -2032,6 +2032,50 @@ func (store *IAMStoreSys) SetTempUser(ctx context.Context, accessKey string, cre
return u.UpdatedAt, nil
}
// RevokeTokens - revokes all temporary credentials, or those with matching type,
// associated with the parent user.
func (store *IAMStoreSys) RevokeTokens(ctx context.Context, parentUser string, tokenRevokeType string) error {
if parentUser == "" {
return errInvalidArgument
}
cache := store.lock()
defer store.unlock()
secret, err := getTokenSigningKey()
if err != nil {
return err
}
var revoked bool
for _, ui := range cache.iamSTSAccountsMap {
if ui.Credentials.ParentUser != parentUser {
continue
}
if tokenRevokeType != "" {
claims, err := getClaimsFromTokenWithSecret(ui.Credentials.SessionToken, secret)
if err != nil {
continue // skip if token is invalid
}
// skip if token type is given and does not match
if v, _ := claims.Lookup(tokenRevokeTypeClaim); v != tokenRevokeType {
continue
}
}
if err := store.deleteUserIdentity(ctx, ui.Credentials.AccessKey, stsUser); err != nil {
return err
}
delete(cache.iamSTSAccountsMap, ui.Credentials.AccessKey)
revoked = true
}
if revoked {
cache.updatedAt = time.Now()
}
return nil
}
// DeleteUsers - given a set of users or access keys, deletes them along with
// any derived credentials (STS or service accounts) and any associated policy
// mappings.