Skip to content

Vault: configurable appRole authentication path#612

Merged
jetstack-bot merged 4 commits intocert-manager:masterfrom
vdesjardins:custom-approle-path
Jul 11, 2018
Merged

Vault: configurable appRole authentication path#612
jetstack-bot merged 4 commits intocert-manager:masterfrom
vdesjardins:custom-approle-path

Conversation

@vdesjardins
Copy link
Copy Markdown
Contributor

What this PR does / why we need it:
Configurable appRole authentication path in Vault.

Which issue this PR fixes
fixes #560

Special notes for your reviewer:

Release note:

Configurable Vault appRole authentication path using the attribute is spec.vault.auth.authPath in the issuer.

@jetstack-bot jetstack-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 5, 2018
@jetstack-bot jetstack-bot requested review from kragniz and munnerz June 5, 2018 02:43
@munnerz
Copy link
Copy Markdown
Member

munnerz commented Jun 5, 2018

/ok-to-test

@jetstack-bot jetstack-bot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jun 5, 2018
path: pki_int/sign/example-dot-com
server: https://vault
auth:
authPath: approle
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This feels a bit awkward - we have auth.authPath, which actually only applies to AppRole currently, and defaults to something that is specific to the approle auth backend.

I guess this is because token based auth does not use a mounted backend, and we support no others right now.

We can work around this either by making auth.approle.path the key to set (and in future, creating auth.kubernetes.path, auth.pki.path etc). OR we have auth.path, which becomes a required field iff the auth backend selected is not 'token'.

I'm keen to choose whatever is most obvious to users 😄

Copy link
Copy Markdown
Contributor Author

@vdesjardins vdesjardins Jun 6, 2018

Choose a reason for hiding this comment

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

Indeed that's the reason why I put it directly under the auth struct. I have no problem moving it under the appRole and supply a specific path for other authentication mechanisms when we implement them.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

s/authPath/path/g (as you changed this as part of review 😄)

// This Secret contains a AppRole and Secret
AppRole VaultAppRole `json:"appRole,omitempty"`
// Where the authentication path is mounted in Vault.
AuthPath string `json:"authPath,omitempty"`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As this is already a child of auth, I think we can shorten this to path


if authPath == "" {
authPath = "approle"
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We're defaulting this field in multiple places - I'd rather return an error if it isn't specified than default to the same value again

url := path.Join("/v1/auth/approle/role", v.role)
_, err = v.callVault("POST", url, "", params)

baseUrl := path.Join("/v1/auth", v.authPath, "role", v.role)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

should be path.Join("v1", "auth", v.authPath, "role", v.role) (i.e. let path.Join join v1 and auth)

certificateName := "test-vault-certificate"
certificateSecretName := "test-vault-certificate"
vaultSecretAppRoleName := "vault-role"
vaultPath := fmt.Sprintf("%s/sign/%s", intermediateMount, role)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we can use path.Join here?

@munnerz munnerz added the area/vault Indicates a PR directly modifies the Vault Issuer code label Jun 5, 2018
@avoidik
Copy link
Copy Markdown

avoidik commented Jun 7, 2018

I'd like to suggest to use the same approach like with roleId and name it roleName

@vdesjardins vdesjardins force-pushed the custom-approle-path branch 3 times, most recently from a833406 to e3f67ec Compare June 15, 2018 16:02
path: pki_int/sign/example-dot-com
server: https://vault
auth:
authPath: approle
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

s/authPath/path/g (as you changed this as part of review 😄)

references the Kubernetes secret created previously. More specifically, the field
*name* is the Kubernetes secret name and *key* is the name given as the
key value that store the *secretId*.
key value that store the *secretId*. The optional attribute *authPath* specifies
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

s/authPath/path

key value that store the *secretId*.
key value that store the *secretId*. The optional attribute *authPath* specifies
where the AppRole authentication is mounted in Vault. The *authPath* default value
is *approle*.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

s/authPath/path - also, is this comment still true?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes if the path is empty it still default to approle.


type VaultAppRole struct {
// Where the authentication path is mounted in Vault.
Path string `json:"path,omitempty"`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Remove omitempty

url := "/v1/auth/approle/login"
authPath := appRole.Path
if authPath == "" {
authPath = "approle"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍 this is okay for now. We will look at moving defaulting etc. out after the webhooks PR has merged

resp, err := client.RawRequest(request)
if err != nil {
return nil, fmt.Errorf("error calling Vault server: %s", err.Error())
return nil, fmt.Errorf("error logging in to Vault server: %s", err.Error())
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think the request made here is to log in? Update error message

(v.issuer.GetSpec().Vault.Auth.AppRole.RoleId != "" ||
v.issuer.GetSpec().Vault.Auth.AppRole.SecretRef.Name != "") {
v.issuer.GetSpec().Vault.Auth.AppRole.SecretRef.Name != "" ||
v.issuer.GetSpec().Vault.Auth.AppRole.Path != "") {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

From what I can tell, v.issuer.GetSpec().Vault.Auth.AppRole.Path might be blank (as we default it elsewhere in memory). Does this not break approle auth where the Path is not set?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also, just taking a look over the brace above this block:

https://github.com/vdesjardins/cert-manager/blob/e3f67ecaab3a8fec4da7d4e86c78d2593cee20c3/pkg/issuer/vault/setup.go#L40-L42

Should this not be using || instead of && for the check?

Either way, can we add some comments to each of these if blocks to make it clear what we're checking for? 😄


if authPath == "" {
return nil, fmt.Errorf("Error authPath must be set")
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

authPath is an optional field, we needn't require it be set in our fixtures (this causes disparity between tests and docs 😄)

@munnerz
Copy link
Copy Markdown
Member

munnerz commented Jul 11, 2018

Sorry for the delay looking at this again - this should land in the 0.4 release later today 😄

/lgtm
/approve

@jetstack-bot jetstack-bot added the lgtm Indicates that a PR is ready to be merged. label Jul 11, 2018
@jetstack-bot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: munnerz

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@jetstack-bot jetstack-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 11, 2018
@munnerz
Copy link
Copy Markdown
Member

munnerz commented Jul 11, 2018

/test chart-verify

@munnerz munnerz force-pushed the custom-approle-path branch from 51313b8 to cb7eaf9 Compare July 11, 2018 16:03
@jetstack-bot jetstack-bot removed the lgtm Indicates that a PR is ready to be merged. label Jul 11, 2018
@jetstack-bot
Copy link
Copy Markdown
Contributor

New changes are detected. LGTM label has been removed.

@munnerz
Copy link
Copy Markdown
Member

munnerz commented Jul 11, 2018

Rebased and run hack/update-reference-docs-dockerized.sh for this PR so we can get it merged for 0.4 😄

@munnerz munnerz added the lgtm Indicates that a PR is ready to be merged. label Jul 11, 2018
@jetstack-bot jetstack-bot merged commit a162a5b into cert-manager:master Jul 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. area/vault Indicates a PR directly modifies the Vault Issuer code lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Vault approle backend path is not static

4 participants