Skip to content

Commit

Permalink
remote-cluster: add ServiceAccount secret for 1.24+ (#150)
Browse files Browse the repository at this point in the history
* feat(remote-cluster): NOTES.txt namespace var

Signed-off-by: JJGadgets <git@jjgadgets.tech>

* fix(remote-cluster): add ServiceAccount secret

In Kubernetes 1.24, Service Accounts no longer create a default Secret.

Since the user relies on fetching said secret for generating the kubeconfig, this commit fixes the missing Secret by creating it and referencing the Service Account as part of the Helm Chart install.

Signed-off-by: JJGadgets <git@jjgadgets.tech>

* add toggle to disable secret when used as subchart, bump version

* get kubeapi from kubectl

* fix docs

---------

Signed-off-by: JJGadgets <git@jjgadgets.tech>
Co-authored-by: Jens Langhammer <jens.langhammer@beryju.org>
  • Loading branch information
JJGadgets and BeryJu committed Apr 22, 2023
1 parent 82e24cb commit bd155e3
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 9 deletions.
4 changes: 2 additions & 2 deletions charts/authentik-remote-cluster/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v2
version: 1.1.0
appVersion: 2021.10.2
version: 1.1.1
appVersion: 2023.4.1
name: authentik-remote-cluster
description: RBAC required for a remote cluster to be connected to authentik.
type: application
Expand Down
1 change: 1 addition & 0 deletions charts/authentik-remote-cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ RBAC required for a remote cluster to be connected to authentik.
| annotations | object | `{}` | |
| fullnameOverride | string | `""` | |
| nameOverride | string | `""` | |
| serviceAccountSecret.enabled | bool | `true` | |
13 changes: 6 additions & 7 deletions charts/authentik-remote-cluster/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
Run the commands below to get a kubeconfig file for authentik:

# your server name goes here
KUBE_API=https://localhost:8443

SECRET_NAME=$(kubectl get serviceaccount {{ include "authentik-remote-cluster.fullname" . }} -o jsonpath='{.secrets[0].name}')
KUBE_CA=$(kubectl get secret/$SECRET_NAME -o jsonpath='{.data.ca\.crt}')
KUBE_TOKEN=$(kubectl get secret/$SECRET_NAME -o jsonpath='{.data.token}' | base64 --decode)
KUBE_API=$(kubectl config view --minify --output jsonpath="{.clusters[*].cluster.server}")
NAMESPACE={{ .Release.Namespace }}
SECRET_NAME=$(kubectl get serviceaccount {{ include "authentik-remote-cluster.fullname" . }} -o jsonpath='{.secrets[0].name}' 2>/dev/null || echo -n "{{ include "authentik-remote-cluster.fullname" . }}")
KUBE_CA=$(kubectl -n $NAMESPACE get secret/$SECRET_NAME -o jsonpath='{.data.ca\.crt}')
KUBE_TOKEN=$(kubectl -n $NAMESPACE get secret/$SECRET_NAME -o jsonpath='{.data.token}' | base64 --decode)

echo "apiVersion: v1
kind: Config
Expand All @@ -18,7 +17,7 @@ contexts:
- name: default-context
context:
cluster: default-cluster
namespace: {{ .Release.Namespace }}
namespace: $NAMESPACE
user: authentik-user
current-context: default-context
users:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
Expand Down
1 change: 1 addition & 0 deletions charts/authentik-remote-cluster/templates/role.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{- if .Values.serviceAccountSecret.enabled -}}
---
apiVersion: v1
kind: Secret
type: kubernetes.io/service-account-token
metadata:
name: {{ include "authentik-remote-cluster.fullname" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "authentik-remote-cluster.labels" . | nindent 4 }}
annotations:
kubernetes.io/service-account.name: {{ include "authentik-remote-cluster.fullname" . }}
{{- with .Values.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
apiVersion: v1
kind: ServiceAccount
metadata:
Expand Down
3 changes: 3 additions & 0 deletions charts/authentik-remote-cluster/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ nameOverride: ""
fullnameOverride: ""

annotations: {}

serviceAccountSecret:
enabled: true
1 change: 1 addition & 0 deletions charts/authentik/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ redis:
| service.type | string | `"ClusterIP"` | |
| serviceAccount.annotations | object | `{}` | |
| serviceAccount.create | bool | `true` | Service account is needed for managed outposts |
| serviceAccount.serviceAccountSecret.enabled | bool | `false` | As we use the authentik-remote-cluster chart as subchart, and that chart creates a service account secret by default which we don't need here, disable its creation |
| tolerations | list | `[]` | |
| volumeMounts | list | `[]` | |
| volumes | list | `[]` | |
Expand Down
4 changes: 4 additions & 0 deletions charts/authentik/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ serviceAccount:
# -- Service account is needed for managed outposts
create: true
annotations: {}
serviceAccountSecret:
# -- As we use the authentik-remote-cluster chart as subchart, and that chart
# creates a service account secret by default which we don't need here, disable its creation
enabled: false

prometheus:
serviceMonitor:
Expand Down

0 comments on commit bd155e3

Please sign in to comment.