devzone 1.1.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.devcontainer/Dockerfile +4 -4
- package/.devcontainer/{agent-erreurs.sh → agent-errors.sh} +6 -6
- package/.devcontainer/agent-local.sh +2 -2
- package/.devcontainer/{agent-modele.messages → agent-model.messages} +1 -1
- package/.devcontainer/{agent-modele.sh → agent-model.sh} +5 -5
- package/.devcontainer/agent-pod-manifest.sh +4 -4
- package/.devcontainer/{agent-droits.sh → agent-rights.sh} +2 -2
- package/.devcontainer/agent-session.sh +3 -3
- package/.devcontainer/{agent-etat-json.sh → agent-state-json.sh} +6 -6
- package/.devcontainer/agent-workspace.sh +1 -1
- package/.devcontainer/agent.sh +14 -14
- package/.devcontainer/{ia/docker-garde.sh → ai/docker-guard.sh} +1 -1
- package/.devcontainer/{ia → ai}/host-models.sh +2 -2
- package/.devcontainer/{ia/plugins/devzone-garde-v2.js → ai/plugins/devzone-guard-v2.js} +7 -7
- package/.devcontainer/{ia/plugins/devzone-garde.js → ai/plugins/devzone-guard.js} +6 -6
- package/.devcontainer/argocd/argocd.sh +94 -93
- package/.devcontainer/argocd/{catalogue-argocd.sh → catalog-argocd.sh} +3 -3
- package/.devcontainer/argocd/services-hook.sh +8 -8
- package/.devcontainer/argocd/services.sh +1 -1
- package/.devcontainer/catalog/app.sh +209 -0
- package/.devcontainer/catalog/catalog-watcher.sh +130 -0
- package/.devcontainer/{catalogue → catalog}/mysql/app.conf +1 -1
- package/.devcontainer/catalog/mysql/install.sh +87 -0
- package/.devcontainer/catalog/mysql/mysql.sh +262 -0
- package/.devcontainer/catalog/mysql/volume.sh +71 -0
- package/.devcontainer/catalog.sh +231 -0
- package/.devcontainer/chart-direct.sh +1 -1
- package/.devcontainer/cluster.sh +222 -224
- package/.devcontainer/clusters.sh +41 -41
- package/.devcontainer/devcontainer.json +1 -1
- package/.devcontainer/devzone +103 -1506
- package/.devcontainer/devzone-ai-guard.sh +76 -0
- package/.devcontainer/devzone-ai.sh +201 -0
- package/.devcontainer/devzone-cluster.sh +210 -0
- package/.devcontainer/devzone-modules.sh +126 -0
- package/.devcontainer/devzone-platform.sh +189 -0
- package/.devcontainer/devzone-repair.sh +94 -0
- package/.devcontainer/devzone-services.sh +241 -0
- package/.devcontainer/devzone-skill.sh +97 -0
- package/.devcontainer/devzone-status.sh +140 -0
- package/.devcontainer/devzone-version.sh +78 -0
- package/.devcontainer/git-identity.sh +28 -0
- package/.devcontainer/gitlab/argocd.sh +2 -2
- package/.devcontainer/gitlab/chart.sh +2 -2
- package/.devcontainer/gitlab/gitlab.sh +83 -84
- package/.devcontainer/gitlab/installation.sh +111 -111
- package/.devcontainer/gitlab/secrets.sh +47 -47
- package/.devcontainer/gitlab/seed.sh +77 -77
- package/.devcontainer/gitlab/test-gitlab.sh +242 -243
- package/.devcontainer/help.sh +1 -1
- package/.devcontainer/isolation.sh +65 -0
- package/.devcontainer/kind-wrapper.sh +45 -0
- package/.devcontainer/kube-account.sh +199 -0
- package/.devcontainer/kube-config.sh +45 -46
- package/.devcontainer/{invite-kube.sh → kube-prompt.sh} +6 -6
- package/.devcontainer/kube-reachable.sh +64 -0
- package/.devcontainer/{memoire.sh → memory.sh} +1 -1
- package/.devcontainer/metrics-server.sh +2 -2
- package/.devcontainer/opencode.jsonc +2 -2
- package/.devcontainer/packages.sh +228 -0
- package/.devcontainer/password.sh +1 -1
- package/.devcontainer/ports-auto.sh +152 -153
- package/.devcontainer/ports-json.sh +16 -15
- package/.devcontainer/ports.sh +127 -123
- package/.devcontainer/post-create.sh +52 -52
- package/.devcontainer/postgres/postgres.sh +176 -176
- package/.devcontainer/rename-legacy-files.sh +103 -0
- package/.devcontainer/services-admin.sh +5 -5
- package/.devcontainer/skills/devzone/SKILL.md +40 -41
- package/.devcontainer/startup.sh +65 -0
- package/.devcontainer/{etat-gitops.sh → state-gitops.sh} +1 -1
- package/.devcontainer/{etat-json.sh → state-json.sh} +39 -65
- package/.devcontainer/{etat-verrou.sh → state-lock.sh} +1 -1
- package/.devcontainer/{etat.sh → state.sh} +4 -4
- package/.devcontainer/workspace-init.sh +17 -3
- package/Makefile +8 -8
- package/README.md +195 -194
- package/charts/devzone-workspace/templates/statefulset.yaml +1 -1
- package/manage/devzone +8 -10
- package/manage/scripts/argocd-workspace.sh +1 -1
- package/manage/scripts/check-go-layout.sh +40 -0
- package/manage/scripts/check-names.sh +61 -0
- package/manage/scripts/create-cluster.sh +1 -1
- package/manage/scripts/create-mode.sh +2 -2
- package/manage/scripts/devzone-create.sh +5 -5
- package/manage/scripts/devzone-manifest.sh +3 -3
- package/manage/scripts/devzone-update.sh +12 -8
- package/manage/scripts/docker-workstation.sh +2 -2
- package/manage/scripts/docker.sh +2 -2
- package/manage/scripts/{lancer.sh → launch.sh} +10 -51
- package/manage/scripts/{migrer-retour.sh → migrate-revert.sh} +4 -4
- package/manage/scripts/{migrer.sh → migrate.sh} +8 -14
- package/manage/scripts/ports-apps.sh +1 -1
- package/manage/scripts/ports-workspace.sh +7 -7
- package/manage/scripts/{desinstaller.sh → uninstall.sh} +8 -8
- package/manage/scripts/workspace-egress.sh +2 -2
- package/manage/scripts/workspace-update.sh +5 -2
- package/manage/scripts/workspace-wait.sh +2 -2
- package/manage/workspace.sh +4 -4
- package/package.json +1 -1
- package/.devcontainer/catalogue/app.sh +0 -211
- package/.devcontainer/catalogue/catalogue-veilleur.sh +0 -130
- package/.devcontainer/catalogue/mysql/installer.sh +0 -87
- package/.devcontainer/catalogue/mysql/mysql.sh +0 -262
- package/.devcontainer/catalogue/mysql/volume.sh +0 -71
- package/.devcontainer/catalogue.sh +0 -231
- package/.devcontainer/demarrage.sh +0 -66
- package/.devcontainer/docker-relais.sh +0 -149
- package/.devcontainer/docker-sans-hote.sh +0 -12
- package/.devcontainer/git-identite.sh +0 -28
- package/.devcontainer/isolement.sh +0 -65
- package/.devcontainer/kind-enveloppe.sh +0 -45
- package/.devcontainer/kube-compte.sh +0 -200
- package/.devcontainer/kube-joignable.sh +0 -64
- package/.devcontainer/paquets.sh +0 -227
- /package/.devcontainer/{ia/docker-garde.message → ai/docker-guard.message} +0 -0
- /package/.devcontainer/{ia → ai}/host-check.message +0 -0
- /package/.devcontainer/{ia → ai}/host-check.sh +0 -0
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Relais du socket Docker (#293), lancé en premier par demarrage.sh.
|
|
3
|
-
#
|
|
4
|
-
# Pourquoi : la feature docker-outside-of-docker relaie le socket de l'hôte
|
|
5
|
-
# par « socat UNIX-LISTEN:/var/run/docker.sock,… UNIX-CONNECT:… » sans
|
|
6
|
-
# option -t (seulement sous Docker Desktop, socket au gid 0 ; sous Linux elle
|
|
7
|
-
# passe par un groupe, sans socat). Dès que le client ferme son côté (un
|
|
8
|
-
# « docker exec » sans entrée standard), socat coupe la connexion 0,5 s plus
|
|
9
|
-
# tard : la sortie est tronquée et docker exec renvoie quand même 0. kind lance
|
|
10
|
-
# kubeadm init ainsi, et le croit réussi au bout de 0,5 s (cluster kind et
|
|
11
|
-
# module gitlab impossibles depuis devzone). Le même socat avec -t 86400 laisse
|
|
12
|
-
# passer la réponse du démon jusqu'à ce qu'il ferme lui-même.
|
|
13
|
-
#
|
|
14
|
-
# Ce que fait le script : relais de la feature sans -t → remplacé par le même
|
|
15
|
-
# avec -t 86400 (fichier PID de la feature mis à jour, docker-init.sh ne le
|
|
16
|
-
# relance donc pas) ; puis contrôle qu'un docker exec long va au bout. Sans
|
|
17
|
-
# relais socat (Linux), seul le contrôle est fait. Idempotent.
|
|
18
|
-
#
|
|
19
|
-
# Sûr par construction : chemins et commandes réglables (tests : tout sous un
|
|
20
|
-
# dossier temporaire), et refus de toucher au vrai socket sans
|
|
21
|
-
# DEVZONE_RELAIS_REEL=oui, que seuls demarrage.sh et devzone repair posent.
|
|
22
|
-
# Code : 0 contrôle réussi, 1 contrôle en échec (marque écrite pour le
|
|
23
|
-
# récapitulatif devzone), 2 refus de la garde. Compatible bash 3.2.
|
|
24
|
-
set -euo pipefail
|
|
25
|
-
|
|
26
|
-
SOCKET="${DEVZONE_RELAIS_SOCKET:-/var/run/docker.sock}"
|
|
27
|
-
SOURCE="${DEVZONE_RELAIS_SOURCE:-/var/run/docker-host.sock}"
|
|
28
|
-
# Fichiers de la feature (/usr/local/share/docker-init.sh : SOCAT_PID, SOCAT_LOG)
|
|
29
|
-
PID_FICHIER="${DEVZONE_RELAIS_PID:-/tmp/vscr-docker-from-docker.pid}"
|
|
30
|
-
JOURNAL="${DEVZONE_RELAIS_LOG:-/tmp/vscr-docker-from-docker.log}"
|
|
31
|
-
UTILISATEUR="${DEVZONE_RELAIS_UTILISATEUR:-vscode}"
|
|
32
|
-
DOCKER="${DEVZONE_RELAIS_DOCKER:-docker}"
|
|
33
|
-
# Marque d'échec lue par le récapitulatif (.devcontainer/devzone) : propre au
|
|
34
|
-
# conteneur, effacée à chaque redémarrage avec /tmp
|
|
35
|
-
MARQUE="${DEVZONE_RELAIS_MARQUE:-/tmp/devzone-relais-docker.echec}"
|
|
36
|
-
ATTENTE="${DEVZONE_RELAIS_ATTENTE:-10}"
|
|
37
|
-
# Le relais de la feature tourne en root : sudo sauf si on est déjà root
|
|
38
|
-
if [ -n "${DEVZONE_RELAIS_SUDO+x}" ]; then
|
|
39
|
-
SUDO="$DEVZONE_RELAIS_SUDO"
|
|
40
|
-
elif [ "$(id -u)" = 0 ]; then
|
|
41
|
-
SUDO=""
|
|
42
|
-
else
|
|
43
|
-
SUDO=sudo
|
|
44
|
-
fi
|
|
45
|
-
|
|
46
|
-
if [ -n "${BATS_TEST_TMPDIR:-}" ] && [ "$SOCKET" = /var/run/docker.sock ]; then
|
|
47
|
-
echo "docker-relais : refus sous bats (tests)" >&2
|
|
48
|
-
exit 2
|
|
49
|
-
fi
|
|
50
|
-
|
|
51
|
-
if [ "$SOCKET" = /var/run/docker.sock ] && [ "${DEVZONE_RELAIS_REEL:-}" != oui ]; then
|
|
52
|
-
echo "docker-relais : refus de toucher au vrai socket ($SOCKET) : lancer plutôt devzone repair" >&2
|
|
53
|
-
exit 2
|
|
54
|
-
fi
|
|
55
|
-
|
|
56
|
-
# Sans socket (option docker-hote=off, #432) : rien à relayer ni à contrôler.
|
|
57
|
-
# Sortie 0 pour ne pas gêner le démarrage ; docker renvoie au workspace.
|
|
58
|
-
if [ ! -e "$SOCKET" ]; then
|
|
59
|
-
rm -f "$MARQUE" 2>/dev/null || true
|
|
60
|
-
echo "docker-relais : pas de socket Docker de l'hôte (option docker-hote=off)"
|
|
61
|
-
exit 0
|
|
62
|
-
fi
|
|
63
|
-
|
|
64
|
-
# $SUDO vide : commande lancée par env, jamais en commande intégrée (kill est
|
|
65
|
-
# un builtin de bash : env passe par le PATH, comme sudo ; les tests y mettent
|
|
66
|
-
# leurs faux outils)
|
|
67
|
-
en_root() {
|
|
68
|
-
if [ -n "$SUDO" ]; then
|
|
69
|
-
"$SUDO" "$@"
|
|
70
|
-
else
|
|
71
|
-
env "$@"
|
|
72
|
-
fi
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
echec() {
|
|
76
|
-
echo "docker-relais : $1" >&2
|
|
77
|
-
printf '%s\n' "$1" >"$MARQUE" 2>/dev/null || true
|
|
78
|
-
exit 1
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
# « <pid> <a_t> » du socat qui écoute sur $SOCKET (a_t : 1 s'il a -t), rien
|
|
82
|
-
# sinon. Seul le processus socat lui-même compte (pas un « sudo socat » parent),
|
|
83
|
-
# et seulement s'il écoute sur ce socket-là.
|
|
84
|
-
relais_trouve() {
|
|
85
|
-
local pid args
|
|
86
|
-
while read -r pid args; do
|
|
87
|
-
case "$args" in
|
|
88
|
-
"socat "*) ;;
|
|
89
|
-
*) continue ;;
|
|
90
|
-
esac
|
|
91
|
-
case "$args" in
|
|
92
|
-
*"UNIX-LISTEN:$SOCKET,"* | *"UNIX-LISTEN:$SOCKET "* | *"UNIX-LISTEN:$SOCKET") ;;
|
|
93
|
-
*) continue ;;
|
|
94
|
-
esac
|
|
95
|
-
case " $args " in
|
|
96
|
-
*" -t "*) echo "$pid 1" ;;
|
|
97
|
-
*) echo "$pid 0" ;;
|
|
98
|
-
esac
|
|
99
|
-
return 0
|
|
100
|
-
done < <(ps -eo pid=,args=)
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
remplacer() {
|
|
104
|
-
local ancien="$1" nouveau i
|
|
105
|
-
en_root kill "$ancien" 2>/dev/null || true
|
|
106
|
-
i=0
|
|
107
|
-
while [ "$i" -lt 20 ] && en_root kill -0 "$ancien" 2>/dev/null; do
|
|
108
|
-
sleep 0.1
|
|
109
|
-
i=$((i + 1))
|
|
110
|
-
done
|
|
111
|
-
en_root rm -f "$SOCKET"
|
|
112
|
-
# setsid -f : socat détaché, il survit à la fin du démarrage ; -lf : son
|
|
113
|
-
# journal (fichier de root) est ouvert par socat lui-même
|
|
114
|
-
en_root setsid -f socat -t 86400 -lf "$JOURNAL" \
|
|
115
|
-
"UNIX-LISTEN:$SOCKET,fork,mode=660,user=$UTILISATEUR,backlog=128" \
|
|
116
|
-
"UNIX-CONNECT:$SOURCE" </dev/null >/dev/null 2>&1 ||
|
|
117
|
-
echec "relais non relancé (socat -t 86400)"
|
|
118
|
-
# PID du nouveau socat dans le fichier de la feature : docker-init.sh le
|
|
119
|
-
# voit vivant et ne relance pas l'ancien relais
|
|
120
|
-
i=0
|
|
121
|
-
nouveau=""
|
|
122
|
-
while [ "$i" -lt 20 ]; do
|
|
123
|
-
nouveau="$(relais_trouve || true)"
|
|
124
|
-
[ -n "$nouveau" ] && break
|
|
125
|
-
sleep 0.1
|
|
126
|
-
i=$((i + 1))
|
|
127
|
-
done
|
|
128
|
-
[ -n "$nouveau" ] || echec "relais relancé introuvable (ps)"
|
|
129
|
-
printf '%s\n' "${nouveau%% *}" | en_root tee "$PID_FICHIER" >/dev/null
|
|
130
|
-
echo "✔ relais Docker : socat -t 86400 (docker exec longs non coupés)"
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
trouve="$(relais_trouve || true)"
|
|
134
|
-
if [ -n "$trouve" ] && [ "${trouve##* }" = 0 ]; then
|
|
135
|
-
remplacer "${trouve%% *}"
|
|
136
|
-
fi
|
|
137
|
-
|
|
138
|
-
i=0
|
|
139
|
-
until "$DOCKER" version >/dev/null 2>&1; do
|
|
140
|
-
i=$((i + 1))
|
|
141
|
-
[ "$i" -lt "$ATTENTE" ] || echec "le socket $SOCKET ne répond pas"
|
|
142
|
-
sleep 1
|
|
143
|
-
done
|
|
144
|
-
|
|
145
|
-
# Contrôle : 1 s dépasse les 0,5 s de socat sans -t ; « ok » prouve que la
|
|
146
|
-
# sortie d'un docker exec sans entrée standard arrive en entier
|
|
147
|
-
sortie="$("$DOCKER" exec "$(hostname)" sh -c 'sleep 1; echo ok' </dev/null 2>&1 || true)"
|
|
148
|
-
[ "$sortie" = ok ] || echec "docker exec long coupé (sortie : ${sortie:-vide})"
|
|
149
|
-
rm -f "$MARQUE" 2>/dev/null || true
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Docker du poste non partagé (option docker-hote=off, #432). post-create.sh
|
|
3
|
-
# installe ce script comme commande docker quand la feature
|
|
4
|
-
# docker-outside-of-docker est absente : au lieu d'un « command not found »,
|
|
5
|
-
# un message clair renvoie au workspace Kubernetes.
|
|
6
|
-
cat >&2 <<'MESSAGE'
|
|
7
|
-
✖ Docker du poste non partagé (option docker-hote=off) : docker n'est pas disponible ici.
|
|
8
|
-
Pour lancer des conteneurs, utilise le workspace Kubernetes : devzone workspace
|
|
9
|
-
(docker et Testcontainers y parlent à kubedock, les images sont construites par BuildKit).
|
|
10
|
-
Pour partager le socket Docker de l'hôte : devzone enable docker-hote, puis make rebuild sur le poste.
|
|
11
|
-
MESSAGE
|
|
12
|
-
exit 1
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Identité git, à chaque démarrage tant qu'elle manque : déduite du compte gh
|
|
3
|
-
# (propre à chaque utilisateur, connexion gardée dans son volume) et écrite dans
|
|
4
|
-
# ~/.config/git/config (volume devzone-git, survit aux rebuilds).
|
|
5
|
-
# Une identité déjà définie (à la main, ou recopiée par VS Code dans
|
|
6
|
-
# ~/.gitconfig) n'est jamais remplacée. Email noreply de GitHub : les commits
|
|
7
|
-
# sont rattachés au compte sans exposer l'email personnel.
|
|
8
|
-
set -euo pipefail
|
|
9
|
-
|
|
10
|
-
CONFIG="$HOME/.config/git/config"
|
|
11
|
-
nom_git="$(git config --get user.name || true)"
|
|
12
|
-
email_git="$(git config --get user.email || true)"
|
|
13
|
-
|
|
14
|
-
[ -n "$nom_git" ] && [ -n "$email_git" ] && exit 0
|
|
15
|
-
|
|
16
|
-
# Sans gh : rien à déduire ; le récapitulatif de devzone le signale
|
|
17
|
-
gh auth status >/dev/null 2>&1 || exit 0
|
|
18
|
-
|
|
19
|
-
id="" login="" nom=""
|
|
20
|
-
IFS=$'\t' read -r id login nom < <(gh api user --jq '[.id, .login, (.name // "")] | @tsv' 2>/dev/null || true)
|
|
21
|
-
if [ -z "$id" ] || [ -z "$login" ]; then
|
|
22
|
-
echo "git-identite : compte GitHub illisible (réseau ?) ; relancer : bash .devcontainer/git-identite.sh"
|
|
23
|
-
exit 0
|
|
24
|
-
fi
|
|
25
|
-
|
|
26
|
-
[ -n "$nom_git" ] || git config --file "$CONFIG" user.name "${nom:-$login}"
|
|
27
|
-
[ -n "$email_git" ] || git config --file "$CONFIG" user.email "${id}+${login}@users.noreply.github.com"
|
|
28
|
-
echo "git-identite : $(git config --get user.name) <$(git config --get user.email)>"
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Isolement network et autorisation d'acces entre namespaces devzone.
|
|
3
|
-
# Fichier <= 250 lignes : fonctions namespace_isoler, autoriser, interdire.
|
|
4
|
-
# Ces fonctions modifient des NetworkPolicies dans le cluster Kubernetes.
|
|
5
|
-
# Aides de manage/test/commun.bash : relais_docker_isole, kube_isole.
|
|
6
|
-
|
|
7
|
-
# Pose une NetworkPolicy isolante dans un namespace.
|
|
8
|
-
# Seuls les pods du meme namespace peuvent joindre les services.
|
|
9
|
-
namespace_isoler() {
|
|
10
|
-
local ns="${1:-}"
|
|
11
|
-
[ -n "$ns" ] || { echo "devzone : namespace manquant" >&2; return 2; }
|
|
12
|
-
|
|
13
|
-
kubectl --context devzone -n "$ns" apply -f - <<EOF
|
|
14
|
-
apiVersion: networking.k8s.io/v1
|
|
15
|
-
kind: NetworkPolicy
|
|
16
|
-
metadata:
|
|
17
|
-
name: devzone-meme-namespace
|
|
18
|
-
labels:
|
|
19
|
-
app.kubernetes.io/managed-by: devzone
|
|
20
|
-
spec:
|
|
21
|
-
podSelector: {}
|
|
22
|
-
ingress:
|
|
23
|
-
- from:
|
|
24
|
-
- podSelector: {}
|
|
25
|
-
EOF
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
# Ajoute une règle namespaceSelector dans la NetworkPolicy du namespace cible,
|
|
29
|
-
# permettant l'accès depuis l'extérieur de ce namespace.
|
|
30
|
-
# Sans cette règle, une application dans un autre namespace ne peut pas
|
|
31
|
-
# joindre les services devzone (postgres, etc.).
|
|
32
|
-
autoriser() {
|
|
33
|
-
local ns_cible="${1:-}" patch sortie
|
|
34
|
-
[ -n "$ns_cible" ] || { echo "devzone : namespace cible manquant" >&2; return 2; }
|
|
35
|
-
|
|
36
|
-
kubectl --context devzone -n "$ns_cible" get networkpolicy devzone-meme-namespace \
|
|
37
|
-
-o yaml 2>/dev/null | kubectl --context devzone -n "$ns_cible" apply -f - >/dev/null 2>&1 ||
|
|
38
|
-
{ echo "devzone : impossible d'appliquer la NetworkPolicy isolante dans $ns_cible" >&2; return 1; }
|
|
39
|
-
|
|
40
|
-
patch="$(jq -nc '{"spec":{"ingress":[{"from":[{"podSelector":{},
|
|
41
|
-
"namespaceSelector":{"matchLabels":{"app.kubernetes.io/managed-by":"devzone"}}}]}]}}')"
|
|
42
|
-
if ! sortie="$(kubectl --context devzone -n "$ns_cible" patch networkpolicy devzone-meme-namespace \
|
|
43
|
-
-p "$patch" 2>&1)"; then
|
|
44
|
-
echo "devzone : impossible d'autoriser l'accès vers $ns_cible : $sortie" >&2
|
|
45
|
-
return 1
|
|
46
|
-
fi
|
|
47
|
-
|
|
48
|
-
echo "devzone : règle autorisée vers $ns_cible"
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
# Retire la règle namespaceSelector de la NetworkPolicy,
|
|
52
|
-
# bloquant à nouveau l'accès depuis le namespace specifie.
|
|
53
|
-
interdire() {
|
|
54
|
-
local ns_cible="${1:-}" patch sortie
|
|
55
|
-
[ -n "$ns_cible" ] || { echo "devzone : namespace cible manquant" >&2; return 2; }
|
|
56
|
-
|
|
57
|
-
patch="$(jq -nc '{"spec":{"ingress":[{"from":[{"podSelector":{}}]}]}}')"
|
|
58
|
-
if ! sortie="$(kubectl --context devzone -n "$ns_cible" patch networkpolicy devzone-meme-namespace \
|
|
59
|
-
-p "$patch" 2>&1)"; then
|
|
60
|
-
echo "devzone : impossible d'interdire l'accès vers $ns_cible : $sortie" >&2
|
|
61
|
-
return 1
|
|
62
|
-
fi
|
|
63
|
-
|
|
64
|
-
echo "devzone : règle interdite vers $ns_cible"
|
|
65
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Enveloppe de kind (#291), installée comme /usr/local/bin/kind ; le vrai
|
|
3
|
-
# binaire est kind-reel. Avec le Docker de l'hôte, un cluster créé par
|
|
4
|
-
# « kind create cluster » écrit server: https://127.0.0.1:<port> : injoignable
|
|
5
|
-
# depuis le conteneur. Après une création ou un export de kubeconfig réussis,
|
|
6
|
-
# l'adresse est rendue joignable (kube-joignable.sh). Tout le reste passe tel quel.
|
|
7
|
-
set -uo pipefail
|
|
8
|
-
|
|
9
|
-
KIND_REEL="${DEVZONE_KIND_REEL:-/usr/local/bin/kind-reel}"
|
|
10
|
-
ICI="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
11
|
-
if [ -f "$ICI/kube-joignable.sh" ]; then
|
|
12
|
-
# shellcheck source=SCRIPTDIR/kube-joignable.sh
|
|
13
|
-
. "$ICI/kube-joignable.sh"
|
|
14
|
-
else
|
|
15
|
-
# shellcheck source=/dev/null
|
|
16
|
-
. /usr/local/lib/devzone/kube-joignable.sh
|
|
17
|
-
fi
|
|
18
|
-
|
|
19
|
-
"$KIND_REEL" "$@"
|
|
20
|
-
code=$?
|
|
21
|
-
[ "$code" -eq 0 ] || exit "$code"
|
|
22
|
-
|
|
23
|
-
case "${1:-} ${2:-}" in
|
|
24
|
-
"create cluster" | "export kubeconfig") ;;
|
|
25
|
-
*) exit 0 ;;
|
|
26
|
-
esac
|
|
27
|
-
|
|
28
|
-
# Fichier écrit par kind : --kubeconfig s'il est donné, sinon le premier de
|
|
29
|
-
# KUBECONFIG, sinon ~/.kube/config (même règle que kind)
|
|
30
|
-
fichier=""
|
|
31
|
-
precedent=""
|
|
32
|
-
for arg in "$@"; do
|
|
33
|
-
case "$arg" in
|
|
34
|
-
--kubeconfig=*) fichier="${arg#--kubeconfig=}" ;;
|
|
35
|
-
esac
|
|
36
|
-
[ "$precedent" = "--kubeconfig" ] && fichier="$arg"
|
|
37
|
-
precedent="$arg"
|
|
38
|
-
done
|
|
39
|
-
if [ -z "$fichier" ] && [ -n "${KUBECONFIG:-}" ]; then
|
|
40
|
-
fichier="${KUBECONFIG%%:*}"
|
|
41
|
-
fi
|
|
42
|
-
[ -n "$fichier" ] || fichier="$HOME/.kube/config"
|
|
43
|
-
|
|
44
|
-
kube_joignable_depuis_conteneur "$fichier"
|
|
45
|
-
exit 0
|
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Compte Kubernetes limité (#430) : le contexte devzone (projets, relais,
|
|
3
|
-
# agents) ne peut agir que dans les namespaces devzone-*. Le compte est le
|
|
4
|
-
# ServiceAccount devzone-agent du namespace devzone-system, lié au ClusterRole
|
|
5
|
-
# edit (ni RBAC ni quotas) dans chaque namespace de devzone par un RoleBinding,
|
|
6
|
-
# avec un jeton TokenRequest de 24 h renouvelé au démarrage (demarrage.sh) et
|
|
7
|
-
# par « devzone repair ». Les installeurs utilisent seuls le contexte
|
|
8
|
-
# administrateur (contexte de l hôte dans ~/.kube/hote.config, cluster kind
|
|
9
|
-
# dans ~/.kube/config) ; les shells et les agents n'ont que ~/.kube/config.
|
|
10
|
-
# Bibliothèque sourcée par cluster.sh ; exécutable pour le jeton :
|
|
11
|
-
# kube-compte.sh jeton
|
|
12
|
-
|
|
13
|
-
COMPTES_NS=devzone-system
|
|
14
|
-
COMPTES_SA=devzone-agent
|
|
15
|
-
COMPTES_DUREE=24h
|
|
16
|
-
COMPTES_CONFIG="${DEVZONE_KUBE_CONFIG:-$HOME/.kube/config}"
|
|
17
|
-
|
|
18
|
-
# Fichier kubeconfig qui porte le contexte administrateur ctx : hote.config
|
|
19
|
-
# s'il y figure (clusters de l'hôte), sinon ~/.kube/config (clusters kind du
|
|
20
|
-
# conteneur).
|
|
21
|
-
compte_config_admin() {
|
|
22
|
-
local ctx="$1" hote="${DEVZONE_KUBE_HOTE:-$HOME/.kube/hote.config}"
|
|
23
|
-
if [ -n "$ctx" ] && [ -f "$hote" ]; then
|
|
24
|
-
if KUBECONFIG="$hote" kubectl config get-contexts -o name 2>/dev/null | grep -qx -- "$ctx"; then
|
|
25
|
-
echo "$hote"
|
|
26
|
-
return 0
|
|
27
|
-
fi
|
|
28
|
-
fi
|
|
29
|
-
echo "$COMPTES_CONFIG"
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
# kubectl sur le contexte administrateur : kubeconfig explicite qui porte ce
|
|
33
|
-
# contexte, jamais le KUBECONFIG combiné (l'administrateur ne passe jamais par
|
|
34
|
-
# le compte limité). Sans contexte connu : celui de kubectl.
|
|
35
|
-
compte_admin() {
|
|
36
|
-
local ctx="$1" conf
|
|
37
|
-
shift
|
|
38
|
-
if [ -z "$ctx" ]; then
|
|
39
|
-
ctx="$(kubectl config current-context 2>/dev/null || true)"
|
|
40
|
-
fi
|
|
41
|
-
conf="$(compte_config_admin "$ctx")"
|
|
42
|
-
if [ -n "$ctx" ]; then
|
|
43
|
-
kubectl --kubeconfig="$conf" --context "$ctx" "$@"
|
|
44
|
-
else
|
|
45
|
-
kubectl --kubeconfig="$conf" "$@"
|
|
46
|
-
fi
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
# helm sur le contexte administrateur ctx : les charts créent des CRD, des
|
|
50
|
-
# ClusterRoles ou des RoleBindings, hors des droits du compte limité (edit).
|
|
51
|
-
# Usage : compte_helm <ctx> <args helm…>
|
|
52
|
-
compte_helm() {
|
|
53
|
-
local ctx="$1" conf
|
|
54
|
-
shift
|
|
55
|
-
if [ -z "$ctx" ]; then
|
|
56
|
-
ctx="$(kubectl config current-context 2>/dev/null || true)"
|
|
57
|
-
fi
|
|
58
|
-
conf="$(compte_config_admin "$ctx")"
|
|
59
|
-
if [ -n "$ctx" ]; then
|
|
60
|
-
helm --kubeconfig "$conf" --kube-context "$ctx" "$@"
|
|
61
|
-
else
|
|
62
|
-
helm --kubeconfig "$conf" "$@"
|
|
63
|
-
fi
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
# Contexte administrateur d'une installation : le cluster des services choisi
|
|
67
|
-
# (cluster_lu de cluster.sh), sinon le contexte courant de kubectl.
|
|
68
|
-
compte_ctx() {
|
|
69
|
-
local ctx
|
|
70
|
-
ctx="$(cluster_lu 2>/dev/null || true)"
|
|
71
|
-
if [ -n "$ctx" ]; then
|
|
72
|
-
echo "$ctx"
|
|
73
|
-
return 0
|
|
74
|
-
fi
|
|
75
|
-
kubectl config current-context 2>/dev/null || true
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
# Pose le compte limité avec le contexte administrateur : namespace
|
|
79
|
-
# devzone-system et ServiceAccount devzone-agent (idempotent, repris au
|
|
80
|
-
# démarrage et à chaque installation).
|
|
81
|
-
compte_poser() {
|
|
82
|
-
local ctx="$1"
|
|
83
|
-
compte_admin "$ctx" create namespace "$COMPTES_NS" --dry-run=client -o yaml |
|
|
84
|
-
compte_admin "$ctx" apply -f - >/dev/null || return 1
|
|
85
|
-
compte_admin "$ctx" -n "$COMPTES_NS" create serviceaccount "$COMPTES_SA" \
|
|
86
|
-
--dry-run=client -o yaml | compte_admin "$ctx" apply -f - >/dev/null || return 1
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
# Autorise le compte dans le namespace ns : RoleBinding devzone-agent vers le
|
|
90
|
-
# ClusterRole edit (lecture, écriture, secrets, NetworkPolicies — ni RBAC ni
|
|
91
|
-
# quotas), posé avec le contexte administrateur après la création du namespace.
|
|
92
|
-
# Le compte est posé d'abord s'il manque : une installation sur un cluster
|
|
93
|
-
# encore vierge rend le compte utilisable au prochain renouvellement de jeton.
|
|
94
|
-
compte_autoriser() {
|
|
95
|
-
local ctx="$1" ns="$2"
|
|
96
|
-
compte_poser "$ctx" || return 1
|
|
97
|
-
compte_admin "$ctx" -n "$ns" create rolebinding "$COMPTES_SA" \
|
|
98
|
-
--clusterrole=edit --serviceaccount="$COMPTES_NS:$COMPTES_SA" \
|
|
99
|
-
--dry-run=client -o yaml | compte_admin "$ctx" apply -f - >/dev/null || return 1
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
# Retire l'autorisation du compte dans le namespace ns (désinstallation) :
|
|
103
|
-
# RoleBinding supprimé avec le contexte administrateur.
|
|
104
|
-
compte_retirer() {
|
|
105
|
-
local ctx="$1" ns="$2"
|
|
106
|
-
compte_admin "$ctx" -n "$ns" delete rolebinding "$COMPTES_SA" \
|
|
107
|
-
--ignore-not-found >/dev/null || return 1
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
# Crée et étiquette le namespace ns par l'administrateur puis autorise le compte.
|
|
111
|
-
compte_namespace() {
|
|
112
|
-
local ctx="$1" ns="$2"
|
|
113
|
-
compte_admin "$ctx" create namespace "$ns" --dry-run=client -o yaml |
|
|
114
|
-
compte_admin "$ctx" apply -f - >/dev/null || return 1
|
|
115
|
-
compte_admin "$ctx" label namespace "$ns" "$CLUSTER_ETIQUETTE" --overwrite >/dev/null || return 1
|
|
116
|
-
compte_autoriser "$ctx" "$ns" || return 1
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
# Rattrape les namespaces devzone existants : RoleBinding posée dans chaque
|
|
120
|
-
# namespace étiqueté CLUSTER_ETIQUETTE (idempotent), pour les installations
|
|
121
|
-
# antérieures au compte limité.
|
|
122
|
-
compte_rattraper() {
|
|
123
|
-
local ctx="$1" ns etiquette="${CLUSTER_ETIQUETTE:-app.kubernetes.io/managed-by=devzone}"
|
|
124
|
-
while IFS= read -r ns; do
|
|
125
|
-
[ -n "$ns" ] || continue
|
|
126
|
-
ns="${ns#namespace/}"
|
|
127
|
-
compte_admin "$ctx" -n "$ns" create rolebinding "$COMPTES_SA" \
|
|
128
|
-
--clusterrole=edit --serviceaccount="$COMPTES_NS:$COMPTES_SA" \
|
|
129
|
-
--dry-run=client -o yaml | compte_admin "$ctx" apply -f - >/dev/null || return 1
|
|
130
|
-
done < <(compte_admin "$ctx" get namespaces -l "$etiquette" -o name 2>/dev/null || true)
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
# Renouvelle le jeton du compte (TokenRequest de 24 h) et l'écrit dans le
|
|
134
|
-
# contexte devzone de ~/.kube/config : user devzone-agent, même cluster que le
|
|
135
|
-
# contexte administrateur (entrée cluster copiée : server, autorité de
|
|
136
|
-
# certificat et tls-server-name du contexte de l'hôte).
|
|
137
|
-
compte_jeton() {
|
|
138
|
-
local ctx="$1" conf jeton cluster serveur tls ca_donnees ca_fichier
|
|
139
|
-
local entree=()
|
|
140
|
-
conf="$(compte_config_admin "$ctx")"
|
|
141
|
-
jeton="$(compte_admin "$ctx" create token "$COMPTES_SA" -n "$COMPTES_NS" \
|
|
142
|
-
--duration="$COMPTES_DUREE")" || return 1
|
|
143
|
-
if [ -z "$jeton" ]; then
|
|
144
|
-
echo "devzone : jeton du compte limité vide" >&2
|
|
145
|
-
return 1
|
|
146
|
-
fi
|
|
147
|
-
cluster="$(KUBECONFIG="$conf" kubectl config view \
|
|
148
|
-
-o jsonpath="{.contexts[?(@.name==\"$ctx\")].context.cluster}" 2>/dev/null || true)"
|
|
149
|
-
if [ -z "$cluster" ]; then
|
|
150
|
-
echo "devzone : cluster du contexte $ctx introuvable dans $conf" >&2
|
|
151
|
-
return 1
|
|
152
|
-
fi
|
|
153
|
-
serveur="$(KUBECONFIG="$conf" kubectl config view \
|
|
154
|
-
-o jsonpath="{.clusters[?(@.name==\"$cluster\")].cluster.server}" 2>/dev/null || true)"
|
|
155
|
-
if [ -z "$serveur" ]; then
|
|
156
|
-
echo "devzone : serveur du cluster $cluster introuvable dans $conf" >&2
|
|
157
|
-
return 1
|
|
158
|
-
fi
|
|
159
|
-
ca_donnees="$(KUBECONFIG="$conf" kubectl config view \
|
|
160
|
-
-o jsonpath="{.clusters[?(@.name==\"$cluster\")].cluster.certificate-authority-data}" 2>/dev/null || true)"
|
|
161
|
-
ca_fichier="$(KUBECONFIG="$conf" kubectl config view \
|
|
162
|
-
-o jsonpath="{.clusters[?(@.name==\"$cluster\")].cluster.certificate-authority}" 2>/dev/null || true)"
|
|
163
|
-
entree=(--server="$serveur")
|
|
164
|
-
if [ -n "$ca_donnees" ]; then
|
|
165
|
-
entree+=(--certificate-authority-data="$ca_donnees")
|
|
166
|
-
elif [ -n "$ca_fichier" ]; then
|
|
167
|
-
entree+=(--certificate-authority="$ca_fichier" --embed-certs=true)
|
|
168
|
-
fi
|
|
169
|
-
tls="$(KUBECONFIG="$conf" kubectl config view \
|
|
170
|
-
-o jsonpath="{.clusters[?(@.name==\"$cluster\")].cluster.tls-server-name}" 2>/dev/null || true)"
|
|
171
|
-
if [ -n "$tls" ]; then
|
|
172
|
-
entree+=(--tls-server-name="$tls")
|
|
173
|
-
fi
|
|
174
|
-
KUBECONFIG="$COMPTES_CONFIG" kubectl config set-cluster "$cluster" \
|
|
175
|
-
${entree[@]+"${entree[@]}"} >/dev/null
|
|
176
|
-
KUBECONFIG="$COMPTES_CONFIG" kubectl config set-credentials "$COMPTES_SA" \
|
|
177
|
-
--token="$jeton" >/dev/null
|
|
178
|
-
KUBECONFIG="$COMPTES_CONFIG" kubectl config set-context devzone \
|
|
179
|
-
--cluster="$cluster" --user="$COMPTES_SA" >/dev/null
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
# Exécution directe : jeton du compte renouvelé au démarrage (demarrage.sh) et
|
|
183
|
-
# par « devzone repair ». Sans cluster des services choisi : rien à faire.
|
|
184
|
-
# Quand le fichier est sourcé, $0 diffère de BASH_SOURCE : rien ne s'exécute.
|
|
185
|
-
if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
|
|
186
|
-
if [ "${1:-}" != jeton ]; then
|
|
187
|
-
echo "devzone : kube-compte : jeton" >&2
|
|
188
|
-
exit 1
|
|
189
|
-
fi
|
|
190
|
-
ICI="$(cd "$(dirname "$0")" && pwd)"
|
|
191
|
-
RACINE="${DEVZONE_RACINE:-$(dirname "$ICI")}"
|
|
192
|
-
ETAT="${DEVZONE_ETAT:-$RACINE/.devzone.modules}"
|
|
193
|
-
ctx="$(grep -E '^cluster=' "$ETAT" 2>/dev/null | tail -1 | cut -d= -f2- || true)"
|
|
194
|
-
if [ -z "$ctx" ]; then
|
|
195
|
-
exit 0
|
|
196
|
-
fi
|
|
197
|
-
compte_poser "$ctx" || exit 1
|
|
198
|
-
compte_rattraper "$ctx" || exit 1
|
|
199
|
-
compte_jeton "$ctx" || exit 1
|
|
200
|
-
fi
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Clusters joignables depuis le conteneur (#291). Avec le Docker de l'hôte,
|
|
3
|
-
# l'API d'un cluster kind écoute sur 127.0.0.1 DU POSTE : dans le conteneur,
|
|
4
|
-
# 127.0.0.1 est le conteneur lui-même.
|
|
5
|
-
# 1. Nœud kind trouvé (conteneur qui publie ce port) : le conteneur devzone
|
|
6
|
-
# rejoint le réseau Docker du nœud et vise https://<nœud>:6443, l'adresse
|
|
7
|
-
# que kind prévoit pour les conteneurs (kind get kubeconfig --internal) ;
|
|
8
|
-
# le nom du nœud est dans le certificat de l'API. Marche sous Linux comme
|
|
9
|
-
# avec Docker Desktop, sans rien exposer sur le réseau du poste.
|
|
10
|
-
# 2. Sinon : https://host.docker.internal:<port>, avec le nom d'origine pour
|
|
11
|
-
# la vérification TLS (--tls-server-name) ; suffit avec Docker Desktop, où
|
|
12
|
-
# host.docker.internal mène au 127.0.0.1 du poste.
|
|
13
|
-
# Bibliothèque sourcée (cluster.sh, enveloppe kind) ; exécutée directement :
|
|
14
|
-
# kube-joignable.sh FICHIER
|
|
15
|
-
# kube_joignable_depuis_conteneur FICHIER réécrit 127.0.0.1/localhost, idempotent
|
|
16
|
-
|
|
17
|
-
# Nœud kind de plan de contrôle qui publie ce port sur le poste (vide sinon)
|
|
18
|
-
kube_noeud_kind() {
|
|
19
|
-
docker ps --filter "label=io.x-k8s.kind.role=control-plane" --filter "publish=$1" \
|
|
20
|
-
--format '{{.Names}}' 2>/dev/null | head -1
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
# Le conteneur devzone rejoint le réseau du nœud (idempotent : déjà membre = rien)
|
|
24
|
-
kube_rejoindre_reseau() {
|
|
25
|
-
local noeud="$1" moi reseau
|
|
26
|
-
moi="$(hostname)"
|
|
27
|
-
for reseau in $(docker inspect "$noeud" \
|
|
28
|
-
--format '{{range $nom, $v := .NetworkSettings.Networks}}{{$nom}} {{end}}' 2>/dev/null); do
|
|
29
|
-
docker network connect "$reseau" "$moi" >/dev/null 2>&1 || true
|
|
30
|
-
done
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
kube_joignable_depuis_conteneur() {
|
|
34
|
-
local fichier="${1:-}" nom serveur hote port noeud
|
|
35
|
-
[ -n "$fichier" ] || return 0
|
|
36
|
-
# Kubernetes workspace (#517): the pod reaches the API through the cluster service, no docker call
|
|
37
|
-
if [ "${DEVZONE_WORKSPACE:-}" = kubernetes ]; then return 0; fi
|
|
38
|
-
KUBECONFIG="$fichier" kubectl config view \
|
|
39
|
-
-o jsonpath='{range .clusters[*]}{.name}{"\t"}{.cluster.server}{"\n"}{end}' 2>/dev/null |
|
|
40
|
-
while IFS=$'\t' read -r nom serveur; do
|
|
41
|
-
case "$serveur" in
|
|
42
|
-
https://127.0.0.1:* | https://localhost:*) ;;
|
|
43
|
-
*) continue ;;
|
|
44
|
-
esac
|
|
45
|
-
hote="${serveur#https://}"
|
|
46
|
-
hote="${hote%%:*}"
|
|
47
|
-
port="${serveur##*:}"
|
|
48
|
-
noeud="$(kube_noeud_kind "$port")"
|
|
49
|
-
if [ -n "$noeud" ]; then
|
|
50
|
-
kube_rejoindre_reseau "$noeud"
|
|
51
|
-
KUBECONFIG="$fichier" kubectl config set-cluster "$nom" \
|
|
52
|
-
--server="https://${noeud}:6443" >/dev/null 2>&1 || true
|
|
53
|
-
else
|
|
54
|
-
KUBECONFIG="$fichier" kubectl config set-cluster "$nom" \
|
|
55
|
-
--server="https://host.docker.internal:${port}" \
|
|
56
|
-
--tls-server-name="$hote" >/dev/null 2>&1 || true
|
|
57
|
-
fi
|
|
58
|
-
done
|
|
59
|
-
return 0
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if [ "${BASH_SOURCE[0]}" = "$0" ]; then
|
|
63
|
-
kube_joignable_depuis_conteneur "${1:-}"
|
|
64
|
-
fi
|