@moondeck/station 1.0.2 → 1.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.
@@ -43,6 +43,31 @@ ASDF_VOLUME="moondeck-asdf-data"
43
43
  STANDARD_DEFAULT_NODE_VERSION="22.11.0"
44
44
  TASK_NPM_PREFIX="/home/node/.local/share/uai-npm"
45
45
  TASK_NPM_CACHE="/home/node/.cache/uai-npm"
46
+ # Root's npm settings for every root exec (keep in sync with
47
+ # ROOT_NPM_AUTHORITY_ENV in lib/runtime-authority.ts). The TASK_NPM_* paths
48
+ # and node's ~/.npmrc are node-controlled, so a root exec must never inherit
49
+ # them from Compose or managed_exec_env: npm would resolve its cache, logs,
50
+ # prefix (and <prefix>/etc/npmrc) into files node can plant. /root is
51
+ # root-only. userconfig is /dev/null; globalconfig is a never-created file in
52
+ # the root-only state dir (npm exits if both name /dev/null). Both spellings, because npm
53
+ # matches npm_config_* case-insensitively.
54
+ ROOT_NPM_STATE_DIR="/root/.uai-npm"
55
+ root_npm_exec_env=(
56
+ -e "NPM_CONFIG_PREFIX=$ROOT_NPM_STATE_DIR/prefix"
57
+ -e "npm_config_prefix=$ROOT_NPM_STATE_DIR/prefix"
58
+ -e "NPM_CONFIG_CACHE=$ROOT_NPM_STATE_DIR/cache"
59
+ -e "npm_config_cache=$ROOT_NPM_STATE_DIR/cache"
60
+ -e "NPM_CONFIG_LOGS_DIR=$ROOT_NPM_STATE_DIR/cache/_logs"
61
+ -e "npm_config_logs_dir=$ROOT_NPM_STATE_DIR/cache/_logs"
62
+ -e "NPM_CONFIG_USERCONFIG=/dev/null"
63
+ -e "npm_config_userconfig=/dev/null"
64
+ -e "NPM_CONFIG_GLOBALCONFIG=$ROOT_NPM_STATE_DIR/npmrc"
65
+ -e "npm_config_globalconfig=$ROOT_NPM_STATE_DIR/npmrc"
66
+ -e "NPM_CONFIG_REGISTRY=https://registry.npmjs.org/"
67
+ -e "npm_config_registry=https://registry.npmjs.org/"
68
+ -e "NPM_CONFIG_UMASK=0022"
69
+ -e "npm_config_umask=0022"
70
+ )
46
71
  # Host-proved shims and system controls always win. A task-global package with
47
72
  # a new command name remains discoverable at the final path component, while a
48
73
  # package named node/claude/git/sh cannot intercept managed or agent startup.
@@ -2877,7 +2902,7 @@ fi
2877
2902
  if [ "$TASK_RUNTIME_MODE" = "apple-container" ]; then
2878
2903
  step "CONTAINER_INIT_FAILED" "establish task runtime overlay"
2879
2904
  overlay_rc=0
2880
- "$CONTAINER_CLI" exec -u root "$app_container" /bin/sh -c '
2905
+ "$CONTAINER_CLI" exec -u root "${root_npm_exec_env[@]}" "$app_container" /bin/sh -c '
2881
2906
  set -e
2882
2907
  # Apple has no run --sysctl option. This guest has its own kernel and
2883
2908
  # CAP_NET_ADMIN, so set the equivalent before any task process starts.
@@ -2981,7 +3006,8 @@ step "CONTAINER_INIT_FAILED" "uai-init (deps + code-server)"
2981
3006
  # plus absolute command paths so a project value cannot redirect this managed
2982
3007
  # credential operation to workspace code or another config directory.
2983
3008
  managed_gh_config_dir="/home/node/.config/gh"
2984
- managed_exec_env=(
3009
+ # Shared by root and node managed execs; each adds its own npm settings below.
3010
+ managed_common_exec_env=(
2985
3011
  -e "HOME=/home/node"
2986
3012
  -e "GH_CONFIG_DIR=$managed_gh_config_dir"
2987
3013
  -e "PATH=/usr/bin:/bin"
@@ -3009,14 +3035,6 @@ managed_exec_env=(
3009
3035
  -e "COREPACK_ENABLE_STRICT=1"
3010
3036
  -e "COREPACK_ENABLE_UNSAFE_CUSTOM_URLS=0"
3011
3037
  -e "COREPACK_INTEGRITY_CHECK=1"
3012
- -e "NPM_CONFIG_PREFIX=$TASK_NPM_PREFIX"
3013
- -e "npm_config_prefix=$TASK_NPM_PREFIX"
3014
- -e "NPM_CONFIG_CACHE=$TASK_NPM_CACHE"
3015
- -e "npm_config_cache=$TASK_NPM_CACHE"
3016
- -e "NPM_CONFIG_LOGS_DIR=$TASK_NPM_CACHE/_logs"
3017
- -e "npm_config_logs_dir=$TASK_NPM_CACHE/_logs"
3018
- -e "NPM_CONFIG_UMASK=0002"
3019
- -e "npm_config_umask=0002"
3020
3038
  -e "LD_PRELOAD="
3021
3039
  -e "LD_AUDIT="
3022
3040
  -e "LD_LIBRARY_PATH="
@@ -3038,6 +3056,24 @@ managed_exec_env=(
3038
3056
  -e "GH_TOKEN="
3039
3057
  -e "GITHUB_TOKEN="
3040
3058
  )
3059
+ # Node managed execs: node's own task-private npm locations, as before.
3060
+ managed_exec_env=(
3061
+ "${managed_common_exec_env[@]}"
3062
+ -e "NPM_CONFIG_PREFIX=$TASK_NPM_PREFIX"
3063
+ -e "npm_config_prefix=$TASK_NPM_PREFIX"
3064
+ -e "NPM_CONFIG_CACHE=$TASK_NPM_CACHE"
3065
+ -e "npm_config_cache=$TASK_NPM_CACHE"
3066
+ -e "NPM_CONFIG_LOGS_DIR=$TASK_NPM_CACHE/_logs"
3067
+ -e "npm_config_logs_dir=$TASK_NPM_CACHE/_logs"
3068
+ -e "NPM_CONFIG_UMASK=0002"
3069
+ -e "npm_config_umask=0002"
3070
+ )
3071
+ # Root managed execs: the same controls with root-only npm settings, so a
3072
+ # root exec never carries an npm path under /home/node.
3073
+ root_exec_env=(
3074
+ "${managed_common_exec_env[@]}"
3075
+ "${root_npm_exec_env[@]}"
3076
+ )
3041
3077
  managed_clean_env=(
3042
3078
  /usr/bin/env -i
3043
3079
  "HOME=/home/node"
@@ -3127,7 +3163,7 @@ secrets_proxy_report() {
3127
3163
  }
3128
3164
  if [ "$UAI_PROJECT_ENV_MODE" = "loader" ] && [ -n "$secrets_proxy_dir" ]; then
3129
3165
  if [ -f "$secrets_proxy_dir/ca-install.sh" ] && [ -f "$secrets_proxy_dir/ca-bundle.pem" ] \
3130
- && crt exec -i -u root "${managed_exec_env[@]}" "$app_container" \
3166
+ && crt exec -i -u root "${root_exec_env[@]}" "$app_container" \
3131
3167
  /bin/sh -c "$(cat "$secrets_proxy_dir/ca-install.sh")" \
3132
3168
  < "$secrets_proxy_dir/ca-bundle.pem" >/dev/null; then
3133
3169
  secrets_proxy_trust=installed
@@ -3199,7 +3235,7 @@ ensure_block /etc/zsh/zshrc '[ "${UAI_ENV_HOOK-0}" != 1 ] || { type __uai_env_in
3199
3235
  ensure_block /etc/bash.bashrc '[ "${UAI_ENV_HOOK-0}" != 1 ] || { . /usr/local/share/uai/env-hook.sh; __uai_env_sync; __uai_env_install_bash_preexec; }'
3200
3236
  ensure_block /etc/profile.d/uai-env.sh '[ "${UAI_ENV_HOOK-0}" != 1 ] || { . /usr/local/share/uai/env-hook.sh; if [ -z "${BASH_EXECUTION_STRING-}" ] || [ -z "${BASH_ENV-}" ]; then __uai_env_sync; fi; }'
3201
3237
  UAI_ENV_STUB_INSTALLER
3202
- if ! crt exec -u root "${managed_exec_env[@]}" "$app_container" \
3238
+ if ! crt exec -u root "${root_exec_env[@]}" "$app_container" \
3203
3239
  /bin/bash -c "$env_stub_installer" >/dev/null; then
3204
3240
  emit_err "CONTAINER_INIT_FAILED" \
3205
3241
  "Moondeck could not install the root-owned task env shell hooks. Retry the task; project env remains withheld until this succeeds." \
@@ -3316,7 +3352,7 @@ UAI_TASK_FORWARDER_LAUNCHER
3316
3352
  fi
3317
3353
  if ! printf '%s' "$task_gateway_secret_b64" \
3318
3354
  | base64 "${base64_decode_args[@]}" \
3319
- | crt exec -i -u root "${managed_exec_env[@]}" "$app_container" \
3355
+ | crt exec -i -u root "${root_exec_env[@]}" "$app_container" \
3320
3356
  /bin/bash -c "$task_forwarder_launcher" uai-task-forwarder \
3321
3357
  "$task_id" "$task_gateway_generation" "$task_gateway_host" \
3322
3358
  "$task_gateway_port" "$task_forwarder_node" \
@@ -3344,12 +3380,12 @@ secrets_proxy_chain() {
3344
3380
  else
3345
3381
  set -- docker exec --privileged -u root
3346
3382
  fi
3347
- "$@" "${managed_exec_env[@]}" "$app_container" \
3383
+ "$@" "${root_exec_env[@]}" "$app_container" \
3348
3384
  /bin/sh -c "$(cat "$secrets_proxy_dir/chain.sh")" >/dev/null \
3349
3385
  || { log "warning: could not redirect the secrets proxy's names in ${app_container}"; return 1; }
3350
3386
  }
3351
3387
  secrets_proxy_names() {
3352
- crt exec -u root "${managed_exec_env[@]}" "$app_container" \
3388
+ crt exec -u root "${root_exec_env[@]}" "$app_container" \
3353
3389
  /bin/sh -c "$(cat "$secrets_proxy_dir/pins.sh")" >/dev/null \
3354
3390
  || { log "warning: could not pin the secrets proxy's names in ${app_container}"; return 1; }
3355
3391
  }
@@ -3382,7 +3418,12 @@ for node_data_phase in repair create repair; do
3382
3418
  node_data_user=root
3383
3419
  node_data_argv=( /usr/bin/python3 -I -c "$NODE_STATE_SETUP_SCRIPT" )
3384
3420
  fi
3385
- if ! crt exec -u "$node_data_user" "${managed_exec_env[@]}" "$app_container" "${node_data_argv[@]}" >/dev/null; then
3421
+ if [ "$node_data_user" = root ]; then
3422
+ node_data_env=( "${root_exec_env[@]}" )
3423
+ else
3424
+ node_data_env=( "${managed_exec_env[@]}" )
3425
+ fi
3426
+ if ! crt exec -u "$node_data_user" "${node_data_env[@]}" "$app_container" "${node_data_argv[@]}" >/dev/null; then
3386
3427
  emit_err "CONTAINER_INIT_FAILED" \
3387
3428
  "Moondeck could not prepare node-owned application data directory metadata." \
3388
3429
  "prepare container application data"
@@ -3495,27 +3536,66 @@ if [ -n "$github_credential_socket" ]; then
3495
3536
  fi
3496
3537
  fi
3497
3538
 
3539
+ # Root never creates, copies, chowns or chmods a path inside /home/node: on a
3540
+ # resumed container node can plant a symlink or hardlink there in advance (or
3541
+ # swap one in mid-run) and redirect root onto a file node does not own. Host
3542
+ # copies therefore stream over stdin to node, which writes its own files
3543
+ # (uai-write-node-data, the same asset lib/node-state.ts sends). Root only hands
3544
+ # entries an older root-run step left root-owned back to node, through pinned
3545
+ # no-follow descriptors (uai-repair-node-data.py): links, hardlinks, foreign
3546
+ # owners and other filesystems are logged and skipped, and it never fails.
3547
+ NODE_DATA_WRITE_SCRIPT=$(cat "$STANDARD_CONTAINER_DIR/uai-write-node-data")
3548
+ node_home_repair() {
3549
+ node_home_repair_log=$(crt exec -u root "${root_exec_env[@]}" "$app_container" \
3550
+ /usr/bin/python3 -I -c "$NODE_STATE_SETUP_SCRIPT" "$@" 2>&1 >/dev/null) \
3551
+ || log "warning: node home metadata repair could not run ($*)"
3552
+ if [ -n "$node_home_repair_log" ]; then
3553
+ printf '%s\n' "$node_home_repair_log" | while IFS= read -r node_home_repair_line; do
3554
+ log "warning: $node_home_repair_line"
3555
+ done
3556
+ fi
3557
+ }
3558
+ # Octal permission bits of a host file (GNU stat, else BSD stat), like the
3559
+ # mode `docker cp` used to preserve.
3560
+ host_file_mode() {
3561
+ host_mode=$(stat -c '%a' "$1" 2>/dev/null) \
3562
+ || host_mode=$(stat -f '%Lp' "$1" 2>/dev/null) || host_mode=600
3563
+ case $host_mode in '' | *[!0-7]*) host_mode=600 ;; esac
3564
+ printf '%s\n' "$host_mode"
3565
+ }
3566
+ # <host-file> <container-dest> [<mode> [<parent-mode>]]: node writes it atomically.
3567
+ node_home_put_file() {
3568
+ node_put_mode=${3:-}
3569
+ [ -n "$node_put_mode" ] || node_put_mode=$(host_file_mode "$1")
3570
+ crt exec -i -u node "${managed_exec_env[@]}" "$app_container" \
3571
+ /bin/sh -c "$NODE_DATA_WRITE_SCRIPT" uai-write-node-data file "$2" \
3572
+ "$node_put_mode" ${4:+"$4"} <"$1" >/dev/null
3573
+ }
3574
+ # <host-dir> <container-dest-dir> <member>: node extracts a host tar of it.
3575
+ node_home_put_tree() {
3576
+ COPYFILE_DISABLE=1 tar -C "$1" -cf - "$3" \
3577
+ | crt exec -i -u node "${managed_exec_env[@]}" "$app_container" \
3578
+ /bin/sh -c "$NODE_DATA_WRITE_SCRIPT" uai-write-node-data tar "$2" >/dev/null
3579
+ }
3580
+ node_home_repair .claude.json:-:- .codex:-:r .kimi-code:-:r .grok:-:r \
3581
+ .ssh:0700:r .ssh/id_ed25519:0600:-
3582
+
3498
3583
  # Copy `.claude.json` into the container instead of bind-mounting it.
3499
3584
  # Single-file bind mounts on Docker Desktop macOS are fragile — claude
3500
3585
  # CLI atomically rewrites the file on every start, which can invalidate
3501
3586
  # the bind mount and leave a stale dentry, after which claude refuses to
3502
- # start. docker cp gives the container its own stable copy. Best-effort.
3587
+ # start. A container-local copy is stable. Best-effort.
3503
3588
  if [ "$uai_on_cloud_credentials" != "1" ] && [ -f "$UAI_OWNER_HOME/.claude.json" ]; then
3504
- crt cp "$UAI_OWNER_HOME/.claude.json" \
3505
- "$app_container":/home/node/.claude.json >/dev/null 2>&1 \
3506
- || log "warning: crt cp of .claude.json failed; claude may need re-login"
3507
- crt exec -u root "${managed_exec_env[@]}" "$app_container" \
3508
- /usr/bin/chown node:node /home/node/.claude.json >/dev/null 2>&1 || true
3589
+ node_home_put_file "$UAI_OWNER_HOME/.claude.json" /home/node/.claude.json \
3590
+ || log "warning: copy of .claude.json failed; claude may need re-login"
3509
3591
  fi
3510
3592
 
3511
3593
  # Copy Codex credentials/config into a task-private /home/node/.codex.
3512
3594
  # Do not mount the host ~/.codex writable: Codex stores live SQLite state
3513
3595
  # there, and concurrent host/container access can corrupt it.
3514
- # Failures here are REAL errors (the container is running at task-up):
3515
- # docker cp preserves the host uid/gid, so a skipped chown leaves 0600
3516
- # files owned by e.g. macOS 501:20 that the container's node (1000:1000)
3517
- # cannot read — Codex then dies at startup.
3518
- if crt exec -u root "${managed_exec_env[@]}" "$app_container" \
3596
+ # Failures here are REAL errors (the container is running at task-up): node
3597
+ # writes these files, so they are node-owned with the host's modes.
3598
+ if crt exec -u node "${managed_exec_env[@]}" "$app_container" \
3519
3599
  /usr/bin/mkdir -p /home/node/.codex >/dev/null; then
3520
3600
  for codex_item in auth.json config.toml AGENTS.md version.json installation_id rules; do
3521
3601
  [ "$uai_on_cloud_credentials" = "1" ] && continue
@@ -3528,22 +3608,18 @@ if crt exec -u root "${managed_exec_env[@]}" "$app_container" \
3528
3608
  brokered_auth="$(mktemp "${TMPDIR:-/tmp}/uai-codex-auth.XXXXXX")"
3529
3609
  if jq 'if (.tokens|type) == "object" and (.tokens.refresh_token|type) == "string" then .tokens.refresh_token = "uai-broker-managed-no-refresh" else . end' \
3530
3610
  "$UAI_OWNER_HOME/.codex/auth.json" > "$brokered_auth" 2>/dev/null && [ -s "$brokered_auth" ]; then
3531
- crt cp "$brokered_auth" "$app_container":/home/node/.codex/auth.json >/dev/null \
3532
- || log "ERROR: crt cp of brokered .codex/auth.json failed; Codex in this task may not authenticate"
3611
+ node_home_put_file "$brokered_auth" /home/node/.codex/auth.json 600 \
3612
+ || log "ERROR: copy of brokered .codex/auth.json failed; Codex in this task may not authenticate"
3533
3613
  rm -f "$brokered_auth"
3534
3614
  continue
3535
3615
  fi
3536
3616
  rm -f "$brokered_auth"
3537
3617
  log "warning: could not broker .codex/auth.json; copying it verbatim"
3538
3618
  fi
3539
- crt cp "$UAI_OWNER_HOME/.codex/$codex_item" \
3540
- "$app_container":/home/node/.codex/ >/dev/null \
3541
- || log "ERROR: crt cp of .codex/$codex_item failed; Codex in this task may not authenticate"
3619
+ node_home_put_tree "$UAI_OWNER_HOME/.codex" /home/node/.codex "$codex_item" \
3620
+ || log "ERROR: copy of .codex/$codex_item failed; Codex in this task may not authenticate"
3542
3621
  fi
3543
3622
  done
3544
- crt exec -u root "${managed_exec_env[@]}" "$app_container" \
3545
- /usr/bin/chown -R node:node /home/node/.codex >/dev/null \
3546
- || log "ERROR: chown of /home/node/.codex failed — 0600 credentials remain unreadable by node. Fix (docker mode; use the bundled container CLI on Apple hosts): docker exec -u root -e PATH=/usr/bin:/bin $app_container /usr/bin/chown -R node:node /home/node/.codex"
3547
3623
  else
3548
3624
  log "ERROR: mkdir /home/node/.codex failed in $app_container; Codex credentials were not injected"
3549
3625
  fi
@@ -3552,31 +3628,22 @@ fi
3552
3628
  # The Linux `kimi` binary is baked into the image; here we copy ONLY the
3553
3629
  # arch-independent config + credential (never the host's macOS bin/, nor live
3554
3630
  # session state) so the container's kimi runs on the operator's subscription.
3555
- crt exec -u root "${managed_exec_env[@]}" "$app_container" \
3631
+ crt exec -u node "${managed_exec_env[@]}" "$app_container" \
3556
3632
  /usr/bin/mkdir -p /home/node/.kimi-code/credentials >/dev/null 2>&1 || true
3557
- if [ "$uai_on_cloud_credentials" != "1" ] && [ -e "$UAI_OWNER_HOME/.kimi-code/config.toml" ]; then
3558
- crt cp "$UAI_OWNER_HOME/.kimi-code/config.toml" \
3559
- "$app_container":/home/node/.kimi-code/config.toml >/dev/null 2>&1 \
3560
- || log "warning: crt cp of .kimi-code/config.toml failed; kimi may need re-login"
3561
- fi
3562
- if [ "$uai_on_cloud_credentials" != "1" ] && [ -e "$UAI_OWNER_HOME/.kimi-code/device_id" ]; then
3563
- crt cp "$UAI_OWNER_HOME/.kimi-code/device_id" \
3564
- "$app_container":/home/node/.kimi-code/device_id >/dev/null 2>&1 || true
3565
- fi
3566
- if [ "$uai_on_cloud_credentials" != "1" ] && [ -e "$UAI_OWNER_HOME/.kimi-code/credentials/kimi-code.json" ]; then
3567
- crt cp "$UAI_OWNER_HOME/.kimi-code/credentials/kimi-code.json" \
3568
- "$app_container":/home/node/.kimi-code/credentials/kimi-code.json >/dev/null 2>&1 \
3569
- || log "warning: crt cp of .kimi-code credential failed; kimi may need re-login"
3570
- fi
3571
- crt exec -u root "${managed_exec_env[@]}" "$app_container" \
3572
- /usr/bin/chown -R node:node /home/node/.kimi-code >/dev/null 2>&1 || true
3633
+ for kimi_item in config.toml device_id credentials/kimi-code.json; do
3634
+ [ "$uai_on_cloud_credentials" = "1" ] && continue
3635
+ if [ -e "$UAI_OWNER_HOME/.kimi-code/$kimi_item" ]; then
3636
+ node_home_put_file "$UAI_OWNER_HOME/.kimi-code/$kimi_item" "/home/node/.kimi-code/$kimi_item" \
3637
+ || log "warning: copy of .kimi-code/$kimi_item failed; kimi may need re-login"
3638
+ fi
3639
+ done
3573
3640
 
3574
3641
  # Copy Grok subscription/config into a task-private /home/node/.grok. The Linux
3575
3642
  # `grok` binary is baked into the image; here we copy the arch-independent
3576
3643
  # auth + config. auth.json is an OIDC token: the task's copy gets the broker
3577
3644
  # placeholder in every entry's refresh_token (ADR-135) so it can never rotate
3578
3645
  # the family; the host is the only refresher.
3579
- crt exec -u root "${managed_exec_env[@]}" "$app_container" \
3646
+ crt exec -u node "${managed_exec_env[@]}" "$app_container" \
3580
3647
  /usr/bin/mkdir -p /home/node/.grok >/dev/null 2>&1 || true
3581
3648
  for grok_item in auth.json config.toml models_cache.json agent_id; do
3582
3649
  [ "$uai_on_cloud_credentials" = "1" ] && continue
@@ -3585,21 +3652,18 @@ for grok_item in auth.json config.toml models_cache.json agent_id; do
3585
3652
  brokered_auth="$(mktemp "${TMPDIR:-/tmp}/uai-grok-auth.XXXXXX")"
3586
3653
  if jq 'with_entries(if (.value|type) == "object" and (.value.refresh_token|type) == "string" then .value.refresh_token = "uai-broker-managed-no-refresh" else . end)' \
3587
3654
  "$UAI_OWNER_HOME/.grok/auth.json" > "$brokered_auth" 2>/dev/null && [ -s "$brokered_auth" ]; then
3588
- crt cp "$brokered_auth" "$app_container":/home/node/.grok/auth.json >/dev/null 2>&1 \
3589
- || log "warning: crt cp of brokered .grok/auth.json failed; grok may need re-login"
3655
+ node_home_put_file "$brokered_auth" /home/node/.grok/auth.json 600 \
3656
+ || log "warning: copy of brokered .grok/auth.json failed; grok may need re-login"
3590
3657
  rm -f "$brokered_auth"
3591
3658
  continue
3592
3659
  fi
3593
3660
  rm -f "$brokered_auth"
3594
3661
  log "warning: could not broker .grok/auth.json; copying it verbatim"
3595
3662
  fi
3596
- crt cp "$UAI_OWNER_HOME/.grok/$grok_item" \
3597
- "$app_container":/home/node/.grok/ >/dev/null 2>&1 \
3598
- || log "warning: crt cp of .grok/$grok_item failed; grok may need re-login"
3663
+ node_home_put_tree "$UAI_OWNER_HOME/.grok" /home/node/.grok "$grok_item" \
3664
+ || log "warning: copy of .grok/$grok_item failed; grok may need re-login"
3599
3665
  fi
3600
3666
  done
3601
- crt exec -u root "${managed_exec_env[@]}" "$app_container" \
3602
- /usr/bin/chown -R node:node /home/node/.grok >/dev/null 2>&1 || true
3603
3667
 
3604
3668
  # Copy OpenCode provider auth into a task-private /home/node/.local/share/opencode
3605
3669
  # (ADR-077), same per-task-writable-copy pattern as Codex. The Linux `opencode`
@@ -3610,12 +3674,12 @@ crt exec -u root "${managed_exec_env[@]}" "$app_container" \
3610
3674
  for oc_item in auth.json config.json; do
3611
3675
  [ "$uai_on_cloud_credentials" = "1" ] && continue
3612
3676
  if [ -e "$UAI_OWNER_HOME/.local/share/opencode/$oc_item" ]; then
3613
- crt cp "$UAI_OWNER_HOME/.local/share/opencode/$oc_item" \
3614
- "$app_container":/home/node/.local/share/opencode/ >/dev/null 2>&1 \
3615
- || log "warning: crt cp of opencode/$oc_item failed; opencode may need re-login"
3677
+ node_home_put_file "$UAI_OWNER_HOME/.local/share/opencode/$oc_item" \
3678
+ "/home/node/.local/share/opencode/$oc_item" 600 \
3679
+ || log "warning: copy of opencode/$oc_item failed; opencode may need re-login"
3616
3680
  fi
3617
3681
  done
3618
- crt exec -u root "${managed_exec_env[@]}" "$app_container" \
3682
+ crt exec -u root "${root_exec_env[@]}" "$app_container" \
3619
3683
  /usr/bin/python3 -I -c "$NODE_STATE_SETUP_SCRIPT" >/dev/null || log "warning: opencode metadata repair failed"
3620
3684
 
3621
3685
  # Copy the resolved SSH identity into the container for commit/tag signing and
@@ -3624,21 +3688,13 @@ crt exec -u root "${managed_exec_env[@]}" "$app_container" \
3624
3688
  # Best-effort: signing + the SSH fallback stay off if the identity is absent —
3625
3689
  # but every failure is LOGGED (a silent miss here reads as a GitHub
3626
3690
  # permissions problem hours later; live 2026-07-21). The channel-ensure path
3627
- # (ensureTaskSshIdentity) re-asserts all of this on reconnects.
3691
+ # (ensureTaskSshIdentity) re-asserts all of this on reconnects. Node writes
3692
+ # both files and sets ~/.ssh to 0700 itself; the key lands 0600.
3628
3693
  if [ -f "$uai_identity_key" ]; then
3629
- crt exec -u root "${managed_exec_env[@]}" "$app_container" \
3630
- /usr/bin/mkdir -p /home/node/.ssh >/dev/null 2>&1 \
3631
- || log "warning: ssh setup: mkdir ~/.ssh failed in $app_container"
3632
- crt cp "$uai_identity_key" \
3633
- "$app_container":/home/node/.ssh/id_ed25519 >/dev/null 2>&1 \
3694
+ node_home_put_file "$uai_identity_key" /home/node/.ssh/id_ed25519 600 700 \
3634
3695
  || log "warning: ssh setup: key copy failed — signing and SSH fallback unavailable"
3635
- crt cp "${uai_identity_key}.pub" \
3636
- "$app_container":/home/node/.ssh/id_ed25519.pub >/dev/null 2>&1 \
3696
+ node_home_put_file "${uai_identity_key}.pub" /home/node/.ssh/id_ed25519.pub "" 700 \
3637
3697
  || log "warning: ssh setup: pubkey copy failed (signing will be off)"
3638
- crt exec -u root "${managed_exec_env[@]}" "$app_container" /bin/sh -c \
3639
- '/usr/bin/chown -R node:node /home/node/.ssh && /usr/bin/chmod 700 /home/node/.ssh && /usr/bin/chmod 600 /home/node/.ssh/id_ed25519' \
3640
- >/dev/null 2>&1 \
3641
- || log "warning: ssh setup: chown/chmod failed — key may be unreadable by node"
3642
3698
  fi
3643
3699
 
3644
3700
  # uai-init (workspace deps + code-server) is re-runnable, and its death must