Skip to content

Commit

Permalink
Support per-listener TLS configuration for servers and clients (hashi…
Browse files Browse the repository at this point in the history
  • Loading branch information
ishustava authored Apr 14, 2022
1 parent ba1479f commit 0d7552e
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 46 deletions.
2 changes: 2 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ commands:
${ENABLE_ENTERPRISE:+-enable-enterprise} \
-enable-multi-cluster \
-debug-directory="$TEST_RESULTS/debug" \
-consul-image=docker.mirror.hashicorp.services/hashicorp/consul-enterprise:1.12.0-beta1-ent \
-consul-k8s-image=<< parameters.consul-k8s-image >>
then
echo "Tests in ${pkg} failed, aborting early"
Expand Down Expand Up @@ -134,6 +135,7 @@ commands:
-enable-multi-cluster \
${ENABLE_ENTERPRISE:+-enable-enterprise} \
-debug-directory="$TEST_RESULTS/debug" \
-consul-image=docker.mirror.hashicorp.services/hashicorp/consul-enterprise:1.12.0-beta1-ent \
-consul-k8s-image=<< parameters.consul-k8s-image >>
jobs:
Expand Down
14 changes: 7 additions & 7 deletions charts/consul/templates/client-daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -285,22 +285,22 @@ spec:
-hcl='leave_on_terminate = true' \
{{- if .Values.global.tls.enabled }}
{{- if .Values.global.secretsBackend.vault.enabled }}
-hcl='ca_file = "/vault/secrets/serverca.crt"' \
-hcl='tls { defaults { ca_file = "/vault/secrets/serverca.crt" }}' \
{{- else }}
-hcl='ca_file = "/consul/tls/ca/tls.crt"' \
-hcl='tls { defaults { ca_file = "/consul/tls/ca/tls.crt" }}' \
{{- end }}
{{- if .Values.global.tls.enableAutoEncrypt }}
-hcl='auto_encrypt = {tls = true}' \
-hcl="auto_encrypt = {ip_san = [\"$HOST_IP\",\"$POD_IP\"]}" \
{{- else }}
-hcl='cert_file = "/consul/tls/client/tls.crt"' \
-hcl='key_file = "/consul/tls/client/tls.key"' \
-hcl='tls { defaults { cert_file = "/consul/tls/client/tls.crt" }}' \
-hcl='tls { defaults { key_file = "/consul/tls/client/tls.key" }}' \
{{- end }}
{{- if .Values.global.tls.verify }}
-hcl='verify_outgoing = true' \
-hcl='tls { defaults { verify_outgoing = true }}' \
{{- if not .Values.global.tls.enableAutoEncrypt }}
-hcl='verify_incoming_rpc = true' \
-hcl='verify_server_hostname = true' \
-hcl='tls { internal_rpc { verify_incoming = true }}' \
-hcl='tls { internal_rpc { verify_server_hostname = true }}' \
{{- end }}
{{- end }}
-hcl='ports { https = 8501 }' \
Expand Down
48 changes: 28 additions & 20 deletions charts/consul/templates/server-config-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,31 +83,39 @@ data:
{{- if .Values.global.tls.enabled }}
tls-config.json: |-
{
{{- if .Values.global.secretsBackend.vault.enabled }}
"ca_file": "/vault/secrets/serverca.crt",
"cert_file": "/vault/secrets/servercert.crt",
"key_file": "/vault/secrets/servercert.key",
{{- else }}
"ca_file": "/consul/tls/ca/tls.crt",
"cert_file": "/consul/tls/server/tls.crt",
"key_file": "/consul/tls/server/tls.key",
{{- end }}
"tls": {
{{- if .Values.global.tls.verify }}
"internal_rpc": {
"verify_incoming": true,
"verify_server_hostname": true
},
{{- end }}
"defaults": {
{{- if .Values.global.tls.verify }}
"verify_outgoing": true,
{{- end }}
{{- if .Values.global.secretsBackend.vault.enabled }}
"ca_file": "/vault/secrets/serverca.crt",
"cert_file": "/vault/secrets/servercert.crt",
"key_file": "/vault/secrets/servercert.key"
{{- else }}
"ca_file": "/consul/tls/ca/tls.crt",
"cert_file": "/consul/tls/server/tls.crt",
"key_file": "/consul/tls/server/tls.key"
{{- end }}
}
},
{{- if .Values.global.tls.enableAutoEncrypt }}
"auto_encrypt": {
"allow_tls": true
"allow_tls": true
},
{{- end }}
{{- if .Values.global.tls.verify }}
"verify_incoming_rpc": true,
"verify_outgoing": true,
"verify_server_hostname": true,
{{- end }}
"ports": {
{{- if .Values.global.tls.httpsOnly }}
"http": -1,
{{- end }}
"https": 8501
}
{{- if .Values.global.tls.httpsOnly }}
"http": -1,
{{- end }}
"https": 8501
}
}
{{- end }}
{{- if .Values.ui.enabled }}
Expand Down
6 changes: 3 additions & 3 deletions charts/consul/test/unit/client-daemonset.bats
Original file line number Diff line number Diff line change
Expand Up @@ -903,13 +903,13 @@ load _helpers
yq '.spec.template.spec.containers[0].command | join(" ")' | tee /dev/stderr)

local actual
actual=$(echo $command | jq -r '. | contains("verify_incoming_rpc = true")' | tee /dev/stderr)
actual=$(echo $command | jq -r '. | contains("tls { internal_rpc { verify_incoming = true }}")' | tee /dev/stderr)
[ "${actual}" = "true" ]

actual=$(echo $command | jq -r '. | contains("verify_outgoing = true")' | tee /dev/stderr)
actual=$(echo $command | jq -r '. | contains("tls { defaults { verify_outgoing = true }}")' | tee /dev/stderr)
[ "${actual}" = "true" ]

actual=$(echo $command | jq -r '. | contains("verify_server_hostname = true")' | tee /dev/stderr)
actual=$(echo $command | jq -r '. | contains("tls { internal_rpc { verify_server_hostname = true }}")' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

Expand Down
27 changes: 12 additions & 15 deletions charts/consul/test/unit/server-config-configmap.bats
Original file line number Diff line number Diff line change
Expand Up @@ -678,22 +678,22 @@ load _helpers
yq -r '.data["tls-config.json"]' | tee /dev/stderr)

local actual
actual=$(echo $config | jq -r .ca_file | tee /dev/stderr)
actual=$(echo $config | jq -r .tls.defaults.ca_file | tee /dev/stderr)
[ "${actual}" = "/consul/tls/ca/tls.crt" ]

actual=$(echo $config | jq -r .cert_file | tee /dev/stderr)
actual=$(echo $config | jq -r .tls.defaults.cert_file | tee /dev/stderr)
[ "${actual}" = "/consul/tls/server/tls.crt" ]

actual=$(echo $config | jq -r .key_file | tee /dev/stderr)
actual=$(echo $config | jq -r .tls.defaults.key_file | tee /dev/stderr)
[ "${actual}" = "/consul/tls/server/tls.key" ]

actual=$(echo $config | jq -r .verify_incoming_rpc | tee /dev/stderr)
actual=$(echo $config | jq -r .tls.internal_rpc.verify_incoming | tee /dev/stderr)
[ "${actual}" = "true" ]

actual=$(echo $config | jq -r .verify_outgoing | tee /dev/stderr)
actual=$(echo $config | jq -r .tls.defaults.verify_outgoing | tee /dev/stderr)
[ "${actual}" = "true" ]

actual=$(echo $config | jq -r .verify_server_hostname | tee /dev/stderr)
actual=$(echo $config | jq -r .tls.internal_rpc.verify_server_hostname | tee /dev/stderr)
[ "${actual}" = "true" ]

actual=$(echo $config | jq -c .ports | tee /dev/stderr)
Expand All @@ -710,13 +710,10 @@ load _helpers
yq -r '.data["tls-config.json"]' | tee /dev/stderr)

local actual
actual=$(echo $config | jq -r .verify_incoming_rpc | tee /dev/stderr)
actual=$(echo $config | jq -r .tls.internal_rpc | tee /dev/stderr)
[ "${actual}" = "null" ]

actual=$(echo $config | jq -r .verify_outgoing | tee /dev/stderr)
[ "${actual}" = "null" ]

actual=$(echo $config | jq -r .verify_server_hostname | tee /dev/stderr)
actual=$(echo $config | jq -r .tls.defaults.verify_outgoing | tee /dev/stderr)
[ "${actual}" = "null" ]
}

Expand Down Expand Up @@ -748,7 +745,7 @@ load _helpers
#--------------------------------------------------------------------
# TLS + Vault

@test "server/ConfigMap: sets TLS file paths point to vault secrets when Vault is enabled" {
@test "server/ConfigMap: sets TLS file paths to point to vault secrets when Vault is enabled" {
cd `chart_dir`
local object=$(helm template \
-s templates/server-config-configmap.yaml \
Expand All @@ -764,13 +761,13 @@ load _helpers
. | tee /dev/stderr |
yq -r '.data["tls-config.json"]' | tee /dev/stderr)

local actual=$(echo $object | jq -r .ca_file | tee /dev/stderr)
local actual=$(echo $object | jq -r .tls.defaults.ca_file | tee /dev/stderr)
[ "${actual}" = "/vault/secrets/serverca.crt" ]

local actual=$(echo $object | jq -r .cert_file | tee /dev/stderr)
local actual=$(echo $object | jq -r .tls.defaults.cert_file | tee /dev/stderr)
[ "${actual}" = "/vault/secrets/servercert.crt" ]

local actual=$(echo $object | jq -r .key_file | tee /dev/stderr)
local actual=$(echo $object | jq -r .tls.defaults.key_file | tee /dev/stderr)
[ "${actual}" = "/vault/secrets/servercert.key" ]
}

Expand Down
2 changes: 1 addition & 1 deletion charts/consul/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ global:
serverAdditionalIPSANs: []

# If true, `verify_outgoing`, `verify_server_hostname`,
# and `verify_incoming_rpc` will be set to `true` for Consul servers and clients.
# and `verify_incoming` for internal RPC communication will be set to `true` for Consul servers and clients.
# Set this to false to incrementally roll out TLS on an existing Consul cluster.
# Please see https://consul.io/docs/k8s/operations/tls-on-existing-cluster
# for more details.
Expand Down

0 comments on commit 0d7552e

Please sign in to comment.