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

Support vault namespaces in connect CA #12904

Merged
merged 7 commits into from
May 5, 2022

Conversation

markan
Copy link
Contributor

@markan markan commented Apr 30, 2022

Follow on to some missed items from #12655

Description

From an internal ticket "Support standard "Vault namespace in the
path" semantics for Connect Vault CA Provider"

Vault allows the namespace to be specified as a prefix in the path of
a PKI definition, but our usage of the Vault API includes calls that
don't support a namespaced key. In particular the sys.* family of
calls simply appends the key, instead of prefixing the namespace in
front of the path.

Unfortunately it is difficult to reliably parse a path with a
namespace; only vault knows what namespaces are present, and the '/'
separator can be inside a key name, as well as separating path
elements. This is in use in the wild; for example
'dc1/intermediate-key' is a relatively common naming schema.

Instead we add two new fields: RootPKINamespace and
IntermediatePKINamespace, which are the absolute namespace paths
'prefixed' in front of the respective PKI Paths.

Testing & Reproduction steps

[ ] manual testing

Links

Asana task

PR Checklist

  • updated test coverage
  • external facing docs updated
  • not a security concern
  • checklist folder consulted

Signed-off-by: Mark Anderson [email protected]

@github-actions github-actions bot added theme/config Relating to Consul Agent configuration, including reloading theme/connect Anything related to Consul Connect, Service Mesh, Side Car Proxies type/docs Documentation needs to be created/updated/clarified labels Apr 30, 2022
@hashicorp-ci
Copy link
Contributor

🤔 This PR has changes in the website/ directory but does not have a type/docs-cherrypick label. If the changes are for the next version, this can be ignored. If they are updates to current docs, attach the label to auto cherrypick to the stable-website branch after merging.

Copy link
Contributor

@jkirschner-hashicorp jkirschner-hashicorp left a comment

Choose a reason for hiding this comment

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

@markan : a few questions we can discuss Monday!

"key_file": "KeyFile",
"tls_server_name": "TLSServerName",
"tls_skip_verify": "TLSSkipVerify",
"address": "Address",
Copy link
Contributor

Choose a reason for hiding this comment

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

I noticed some config params (AuthMethod, Namespace) aren't here. Do they need to be?

@markan markan marked this pull request as ready for review May 3, 2022 04:07
@markan markan requested a review from a team as a code owner May 3, 2022 04:07
@markan markan requested review from a team and kyhavlov and removed request for a team May 3, 2022 21:18
@markan markan force-pushed the ma/vault-namespace-intermediate-provider-v2 branch from 7ffb0a0 to 609fbfb Compare May 4, 2022 15:52
@trujillo-adam trujillo-adam self-assigned this May 4, 2022
@boxofrad
Copy link
Contributor

boxofrad commented May 4, 2022

@markan as discussed (again, I'm totally fine with copy-pasta 🍝) here are a couple of options for extracting the concurrency-safe namespace swapping pattern into a helper method:

func (v *VaultProvider) setNamespace(namespace string) func() {
	v.mu.Lock()
	v.client.SetNamespace(namespace)
	return func() {
		v.client.SetNamsepace(v.baseNamspace)
		v.mu.Unlock()
	}
}

func (v *VaultProvider) someMethod(namespace string, arg2 any) {
	restoreNamespace := v.setNamespace(namespace)
	defer restoreNamespace()

	// or..

	defer v.setNamsepace(namespace)()
}
func (v *VaultProvider) withNamespace(namespace string, fn func()) {
	v.mu.Lock()
	v.client.SetNamespace(namespace)
	fn()
	v.client.SetNamsepace(v.baseNamspace)
	v.mu.Unlock()
}

func (v *VaultProvider) someMethod(namespace string, arg2 any) someType {
	var result someType
	v.withNamespace(namespace, func() {
		result = v.client.SomeMethod()
	})
	return result
}

Copy link
Contributor

@boxofrad boxofrad left a comment

Choose a reason for hiding this comment

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

Looks good to me, nice work! 🎉

Copy link
Contributor

@trujillo-adam trujillo-adam left a comment

Choose a reason for hiding this comment

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

One bit of feedback about formatting.

markan added 7 commits May 4, 2022 14:53
Follow on to some missed items from #12655

From an internal ticket "Support standard "Vault namespace in the
path" semantics for Connect Vault CA Provider"

Vault allows the namespace to be specified as a prefix in the path of
a PKI definition, but our usage of the Vault API includes calls that
don't support a namespaced key. In particular the sys.* family of
calls simply appends the key, instead of prefixing the namespace in
front of the path.

Unfortunately it is difficult to reliably parse a path with a
namespace; only vault knows what namespaces are present, and the '/'
separator can be inside a key name, as well as separating path
elements. This is in use in the wild; for example
'dc1/intermediate-key' is a relatively common naming schema.

Instead we add two new fields: RootPKINamespace and
IntermediatePKINamespace, which are the absolute namespace paths
'prefixed' in front of the respective PKI Paths.

Signed-off-by: Mark Anderson <[email protected]>
Signed-off-by: Mark Anderson <[email protected]>
Signed-off-by: Mark Anderson <[email protected]>
Signed-off-by: Mark Anderson <[email protected]>
Signed-off-by: Mark Anderson <[email protected]>
@markan markan merged commit c6ff4ba into main May 5, 2022
@markan markan deleted the ma/vault-namespace-intermediate-provider-v2 branch May 5, 2022 02:41
@hc-github-team-consul-core
Copy link
Collaborator

🍒 If backport labels were added before merging, cherry-picking will start automatically.

To retroactively trigger a backport after merging, add backport labels and re-run https://circleci.com/gh/hashicorp/consul/662352.

@hashicorp-ci
Copy link
Contributor

After merging, confirm that you see messages like: 🍒✅ Cherry pick of commit ... onto ... succeeded!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme/config Relating to Consul Agent configuration, including reloading theme/connect Anything related to Consul Connect, Service Mesh, Side Car Proxies type/docs Documentation needs to be created/updated/clarified
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants