From 0ca4a9fa4ffd42b68a3db88aad9aca0f891c1c1a Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Mon, 8 Aug 2016 15:28:25 -0700 Subject: [PATCH] Change token/role names --- command/agent/config-test-fixtures/basic.hcl | 4 ++-- command/agent/config_parse.go | 6 +++--- command/agent/config_parse_test.go | 4 ++-- command/agent/config_test.go | 8 +++---- nomad/structs/config/vault.go | 22 ++++++++++---------- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/command/agent/config-test-fixtures/basic.hcl b/command/agent/config-test-fixtures/basic.hcl index 8c310183c..e6855e138 100644 --- a/command/agent/config-test-fixtures/basic.hcl +++ b/command/agent/config-test-fixtures/basic.hcl @@ -111,12 +111,12 @@ vault { address = "127.0.0.1:9500" allow_unauthenticated = true child_token_ttl = "1s" - role_name = "roleFoo" - role_token = "12345" + periodic_token = "12345" tls_ca_file = "/path/to/ca/file" tls_ca_path = "/path/to/ca" tls_cert_file = "/path/to/cert/file" tls_key_file = "/path/to/key/file" tls_server_name = "foobar" tls_skip_verify = true + token_role_name = "roleFoo" } diff --git a/command/agent/config_parse.go b/command/agent/config_parse.go index 6dcb19189..fd5a3cde5 100644 --- a/command/agent/config_parse.go +++ b/command/agent/config_parse.go @@ -655,15 +655,15 @@ func parseVaultConfig(result **config.VaultConfig, list *ast.ObjectList) error { valid := []string{ "address", "allow_unauthenticated", + "child_token_ttl", + "periodic_token", "tls_ca_file", "tls_ca_path", "tls_cert_file", - "child_token_ttl", "tls_key_file", - "role_name", - "role_token", "tls_server_name", "tls_skip_verify", + "token_role_name", } if err := checkHCLKeys(listVal, valid); err != nil { diff --git a/command/agent/config_parse_test.go b/command/agent/config_parse_test.go index 5a4e8aacf..ced42b9cd 100644 --- a/command/agent/config_parse_test.go +++ b/command/agent/config_parse_test.go @@ -130,8 +130,8 @@ func TestConfig_Parse(t *testing.T) { TLSCertFile: "/path/to/cert/file", ChildTokenTTL: "1s", TLSKeyFile: "/path/to/key/file", - RoleName: "roleFoo", - RoleToken: "12345", + TokenRoleName: "roleFoo", + PeriodicToken: "12345", TLSServerName: "foobar", TLSSkipVerify: true, }, diff --git a/command/agent/config_test.go b/command/agent/config_test.go index aaae2a685..bd0aa70e7 100644 --- a/command/agent/config_test.go +++ b/command/agent/config_test.go @@ -96,8 +96,8 @@ func TestConfig_Merge(t *testing.T) { "Access-Control-Allow-Origin": "*", }, Vault: &config.VaultConfig{ - RoleName: "1", - RoleToken: "1", + TokenRoleName: "1", + PeriodicToken: "1", AllowUnauthenticated: false, ChildTokenTTL: "1", Addr: "1", @@ -223,8 +223,8 @@ func TestConfig_Merge(t *testing.T) { "Access-Control-Allow-Methods": "GET, POST, OPTIONS", }, Vault: &config.VaultConfig{ - RoleName: "2", - RoleToken: "2", + TokenRoleName: "2", + PeriodicToken: "2", AllowUnauthenticated: true, ChildTokenTTL: "2", Addr: "2", diff --git a/nomad/structs/config/vault.go b/nomad/structs/config/vault.go index 5d1dc03a9..397ae4225 100644 --- a/nomad/structs/config/vault.go +++ b/nomad/structs/config/vault.go @@ -12,14 +12,14 @@ import vault "github.com/hashicorp/vault/api" // - Create child tokens with policy subsets of the Server's token. type VaultConfig struct { - // RoleName is the Vault role in which Nomad will derive child tokens using - // /auth/token/create/[role_name] - RoleName string `mapstructure:"role_name"` + // TokenRoleName is the Vault role in which Nomad will derive child tokens using + // /auth/token/create/[token_role_name] + TokenRoleName string `mapstructure:"token_role_name"` - // RoleToken is the periodic Vault token given to Nomad such that it can - // derive child tokens. The RoleToken should be created from the passed - // RoleName. Nomad will renew this token at half its lease lifetime. - RoleToken string `mapstructure:"role_token"` + // PeriodicToken is the periodic Vault token given to Nomad such that it can + // derive child tokens. The PeriodicToken should be created from the passed + // TokenRoleName. Nomad will renew this token at half its lease lifetime. + PeriodicToken string `mapstructure:"periodic_token"` // AllowUnauthenticated allows users to submit jobs requiring Vault tokens // without providing a Vault token proving they have access to these @@ -68,11 +68,11 @@ func DefaultVaultConfig() *VaultConfig { func (a *VaultConfig) Merge(b *VaultConfig) *VaultConfig { result := *a - if b.RoleName != "" { - result.RoleName = b.RoleName + if b.TokenRoleName != "" { + result.TokenRoleName = b.TokenRoleName } - if b.RoleToken != "" { - result.RoleToken = b.RoleToken + if b.PeriodicToken != "" { + result.PeriodicToken = b.PeriodicToken } if b.AllowUnauthenticated { result.AllowUnauthenticated = b.AllowUnauthenticated