-
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
[WIP] Support custom max Nomad token name length [supersedes https://github.com/hashicorp/vault/pull/4361] #5117
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b9aa628
Nomad: updating max token length to 256
burdandrei b1ad204
Initial support for supporting custom max token name length for Nomad
catsby 3bd07ee
simplify/correct tests
catsby 024fc96
document nomad max_token_name_length
catsby 73e77f4
removed support for max token length env var. Rename field for clarity
catsby aba9594
cleanups after removing env var support
catsby ea46e62
move RandomWithPrefix to testhelpers
catsby 3c3aa32
fix spelling
catsby 5e54700
Remove default 256 value. Use zero as a sentinel value and ignore it
catsby 39ff353
update docs
catsby File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,12 @@ func pathCredsCreate(b *backend) *framework.Path { | |
|
||
func (b *backend) pathTokenRead(ctx context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) { | ||
name := d.Get("name").(string) | ||
conf, _ := b.readConfigAccess(ctx, req.Storage) | ||
// establish a default | ||
tokenNameLength := maxTokenNameLength | ||
if conf != nil && conf.MaxTokenNameLength > 0 { | ||
tokenNameLength = conf.MaxTokenNameLength | ||
} | ||
|
||
role, err := b.Role(ctx, req.Storage, name) | ||
if err != nil { | ||
|
@@ -56,10 +62,11 @@ func (b *backend) pathTokenRead(ctx context.Context, req *logical.Request, d *fr | |
// Generate a name for the token | ||
tokenName := fmt.Sprintf("vault-%s-%s-%d", name, req.DisplayName, time.Now().UnixNano()) | ||
|
||
// Handling nomad maximum token length | ||
// https://github.com/hashicorp/nomad/blob/d9276e22b3b74674996fb548cdb6bc4c70d5b0e4/nomad/structs/structs.go#L115 | ||
if len(tokenName) > 64 { | ||
tokenName = tokenName[0:63] | ||
// Note: if the given role name is suffeciently long, the UnixNano() portion | ||
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. typo: suffeciently |
||
// of the pseudo randomized token name is the part that gets trimmed off, | ||
// weaking it's randomness. | ||
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. typo: weakening |
||
if len(tokenName) > tokenNameLength { | ||
tokenName = tokenName[:tokenNameLength] | ||
} | ||
|
||
// Create it | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
One more thing here. You should probably not set the default value in the path config. This will mean we will store this value in storage and if we change the default again, they will have an explicit value. You can just omit the Default.
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.
Omitting the default will leave a zero value in the struct and be serialized like that. We could change the
accessConfig.MaxTokenNameLength
to be an*int
and usenil
there, or just ignore the value when it's zero. I'll assume the later for nowThere 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.
Or set it the default to -1 maybe?
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 think the zero value is fine, it is the same as default. I don't think we need to do any int pointer work. Does this api support create vs update? If so, you should be able to handle the case where they don't provide the value and just patch the updated fields.