-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Alex/add max num uses to tokenhelper v2 #6701
Changes from 6 commits
2b37059
c598e74
26b778f
2bd0c21
ce353a2
bd53597
7ad55ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -409,7 +409,7 @@ func (ts *TokenStore) paths() []*framework.Path { | |
ExistenceCheck: ts.tokenStoreRoleExistenceCheck, | ||
} | ||
|
||
tokenhelper.AddTokenFieldsWithAllowList(rolesPath.Fields, []string{"token_bound_cidrs", "token_explicit_max_ttl", "token_period", "token_type", "token_no_default_policy"}) | ||
tokenhelper.AddTokenFieldsWithAllowList(rolesPath.Fields, []string{"token_bound_cidrs", "token_explicit_max_ttl", "token_period", "token_type", "token_no_default_policy", "token_num_uses"}) | ||
p = append(p, rolesPath) | ||
|
||
return p | ||
|
@@ -2234,6 +2234,16 @@ func (ts *TokenStore) handleCreateCommon(ctx context.Context, req *logical.Reque | |
renewable = false | ||
} | ||
|
||
// Update num_uses which is equal to req.Data["num_uses"] at this point | ||
// 0 means unlimited so 1 is actually less than 0 | ||
switch { | ||
case role.TokenNumUses > 0 && te.NumUses == 0: | ||
te.NumUses = role.TokenNumUses | ||
case role.TokenNumUses < te.NumUses: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If TokenNumUses is 0 and te.NumUses is 2, this will actually end up setting te.NumUses to 0. As a base case, if role.TokenNumUses is zero, it should probably just use whatever te.NumUses is. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. Oops. |
||
te.NumUses = role.TokenNumUses | ||
default: | ||
} | ||
|
||
if role.PathSuffix != "" { | ||
te.Path = fmt.Sprintf("%s/%s", te.Path, role.PathSuffix) | ||
} | ||
|
@@ -2978,6 +2988,9 @@ func (ts *TokenStore) tokenStoreRoleRead(ctx context.Context, req *logical.Reque | |
if len(role.BoundCIDRs) > 0 { | ||
resp.Data["bound_cidrs"] = role.BoundCIDRs | ||
} | ||
if role.TokenNumUses > 0 { | ||
resp.Data["token_num_uses"] = role.TokenNumUses | ||
} | ||
|
||
return resp, nil | ||
} | ||
|
@@ -3149,6 +3162,12 @@ func (ts *TokenStore) tokenStoreRoleCreateUpdate(ctx context.Context, req *logic | |
} | ||
} | ||
|
||
// no legacy version without the token_ prefix to check for | ||
tokenNumUses, ok := data.GetOk("token_num_uses") | ||
if ok { | ||
entry.TokenNumUses = tokenNumUses.(int) | ||
} | ||
|
||
// Run validity checks on token type | ||
if entry.TokenType == logical.TokenTypeBatch { | ||
if !entry.Orphan { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this should be omitempty or not, but I'm pretty sure we should be consistent with the other parameters, whether we make them all omitempty or none.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also note that because
PopulateTokenData
adds to the map regardless, this actually has no effect currently.