devzone 7.0.2 → 7.0.3

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.
@@ -4,19 +4,24 @@
4
4
  # stderr when a shell command runs docker/docker-compose as the command word.
5
5
  # With python3, one program parses the JSON and detects. Otherwise jq extracts
6
6
  # the tool and command and a best-effort shell detection runs. Without either,
7
- # nothing is blocked.
7
+ # nothing is blocked. The cluster context check runs first: the host override
8
+ # only concerns commands on the host itself, never the administrator context.
8
9
 
9
10
  set -u
10
11
 
11
12
  SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
12
13
  MESSAGE_FILE="$SCRIPT_DIR/docker-guard.message"
14
+ KUBE_MESSAGE_FILE="$SCRIPT_DIR/kube-guard.message"
13
15
  FALLBACK="devzone is Kubernetes-first: only pods are containers. Use kubectl, or a throwaway pod or namespace. Host action: set DEVZONE_ALLOW_DOCKER to 1."
16
+ FALLBACK_KUBE="Cluster administrator access is reserved for installers. Use the devzone context or the devzone commands (enable, disable, repair). An explicit host override does not lift this refusal."
14
17
  MESSAGE="$FALLBACK"
18
+ KUBE_MESSAGE="$FALLBACK_KUBE"
15
19
  if [ -r "$MESSAGE_FILE" ]; then
16
20
  MESSAGE="$(cat "$MESSAGE_FILE" 2>/dev/null)" || MESSAGE="$FALLBACK"
17
21
  fi
18
-
19
- [ "${DEVZONE_ALLOW_DOCKER:-}" = "1" ] && exit 0
22
+ if [ -r "$KUBE_MESSAGE_FILE" ]; then
23
+ KUBE_MESSAGE="$(cat "$KUBE_MESSAGE_FILE" 2>/dev/null)" || KUBE_MESSAGE="$FALLBACK_KUBE"
24
+ fi
20
25
 
21
26
  FORMAT="opencode"
22
27
  [ "${1:-}" = "--format" ] && [ "${2:-}" = "claude" ] && FORMAT="claude"
@@ -25,6 +30,54 @@ INPUT="$(cat 2>/dev/null)" || exit 0
25
30
  [ -n "$INPUT" ] || exit 0
26
31
 
27
32
  block() { printf '%s\n' "$MESSAGE" >&2; exit 2; }
33
+ # Refuses a command that reaches the administrator kubeconfig, with a message
34
+ # of its own: the host override never lifts this refusal (#844).
35
+ block_kube() { printf '%s\n' "$KUBE_MESSAGE" >&2; exit 2; }
36
+
37
+ if command -v python3 >/dev/null 2>&1; then
38
+ HIT="$(__DG_INPUT="$INPUT" __DG_FORMAT="$FORMAT" python3 <<'KUBE_PYTHON'
39
+ import json, os, re, sys
40
+
41
+ try:
42
+ data = json.loads(os.environ.get("__DG_INPUT", ""))
43
+ except Exception:
44
+ sys.exit(0)
45
+ if not isinstance(data, dict):
46
+ sys.exit(0)
47
+ if os.environ.get("__DG_FORMAT", "opencode") == "claude":
48
+ tool = data.get("tool_name") or ""
49
+ inner = data.get("tool_input")
50
+ else:
51
+ tool = data.get("tool") or ""
52
+ inner = data.get("args")
53
+ cmd = (inner.get("command") if isinstance(inner, dict) else "") or ""
54
+ if tool not in ("bash", "shell", "Bash") or not isinstance(cmd, str) or not cmd:
55
+ sys.exit(0)
56
+ pattern = re.compile(
57
+ r"\.kube/hote\.config|\.kube-host|(?:^|[^\w])KUBECONFIG\s*=|"
58
+ r"(?:^|[^\w])export\s+KUBECONFIG\b|--kubeconfig(?:[=\s]|$)"
59
+ )
60
+ if pattern.search(cmd):
61
+ print("kube")
62
+ KUBE_PYTHON
63
+ )"
64
+ [ "$HIT" = kube ] && block_kube
65
+ elif command -v jq >/dev/null 2>&1; then
66
+ if [ "$FORMAT" = "claude" ]; then
67
+ KUBE_TOOL="$(printf '%s' "$INPUT" | jq -r '.tool_name // ""' 2>/dev/null)" || exit 0
68
+ KUBE_COMMAND="$(printf '%s' "$INPUT" | jq -r '.tool_input.command // ""' 2>/dev/null)" || exit 0
69
+ else
70
+ KUBE_TOOL="$(printf '%s' "$INPUT" | jq -r '.tool // ""' 2>/dev/null)" || exit 0
71
+ KUBE_COMMAND="$(printf '%s' "$INPUT" | jq -r '.args.command // ""' 2>/dev/null)" || exit 0
72
+ fi
73
+ case "$KUBE_TOOL" in bash|shell|Bash) ;; *) exit 0 ;; esac
74
+ [ -n "$KUBE_COMMAND" ] || exit 0
75
+ if printf '%s' "$KUBE_COMMAND" | grep -qE '(^|[^[:alnum:]_])KUBECONFIG[[:space:]]*=|\.kube/hote\.config|\.kube-host|(^|[^[:alnum:]_])export[[:space:]]+KUBECONFIG([^[:alnum:]_]|$)|--kubeconfig([[:space:]]|=|$)'; then
76
+ block_kube
77
+ fi
78
+ fi
79
+
80
+ [ "${DEVZONE_ALLOW_DOCKER:-}" = "1" ] && exit 0
28
81
 
29
82
  if command -v python3 >/dev/null 2>&1; then
30
83
  __DG_INPUT="$INPUT" __DG_FORMAT="$FORMAT" __DG_MESSAGE="$MESSAGE" python3 <<'PYTHON'
@@ -0,0 +1 @@
1
+ Cluster administrator access is reserved for the installers. Use the devzone context or the devzone commands (enable, disable, repair). An explicit host override does not lift this refusal.
@@ -7,6 +7,7 @@
7
7
  # Docker guard for the folders that are not this repository: a Claude Code
8
8
  # PreToolUse hook in the global settings and the two opencode plugins in the
9
9
  # global plugins folder. Idempotent, other user settings and hooks preserved.
10
+ # Claude Code also receives the limited Kubernetes context via env.KUBECONFIG.
10
11
  install_docker_guard() {
11
12
  local script="$ICI/ai/docker-guard.sh" config="$HOME/.claude/settings.json"
12
13
  local src="$ICI/ai/plugins" dst="$HOME/.config/opencode/plugins"
@@ -19,13 +20,17 @@ install_docker_guard() {
19
20
  echo "devzone : $config unreadable (invalid JSON): docker guard not installed for Claude Code" >&2
20
21
  else
21
22
  tmp="$(mktemp)"
22
- if jq --arg cmd "bash \"$script\" --format claude" '
23
+ if jq --arg cmd "bash \"$script\" --format claude" \
24
+ --arg kube "$HOME/.kube/agent.config" '
23
25
  .hooks = (.hooks // {}) |
24
26
  .hooks.PreToolUse = (.hooks.PreToolUse // []) |
25
27
  if ([.hooks.PreToolUse[]? | .hooks[]? | (.command // "")] | any(contains("docker-guard.sh")))
26
28
  then .
27
29
  else .hooks.PreToolUse += [{"matcher": "Bash", "hooks": [{"type": "command", "command": $cmd}]}]
28
- end
30
+ end |
31
+ if (.env | type) == "object" then .env = (.env + {"KUBECONFIG": $kube})
32
+ elif (.env | type) == "null" then .env = {"KUBECONFIG": $kube}
33
+ else . end
29
34
  ' "$config" >"$tmp" 2>/dev/null; then
30
35
  mv "$tmp" "$config"
31
36
  else
@@ -43,8 +48,9 @@ install_docker_guard() {
43
48
 
44
49
  # Removes only the Docker guard entries (commands containing docker-guard.sh)
45
50
  # and the two plugins; the rest of settings.json and of the plugins is kept.
51
+ # The Kubernetes context key is removed too, and an empty env object is dropped.
46
52
  remove_docker_guard() {
47
- local config="$HOME/.claude/settings.json" tmp
53
+ local config="$HOME/.claude/settings.json" tmp tmp2
48
54
  if [ -f "$config" ] && jq -e . "$config" >/dev/null 2>&1; then
49
55
  tmp="$(mktemp)"
50
56
  if jq '
@@ -65,7 +71,23 @@ remove_docker_guard() {
65
71
  if [ "$(cat "$tmp")" = "{}" ]; then
66
72
  rm -f "$tmp" "$config"
67
73
  else
68
- mv "$tmp" "$config"
74
+ tmp2="$(mktemp)"
75
+ if jq '
76
+ if (.env | type) == "object" then
77
+ .env = (.env | del(.KUBECONFIG)) |
78
+ if (.env | length) == 0 then del(.env) else . end
79
+ else . end
80
+ ' "$tmp" >"$tmp2" 2>/dev/null; then
81
+ if [ "$(cat "$tmp2")" = "{}" ]; then
82
+ rm -f "$tmp2" "$config"
83
+ else
84
+ mv "$tmp2" "$config"
85
+ fi
86
+ else
87
+ rm -f "$tmp2"
88
+ mv "$tmp" "$config"
89
+ fi
90
+ rm -f "$tmp"
69
91
  fi
70
92
  else
71
93
  rm -f "$tmp"
@@ -6,7 +6,8 @@
6
6
  # RoleBinding, with a 24 h TokenRequest token renewed at startup (startup.sh),
7
7
  # by « devzone repair » and by the summary before expiry. The installers alone
8
8
  # use the admin context (host context in ~/.kube/hote.config, kind cluster in
9
- # ~/.kube/config); shells and agents only have ~/.kube/config.
9
+ # ~/.kube/config); the shells use ~/.kube/config and the agents the limited
10
+ # ~/.kube/agent.config (devzone context only, #844).
10
11
  # Library sourced by cluster.sh; executable for the token:
11
12
  # kube-account.sh jeton (argument kept: called by startup.sh and devzone repair)
12
13
 
@@ -163,9 +164,10 @@ account_token_fresh() {
163
164
  # context of ~/.kube/config: user devzone-agent, same cluster as the admin
164
165
  # context (cluster entry copied: server, certificate authority and
165
166
  # tls-server-name of the host context). The expiry timestamp of the TokenRequest
166
- # response is kept in ACCOUNT_TOKEN_EXPIRY (now + 24 h if it is unreadable).
167
+ # response is kept in ACCOUNT_TOKEN_EXPIRY (now + 24 h if it is unreadable), only
168
+ # once a real call through the devzone context has succeeded.
167
169
  account_token() {
168
- local ctx="$1" conf token cluster server tls ca_data ca_file out expires expiry now
170
+ local ctx="$1" conf token cluster server tls ca_data ca_file out expires expiry now answer
169
171
  local entry=()
170
172
  conf="$(account_admin_config "$ctx")"
171
173
  out="$(account_admin "$ctx" create token "$ACCOUNT_SA" -n "$ACCOUNT_NS" \
@@ -189,14 +191,11 @@ account_token() {
189
191
  echo "devzone : server of cluster $cluster not found in $conf" >&2
190
192
  return 1
191
193
  fi
192
- ca_data="$(KUBECONFIG="$conf" kubectl config view \
193
- -o jsonpath="{.clusters[?(@.name==\"$cluster\")].cluster.certificate-authority-data}" 2>/dev/null || true)"
194
+ ca_data="$(KUBECONFIG="$conf" kubectl config view --raw -o jsonpath="{.clusters[?(@.name==\"$cluster\")].cluster.certificate-authority-data}" 2>/dev/null || true)"
194
195
  ca_file="$(KUBECONFIG="$conf" kubectl config view \
195
196
  -o jsonpath="{.clusters[?(@.name==\"$cluster\")].cluster.certificate-authority}" 2>/dev/null || true)"
196
197
  entry=(--server="$server")
197
- if [ -n "$ca_data" ]; then
198
- entry+=(--certificate-authority-data="$ca_data")
199
- elif [ -n "$ca_file" ]; then
198
+ if [ -n "$ca_file" ]; then
200
199
  entry+=(--certificate-authority="$ca_file" --embed-certs=true)
201
200
  fi
202
201
  tls="$(KUBECONFIG="$conf" kubectl config view \
@@ -205,11 +204,25 @@ account_token() {
205
204
  entry+=(--tls-server-name="$tls")
206
205
  fi
207
206
  KUBECONFIG="$ACCOUNT_CONFIG" kubectl config set-cluster "$cluster" \
208
- ${entry[@]+"${entry[@]}"} >/dev/null
207
+ ${entry[@]+"${entry[@]}"} >/dev/null || return 1
208
+ if [ -n "$ca_data" ]; then
209
+ KUBECONFIG="$ACCOUNT_CONFIG" kubectl config set \
210
+ "clusters.$cluster.certificate-authority-data" "$ca_data" >/dev/null || return 1
211
+ fi
209
212
  KUBECONFIG="$ACCOUNT_CONFIG" kubectl config set-credentials "$ACCOUNT_SA" \
210
- --token="$token" >/dev/null
213
+ --token="$token" >/dev/null || return 1
211
214
  KUBECONFIG="$ACCOUNT_CONFIG" kubectl config set-context devzone \
212
215
  --cluster="$cluster" --user="$ACCOUNT_SA" >/dev/null || return 1
216
+ answer="$(KUBECONFIG="$ACCOUNT_CONFIG" kubectl --context devzone \
217
+ auth can-i get pods -n "$ACCOUNT_NS" 2>/dev/null || true)"
218
+ case "$answer" in
219
+ yes | no) ;;
220
+ *)
221
+ echo "devzone : limited account context not reachable" >&2
222
+ rm -f "$ACCOUNT_TOKEN_EXPIRY"
223
+ return 1
224
+ ;;
225
+ esac
213
226
  now="$(date +%s)"
214
227
  expiry="$(account_expiry_epoch "$expires")"
215
228
  [ -n "$expiry" ] || expiry=$((now + 86400))
@@ -218,6 +231,21 @@ account_token() {
218
231
  chmod 600 "$ACCOUNT_TOKEN_EXPIRY"
219
232
  }
220
233
 
234
+ # Writes the limited agent kubeconfig: the devzone context only, current context
235
+ # set to it, for the agents that hold the limited account (Claude Code, #844).
236
+ # The contexts are read from ACCOUNT_CONFIG, never from the file being written:
237
+ # the view goes to a temporary file of the same folder, moved in place (atomic,
238
+ # mode 600); a failure empties the target and returns 1.
239
+ account_agent_config() {
240
+ local conf="${DEVZONE_KUBE_AGENT_CONFIG:-$HOME/.kube/agent.config}" tmp
241
+ tmp="$(mktemp "$(dirname "$conf")/.agent.config.XXXXXX")" || return 1
242
+ # shellcheck disable=SC2015 # the failure branch must empty the target too
243
+ ( umask 077; KUBECONFIG="$ACCOUNT_CONFIG" kubectl config view --minify --flatten \
244
+ --context devzone >"$tmp" ) && KUBECONFIG="$tmp" kubectl config use-context devzone >/dev/null 2>&1 \
245
+ || { rm -f "$tmp"; : >"$conf"; return 1; }
246
+ chmod 600 "$tmp"; mv "$tmp" "$conf"
247
+ }
248
+
221
249
  # Direct execution: account token renewed at startup (startup.sh) and by
222
250
  # « devzone repair ». Without a chosen services cluster: nothing to do.
223
251
  # When the file is sourced, $0 differs from BASH_SOURCE: nothing runs.
@@ -236,4 +264,5 @@ if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
236
264
  account_setup "$ctx" || exit 1
237
265
  account_catch_up "$ctx" || exit 1
238
266
  account_token "$ctx" || exit 1
267
+ account_agent_config || exit 1
239
268
  fi
@@ -1,5 +1,5 @@
1
1
  # Single source for the repowarden version used by post-create.sh and workspace-init.sh.
2
- REPOWARDEN_VERSION=4.17.6
2
+ REPOWARDEN_VERSION=4.18.0
3
3
 
4
4
  # BuildKit client version installed in the workspace image (#514). Must match
5
5
  # buildkit.image in charts/devzone-workspace/values.yaml.
package/README.md CHANGED
@@ -24,7 +24,8 @@ devzone avoids them: the same environment on every workstation, on your machine.
24
24
 
25
25
  - No systemd: the services provided by devzone start with devzone, not with `systemctl`.
26
26
  - No graphical desktop: everything happens in a terminal or in VS Code.
27
- - The terminal keeps the cluster administrator; agents only have the account limited to the `devzone-*` namespaces (`edit` role, token renewed every 24 h). Only the installers act as administrator ([#430](https://github.com/SimBienvenueHoulBoumi/devzone/issues/430)).
27
+ - Pod mode (default): the terminal in the pod has no rights on the cluster; the workstation acts as administrator for the time of an operation ([#528](https://github.com/SimBienvenueHoulBoumi/devzone/issues/528)).
28
+ - Container mode: the terminal keeps the cluster administrator; agents (opencode and Claude Code) only have the account limited to the `devzone-*` namespaces (`edit` role, token renewed every 24 h), Claude Code with the reduced kubeconfig `~/.kube/agent.config` ([#430](https://github.com/SimBienvenueHoulBoumi/devzone/issues/430), [#844](https://github.com/SimBienvenueHoulBoumi/devzone/issues/844)).
28
29
 
29
30
  ## How it works
30
31
 
package/bin/SHA256SUMS CHANGED
@@ -1,6 +1,6 @@
1
- dae2956fa9a2975b9295c6f1d5e24ac6c772c2d9cd1f5e63bb581d7c7bdf0495 devzone-linux-amd64
2
- a4bab424148b4aa019e51ed859e439dd03be1ebd43d03adc99879c69e8575e66 devzone-linux-arm64
3
- d8876e58859e18cf93bf3e97536c53d7cebfc6038175cd56a0a6222be83d6e47 devzone-darwin-amd64
4
- f33bfbfa7e8e21a65e94c9f3ac07a7f55ccfa2f99b080fb2b6385b1942f86886 devzone-darwin-arm64
5
- bf2edc599d52a290a942fdf14ca56e04c19b94f18f916fa1b26a4e7342226005 devzone-windows-amd64.exe
6
- b21d0014a75782033e8faece7bbc6fe0b980e103f53be91a935d0930fe287efc devzone-windows-arm64.exe
1
+ b6dccc1d9f2bd27f1dfc9b2e841ff4b3b82a362826146fb16d2955200235d8d5 devzone-linux-amd64
2
+ f3bc328b7f266ec1ce878a3df76d5e14496861e3ec376a62e546653ae41f1a11 devzone-linux-arm64
3
+ 17e0d97a2b60a064ddbf3d041ad76ed2357b2aeae1d90e0ecdfb4052b7984df5 devzone-darwin-amd64
4
+ 6eb07e8d5d2f168f1432bca3c2acb451df063773e7e14428acb6a61d752919b0 devzone-darwin-arm64
5
+ 7b4a96e1ef37cf611b3f1abeff3ef516c370e7504bf1dc2acccad45ad05be205 devzone-windows-amd64.exe
6
+ 035aaa2d06954d20288a7146a6967a57759dd90603a40b8e0bc4076f323c86eb devzone-windows-arm64.exe
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "devzone",
3
- "version": "7.0.2",
3
+ "version": "7.0.3",
4
4
  "description": "Ton poste de développement Linux, prêt en une commande, identique sur Mac, Windows et Linux.",
5
5
  "license": "GPL-3.0-only",
6
6
  "repository": {