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

vault: check token_explicit_max_ttl as well #6680

Merged
merged 1 commit into from
Nov 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions nomad/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -880,11 +880,12 @@ func (v *vaultClient) validateRole(role string) error {

// Read and parse the fields
var data struct {
ExplicitMaxTtl int `mapstructure:"explicit_max_ttl"`
Orphan bool
Period int
TokenPeriod int `mapstructure:"token_period"`
Renewable bool
ExplicitMaxTtl int `mapstructure:"explicit_max_ttl"`
TokenExplicitMaxTtl int `mapstructure:"token_explicit_max_ttl"`
Orphan bool
Period int
TokenPeriod int `mapstructure:"token_period"`
Renewable bool
}
if err := mapstructure.WeakDecode(rsecret.Data, &data); err != nil {
return fmt.Errorf("failed to parse Vault role's data block: %v", err)
Expand All @@ -896,7 +897,7 @@ func (v *vaultClient) validateRole(role string) error {
multierror.Append(&mErr, fmt.Errorf("Role must allow tokens to be renewed"))
}

if data.ExplicitMaxTtl != 0 {
if data.ExplicitMaxTtl != 0 || data.TokenExplicitMaxTtl != 0 {
multierror.Append(&mErr, fmt.Errorf("Role can not use an explicit max ttl. Token must be periodic."))
}

Expand Down
9 changes: 5 additions & 4 deletions nomad/vault_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,10 @@ func TestVaultClient_ValidateRole(t *testing.T) {
"nomad-role-management": nomadRoleManagementPolicy,
}
data := map[string]interface{}{
"allowed_policies": "default,root",
"orphan": true,
"renewable": true,
"explicit_max_ttl": 10,
"allowed_policies": "default,root",
"orphan": true,
"renewable": true,
"token_explicit_max_ttl": 10,
}
v.Config.Token = testVaultRoleAndToken(v, t, vaultPolicies, data, nil)

Expand Down Expand Up @@ -328,6 +328,7 @@ func TestVaultClient_ValidateRole(t *testing.T) {
})

require.Contains(t, connErr.Error(), "explicit max ttl")
require.Contains(t, connErr.Error(), "non-zero period")
}

// TestVaultClient_ValidateRole_Success asserts that a valid token role
Expand Down