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

AWS Load Balancer Controller Helm chart option to reuse existing TLS secrets #2239

Closed
ghost opened this issue Sep 21, 2021 · 12 comments
Closed
Assignees
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines.

Comments

@ghost
Copy link

ghost commented Sep 21, 2021

Reposting to this repo as suggested by @kishorj
Original post from #aws/eks-charts#555

Describe the bug
We use the AWS Load Balancer Controller Helm chart from https://github.com/aws/eks-charts but hit an issue when we use it as a subchart with Helm generated TLS certs for the WebHook https://github.com/aws/eks-charts/blob/master/stable/aws-load-balancer-controller/templates/_helpers.tpl#L78 The TLS certs are regenerated unconditionally on every install/upgrade. Our parent chart creates TargetGroupBinding custom resources, so due to the Helm upgrade order, this is what happens during upgrade:

Existing WebHook is running with the current TLS serving cert
Helm upgrades the WebhookConfiguration first and puts in a new CA
TargetGroupBinding CR is applied
WebHook is triggered due to above, but the CA has been updated, and WebHook validation fails with x509 error (CA doesn’t match the TLS serving certs from the previous install)
Upgrade fails consistently
Steps to reproduce

Expected outcome
Fortunately this is easy to fix, and I’ve attached a patch to it that I put together last night. If the Kubernetes Secret for TLS materials exists and keepTLSSecret variable is set, the Secret is not updated but the existing one is used instead. WebHook CA stays the same, validation succeeds and so does the upgrade. This works with Helm 3.1 onwards where the lookup function was added. The default value of keepTLSSecret, if not set, is false, so this does not change the current behavior of the chart. Can you help us ask upstream if this could be included in a future version please?

Environment

Chart name: AWS Load Balancer Controller Helm chart
Chart version: Helm 3.1+
Kubernetes version:
Using EKS (yes/no), if so version? yes
Additional Context:
diff --git a/stable/aws-load-balancer-controller/templates/_helpers.tpl b/stable/aws-load-balancer-controller/templates/_helpers.tpl
index 4304085..d697680 100644
--- a/stable/aws-load-balancer-controller/templates/_helpers.tpl
+++ b/stable/aws-load-balancer-controller/templates/_helpers.tpl
@@ -77,6 +77,12 @@ Generate certificates for webhook
*/}}
{{- define "aws-load-balancer-controller.gen-certs" -}}
{{- $namePrefix := ( include "aws-load-balancer-controller.namePrefix" . ) -}}
+{{- $secret := lookup "v1" "Secret" .Release.Namespace (printf "%s-tls" $namePrefix) -}}
+{{- if and .Values.keepTLSSecret $secret -}}
+caCert: {{ index $secret.data "ca.crt" }}
+clientCert: {{ index $secret.data "tls.crt" }}
+clientKey: {{ index $secret.data "tls.key" }}
+{{- else -}}
{{- $altNames := list ( printf "%s-%s.%s" $namePrefix "webhook-service" .Release.Namespace ) ( printf "%s-%s.%s.svc" $namePrefix "webhook-service" .Release.Namespace ) -}}
{{- $ca := genCA "aws-load-balancer-controller-ca" 3650 -}}
{{- $cert := genSignedCert ( include "aws-load-balancer-controller.fullname" . ) nil $altNames 3650 $ca -}}
@@ -84,6 +90,7 @@ caCert: {{ $ca.Cert | b64enc }}
clientCert: {{ $cert.Cert | b64enc }}
clientKey: {{ $cert.Key | b64enc }}
{{- end -}}
+{{- end -}}

{{/*
Convert map to comma separated key=value string

@kishorj kishorj added the good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. label Sep 21, 2021
@kishorj kishorj changed the title AWS Load Balancer Controller Helm chart AWS Load Balancer Controller Helm chart option to reuse existing TLS secrets Sep 21, 2021
@Rahul-D78
Copy link

/assign

@Rahul-D78
Copy link

I am new to Kubernetes can you please guide me how to fix this bug

@oliviassss
Copy link
Collaborator

@Rahul-D78 Hi are you working on this issue currently? If not I can take it, thanks

@oliviassss
Copy link
Collaborator

/assign

@jdomag
Copy link

jdomag commented Oct 8, 2021

@oliviassss
Yesterday I've fetched the latest master of the helm chart and set below value in values.yaml and upgrade my release. Existing pods were not recreated, but I believe they don't need to be. However I noticed today that my argoCD detected the change in TLS secret, so I'm not sure if it works as expected or maybe I should take some extra steps to make a use of your change?

# keepTLSSecret specifies whether to reuse existing TLS secret for chart upgrade
keepTLSSecret: true

@oliviassss
Copy link
Collaborator

@jdomag can you check which helm version are you using? if the keepTLSSecret is set to true it should reuse the existing TLS secret.

@kishorj
Copy link
Collaborator

kishorj commented Oct 8, 2021

@jdomag, could you also run helm template and verify helm generates the correct manifest?

@jdomag
Copy link

jdomag commented Oct 8, 2021

I use argoCD, not helm directly, however argoCD uses helm v3 as a default as described here https://argo-cd.readthedocs.io/en/stable/user-guide/helm/#helm-version

I see in ArgoCD that manifest was rendered properly setting TLSSecret to true - see screenshot:
image

@jdomag
Copy link

jdomag commented Oct 14, 2021

@kishorj @oliviassss
Is it possible that the fix suggested here prevents updating a secret during the helm upgrade, but aws load balancer controller rotate the certificates anyway every X hours? That would explain why argoCD goes out of sync after some time

@kishorj
Copy link
Collaborator

kishorj commented Oct 14, 2021

@jdomag, the controller does not modify the secrets/rotate certificates. The keepTLSSecret applies during chart upgrades only. We haven't released a new chart with the keepTLSSecret option yet, we plan to do that with the v2.3.0 release. Did you build the helm chart into your own repository?

@jdomag
Copy link

jdomag commented Oct 14, 2021

@kishorj
Yes I cloned the latest master of the repository and installed the controller using that helm chart.

@kishorj
Copy link
Collaborator

kishorj commented Oct 26, 2021

keepTLSSecret option is supported in the v2.3.0 release. Closing this issue.

@jdomag, your issue seems to be related to #2312, you can create a new issue if it is something else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines.
Projects
None yet
Development

No branches or pull requests

4 participants