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

NET-581 - Added vault namespace in helm #2841

Conversation

absolutelightning
Copy link
Contributor

@absolutelightning absolutelightning commented Aug 25, 2023

Changes proposed in this PR:

  • Adds vaultNamespace in secretsBackend.vault in values.yaml
  • This namespace is used for Vault namespace, this introduces one more way to specify namespace other than
    "{"connect": [{ "ca_config": [{ "namespace": "value"}]}]}" in connectCA.additionalConfig
  • If vaultNamespace is present, it automatically adds annotation below to the templates.
    vault:
      agentAnnotations: |
        vault.hashicorp.com/namespace: vaultNamespace

How I've tested this PR:
a. CI
b. Updated test TestVault_VaultNamespace
Test Steps -

1. kind create cluster --name=dc1
2. kind create cluster --name=dc2
3. cd acceptance/test/vault
4. go test ./... -p 1 -timeout 2h -failfast -no-cleanup-on-failure -debug-directory=/tmp/debug -use-kind -enable-multi-cluster -kube-contexts=kind-dc1,kind-dc2  -run ^TestVault

Output -

asheshvidyut@absolutelightning-H2GX766V9T acceptance/tests (NET-581-Configure-Vault-namespaces-for-Connect-CA-via-Helm-Stanza) » go test ./... -p 1 -timeout 2h -failfast -no-cleanup-on-failure -debug-directory=/tmp/debug -use-kind -enable-multi-cluster -kube-contexts=kind-dc1,kind-dc2  -run ^TestVault
ok  	github.com/hashicorp/consul-k8s/acceptance/tests/api-gateway	0.492s [no tests to run]
ok  	github.com/hashicorp/consul-k8s/acceptance/tests/basic	0.547s [no tests to run]
ok  	github.com/hashicorp/consul-k8s/acceptance/tests/cli	0.529s [no tests to run]
ok  	github.com/hashicorp/consul-k8s/acceptance/tests/cloud	0.565s [no tests to run]
ok  	github.com/hashicorp/consul-k8s/acceptance/tests/config-entries	0.524s [no tests to run]
ok  	github.com/hashicorp/consul-k8s/acceptance/tests/connect	0.556s [no tests to run]
ok  	github.com/hashicorp/consul-k8s/acceptance/tests/consul-dns	0.543s [no tests to run]
ok  	github.com/hashicorp/consul-k8s/acceptance/tests/example	0.540s
ok  	github.com/hashicorp/consul-k8s/acceptance/tests/ingress-gateway	0.553s [no tests to run]
ok  	github.com/hashicorp/consul-k8s/acceptance/tests/metrics	0.555s [no tests to run]
ok  	github.com/hashicorp/consul-k8s/acceptance/tests/partitions	0.561s [no tests to run]
ok  	github.com/hashicorp/consul-k8s/acceptance/tests/peering	0.568s [no tests to run]
ok  	github.com/hashicorp/consul-k8s/acceptance/tests/sameness	0.552s
ok  	github.com/hashicorp/consul-k8s/acceptance/tests/snapshot-agent	0.572s [no tests to run]
ok  	github.com/hashicorp/consul-k8s/acceptance/tests/sync	0.554s [no tests to run]
ok  	github.com/hashicorp/consul-k8s/acceptance/tests/terminating-gateway	0.553s [no tests to run]
ok  	github.com/hashicorp/consul-k8s/acceptance/tests/vault	916.339s
ok  	github.com/hashicorp/consul-k8s/acceptance/tests/wan-federation	0.587s [no tests to run]

How I expect reviewers to test this PR:

Checklist:

@absolutelightning absolutelightning changed the title NET-581 - Added value namespace in helm WIP - NET-581 - Added value namespace in helm Aug 25, 2023
@absolutelightning absolutelightning changed the title WIP - NET-581 - Added value namespace in helm WIP - NET-581 - Added vault namespace in helm Aug 25, 2023
@absolutelightning absolutelightning changed the title WIP - NET-581 - Added vault namespace in helm NET-581 - Added vault namespace in helm Aug 29, 2023
@absolutelightning absolutelightning added the pr/no-backport signals that a PR will not contain a backport label label Aug 29, 2023
@absolutelightning absolutelightning marked this pull request as ready for review August 29, 2023 09:08
@absolutelightning absolutelightning added the consul-india PRs/Issues assigned to Consul India team label Aug 29, 2023
@curtbushko curtbushko requested review from zalimeni and wilkermichael and removed request for kschoche August 29, 2023 11:24
@curtbushko curtbushko added the backport/1.2.x This release branch is no longer active. label Aug 29, 2023
@absolutelightning absolutelightning removed the pr/no-backport signals that a PR will not contain a backport label label Aug 29, 2023
Copy link
Member

@zalimeni zalimeni 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 overall! Added some minor feedback inline.

One clarifying question about requirements: I think @david-yu 's example in the ticket had namespace under the higher-level secretsBackend.vault key. I'm not opposed to keeping it under connectCA because that aligns w/ the existing agent config, but I could see a higher-level key being used for other namespaced Vault config, if we expect that one Vault namespace would always be used across Vault->Consul integrations (I'm not 100% certain whether that's the case).

  1. Do we think it's best to move the namespace KV up, or keep it under connectCA?
  2. If we move it, a suggestion in one of the linked Slack 🧵s was to call it vaultNamespace to disambiguate from Consul. That would align w/ other names such as consulServerRole.

.changelog/2841.txt Outdated Show resolved Hide resolved
charts/consul/values.yaml Show resolved Hide resolved
acceptance/tests/vault/vault_namespaces_test.go Outdated Show resolved Hide resolved
charts/consul/values.yaml Outdated Show resolved Hide resolved
charts/consul/values.yaml Outdated Show resolved Hide resolved
@david-yu
Copy link
Contributor

@curtbushko Is there a reason why you only added backport 1.2.x instead of 1.0.x, 1.1.x and 1.2.x?

@curtbushko
Copy link
Contributor

@david-yu No reason. I was just doing a passby label adding. I didn't look too deep to see where this should go.

@david-yu david-yu added backport/1.0.x backport/1.1.x Backport to release/1.1.x branch labels Aug 29, 2023
@david-yu
Copy link
Contributor

-yu 's example in the ticket had namespace under the higher-level secretsBackend.vault key. I'm not opposed to keeping it under connectCA because that aligns w/ the existing agent config, but I could see a higher-level key being used for other namespaced Vault config, if we expect that one Vault namespace would always be used across Vault->Consul integrations (I'm not 100% certain whether that's the case).

  1. Do we think it's best to move the namespace KV up, or keep it under connectCA?
  2. If we move it, a suggestion in one of the linked Slack 🧵s was to call it vaultNamespace to disambiguate from Consul. That would align w/ other names such as consulServerRole.

I would prefer it be under the secretsBackend.vault stanza. If we do that we should automatically set agent annotations to the associated vault namespace as well as that is also required to get the vault namespace working. Below is an example of full desired secrets backend config to set the vault namespace to admin:

vault:
      enabled: true
      vaultNamespace: admin
      consulServerRole: consul-server
      consulClientRole: consul-client
      consulCARole: consul-ca
      manageSystemACLsRole: consul-server-acl-init
      controllerRole: consul-controller
      connectInjectRole: consul-connect-inject
      controller:
        caCert:
          secretName: "consul_controller_int/cert/ca"
        tlsCert:
          secretName: "consul_controller_int/issue/consul-controller"
      connectInject:
        caCert:
          secretName: "consul_connect_inject_int/cert/ca"
        tlsCert:
          secretName: "consul_connect_inject_int/issue/consul-connect-inject"
      connectCA:
        address: https://hcp-vault-cluster:8200/
        rootPKIPath: consul_pki/
        intermediatePKIPath: consul_connect_int/

Behind the scenes it should also set the following annotation to admin:

    vault:
      agentAnnotations: |
        vault.hashicorp.com/namespace: admin

It would be best to call it vaultNamespace as well since it makes it clear this a vault namespace versus Consul.

absolutelightning and others added 2 commits August 30, 2023 03:49
Co-authored-by: Michael Zalimeni <michael.zalimeni@hashicorp.com>
Co-authored-by: Michael Zalimeni <michael.zalimeni@hashicorp.com>
@absolutelightning
Copy link
Contributor Author

absolutelightning commented Aug 29, 2023

@david-yu I am not super familiar with vault namespace. but can this situation arise where user would want different vault namespace for agentAnnotation and different for connectCA?

@david-yu
Copy link
Contributor

I don't think it's very likely that the Connect CA will live in a different place than the Vault KV store but you can have it separate if they want to do that. I would think we set the namespace to the value provided by vaultNamespace by default and have it overridden by the user if need be.

@absolutelightning
Copy link
Contributor Author

absolutelightning commented Aug 30, 2023

Thanks for reply. Also can user give some other annotations as well for vault? we are going to remove agentAnnotations field right.
Now it can only have one value. @david-yu

@absolutelightning
Copy link
Contributor Author

@david-yu Removing agent annotations is probably incorrect as I see there are other annotations as well which users can add - https://developer.hashicorp.com/vault/docs/platform/k8s/injector/annotations. Let me know you thoughts.

@david-yu david-yu requested a review from a team September 5, 2023 18:12
@david-yu
Copy link
Contributor

david-yu commented Sep 5, 2023

Added consul-docs for review of values.yaml

charts/consul/test/unit/server-config-configmap.bats Outdated Show resolved Hide resolved
@@ -72,6 +72,9 @@ data:
"ca_file": "/consul/vault-ca/tls.crt",
{{- end }}
"intermediate_pki_path": "{{ .connectCA.intermediatePKIPath }}",
{{- if (and (.vaultNamespace) (not (contains "namespace" (default "" .connectCA.additionalConfig)))) }}
Copy link
Member

Choose a reason for hiding this comment

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

@absolutelightning good catch, my example was off - but I think this is still possible, see this updated version.

From the link above, if you use:

{{- if (and (.vaultNamespace) (not (hasKey (default "" .connectCA.additionalConfig | fromJson).connect.ca_config "namespace"))) }}
  "namespace": "{{ .vaultNamespace }}",
{{- end }}

does that work?

charts/consul/test/unit/server-config-configmap.bats Outdated Show resolved Hide resolved
absolutelightning and others added 3 commits September 6, 2023 10:45
Co-authored-by: Michael Zalimeni <michael.zalimeni@hashicorp.com>
Co-authored-by: Michael Zalimeni <michael.zalimeni@hashicorp.com>
Co-authored-by: David Yu <dyu@hashicorp.com>
@curtbushko curtbushko removed their request for review September 6, 2023 14:07
Copy link
Member

@zalimeni zalimeni left a comment

Choose a reason for hiding this comment

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

LGTM pending any input from docs team or @david-yu. Thank you again for working through my feedback and questions, @absolutelightning !

.changelog/2841.txt Outdated Show resolved Hide resolved
Co-authored-by: Michael Zalimeni <michael.zalimeni@hashicorp.com>
@absolutelightning
Copy link
Contributor Author

LGTM pending any input from docs team or @david-yu. Thank you again for working through my feedback and questions, @absolutelightning !

Thanks @zalimeni for review.

@absolutelightning absolutelightning merged commit fd35b89 into main Sep 8, 2023
3 checks passed
@absolutelightning absolutelightning deleted the NET-581-Configure-Vault-namespaces-for-Connect-CA-via-Helm-Stanza branch September 8, 2023 09:23
absolutelightning added a commit that referenced this pull request Sep 8, 2023
* added namespace

* namespace in connect ca

* updated tests

* fix test desc

* changelog

* Update .changelog/2841.txt

Co-authored-by: Michael Zalimeni <michael.zalimeni@hashicorp.com>

* Update charts/consul/values.yaml

Co-authored-by: Michael Zalimeni <michael.zalimeni@hashicorp.com>

* removed new line added

* fix templates

* bats test

* fix double colon

* fix template

* added 2 more tests

* fixes bats tests

* fix json in api gateway

* updated bats test

* Update charts/consul/values.yaml

Co-authored-by: Michael Zalimeni <michael.zalimeni@hashicorp.com>

* fix client daemon set bats

* fix bats test

* fix bats

* api gateway fix

* fix bats

* fix clientdaemon set and api gateway controller

* fix connect inject deployment

* fix mesh gateway deployment

* added tests for partition init job

* server acl init job tests added

* fix server stateful bats

* fix sync catalog

* fix includes check

* bats test fixes

* fix connect inject

* fix yaml

* fix yaml

* fix assertions in bats

* fix client daemon set bats

* Update charts/consul/values.yaml

Co-authored-by: Michael Zalimeni <michael.zalimeni@hashicorp.com>

* Update charts/consul/templates/server-config-configmap.yaml

Co-authored-by: Michael Zalimeni <michael.zalimeni@hashicorp.com>

* change yaml

* added addional config test

* fix tests

* added more tests

* fix bats

* Update charts/consul/test/unit/server-config-configmap.bats

Co-authored-by: Michael Zalimeni <michael.zalimeni@hashicorp.com>

* Update charts/consul/test/unit/server-config-configmap.bats

Co-authored-by: Michael Zalimeni <michael.zalimeni@hashicorp.com>

* Update .changelog/2841.txt

Co-authored-by: David Yu <dyu@hashicorp.com>

* Update .changelog/2841.txt

Co-authored-by: Michael Zalimeni <michael.zalimeni@hashicorp.com>

* added dummy commit to run CI

* fix change log

* fix comment

---------

Co-authored-by: Michael Zalimeni <michael.zalimeni@hashicorp.com>
Co-authored-by: David Yu <dyu@hashicorp.com>
absolutelightning added a commit that referenced this pull request Sep 8, 2023
* added namespace

* namespace in connect ca

* updated tests

* fix test desc

* changelog

* Update .changelog/2841.txt

Co-authored-by: Michael Zalimeni <michael.zalimeni@hashicorp.com>

* Update charts/consul/values.yaml

Co-authored-by: Michael Zalimeni <michael.zalimeni@hashicorp.com>

* removed new line added

* fix templates

* bats test

* fix double colon

* fix template

* added 2 more tests

* fixes bats tests

* fix json in api gateway

* updated bats test

* Update charts/consul/values.yaml

Co-authored-by: Michael Zalimeni <michael.zalimeni@hashicorp.com>

* fix client daemon set bats

* fix bats test

* fix bats

* api gateway fix

* fix bats

* fix clientdaemon set and api gateway controller

* fix connect inject deployment

* fix mesh gateway deployment

* added tests for partition init job

* server acl init job tests added

* fix server stateful bats

* fix sync catalog

* fix includes check

* bats test fixes

* fix connect inject

* fix yaml

* fix yaml

* fix assertions in bats

* fix client daemon set bats

* Update charts/consul/values.yaml

Co-authored-by: Michael Zalimeni <michael.zalimeni@hashicorp.com>

* Update charts/consul/templates/server-config-configmap.yaml

Co-authored-by: Michael Zalimeni <michael.zalimeni@hashicorp.com>

* change yaml

* added addional config test

* fix tests

* added more tests

* fix bats

* Update charts/consul/test/unit/server-config-configmap.bats

Co-authored-by: Michael Zalimeni <michael.zalimeni@hashicorp.com>

* Update charts/consul/test/unit/server-config-configmap.bats

Co-authored-by: Michael Zalimeni <michael.zalimeni@hashicorp.com>

* Update .changelog/2841.txt

Co-authored-by: David Yu <dyu@hashicorp.com>

* Update .changelog/2841.txt

Co-authored-by: Michael Zalimeni <michael.zalimeni@hashicorp.com>

* added dummy commit to run CI

* fix change log

* fix comment

---------

Co-authored-by: Michael Zalimeni <michael.zalimeni@hashicorp.com>
Co-authored-by: David Yu <dyu@hashicorp.com>
absolutelightning added a commit that referenced this pull request Sep 8, 2023
NET-581 - Added vault namespace in helm   (#2841)

* added namespace

* namespace in connect ca

* updated tests

* fix test desc

* changelog

* Update .changelog/2841.txt



* Update charts/consul/values.yaml



* removed new line added

* fix templates

* bats test

* fix double colon

* fix template

* added 2 more tests

* fixes bats tests

* fix json in api gateway

* updated bats test

* Update charts/consul/values.yaml



* fix client daemon set bats

* fix bats test

* fix bats

* api gateway fix

* fix bats

* fix clientdaemon set and api gateway controller

* fix connect inject deployment

* fix mesh gateway deployment

* added tests for partition init job

* server acl init job tests added

* fix server stateful bats

* fix sync catalog

* fix includes check

* bats test fixes

* fix connect inject

* fix yaml

* fix yaml

* fix assertions in bats

* fix client daemon set bats

* Update charts/consul/values.yaml



* Update charts/consul/templates/server-config-configmap.yaml



* change yaml

* added addional config test

* fix tests

* added more tests

* fix bats

* Update charts/consul/test/unit/server-config-configmap.bats



* Update charts/consul/test/unit/server-config-configmap.bats



* Update .changelog/2841.txt



* Update .changelog/2841.txt



* added dummy commit to run CI

* fix change log

* fix comment

---------

Co-authored-by: Michael Zalimeni <michael.zalimeni@hashicorp.com>
Co-authored-by: David Yu <dyu@hashicorp.com>
absolutelightning added a commit that referenced this pull request Sep 8, 2023
NET-581 - Added vault namespace in helm   (#2841)

* added namespace

* namespace in connect ca

* updated tests

* fix test desc

* changelog

* Update .changelog/2841.txt



* Update charts/consul/values.yaml



* removed new line added

* fix templates

* bats test

* fix double colon

* fix template

* added 2 more tests

* fixes bats tests

* fix json in api gateway

* updated bats test

* Update charts/consul/values.yaml



* fix client daemon set bats

* fix bats test

* fix bats

* api gateway fix

* fix bats

* fix clientdaemon set and api gateway controller

* fix connect inject deployment

* fix mesh gateway deployment

* added tests for partition init job

* server acl init job tests added

* fix server stateful bats

* fix sync catalog

* fix includes check

* bats test fixes

* fix connect inject

* fix yaml

* fix yaml

* fix assertions in bats

* fix client daemon set bats

* Update charts/consul/values.yaml



* Update charts/consul/templates/server-config-configmap.yaml



* change yaml

* added addional config test

* fix tests

* added more tests

* fix bats

* Update charts/consul/test/unit/server-config-configmap.bats



* Update charts/consul/test/unit/server-config-configmap.bats



* Update .changelog/2841.txt



* Update .changelog/2841.txt



* added dummy commit to run CI

* fix change log

* fix comment

---------

Co-authored-by: Michael Zalimeni <michael.zalimeni@hashicorp.com>
Co-authored-by: David Yu <dyu@hashicorp.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/1.1.x Backport to release/1.1.x branch backport/1.2.x This release branch is no longer active. consul-india PRs/Issues assigned to Consul India team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants