HUB
Sign inSign up

equinor/developer-pod:dp-shell-0.3.0

Multi-platform
Manifest digest

sha256:ae6cec498bb143cb41219277285d5b84ce3e5b2e2d6d4c01c76729f33b982afc

Last pushed

about 21 hours by equinor

Type

Sandbox Kit

Manifest digest

sha256:ae6cec498bb143cb41219277285d5b84ce3e5b2e2d6d4c01c76729f33b982afc

yaml
schemaVersion: "3"
displayName: dp shell experience
description: zsh as the login shell with starship, autosuggestions, syntax highlighting and fzf; bash keeps starship, fzf and completion; mise, to install development tools such as Node, Python or Go when a project needs them; Equinor's CA certificates in the system trust store and Python's TLS checks relaxed, so tools work behind Equinor's TLS inspection.
version: 0.3.0
kind: mixin
provides:
    - [email protected]
capabilities:
    - type: com.docker.sandbox/network-policy@1
      config:
        install:
            allow:
                - deb.debian.org
                - dhi.io
        runtime:
            allow:
                - mise-java.jdx.dev
                - builds.dotnet.microsoft.com
                - api.nuget.org
    - type: com.docker.sandbox/lifecycle@1
      config:
        install:
            - command: |
                set -eu
                dir=/usr/local/share/ca-certificates/equinor
                bundle=/etc/ssl/certs/ca-certificates.crt
                # Reads every .crt under /usr/local/share/ca-certificates/,
                # subfolders included, and rewrites the bundle; sbx's own
                # proxy CA stays trusted through its proxy-ca.crt file there
                # (observed 2026-11-16, plan 023 "Research").
                update-ca-certificates
                # Each certificate must now be in the bundle, compared by its
                # base64 body between the PEM markers with the line breaks
                # removed (update-ca-certificates appends the files as they
                # are). Only tr and grep: no openssl or awk is assumed.
                flat="$(tr -d '\r\n' < "$bundle")"
                n=0
                for crt in "$dir"/*.crt; do
                  [ -f "$crt" ] || { echo "dp-shell: no certificate under $dir" >&2; exit 1; }
                  body="$(grep -v -e '-----BEGIN CERTIFICATE-----' -e '-----END CERTIFICATE-----' "$crt" | tr -d '\r\n')"
                  [ -n "$body" ] || { echo "dp-shell: $crt holds no PEM body" >&2; exit 1; }
                  case "$flat" in
                    *"-----BEGIN CERTIFICATE-----$body-----END CERTIFICATE-----"*) n=$((n + 1)) ;;
                    *) echo "dp-shell: $crt is not in $bundle after update-ca-certificates" >&2; exit 1 ;;
                  esac
                done
                echo "dp-shell: $n certificates from $dir are in $bundle ($(grep -c 'BEGIN CERTIFICATE' "$bundle") in total)"
                # Python: the devcontainer template's sitecustomize.py, copied
                # verbatim (the kit's README: source, trade-offs, how to turn
                # it off), into the standard library folder of python3, which
                # every python3 run imports at start, venvs made from it and
                # python3 -I included. Never over a foreign sitecustomize.py.
                src=/usr/local/share/dp-shell/python/sitecustomize.py
                # An if/else, not an early exit: the entry ends normally either
                # way, however sbx runs the kit's install entries (security
                # review of pull request 256, SR-2).
                if ! command -v python3 >/dev/null 2>&1; then
                  echo "dp-shell: no python3 on PATH; Python TLS relaxation skipped"
                else
                  [ -f "$src" ] || { echo "dp-shell: $src is missing" >&2; exit 1; }
                  # -I -S: no environment variables, no site, so no existing
                  # sitecustomize runs while the folder is asked for.
                  stdlib="$(python3 -I -S -c 'import sysconfig; print(sysconfig.get_paths()["stdlib"])')"
                  case "$stdlib" in
                    /*) ;;
                    *) echo "dp-shell: python3 gave no absolute standard library folder: '$stdlib'" >&2; exit 1 ;;
                  esac
                  [ -d "$stdlib" ] || { echo "dp-shell: $stdlib is not a folder" >&2; exit 1; }
                  target="$stdlib/sitecustomize.py"
                  if [ -L "$target" ]; then
                    echo "dp-shell: $target is a symbolic link, not dp-shell's file; not overwritten" >&2; exit 1
                  fi
                  if [ -e "$target" ] && ! cmp -s "$src" "$target"; then
                    echo "dp-shell: $target exists and differs from dp-shell's; not overwritten" >&2; exit 1
                  fi
                  install -m 0644 -o 0 -g 0 "$src" "$target"
                  cmp -s "$src" "$target" || { echo "dp-shell: $target differs from $src after the install" >&2; exit 1; }
                  # Both contexts relaxed, the rest enforced. The flag is read
                  # from ssl.VerifyFlags: the file sets ssl.VERIFY_X509_STRICT
                  # to 0. -B: no bytecode written into the standard library.
                  python3 -B -c '
                import ssl, sys
                strict = int(ssl.VerifyFlags.VERIFY_X509_STRICT)
                mod = sys.modules.get("sitecustomize")
                if strict == 0 or mod is None or getattr(mod, "__file__", None) != sys.argv[1]:
                    sys.exit("dp-shell: python3 did not load " + sys.argv[1])
                bad = []
                for name, ctx in (("create_default_context()", ssl.create_default_context()),
                                  ("SSLContext(PROTOCOL_TLS_CLIENT)", ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT))):
                    if ctx.verify_flags & strict or ctx.security_level != 1 or ctx.verify_mode != ssl.CERT_REQUIRED or not ctx.check_hostname:
                        bad.append("%s: strict=%s security_level=%s verify_mode=%s check_hostname=%s" % (
                            name, bool(ctx.verify_flags & strict), ctx.security_level, ctx.verify_mode.name, ctx.check_hostname))
                if bad:
                    sys.exit("dp-shell: Python TLS relaxation not in effect: " + "; ".join(bad))
                  ' "$target"
                  echo "dp-shell: $target installed for $(python3 -I -S -c 'import sys; print(sys.executable, sys.version.split()[0])'); strict X.509 checks off and security level 1 in both default contexts"
                fi
              description: Add Equinor's CA certificates to the system trust store with update-ca-certificates and check that each one is in the bundle; install the Python TLS relaxation (sitecustomize.py) for python3 and check it is in effect
              user: "0"
            - command: |
                set -eu
                export DEBIAN_FRONTEND=noninteractive
                apt-get update -qq
                apt-get install -y -qq --no-install-recommends zsh zsh-autosuggestions zsh-syntax-highlighting bash-completion libicu76 >/dev/null
                rm -rf /var/lib/apt/lists/*
                # chsh fails under PAM in a hook (observed); usermod works.
                usermod --shell /bin/zsh agent
                # Both system files belong to Debian packages, so the lines are
                # appended after the install, once (grep before append).
                line='[ -r /etc/dp/zshrc ] && . /etc/dp/zshrc'
                grep -qxF "$line" /etc/zsh/zshrc || printf '\n# dp-shell kit\n%s\n' "$line" >> /etc/zsh/zshrc
                # mise's shim folder on PATH for every zsh, not only the
                # interactive ones (plan 025 D6); /etc/zsh/zshenv is
                # zsh-common's file too.
                line='[ -r /etc/dp/mise-env.sh ] && . /etc/dp/mise-env.sh'
                grep -qxF "$line" /etc/zsh/zshenv || printf '\n# dp-shell kit\n%s\n' "$line" >> /etc/zsh/zshenv
                line='[ -r /etc/dp/bashrc ] && . /etc/dp/bashrc'
                grep -qxF "$line" /etc/bash.bashrc || printf '\n# dp-shell kit\n%s\n' "$line" >> /etc/bash.bashrc
                # The base ships /home/agent/.bashrc, which ends by setting
                # PROMPT_COMMAND to its own prompt after /etc/bash.bashrc ran
                # (observed, Docker Hardened Images Debian 13 base, 2026-11-13),
                # so bash gets starship only if the line also runs from there.
                home="$(getent passwd agent | cut -d: -f6)"
                if [ -f "$home/.bashrc" ] && ! grep -qxF "$line" "$home/.bashrc"; then
                  printf '\n# dp-shell kit\n%s\n' "$line" >> "$home/.bashrc"
                fi
                # Without any of its four startup files in the home, zsh's
                # zsh/newuser module runs the new-user menu on the first
                # interactive start (zsh 5.9 Src/Modules/newuser.c; Debian ships
                # scripts/newuser). An empty .zshrc, the agent's own, skips it;
                # it is the file a user edits for personal settings.
                if [ ! -e "$home/.zshrc" ] && [ ! -e "$home/.zshenv" ] && [ ! -e "$home/.zprofile" ] && [ ! -e "$home/.zlogin" ]; then
                  printf '%s\n' "# Your zsh settings. The dp-shell kit keeps its own in /etc/dp/zshrc (sourced by /etc/zsh/zshrc before this file)." > "$home/.zshrc"
                  chown agent:agent "$home/.zshrc"
                fi
              description: Install zsh, its two plugins and bash-completion from Debian; make zsh the agent user's login shell; wire dp's configuration into the system rc files
              user: "0"
            - command: |
                set -eu
                # sbx's file: the base ships it empty, owned by agent, and
                # sets BASH_ENV to it, so every bash sources it, an agent's
                # included (observed 2026-11-18, sbx v0.51.0 and v0.54.0, both kinds;
                # Docker's usage page). Created only if the base has none.
                file=/etc/sandbox-persistent.sh
                line='[ -r /etc/dp/mise-env.sh ] && . /etc/dp/mise-env.sh'
                [ -e "$file" ] || install -m 0644 -o agent -g agent /dev/null "$file"
                grep -qxF "$line" "$file" || printf '\n# dp-shell kit\n%s\n' "$line" >> "$file"
              description: Put mise's shim folder on PATH for non-interactive bash, with one line in /etc/sandbox-persistent.sh
              user: "0"