Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,46 @@ jobs:

- name: End-to-end tests
run: test/e2e/data-encryption.sh

webhook-cert-manager:
name: Webhook certificate (Helm ${{ matrix.helm }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- helm: v3.22.1
sha256: 896cf63684a42a723d61c980369d6e588330927deb13676ca0d85006dd6da0ea
- helm: v4.2.4
sha256: c306b46f719b0a4da32d0f78ee21bf90ce8d602f15b22ab753f0674d1670a7f3
steps:

- name: Checkout
uses: actions/checkout@v2
with:
submodules: recursive

- name: Install Helm ${{ matrix.helm }}
run: |
curl -fsSLO https://get.helm.sh/helm-${{ matrix.helm }}-linux-amd64.tar.gz
echo "${{ matrix.sha256 }} helm-${{ matrix.helm }}-linux-amd64.tar.gz" | sha256sum -c
mkdir -p "$RUNNER_TEMP/helm"
tar -xzf helm-${{ matrix.helm }}-linux-amd64.tar.gz -C "$RUNNER_TEMP/helm"
echo "HELM=$RUNNER_TEMP/helm/linux-amd64/helm" >> "$GITHUB_ENV"
"$RUNNER_TEMP/helm/linux-amd64/helm" version --short

- name: Build chart dependencies
run: |
"$HELM" dependency build charts/apisix-ingress-controller

- name: Render tests
run: test/render/webhook-cert-manager.sh

- name: Create Kubernetes cluster
uses: ./.github/actions/setup-kind
with:
version: v0.33.0
image: kindest/node:v1.37.0@sha256:a1ed56cfb0e7b93589bdf97c8cd566405a265939e3620fc4f5de89adff580ae5

- name: End-to-end tests
run: test/e2e/webhook-cert-manager.sh
2 changes: 1 addition & 1 deletion charts/apisix-ingress-controller/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ keywords:
- nginx
- crd
type: application
version: 1.5.0
version: 1.6.0
appVersion: 2.2.0
sources:
- https://github.com/apache/apisix-helm-chart
Expand Down
3 changes: 3 additions & 0 deletions charts/apisix-ingress-controller/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ The same for container level, you need to set:
| serviceMonitor.metricRelabelings | object | `{}` | @param serviceMonitor.metricRelabelings MetricRelabelConfigs to apply to samples before ingestion. ref: https://prometheus.io/docs/prometheus/latest/configuration/configuration/#metric_relabel_configs |
| serviceMonitor.namespace | string | `"monitoring"` | @param serviceMonitor.namespace Namespace in which to create the ServiceMonitor |
| webhook.annotations | object | `{}` | Annotations for the ValidatingWebhookConfiguration, e.g. `cert-manager.io/inject-ca-from: <namespace>/<certificate>` so cert-manager's cainjector maintains the webhook caBundle. Only use CA injection with `certificate.provided: true` and `certificate.caBundle` unset; otherwise the injected CA replaces the chart-generated one and the webhook TLS handshake fails. |
| webhook.certManager.duration | string | `"8760h"` | Lifetime of the webhook certificate. cert-manager renews it before it expires. |
| webhook.certManager.enabled | bool | `false` | Use cert-manager to issue the webhook certificate and inject its CA into the webhook configuration. The chart then renders the same manifests every time instead of generating a certificate at render time, which keeps GitOps tools such as Argo CD in sync. Requires cert-manager in the cluster. Cannot be combined with `certificate.provided`. |
| webhook.certManager.issuerRef | object | `{}` | Issuer for the webhook certificate, e.g. `{name: my-issuer, kind: ClusterIssuer}`. When empty, the chart creates a self-signed Issuer. |
| webhook.certificate.provided | bool | `false` | Set to true if you want to provide your own certificate |
| webhook.enabled | bool | `true` | Enable or disable admission webhook |
| webhook.failurePolicy | string | `"Ignore"` | Failure policy for the webhook (Fail or Ignore) |
Expand Down
7 changes: 7 additions & 0 deletions charts/apisix-ingress-controller/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ Webhook service name - ensure it stays within 63 character limit
{{/*
Webhook secret name - use value from values.yaml if provided, otherwise generate one
*/}}
{{- define "apisix-ingress-controller-manager.webhook.issuerName" -}}
{{- $suffix := "-webhook-issuer" -}}
{{- $maxLen := sub 63 (len $suffix) | int -}}
{{- $baseName := include "apisix-ingress-controller-manager.name.fullname" . | trunc $maxLen | trimSuffix "-" -}}
{{- printf "%s%s" $baseName $suffix -}}
{{- end }}

{{- define "apisix-ingress-controller-manager.webhook.secretName" -}}
{{- if and .Values.webhook.certificate.provided .Values.webhook.certificate.secretName -}}
{{- .Values.webhook.certificate.secretName -}}
Expand Down
110 changes: 83 additions & 27 deletions charts/apisix-ingress-controller/templates/webhook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,19 @@
# limitations under the License.
#
{{- if .Values.webhook.enabled }}
{{- /* webhook.certManager is missing from the values of chart versions before 1.6.0, which
helm upgrade --reuse-values renders with */}}
{{- $certManager := .Values.webhook.certManager | default dict -}}
{{- $certManagerEnabled := $certManager.enabled | default false -}}
{{- if and $certManagerEnabled .Values.webhook.certificate.provided }}
{{- fail "webhook.certManager.enabled and webhook.certificate.provided cannot both be true" }}
{{- end }}
{{- /* the chart only generates a certificate when neither the user nor cert-manager provides one */}}
{{- $generateCert := and (not .Values.webhook.certificate.provided) (not $certManagerEnabled) -}}
{{- $certCert := "" -}}
{{- $certKey := "" -}}
{{- $caCert := "" -}}
{{- if not .Values.webhook.certificate.provided }}
{{- if $generateCert }}
{{- $cn := printf "%s.%s.svc" (include "apisix-ingress-controller-manager.webhook.serviceName" .) .Release.Namespace -}}
{{- $ca := genCA "apisix-ingress-webhook-ca" 3650 -}}
{{- $cert := genSignedCert $cn nil (list $cn) 3650 $ca -}}
Expand All @@ -39,7 +48,11 @@ apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
metadata:
name: {{ include "apisix-ingress-controller-manager.name.fullname" . }}-webhook
{{- with .Values.webhook.annotations }}
{{- $annotations := deepCopy (.Values.webhook.annotations | default dict) }}
{{- if $certManagerEnabled }}
{{- $_ := set $annotations "cert-manager.io/inject-ca-from" (printf "%s/%s" .Release.Namespace (include "apisix-ingress-controller-manager.webhook.secretName" .)) }}
{{- end }}
{{- with $annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
Expand All @@ -49,9 +62,9 @@ webhooks:
- name: vapisixroute-v2.kb.io
admissionReviewVersions: ["v1"]
clientConfig:
{{- if not .Values.webhook.certificate.provided }}
{{- if $generateCert }}
caBundle: {{ b64enc $caCert }}
{{- else }}
{{- else if not $certManagerEnabled }}
caBundle: {{ .Values.webhook.certificate.caBundle }}
{{- end }}
service:
Expand All @@ -71,9 +84,9 @@ webhooks:
- name: vapisixconsumer-v2.kb.io
admissionReviewVersions: ["v1"]
clientConfig:
{{- if not .Values.webhook.certificate.provided }}
{{- if $generateCert }}
caBundle: {{ b64enc $caCert }}
{{- else }}
{{- else if not $certManagerEnabled }}
caBundle: {{ .Values.webhook.certificate.caBundle }}
{{- end }}
service:
Expand All @@ -93,9 +106,9 @@ webhooks:
- name: vapisixtls-v2.kb.io
admissionReviewVersions: ["v1"]
clientConfig:
{{- if not .Values.webhook.certificate.provided }}
{{- if $generateCert }}
caBundle: {{ b64enc $caCert }}
{{- else }}
{{- else if not $certManagerEnabled }}
caBundle: {{ .Values.webhook.certificate.caBundle }}
{{- end }}
service:
Expand All @@ -115,9 +128,9 @@ webhooks:
- name: vconsumer-v1alpha1.kb.io
admissionReviewVersions: ["v1"]
clientConfig:
{{- if not .Values.webhook.certificate.provided }}
{{- if $generateCert }}
caBundle: {{ b64enc $caCert }}
{{- else }}
{{- else if not $certManagerEnabled }}
caBundle: {{ .Values.webhook.certificate.caBundle }}
{{- end }}
service:
Expand All @@ -137,9 +150,9 @@ webhooks:
- name: vgatewayproxy-v1alpha1.kb.io
admissionReviewVersions: ["v1"]
clientConfig:
{{- if not .Values.webhook.certificate.provided }}
{{- if $generateCert }}
caBundle: {{ b64enc $caCert }}
{{- else }}
{{- else if not $certManagerEnabled }}
caBundle: {{ .Values.webhook.certificate.caBundle }}
{{- end }}
service:
Expand All @@ -159,9 +172,9 @@ webhooks:
- name: vingress-v1.kb.io
admissionReviewVersions: ["v1"]
clientConfig:
{{- if not .Values.webhook.certificate.provided }}
{{- if $generateCert }}
caBundle: {{ b64enc $caCert }}
{{- else }}
{{- else if not $certManagerEnabled }}
caBundle: {{ .Values.webhook.certificate.caBundle }}
{{- end }}
service:
Expand All @@ -181,9 +194,9 @@ webhooks:
- name: vingressclass-v1.kb.io
admissionReviewVersions: ["v1"]
clientConfig:
{{- if not .Values.webhook.certificate.provided }}
{{- if $generateCert }}
caBundle: {{ b64enc $caCert }}
{{- else }}
{{- else if not $certManagerEnabled }}
caBundle: {{ .Values.webhook.certificate.caBundle }}
{{- end }}
service:
Expand All @@ -203,9 +216,9 @@ webhooks:
- name: vgateway-v1.kb.io
admissionReviewVersions: ["v1"]
clientConfig:
{{- if not .Values.webhook.certificate.provided }}
{{- if $generateCert }}
caBundle: {{ b64enc $caCert }}
{{- else }}
{{- else if not $certManagerEnabled }}
caBundle: {{ .Values.webhook.certificate.caBundle }}
{{- end }}
service:
Expand All @@ -225,9 +238,9 @@ webhooks:
- name: vgrpcroute-v1.kb.io
admissionReviewVersions: ["v1"]
clientConfig:
{{- if not .Values.webhook.certificate.provided }}
{{- if $generateCert }}
caBundle: {{ b64enc $caCert }}
{{- else }}
{{- else if not $certManagerEnabled }}
caBundle: {{ .Values.webhook.certificate.caBundle }}
{{- end }}
service:
Expand All @@ -247,9 +260,9 @@ webhooks:
- name: vhttproute-v1.kb.io
admissionReviewVersions: ["v1"]
clientConfig:
{{- if not .Values.webhook.certificate.provided }}
{{- if $generateCert }}
caBundle: {{ b64enc $caCert }}
{{- else }}
{{- else if not $certManagerEnabled }}
caBundle: {{ .Values.webhook.certificate.caBundle }}
{{- end }}
service:
Expand All @@ -269,9 +282,9 @@ webhooks:
- name: vtcproute-v1.kb.io
admissionReviewVersions: ["v1"]
clientConfig:
{{- if not .Values.webhook.certificate.provided }}
{{- if $generateCert }}
caBundle: {{ b64enc $caCert }}
{{- else }}
{{- else if not $certManagerEnabled }}
caBundle: {{ .Values.webhook.certificate.caBundle }}
{{- end }}
service:
Expand All @@ -291,9 +304,9 @@ webhooks:
- name: vudproute-v1.kb.io
admissionReviewVersions: ["v1"]
clientConfig:
{{- if not .Values.webhook.certificate.provided }}
{{- if $generateCert }}
caBundle: {{ b64enc $caCert }}
{{- else }}
{{- else if not $certManagerEnabled }}
caBundle: {{ .Values.webhook.certificate.caBundle }}
{{- end }}
service:
Expand Down Expand Up @@ -328,7 +341,7 @@ spec:
selector:
{{- include "apisix-ingress-controller-manager.selectorLabels" . | nindent 4 }}

{{- if not .Values.webhook.certificate.provided }}
{{- if $generateCert }}
---
apiVersion: v1
kind: Secret
Expand All @@ -343,4 +356,47 @@ data:
tls.key: {{ b64enc $certKey }}
ca.crt: {{ b64enc $caCert }}
{{- end }}
{{- if $certManagerEnabled }}
{{- $issuerRef := $certManager.issuerRef | default dict }}
{{- if not $issuerRef.name }}
---
apiVersion: cert-manager.io/v1
kind: Issuer
metadata:
name: {{ include "apisix-ingress-controller-manager.webhook.issuerName" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "apisix-ingress-controller-manager.labels" . | nindent 4 }}
spec:
selfSigned: {}
{{- end }}
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: {{ include "apisix-ingress-controller-manager.webhook.secretName" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "apisix-ingress-controller-manager.labels" . | nindent 4 }}
spec:
secretName: {{ include "apisix-ingress-controller-manager.webhook.secretName" . }}
{{- with $certManager.duration }}
duration: {{ . }}
{{- end }}
commonName: apisix-ingress-webhook
dnsNames:
- {{ include "apisix-ingress-controller-manager.webhook.serviceName" . }}
- {{ include "apisix-ingress-controller-manager.webhook.serviceName" . }}.{{ .Release.Namespace }}
- {{ include "apisix-ingress-controller-manager.webhook.serviceName" . }}.{{ .Release.Namespace }}.svc
issuerRef:
{{- if $issuerRef.name }}
name: {{ $issuerRef.name }}
kind: {{ $issuerRef.kind | default "Issuer" }}
group: {{ $issuerRef.group | default "cert-manager.io" }}
{{- else }}
name: {{ include "apisix-ingress-controller-manager.webhook.issuerName" . }}
kind: Issuer
group: cert-manager.io
{{- end }}
{{- end }}
{{- end }}
7 changes: 7 additions & 0 deletions charts/apisix-ingress-controller/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ webhook:
failurePolicy: Ignore
# -- Timeout in seconds for the webhook
timeoutSeconds: 10
certManager:
# -- Use cert-manager to issue the webhook certificate and inject its CA into the webhook configuration. The chart then renders the same manifests every time instead of generating a certificate at render time, which keeps GitOps tools such as Argo CD in sync. Requires cert-manager in the cluster. Cannot be combined with `certificate.provided`.
enabled: false
# -- Issuer for the webhook certificate, e.g. `{name: my-issuer, kind: ClusterIssuer}`. When empty, the chart creates a self-signed Issuer.
issuerRef: {}
# -- Lifetime of the webhook certificate. cert-manager renews it before it expires.
duration: 8760h
certificate:
# -- Set to true if you want to provide your own certificate
provided: false
Expand Down
Loading
Loading