Skip to content

Commit 8ec1c2e

Browse files
authored
Optional toggle to use k8s-wireguard-mgr for keygen hook (#51)
What --- When running through a system such as argo, which doesn't correctly handle the helm hook directives and always runs the install phase hook, more graceful handling of the case of the secret already existing is needed. This is also beneficial for cases where the release has been uninstalled and one wants to re-use the existing key on a new install. This introduces a new boolean toggle to opt into using the k8s-wireguard-mgr image found here: https://github.com/bryopsida/k8s-wireguard-mgr This image generates the server key, if an error is returned from the kubernetes API it inspects the reason, if the reason is already exists, it exits with status code 0. The reason it always attempts to create the secret is to avoid giving the hook/job serviceaccount access to read secrets. The toggle is enabled with the value `keygenJob.useWireguardManager`, the image used can be customized with - keygenJob.wireguardMgrImage.repository - keygenJob.wireguardMgrImage.tag Relates to: #46
1 parent 643d87f commit 8ec1c2e

File tree

6 files changed

+45
-4
lines changed

6 files changed

+45
-4
lines changed

ci/test-with-wgmgr-keygen.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
keygenJob:
2+
useWireguardManager: true

helm/wireguard/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v2
22
name: wireguard
33
description: A Helm chart for managing a wireguard vpn in kubernetes
44
type: application
5-
version: 0.24.0
5+
version: 0.25.0
66
appVersion: "0.0.0"
77
maintainers:
88
- name: bryopsida

helm/wireguard/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# wireguard
22

3-
![Version: 0.24.0](https://img.shields.io/badge/Version-0.24.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 0.0.0](https://img.shields.io/badge/AppVersion-0.0.0-informational?style=flat-square)
3+
![Version: 0.25.0](https://img.shields.io/badge/Version-0.25.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 0.0.0](https://img.shields.io/badge/AppVersion-0.0.0-informational?style=flat-square)
44

55
A Helm chart for managing a wireguard vpn in kubernetes
66

@@ -64,6 +64,8 @@ A Helm chart for managing a wireguard vpn in kubernetes
6464
| keygenJob.podSecurityContext.fsGroup | int | `1000` | |
6565
| keygenJob.podSecurityContext.fsGroupChangePolicy | string | `"Always"` | |
6666
| keygenJob.podSecurityContext.seccompProfile.type | string | `"RuntimeDefault"` | |
67+
| keygenJob.useWireguardManager | bool | `false` | when enabled, uses a image with go bindings for k8s and wg to create the secret if it does not exist, on re-runs it it leaves the existing secret in place and exits succesfully |
68+
| keygenJob.wireguardMgrImage | object | `{"pullPolicy":"Always","repository":"ghcr.io/bryopsida/k8s-wireguard-mgr","tag":"main"}` | When useWireguardManager is enabled this image is used instead of the kubectl image |
6769
| labels | object | `{}` | |
6870
| metrics.dashboard.annotations | object | `{}` | Grafana dashboard annotations |
6971
| metrics.dashboard.enabled | bool | `true` | Create a ConfigMap with a Grafana dashboard |
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# kics-scan ignore
2+
service:
3+
type: ClusterIP
4+
wireguard:
5+
clients:
6+
- AllowedIPs: 172.32.32.2/32
7+
# used for testing only
8+
PublicKey: NzYmaNXHi8+3NBpg7uoRFw7wO+fLG65gZToKqtecLAo=
9+
serverAddress: 172.32.32.1/24
10+
serverCidr: 172.32.32.0/24
11+
replicaCount: 1
12+
autoscaling:
13+
enabled: false
14+
deploymentStrategy:
15+
type: Recreate
16+
keygenJob:
17+
useWireguardManager: true

helm/wireguard/templates/privatekey-gen-job.yaml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,17 @@ spec:
119119
mode: 0755
120120
{{- end }}
121121
containers:
122-
- volumeMounts:
122+
- name: keygen-job
123+
{{- if not .Values.keygenJob.useWireguardManager }}
124+
volumeMounts:
123125
- name: script
124126
mountPath: /job/
125-
name: keygen-job
126127
image: "{{ .Values.keygenJob.image.repository }}:{{ .Values.keygenJob.image.tag }}"
127128
imagePullPolicy: "{{ .Values.keygenJob.image.pullPolicy }}"
129+
{{- else }}
130+
image: "{{ .Values.keygenJob.wireguardMgrImage.repository }}:{{ .Values.keygenJob.wireguardMgrImage.tag }}"
131+
imagePullPolicy: "{{ .Values.keygenJob.wireguardMgrImage.pullPolicy }}"
132+
{{- end }}
128133
securityContext: {{ .Values.keygenJob.containerSecurityContext | toYaml | nindent 10 }}
129134
resources:
130135
requests:
@@ -134,7 +139,11 @@ spec:
134139
memory: 64Mi
135140
cpu: "100m"
136141
env:
142+
{{- if .Values.keygenJob.useWireguardManager }}
143+
- name: K8S_WG_MGR_SERVER_SECRET_NAME
144+
{{- else }}
137145
- name: SECRET_NAME
146+
{{- end }}
138147
value: "{{ .Release.Name }}-wg-generated"
139148
- name: RELEASE_NAMESPACE
140149
value: "{{ .Release.Namespace }}"
@@ -151,5 +160,7 @@ spec:
151160
name: {{ tpl $value.secretName $ }}
152161
key: {{ tpl $value.secretPropertyName $ }}
153162
{{- end }}
163+
{{- if not .Values.keygenJob.useWireguardManager }}
154164
command: {{ .Values.keygenJob.command | toYaml | nindent 10}}
165+
{{- end }}
155166
{{- end }}

helm/wireguard/values.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ image:
66
pullPolicy: Always
77

88
keygenJob:
9+
# -- when enabled, uses a image with go bindings for k8s and wg
10+
# to create the secret if it does not exist, on re-runs it
11+
# it leaves the existing secret in place and exits succesfully
12+
useWireguardManager: false
13+
# -- When useWireguardManager is enabled this image is used instead of the kubectl image
14+
wireguardMgrImage:
15+
repository: ghcr.io/bryopsida/k8s-wireguard-mgr
16+
tag: main
17+
pullPolicy: Always
918
image:
1019
repository: ghcr.io/curium-rocks/wg-kubectl
1120
tag: latest

0 commit comments

Comments
 (0)