Skip to content
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

Merged
merged 7 commits into from
Jun 13, 2019

Conversation

ghost
Copy link

@ghost ghost commented May 8, 2019

No description provided.

@ghost ghost requested a review from jefferai May 8, 2019 21:14
Copy link
Contributor

@catsby catsby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few questions mostly due to some unfamiliarity

@@ -38,6 +38,9 @@ type TokenParams struct {

// The TTL to user for the token
TokenTTL time.Duration `json:"token_ttl" mapstructure:"token_ttl"`

// The maximum number of times a token issued from this role may be used.
TokenMaxNumUses int `json:"token_max_num_uses" mapstructure:"token_max_num_uses"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use omitempty here? Assuming this value gets output to the user at some point, I wonder if 0 would be confusing. Internally zero means "unlimited" but that's mostly an implementation detail, yeah?

vault/token_store.go Outdated Show resolved Hide resolved
@@ -2969,6 +2985,7 @@ func (ts *TokenStore) tokenStoreRoleRead(ctx context.Context, req *logical.Reque
"path_suffix": role.PathSuffix,
"renewable": role.Renewable,
"token_type": role.TokenType.String(),
"token_max_num_uses": role.TokenMaxNumUses,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we omit this if the value is zero? It may be confusing to users


"token_max_num_uses": &framework.FieldSchema{
Type: framework.TypeInt,
Description: "The maximum number of times a token issued from this role may be used.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add to the description that in order to remove the limit/max, to set this value to 0, assuming that's valid

@@ -38,6 +38,9 @@ type TokenParams struct {

// The TTL to user for the token
TokenTTL time.Duration `json:"token_ttl" mapstructure:"token_ttl"`

// The maximum number of times a token issued from this role may be used.
TokenNumUses int `json:"token_num_uses,omitempty" mapstructure:"token_num_uses,omitempty"`
Copy link
Member

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.

Copy link
Member

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.

switch {
case role.TokenNumUses > 0 && te.NumUses == 0:
te.NumUses = role.TokenNumUses
case role.TokenNumUses < te.NumUses:
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Oops.
This test case catches that and passes with the new base case.

Copy link
Member

@jefferai jefferai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good. The one logic issue at creation time plus figuring out the right thing for omitempty.

…n created from a token role. Fixes faulty logic. Removes some useless omitempty tags.
@ghost ghost requested a review from jefferai May 14, 2019 18:01
Copy link
Member

@jefferai jefferai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@jefferai jefferai merged commit 8cc0481 into tokenhelper_v2 Jun 13, 2019
@jefferai jefferai deleted the alex/add_max_num_uses_to_tokenhelper_v2 branch June 13, 2019 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants