devzone 0.48.2 → 0.50.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/agent-pod-egress.sh +36 -0
- package/.devcontainer/agent-pod-manifest.sh +5 -2
- package/.devcontainer/devzone +1 -1
- package/README.md +12 -0
- package/charts/devzone-workspace/templates/egress-networkpolicy.yaml +37 -0
- package/charts/devzone-workspace/templates/egress-proxy.yaml +108 -0
- package/charts/devzone-workspace/values.yaml +19 -0
- package/manage/scripts/argocd-services.sh +2 -0
- package/manage/scripts/workspace-egress.sh +184 -0
- package/manage/workspace.sh +10 -10
- package/package.json +1 -1
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Egress proxy helpers for the ephemeral session pod (#220).
|
|
3
|
+
# Sourced by agent-pod-manifest.sh. bash 3.2 compatible ; shellcheck -x clean.
|
|
4
|
+
|
|
5
|
+
agent_pod_egress_mode() {
|
|
6
|
+
kubectl get service -l app.kubernetes.io/component=egress-proxy \
|
|
7
|
+
-o jsonpath='{.items[0].metadata.labels.devzone\.io/egress-mode}' 2>/dev/null || true
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
agent_pod_egress_manifest_lines() {
|
|
11
|
+
local mode="$1"
|
|
12
|
+
[ -n "$mode" ] || return 0
|
|
13
|
+
printf '%s\n' " - name: HTTP_PROXY"
|
|
14
|
+
printf '%s\n' " value: \"http://egress-proxy:3128\""
|
|
15
|
+
printf '%s\n' " - name: HTTPS_PROXY"
|
|
16
|
+
printf '%s\n' " value: \"http://egress-proxy:3128\""
|
|
17
|
+
printf '%s\n' " - name: NO_PROXY"
|
|
18
|
+
printf '%s\n' " value: \"localhost,127.0.0.1,.svc,.cluster.local\""
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
agent_pod_egress_init_lines() {
|
|
22
|
+
local mode="$1" ws_image="$2"
|
|
23
|
+
[ "$mode" = "strict" ] || return 0
|
|
24
|
+
printf '%s\n' " initContainers:"
|
|
25
|
+
printf '%s\n' " - name: wait-egress-restriction"
|
|
26
|
+
printf '%s\n' " image: ${ws_image}"
|
|
27
|
+
printf '%s\n' " command: [\"/bin/bash\", \"-lc\"]"
|
|
28
|
+
printf '%s\n' " args:"
|
|
29
|
+
printf '%s\n' " - 'i=0; while [ \$i -lt 20 ]; do if ! curl --noproxy \"*\" -m 3 -sS https://opencode.ai >/dev/null 2>&1; then exit 0; fi; i=\$((i+1)); sleep 1; done; echo \"egress restriction never became effective: session refused\" >&2; exit 1'"
|
|
30
|
+
printf '%s\n' " securityContext:"
|
|
31
|
+
printf '%s\n' " runAsUser: 1000"
|
|
32
|
+
printf '%s\n' " runAsGroup: 1000"
|
|
33
|
+
printf '%s\n' " allowPrivilegeEscalation: false"
|
|
34
|
+
printf '%s\n' " capabilities:"
|
|
35
|
+
printf '%s\n' " drop: [\"ALL\"]"
|
|
36
|
+
}
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
# Manifest and validation helpers for the ephemeral session pod (#222).
|
|
3
3
|
# Sourced by agent-pod.sh.
|
|
4
4
|
# bash 3.2 compatible ; shellcheck -x clean.
|
|
5
|
+
# shellcheck disable=SC1091
|
|
6
|
+
. "$(dirname "${BASH_SOURCE[0]}")/agent-pod-egress.sh"
|
|
5
7
|
|
|
6
8
|
# --- Defaults ---
|
|
7
9
|
|
|
@@ -147,7 +149,7 @@ agent_pod_build_manifest() {
|
|
|
147
149
|
ticket_block=" devzone.io/agent-ticket: \"${AGENT_POD_TICKET}\""
|
|
148
150
|
fi
|
|
149
151
|
|
|
150
|
-
manifest_file="$(mktemp "${TMPDIR:-/tmp}/devzone-agent-pod-manifest.XXXXXX.yaml")"
|
|
152
|
+
manifest_file="$(mktemp "${TMPDIR:-/tmp}/devzone-agent-pod-manifest.XXXXXX.yaml")"; egress_mode="$(agent_pod_egress_mode)"
|
|
151
153
|
|
|
152
154
|
{
|
|
153
155
|
printf '%s\n' "apiVersion: v1"
|
|
@@ -160,6 +162,7 @@ agent_pod_build_manifest() {
|
|
|
160
162
|
printf '%s\n' "$ticket_block"
|
|
161
163
|
fi
|
|
162
164
|
printf '%s\n' "spec:"
|
|
165
|
+
agent_pod_egress_init_lines "$egress_mode" "$ws_image"
|
|
163
166
|
printf '%s\n' " restartPolicy: Never"
|
|
164
167
|
printf '%s\n' " activeDeadlineSeconds: ${DEVZONE_AGENT_POD_ACTIVE_DEADLINE_SECONDS}"
|
|
165
168
|
printf '%s\n' " automountServiceAccountToken: false"
|
|
@@ -191,7 +194,7 @@ agent_pod_build_manifest() {
|
|
|
191
194
|
printf '%s\n' " - name: DEVZONE_WORKSPACE"
|
|
192
195
|
printf '%s\n' " value: \"kubernetes\""
|
|
193
196
|
printf '%s\n' " - name: DEVZONE_RACINE"
|
|
194
|
-
printf '%s\n' " value: \"/workspaces/projets\""
|
|
197
|
+
printf '%s\n' " value: \"/workspaces/projets\""; agent_pod_egress_manifest_lines "$egress_mode"
|
|
195
198
|
printf '%s\n' " resources:"
|
|
196
199
|
printf '%s\n' " limits:"
|
|
197
200
|
printf '%s\n' " cpu: ${DEVZONE_AGENT_POD_CPU_LIMIT}"
|
package/.devcontainer/devzone
CHANGED
package/README.md
CHANGED
|
@@ -444,3 +444,15 @@ Cette commande retire seulement la commande `devzone` de ta machine ; elle ne su
|
|
|
444
444
|
|
|
445
445
|
devzone est un logiciel libre, distribué sous la [GNU General Public License version 3](https://github.com/SimBienvenueHoulBoumi/devzone/blob/main/LICENSE).
|
|
446
446
|
|
|
447
|
+
|
|
448
|
+
### Mandataire de sortie des sessions d’agent (désactivé par défaut)
|
|
449
|
+
|
|
450
|
+
Limite le réseau sortant des sessions lancées avec `devzone agent --pod` via un mandataire HTTP(S) (Squid) dans le namespace du workspace. Tout est désactivé par défaut : sans activation, le rendu du chart et le manifeste des pods de session restent identiques.
|
|
451
|
+
|
|
452
|
+
- **Modes** : `observation` (le mandataire accepte tout et journalise, aucune coupure, pour construire la liste) ; `strict` (seule la liste de domaines est autorisée, et une NetworkPolicy limite la sortie des pods de session au mandataire et au DNS).
|
|
453
|
+
- **Activer** (Helm) : `egressProxy.enabled=true` et `egressProxy.mode=observation` ou `strict` (liste : `egressProxy.allowedDomains`, par défaut `.opencode.ai`, `.npmjs.org`, `.github.com`).
|
|
454
|
+
- **Lire les contacts** : `kubectl logs deploy/devzone-workspace-egress-proxy -c access-log -n <namespace>`.
|
|
455
|
+
- **Garde (strict)** : une fenêtre de 1 à 2 s existe au démarrage avant que la restriction soit programmée ; un conteneur d’initialisation attend que l’accès direct soit fermé (20 essais, 1 s) et refuse la session si la restriction ne devient jamais effective.
|
|
456
|
+
- **Limites** : le workspace lui-même reste ouvert ; seules les sessions `devzone agent --pod` sont filtrées ; les outils qui ignorent `HTTPS_PROXY` sont bloqués en mode strict.
|
|
457
|
+
- **Commandes** (#633) : `devzone workspace egress observation|strict|off`, `egress status` (domaines contactés et leur état), `egress allow|deny <domaine>`. Le réglage est gardé dans `.devzone.modules` et rejoué à chaque `workspace start` et `workspace update` ; le pod n'est pas recréé.
|
|
458
|
+
- **Parcours** : `devzone workspace egress observation`, puis `egress status` pour voir les domaines contactés, `egress allow <domaine>` pour ceux qui manquent, et enfin `devzone workspace egress strict`.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{{- if and .Values.egressProxy.enabled (eq .Values.egressProxy.mode "strict") -}}
|
|
2
|
+
apiVersion: networking.k8s.io/v1
|
|
3
|
+
kind: NetworkPolicy
|
|
4
|
+
metadata:
|
|
5
|
+
name: {{ include "devzone-workspace.fullname" . }}-egress-strict
|
|
6
|
+
namespace: {{ .Release.Namespace }}
|
|
7
|
+
labels:
|
|
8
|
+
app.kubernetes.io/name: {{ include "devzone-workspace.name" . }}-egress-proxy
|
|
9
|
+
app.kubernetes.io/part-of: devzone
|
|
10
|
+
app.kubernetes.io/managed-by: devzone
|
|
11
|
+
app.kubernetes.io/component: egress-proxy
|
|
12
|
+
spec:
|
|
13
|
+
podSelector:
|
|
14
|
+
matchExpressions:
|
|
15
|
+
- key: devzone.io/agent-session
|
|
16
|
+
operator: Exists
|
|
17
|
+
policyTypes:
|
|
18
|
+
- Egress
|
|
19
|
+
egress:
|
|
20
|
+
- to:
|
|
21
|
+
- podSelector:
|
|
22
|
+
matchLabels:
|
|
23
|
+
app.kubernetes.io/name: {{ include "devzone-workspace.name" . }}-egress-proxy
|
|
24
|
+
app.kubernetes.io/component: egress-proxy
|
|
25
|
+
ports:
|
|
26
|
+
- protocol: TCP
|
|
27
|
+
port: 3128
|
|
28
|
+
- to:
|
|
29
|
+
- namespaceSelector:
|
|
30
|
+
matchLabels:
|
|
31
|
+
kubernetes.io/metadata.name: kube-system
|
|
32
|
+
ports:
|
|
33
|
+
- protocol: UDP
|
|
34
|
+
port: 53
|
|
35
|
+
- protocol: TCP
|
|
36
|
+
port: 53
|
|
37
|
+
{{- end -}}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
{{- if .Values.egressProxy.enabled -}}
|
|
2
|
+
apiVersion: v1
|
|
3
|
+
kind: ConfigMap
|
|
4
|
+
metadata:
|
|
5
|
+
name: {{ include "devzone-workspace.fullname" . }}-egress-proxy
|
|
6
|
+
namespace: {{ .Release.Namespace }}
|
|
7
|
+
labels:
|
|
8
|
+
app.kubernetes.io/name: {{ include "devzone-workspace.name" . }}-egress-proxy
|
|
9
|
+
app.kubernetes.io/part-of: devzone
|
|
10
|
+
app.kubernetes.io/managed-by: devzone
|
|
11
|
+
app.kubernetes.io/component: egress-proxy
|
|
12
|
+
data:
|
|
13
|
+
squid.conf: |
|
|
14
|
+
http_port 3128
|
|
15
|
+
max_filedescriptors 1024
|
|
16
|
+
cache deny all
|
|
17
|
+
access_log daemon:/var/log/squid/access.log
|
|
18
|
+
pid_filename /tmp/squid.pid
|
|
19
|
+
{{- if eq .Values.egressProxy.mode "strict" }}
|
|
20
|
+
{{- range .Values.egressProxy.allowedDomains }}
|
|
21
|
+
acl allowed dstdomain {{ . }}
|
|
22
|
+
{{- end }}
|
|
23
|
+
{{- range splitList "," (default "" .Values.egressProxy.extraDomains) }}
|
|
24
|
+
{{- $domain := trim . }}
|
|
25
|
+
{{- if $domain }}
|
|
26
|
+
acl allowed dstdomain {{ $domain }}
|
|
27
|
+
{{- end }}
|
|
28
|
+
{{- end }}
|
|
29
|
+
acl SSL_ports port 443
|
|
30
|
+
acl CONNECT method CONNECT
|
|
31
|
+
http_access allow CONNECT SSL_ports allowed
|
|
32
|
+
http_access allow allowed
|
|
33
|
+
http_access deny all
|
|
34
|
+
{{- else }}
|
|
35
|
+
http_access allow all
|
|
36
|
+
{{- end }}
|
|
37
|
+
---
|
|
38
|
+
apiVersion: apps/v1
|
|
39
|
+
kind: Deployment
|
|
40
|
+
metadata:
|
|
41
|
+
name: {{ include "devzone-workspace.fullname" . }}-egress-proxy
|
|
42
|
+
namespace: {{ .Release.Namespace }}
|
|
43
|
+
labels:
|
|
44
|
+
app.kubernetes.io/name: {{ include "devzone-workspace.name" . }}-egress-proxy
|
|
45
|
+
app.kubernetes.io/part-of: devzone
|
|
46
|
+
app.kubernetes.io/managed-by: devzone
|
|
47
|
+
app.kubernetes.io/component: egress-proxy
|
|
48
|
+
spec:
|
|
49
|
+
replicas: 1
|
|
50
|
+
selector:
|
|
51
|
+
matchLabels:
|
|
52
|
+
app.kubernetes.io/name: {{ include "devzone-workspace.name" . }}-egress-proxy
|
|
53
|
+
app.kubernetes.io/component: egress-proxy
|
|
54
|
+
template:
|
|
55
|
+
metadata:
|
|
56
|
+
labels:
|
|
57
|
+
app.kubernetes.io/name: {{ include "devzone-workspace.name" . }}-egress-proxy
|
|
58
|
+
app.kubernetes.io/part-of: devzone
|
|
59
|
+
app.kubernetes.io/managed-by: devzone
|
|
60
|
+
app.kubernetes.io/component: egress-proxy
|
|
61
|
+
spec:
|
|
62
|
+
volumes:
|
|
63
|
+
- name: config
|
|
64
|
+
configMap:
|
|
65
|
+
name: {{ include "devzone-workspace.fullname" . }}-egress-proxy
|
|
66
|
+
- name: logs
|
|
67
|
+
emptyDir: {}
|
|
68
|
+
containers:
|
|
69
|
+
- name: squid
|
|
70
|
+
image: {{ .Values.egressProxy.image }}
|
|
71
|
+
ports:
|
|
72
|
+
- name: proxy
|
|
73
|
+
containerPort: 3128
|
|
74
|
+
volumeMounts:
|
|
75
|
+
- name: config
|
|
76
|
+
mountPath: /etc/squid/squid.conf
|
|
77
|
+
subPath: squid.conf
|
|
78
|
+
- name: logs
|
|
79
|
+
mountPath: /var/log/squid
|
|
80
|
+
resources:
|
|
81
|
+
{{- toYaml .Values.egressProxy.resources | nindent 12 }}
|
|
82
|
+
- name: access-log
|
|
83
|
+
image: busybox:1.36
|
|
84
|
+
command: ["sh", "-c", "tail -F /var/log/squid/access.log 2>/dev/null"]
|
|
85
|
+
volumeMounts:
|
|
86
|
+
- name: logs
|
|
87
|
+
mountPath: /var/log/squid
|
|
88
|
+
---
|
|
89
|
+
apiVersion: v1
|
|
90
|
+
kind: Service
|
|
91
|
+
metadata:
|
|
92
|
+
name: egress-proxy
|
|
93
|
+
namespace: {{ .Release.Namespace }}
|
|
94
|
+
labels:
|
|
95
|
+
app.kubernetes.io/name: {{ include "devzone-workspace.name" . }}-egress-proxy
|
|
96
|
+
app.kubernetes.io/part-of: devzone
|
|
97
|
+
app.kubernetes.io/managed-by: devzone
|
|
98
|
+
app.kubernetes.io/component: egress-proxy
|
|
99
|
+
devzone.io/egress-mode: {{ .Values.egressProxy.mode | quote }}
|
|
100
|
+
spec:
|
|
101
|
+
selector:
|
|
102
|
+
app.kubernetes.io/name: {{ include "devzone-workspace.name" . }}-egress-proxy
|
|
103
|
+
app.kubernetes.io/component: egress-proxy
|
|
104
|
+
ports:
|
|
105
|
+
- name: proxy
|
|
106
|
+
port: 3128
|
|
107
|
+
targetPort: 3128
|
|
108
|
+
{{- end -}}
|
|
@@ -97,3 +97,22 @@ networkPolicy:
|
|
|
97
97
|
# workstation needs the Internet (Maven, npm, Docker images). true limits the
|
|
98
98
|
# egress to the namespace and to DNS (kube-system). The egress allow list is #220.
|
|
99
99
|
restrictEgress: false
|
|
100
|
+
|
|
101
|
+
egressProxy:
|
|
102
|
+
enabled: false
|
|
103
|
+
mode: observation
|
|
104
|
+
allowedDomains:
|
|
105
|
+
- .opencode.ai
|
|
106
|
+
- .npmjs.org
|
|
107
|
+
- .github.com
|
|
108
|
+
# Domains added to the strict list (comma-separated, no space), set by
|
|
109
|
+
# devzone workspace egress allow (#633); empty by default
|
|
110
|
+
extraDomains: ""
|
|
111
|
+
image: ubuntu/squid@sha256:6a097f68bae708cedbabd6188d68c7e2e7a38cedd05a176e1cc0ba29e3bbe029
|
|
112
|
+
resources:
|
|
113
|
+
requests:
|
|
114
|
+
memory: 64Mi
|
|
115
|
+
cpu: 50m
|
|
116
|
+
limits:
|
|
117
|
+
memory: 256Mi
|
|
118
|
+
cpu: "1"
|
|
@@ -109,6 +109,8 @@ workspace_deploy() {
|
|
|
109
109
|
params="image.tag=$tag"
|
|
110
110
|
[ -z "$with_image" ] || params="$params image.repository=$repository"
|
|
111
111
|
[ "$tag" != latest ] || params="$params image.pullPolicy=Always"
|
|
112
|
+
# egress proxy settings of .devzone.modules (#633): replayed at each start and update
|
|
113
|
+
params="$params $(egress_params)"
|
|
112
114
|
chart_require workspace || return $?
|
|
113
115
|
# GitOps repository created or designated first, with its root Application
|
|
114
116
|
gitops_init || return 1
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# devzone workspace egress observation|strict|off|status|allow <domain>|deny <domain>
|
|
3
|
+
# (#633), sourced by manage/workspace.sh after workspace-update.sh.
|
|
4
|
+
# egress_workspace <subcommand> [domain] dispatch of the command above
|
|
5
|
+
# egress_params key=value parameters of the chart, replayed
|
|
6
|
+
# by workspace_deploy at each start and update
|
|
7
|
+
# The mode and the added domains are kept in .devzone.modules (egress=,
|
|
8
|
+
# egress_domains=, state_read and state_note of argocd-workspace.sh). Each
|
|
9
|
+
# change redeploys the workspace at the image it runs: same image tag, same
|
|
10
|
+
# Argo CD revision, the pod is not recreated. Only the devzone agent sessions
|
|
11
|
+
# started with --pod go through the proxy in strict mode. bash 3.2 (macOS).
|
|
12
|
+
|
|
13
|
+
# Base list of the chart (egressProxy.allowedDomains in values.yaml): not
|
|
14
|
+
# editable with allow or deny, changed in the chart
|
|
15
|
+
EGRESS_BASE=".opencode.ai .npmjs.org .github.com"
|
|
16
|
+
|
|
17
|
+
# Domain: lowercase letters, digits, hyphens and dots, at least one dot, an
|
|
18
|
+
# optional leading dot (subdomains); no space, comma, * or /
|
|
19
|
+
egress_domain_ok() {
|
|
20
|
+
printf '%s\n' "$1" | grep -Eq '^\.?[a-z0-9-]+(\.[a-z0-9-]+)+$'
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
# Chart parameters of the proxy from .devzone.modules: nothing when off (or
|
|
24
|
+
# unset), else enabled, mode and the added domains (comma-separated)
|
|
25
|
+
egress_params() {
|
|
26
|
+
local mode domains
|
|
27
|
+
mode="$(state_read egress)"
|
|
28
|
+
case "$mode" in
|
|
29
|
+
observation | strict) ;;
|
|
30
|
+
*) return 0 ;;
|
|
31
|
+
esac
|
|
32
|
+
printf 'egressProxy.enabled=true egressProxy.mode=%s' "$mode"
|
|
33
|
+
domains="$(state_read egress_domains)"
|
|
34
|
+
if [ -n "$domains" ]; then printf ' egressProxy.extraDomains=%s' "$domains"; fi
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
# Waits for the proxy after the redeploy. Argo CD creates its Deployment a few
|
|
38
|
+
# seconds to a minute after the sync: the Deployment is looked up every
|
|
39
|
+
# DEVZONE_EGRESS_PAS s (3 by default) up to DEVZONE_EGRESS_WAIT s (90 by
|
|
40
|
+
# default); then its rollout is awaited for DEVZONE_EGRESS_ROLLOUT s (120 by
|
|
41
|
+
# default). Returns 1 when either is not reached.
|
|
42
|
+
egress_wait_proxy() {
|
|
43
|
+
local limit="${DEVZONE_EGRESS_WAIT:-90}" rollout="${DEVZONE_EGRESS_ROLLOUT:-120}" pas="${DEVZONE_EGRESS_PAS:-3}" attendu=0
|
|
44
|
+
until ak -n "$NAMESPACE" get deployment devzone-workspace-egress-proxy >/dev/null 2>&1; do
|
|
45
|
+
if [ "$attendu" -ge "$limit" ]; then
|
|
46
|
+
echo "⚠ the egress proxy was not created by Argo CD after $limit s: the setting is kept, check devzone workspace argocd status" >&2
|
|
47
|
+
return 1
|
|
48
|
+
fi
|
|
49
|
+
if [ $((limit - attendu)) -lt "$pas" ]; then pas=$((limit - attendu)); fi
|
|
50
|
+
sleep "$pas"
|
|
51
|
+
attendu=$((attendu + pas))
|
|
52
|
+
done
|
|
53
|
+
if ! ak -n "$NAMESPACE" rollout status deployment/devzone-workspace-egress-proxy --timeout="${rollout}s"; then
|
|
54
|
+
echo "⚠ egress proxy not ready after $rollout s: the setting is kept, see devzone workspace egress status" >&2
|
|
55
|
+
return 1
|
|
56
|
+
fi
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
# Redeploys the workspace at the image of the current Argo CD Application
|
|
60
|
+
# (targetRevision and image.tag, as update_current); then waits for the proxy
|
|
61
|
+
# when it is on. Without Application (helm direct), the setting is only kept:
|
|
62
|
+
# devzone workspace start applies it.
|
|
63
|
+
egress_redeploy() {
|
|
64
|
+
local rev tag
|
|
65
|
+
read -r rev tag <<<"$(update_current)" || true
|
|
66
|
+
if [ -z "$rev" ] || [ -z "$tag" ]; then
|
|
67
|
+
echo "ℹ no Argo CD Application: the setting is kept, devzone workspace start applies it"
|
|
68
|
+
return 0
|
|
69
|
+
fi
|
|
70
|
+
export DEVZONE_ARGOCD_REVISION="$rev"
|
|
71
|
+
workspace_deploy "$IMAGE_REPO" "$tag" "" || return 1
|
|
72
|
+
if [ -n "$(egress_params)" ]; then
|
|
73
|
+
echo "▶ waiting for the egress proxy…"
|
|
74
|
+
egress_wait_proxy || return 1
|
|
75
|
+
fi
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
# observation | strict | off: memorised, then the workspace is redeployed
|
|
79
|
+
egress_set_mode() {
|
|
80
|
+
kube_ready_reason --hint >&2 || return 1
|
|
81
|
+
state_note egress "$1"
|
|
82
|
+
egress_redeploy || return 1
|
|
83
|
+
echo "✔ egress $1"
|
|
84
|
+
if [ "$1" = strict ]; then
|
|
85
|
+
echo "ℹ strict: only the devzone agent sessions started with --pod are filtered; the workspace stays open"
|
|
86
|
+
fi
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
# allow | deny <domain>: the list of added domains has no duplicate; deny only
|
|
90
|
+
# removes what was added, never the base list
|
|
91
|
+
egress_domain_edit() {
|
|
92
|
+
local action="$1" domain="$2" list new base=no present=no
|
|
93
|
+
if ! egress_domain_ok "$domain"; then
|
|
94
|
+
echo "✖ domain not valid: $domain (lowercase letters, digits, hyphens and dots, at least one dot, optional leading dot; no space, comma, * or /)" >&2
|
|
95
|
+
return 1
|
|
96
|
+
fi
|
|
97
|
+
case " $EGRESS_BASE " in *" $domain "*) base=yes ;; esac
|
|
98
|
+
list="$(state_read egress_domains)"
|
|
99
|
+
case ",$list," in *",$domain,"*) present=yes ;; esac
|
|
100
|
+
if [ "$action" = allow ]; then
|
|
101
|
+
if [ "$base" = yes ]; then
|
|
102
|
+
echo "ℹ $domain is in the base list (egressProxy.allowedDomains): already allowed"
|
|
103
|
+
return 0
|
|
104
|
+
fi
|
|
105
|
+
if [ "$present" = yes ]; then
|
|
106
|
+
echo "ℹ already allowed: $domain"
|
|
107
|
+
return 0
|
|
108
|
+
fi
|
|
109
|
+
new="${list:+$list,}$domain"
|
|
110
|
+
else
|
|
111
|
+
if [ "$base" = yes ]; then
|
|
112
|
+
echo "✖ $domain is in the base list: change it in egressProxy.allowedDomains of the chart (nothing changed)" >&2
|
|
113
|
+
return 1
|
|
114
|
+
fi
|
|
115
|
+
if [ "$present" = no ]; then
|
|
116
|
+
echo "✖ $domain was not added with allow: nothing changed" >&2
|
|
117
|
+
return 1
|
|
118
|
+
fi
|
|
119
|
+
new="$(printf '%s' "$list" | tr ',' '\n' | grep -vxF -- "$domain" | paste -sd, -)" || new=""
|
|
120
|
+
fi
|
|
121
|
+
kube_ready_reason --hint >&2 || return 1
|
|
122
|
+
state_note egress_domains "$new"
|
|
123
|
+
echo "✔ $action $domain"
|
|
124
|
+
egress_redeploy
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
# Mode of the proxy (label of its Service, off when none), readiness, number of
|
|
128
|
+
# allowed domains (ACL lines of the ConfigMap), then the domains contacted in
|
|
129
|
+
# the last 2000 lines of the access log: count and state (allowed, refused, or
|
|
130
|
+
# observed in observation mode). Columns of the squid native log: 4 result, 6
|
|
131
|
+
# method, 7 host:port.
|
|
132
|
+
egress_status() {
|
|
133
|
+
local mode ready count table
|
|
134
|
+
kube_ready_reason --hint >&2 || return 1
|
|
135
|
+
mode="$(ak -n "$NAMESPACE" get service egress-proxy -o 'jsonpath={.metadata.labels.devzone\.io/egress-mode}' 2>/dev/null)" || mode=""
|
|
136
|
+
if [ -z "$mode" ]; then
|
|
137
|
+
echo "egress off"
|
|
138
|
+
return 0
|
|
139
|
+
fi
|
|
140
|
+
ready="$(ak -n "$NAMESPACE" get deployment devzone-workspace-egress-proxy -o 'jsonpath={.status.readyReplicas}' 2>/dev/null || true)"
|
|
141
|
+
if [ "${ready:-0}" -ge 1 ] 2>/dev/null; then ready="ready"; else ready="not ready"; fi
|
|
142
|
+
count="$(ak -n "$NAMESPACE" get configmap devzone-workspace-egress-proxy -o 'jsonpath={.data.squid\.conf}' 2>/dev/null |
|
|
143
|
+
grep -c 'acl allowed dstdomain ' || true)"
|
|
144
|
+
echo "egress $mode, proxy $ready, allowed domains: ${count:-0}"
|
|
145
|
+
table="$(ak -n "$NAMESPACE" logs deployment/devzone-workspace-egress-proxy -c access-log --tail=2000 2>/dev/null |
|
|
146
|
+
awk -v mode="$mode" '
|
|
147
|
+
$6 == "CONNECT" {
|
|
148
|
+
host = $7
|
|
149
|
+
sub(/:[0-9]+$/, "", host)
|
|
150
|
+
hits[host]++
|
|
151
|
+
if ($4 ~ /DENIED/) refused[host] = 1
|
|
152
|
+
}
|
|
153
|
+
END {
|
|
154
|
+
for (h in hits) {
|
|
155
|
+
state = refused[h] ? "refused" : (mode == "observation" ? "observed" : "allowed")
|
|
156
|
+
printf " %-40s %6d %s\n", h, hits[h], state
|
|
157
|
+
}
|
|
158
|
+
}' | sort)" || table=""
|
|
159
|
+
if [ -z "$table" ]; then
|
|
160
|
+
echo " no domain contacted in the recent log"
|
|
161
|
+
else
|
|
162
|
+
printf ' %-40s %6s %s\n' domain accesses state
|
|
163
|
+
echo "$table"
|
|
164
|
+
fi
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
# Dispatch of devzone workspace egress
|
|
168
|
+
egress_workspace() {
|
|
169
|
+
case "${1:-}" in
|
|
170
|
+
observation | strict | off) egress_set_mode "$1" ;;
|
|
171
|
+
status) egress_status ;;
|
|
172
|
+
allow | deny)
|
|
173
|
+
if [ "$#" -ne 2 ]; then
|
|
174
|
+
echo "✖ egress $1 takes one domain: devzone workspace egress $1 <domain>" >&2
|
|
175
|
+
return 1
|
|
176
|
+
fi
|
|
177
|
+
egress_domain_edit "$1" "$2"
|
|
178
|
+
;;
|
|
179
|
+
*)
|
|
180
|
+
echo "✖ unknown egress argument: ${1:-none} (devzone workspace egress observation|strict|off|status|allow <domain>|deny <domain>)" >&2
|
|
181
|
+
return 1
|
|
182
|
+
;;
|
|
183
|
+
esac
|
|
184
|
+
}
|
package/manage/workspace.sh
CHANGED
|
@@ -28,9 +28,7 @@ kubectl_flag() {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
# Chart path in the repository (or installed package).
|
|
31
|
-
chart_path() {
|
|
32
|
-
printf '%s/charts/devzone-workspace' "$ROOT"
|
|
33
|
-
}
|
|
31
|
+
chart_path() { printf '%s/charts/devzone-workspace' "$ROOT"; }
|
|
34
32
|
|
|
35
33
|
# Repository of the image published at each devzone release.
|
|
36
34
|
IMAGE_REPO="ghcr.io/simbienvenuehoulboumi/devzone-workspace"
|
|
@@ -99,9 +97,9 @@ workspace_helm_deploy() {
|
|
|
99
97
|
args+=(--set "image.tag=$tag")
|
|
100
98
|
# latest moves at every release: an image already on the node would stay
|
|
101
99
|
# the old one with IfNotPresent (#515)
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
100
|
+
[ "$tag" != latest ] || args+=(--set "image.pullPolicy=Always")
|
|
101
|
+
# egress proxy settings (#633), replayed at each start: commas escaped for helm
|
|
102
|
+
for p in $(egress_params | sed 's/,/\\,/g'); do args+=(--set "$p"); done
|
|
105
103
|
# shellcheck disable=SC2046
|
|
106
104
|
helm $(helm_flag) upgrade --install devzone-workspace "$(chart_path)" "${args[@]}"
|
|
107
105
|
}
|
|
@@ -191,6 +189,8 @@ copy_from() {
|
|
|
191
189
|
. "$HERE/scripts/argocd-services.sh"
|
|
192
190
|
# shellcheck source=manage/scripts/workspace-update.sh
|
|
193
191
|
. "$HERE/scripts/workspace-update.sh"
|
|
192
|
+
# shellcheck source=manage/scripts/workspace-egress.sh
|
|
193
|
+
. "$HERE/scripts/workspace-egress.sh"
|
|
194
194
|
|
|
195
195
|
# English command names are accepted, French ones unchanged and warned (#502,
|
|
196
196
|
# #532). A copied devzone may miss the aliases file: then no normalization.
|
|
@@ -206,9 +206,7 @@ if [ -f "$ROOT/.devcontainer/command-aliases.sh" ]; then
|
|
|
206
206
|
fi
|
|
207
207
|
fi
|
|
208
208
|
|
|
209
|
-
if [ "$#" -gt 0 ]; then
|
|
210
|
-
set -- "$(workspace_command "$1")" "${@:2}"
|
|
211
|
-
fi
|
|
209
|
+
if [ "$#" -gt 0 ]; then set -- "$(workspace_command "$1")" "${@:2}"; fi
|
|
212
210
|
if [ "${1:-}" = "ports" ] && [ "$#" -gt 1 ]; then
|
|
213
211
|
set -- "$1" "$(workspace_ports_command "$2")" "${@:3}"
|
|
214
212
|
fi
|
|
@@ -229,8 +227,9 @@ case "${1:-}" in
|
|
|
229
227
|
clean-docker) clean_docker "${@:2}" ;;
|
|
230
228
|
services) services "${@:2}" ;;
|
|
231
229
|
argocd) argocd_cmd "${@:2}" ;;
|
|
230
|
+
egress) egress_workspace "${@:2}" ;;
|
|
232
231
|
'' | -h | --help | aide)
|
|
233
|
-
echo "devzone workspace start|stop|status|shell|vscode|copy-to|copy-from|clone|ports|services|argocd|migrate|revert|clean-docker|update"
|
|
232
|
+
echo "devzone workspace start|stop|status|shell|vscode|copy-to|copy-from|clone|ports|services|argocd|migrate|revert|clean-docker|update|egress"
|
|
234
233
|
echo " start [--image repository:tag] install workspace (image for devzone version by default)"
|
|
235
234
|
echo " update [--version X.Y.Z] [--yes] move to the latest stable release (or X.Y.Z); the pod is recreated"
|
|
236
235
|
echo " clone <url> [<name>] git clone into the pod projects folder (gh credentials, identity, repowarden hooks)"
|
|
@@ -242,6 +241,7 @@ case "${1:-}" in
|
|
|
242
241
|
echo " migrate [--yes] copy Docker workstation to Kubernetes workspace (nothing is deleted)"
|
|
243
242
|
echo " revert [--bring-back] back to Docker workstation; --bring-back: copy pod projects first"
|
|
244
243
|
echo " clean-docker remove devzone-* Docker volumes, after confirmation [y/N] (--yes)"
|
|
244
|
+
echo " egress observation|strict|off|status|allow <domain>|deny <domain> egress proxy of the agent sessions (--pod)"
|
|
245
245
|
;;
|
|
246
246
|
*)
|
|
247
247
|
echo "✖ unknown subcommand: $1 (devzone workspace start|stop|status|shell|vscode|copy-to|copy-from|clone|ports|services|argocd|migrate|revert|clean-docker|update)" >&2
|