From 5122969bd52ca14a9bc6e9c440d55545e2fac57e Mon Sep 17 00:00:00 2001 From: Melvin GABALI Date: Thu, 22 Jan 2026 02:54:30 +0100 Subject: [PATCH] k8s --- helm/tls-sync-wildcard/ops/Dockerfile.example | 22 ++++++++++++ .../ops/templates/cronjob.yaml | 34 ++++++++----------- helm/tls-sync-wildcard/ops/values.yaml | 12 ++++--- 3 files changed, 44 insertions(+), 24 deletions(-) create mode 100644 helm/tls-sync-wildcard/ops/Dockerfile.example diff --git a/helm/tls-sync-wildcard/ops/Dockerfile.example b/helm/tls-sync-wildcard/ops/Dockerfile.example new file mode 100644 index 0000000..4705eb4 --- /dev/null +++ b/helm/tls-sync-wildcard/ops/Dockerfile.example @@ -0,0 +1,22 @@ +# Exemple de Dockerfile pour créer une image personnalisée SLE avec kubectl et jq +# Usage: docker build -t harbor.gkdomaine.local/images/kubectl-sle:1.33.0 -f Dockerfile.example . + +FROM registry.suse.com/caasp/v4/kubectl:1.33 + +# Installer jq (nécessite root pour l'installation) +USER root +RUN zypper --non-interactive install -y jq && \ + zypper clean -a + +# Créer un utilisateur non-root +RUN useradd -u 1000 -m -s /bin/bash user && \ + mkdir -p /home/user/.kube && \ + chown -R user:user /home/user + +# Passer à l'utilisateur non-root +USER user +WORKDIR /home/user + +# Vérifier que kubectl et jq sont disponibles +RUN kubectl version --client && jq --version + diff --git a/helm/tls-sync-wildcard/ops/templates/cronjob.yaml b/helm/tls-sync-wildcard/ops/templates/cronjob.yaml index a5cb714..18c5da2 100644 --- a/helm/tls-sync-wildcard/ops/templates/cronjob.yaml +++ b/helm/tls-sync-wildcard/ops/templates/cronjob.yaml @@ -25,31 +25,23 @@ spec: image: {{ .Values.tlsSync.image.repository }}:{{ .Values.tlsSync.image.tag }} imagePullPolicy: {{ .Values.tlsSync.image.pullPolicy }} securityContext: - runAsUser: 0 # Nécessaire pour installer jq avec zypper/yum/apt-get + runAsNonRoot: true + runAsUser: 1000 + allowPrivilegeEscalation: false + readOnlyRootFilesystem: false # Nécessaire pour /tmp + capabilities: + drop: + - ALL command: - /bin/bash - -c - | set -e - # Installer jq si nécessaire (pour SLE) + # Vérifier que jq est disponible (doit être dans l'image) if ! command -v jq &> /dev/null; then - echo "Installation de jq..." - if command -v zypper &> /dev/null; then - zypper --non-interactive install -y jq || echo "⚠️ Impossible d'installer jq avec zypper" - elif command -v yum &> /dev/null; then - yum install -y jq || echo "⚠️ Impossible d'installer jq avec yum" - elif command -v apt-get &> /dev/null; then - apt-get update && apt-get install -y jq || echo "⚠️ Impossible d'installer jq avec apt-get" - else - echo "❌ Aucun gestionnaire de paquets trouvé pour installer jq" - exit 1 - fi - fi - - # Vérifier que jq est maintenant disponible - if ! command -v jq &> /dev/null; then - echo "❌ Erreur: jq n'est pas disponible et n'a pas pu être installé" + echo "❌ Erreur: jq n'est pas disponible dans l'image" + echo " Utilisez une image qui contient jq (ex: alpine/k8s, bitnami/kubectl, ou créez une image personnalisée)" exit 1 fi @@ -63,14 +55,16 @@ spec: --sourceNS "{{ .Values.tlsSync.sourceNamespace }}" volumeMounts: - name: kubeconfig - mountPath: /root/.kube + mountPath: /home/user/.kube readOnly: true - name: script mountPath: /scripts readOnly: true env: - name: KUBECONFIG - value: /root/.kube/config + value: /home/user/.kube/config + - name: HOME + value: /home/user resources: {{- toYaml .Values.tlsSync.resources | nindent 14 }} volumes: diff --git a/helm/tls-sync-wildcard/ops/values.yaml b/helm/tls-sync-wildcard/ops/values.yaml index 4c3da58..96bbcd2 100644 --- a/helm/tls-sync-wildcard/ops/values.yaml +++ b/helm/tls-sync-wildcard/ops/values.yaml @@ -7,11 +7,15 @@ tlsSync: sourceCluster: "cluster-ops" sourceNamespace: "certificates-ops" - # Image à utiliser (doit contenir kubectl et bash) - # Utilise SLE (SUSE Linux Enterprise) kubectl + # Image à utiliser (doit contenir kubectl, bash ET jq) + # IMPORTANT: L'image doit contenir jq car le conteneur s'exécute en non-root (sécurité) + # Options recommandées: + # - alpine/k8s (contient kubectl et jq) + # - bitnami/kubectl (contient kubectl, peut nécessiter jq) + # - Image personnalisée basée sur SLE avec jq pré-installé image: - repository: registry.suse.com/suse/kubectl - tag: "1.33" # ou une version spécifique comme "1.31.0" + repository: alpine/k8s + tag: "1.33.0" # Version de kubectl pullPolicy: IfNotPresent # Ressources