diff --git a/docs/agent-release-signing.md b/docs/agent-release-signing.md index 2b7b9ea..ceb0326 100644 --- a/docs/agent-release-signing.md +++ b/docs/agent-release-signing.md @@ -30,16 +30,18 @@ Central affiche une commande Bash ou PowerShell qui télécharge et exécute l ```sh sudo bash install/install-agent.sh \ - --central-url https://central.example.org \ - --site-token 'JETON_DE_SITE' \ + --central-url-file /chemin/protege/central-url \ + --site-token-file /chemin/protege/site-token \ --update-public-key /chemin/local/agent-release-public.pem ``` +Les deux fichiers d’enrôlement doivent être réguliers, non-symlinks et en mode `0600` ou plus restrictif; placez-les dans un répertoire privé. N’inscrivez jamais l’URL ou le jeton dans les arguments de processus. + L’installateur Linux est servi par Central avec son superviseur. Il installe la release sous `/opt/heimdall/agent/releases/`; le service systemd utilise le lien `current`. Après téléchargement vérifié, le superviseur accorde jusqu’à 180 secondes au démarrage, exige ensuite 60 secondes de réponse continue de `/api/version` pour la version attendue et rétablit la release précédente si cette validation échoue. Sous Windows, copiez la commande PowerShell générée dans l’IHM pour le site, en mode processus utilisateur ou service Windows. Elle télécharge le script depuis Central et applique `ExecutionPolicy Bypass` à la session PowerShell courante uniquement; elle ne change pas la stratégie persistante de la machine. L’installation comme service exige une session PowerShell élevée. Une stratégie imposée par une stratégie de groupe peut toujours interdire l’exécution. -Pour un Agent Docker, le Compose et les commandes `docker run` générés par l’IHM installent le dépôt d’image avec le tag `latest`; Compose et `docker run` vérifient le registre au démarrage. Le parcours CPU est sélectionné par défaut. Le parcours CUDA est proposé quand la release fournit l’image GPU signée; il demande aussi le NVIDIA Container Toolkit sur l’hôte. Aucun fichier de clé n’est à créer manuellement. Pour les mises à jour déclenchées ensuite par Central, l’Agent vérifie la signature et le digest d’image du manifeste signé avant de remplacer le conteneur. Les Agents configurés sur CUDA continuent de sélectionner l’image GPU pendant les mises à jour. +Pour un Agent Docker, le Compose et les commandes `docker run` générés par l’IHM épinglent l’image CPU ou GPU au digest vérifié du manifeste signé (`repository@sha256:digest`). Compose et `docker run` récupèrent cette référence immuable au démarrage (`pull_policy: always` et `--pull always`). Le parcours CPU est sélectionné par défaut. Le parcours CUDA est proposé quand la release fournit l’image GPU signée; il demande aussi le NVIDIA Container Toolkit sur l’hôte. Aucun fichier de clé n’est à créer manuellement. Pour les mises à jour déclenchées ensuite par Central, l’Agent vérifie la signature et le digest d’image du manifeste signé avant de remplacer le conteneur. Les Agents configurés sur CUDA continuent de sélectionner l’image GPU pendant les mises à jour. ## Rotation diff --git a/docs/docker-compose.md b/docs/docker-compose.md index 505d46e..17c96ef 100644 --- a/docs/docker-compose.md +++ b/docs/docker-compose.md @@ -134,10 +134,10 @@ in [`skills/deployment-guide-acceptance/SKILL.md`](../skills/deployment-guide-ac ## Agent -Prefer the Compose shown in the Central UI's site installation panel. It uses -the Agent image's `latest` tag and includes the site token, public Central URL, -Agent name and release public key. Compose uses `pull_policy: always` so an -explicit `docker compose up` checks for the latest image. Save it as +Prefer the Compose shown in the Central UI's site installation panel. It pins +the CPU or GPU Agent image to the signed `repository@sha256:digest` and includes +the site token, public Central URL, Agent name and release public key. Compose +uses `pull_policy: always` to fetch that exact digest. Save it as `docker-compose.yml`, then run `docker compose up -d`. The generated Compose contains the pinned trust key; no separate PEM file is required. Updates dispatched later by Central continue to verify the digest in the signed release diff --git a/docs/ui-pages.md b/docs/ui-pages.md index 7d0cd01..0a9f2f4 100644 --- a/docs/ui-pages.md +++ b/docs/ui-pages.md @@ -242,7 +242,7 @@ Dashboard shows agent offline state │ │ Commandes │ │ │ │ Installer │ │ │ │ ┌──────────────────────────────────────────┐ │ │ -│ │ │ curl ... install-agent.sh ... [⧉]│ │ │ +│ │ │ demander URL/token puis installer [⧉]│ │ │ │ │ └──────────────────────────────────────────┘ │ │ │ │ Lancer │ │ │ │ ┌──────────────────────────────────────────┐ │ │ @@ -273,7 +273,7 @@ Configuration (Docker uniquement si l'image GPU est publiée) Commandes Installer ┌──────────────────────────────────────────────┐ -│ commande/script [⧉]│ +│ demande URL et token masqué, puis installe [⧉]│ └──────────────────────────────────────────────┘ Lancer ┌──────────────────────────────────────────────┐ @@ -281,7 +281,9 @@ Lancer └──────────────────────────────────────────────┘ ``` -Docker Compose affiche le YAML comme une étape « Configuration », suivie des commandes pour démarrer et vérifier l'Agent. Chaque bloc a une copie intégrée en haut à droite; après copie, l'icône devient une coche. Les commandes d'installation restent masquées tant que la release signée correspondante n'est pas disponible. Docker exige aussi les métadonnées d'image vérifiées de la release, puis installe l'image publiée avec le tag `latest`; les remplacements déclenchés par Central restent vérifiés par digest signé. En cas d'indisponibilité, le panneau montre une alerte explicite à la place des commandes. +Docker Compose affiche le YAML comme une étape « Configuration », suivie des commandes pour démarrer et vérifier l'Agent. Chaque bloc a une copie intégrée en haut à droite; après copie, l'icône devient une coche. Les commandes d'installation restent masquées tant que la release signée correspondante n'est pas disponible. Docker exige les métadonnées d'image vérifiées de la release et épingle l'image CPU ou GPU sur son digest signé (`repository@sha256:digest`). Compose utilise `pull_policy: always` pour récupérer exactement ce digest; Docker Run utilise `--pull always`. En cas d'indisponibilité, le panneau montre une alerte explicite à la place des commandes. + +La commande Linux ne contient ni l'URL Central ni le token du site. À son exécution, elle demande l'URL HTTPS puis le token sans afficher sa saisie, place les valeurs dans des fichiers temporaires protégés et télécharge les scripts par HTTPS avant leur exécution. L'installateur exige les fichiers d'enrôlement protégés et conserve le token comme credential systemd. ### États — Détail Site diff --git a/install/install-agent.sh b/install/install-agent.sh index a209b84..ce2b42e 100755 --- a/install/install-agent.sh +++ b/install/install-agent.sh @@ -1,15 +1,25 @@ #!/usr/bin/env bash # install-agent.sh — Heimdall Agent installer for Linux set -euo pipefail -CENTRAL_URL="" SITE_TOKEN="" AGENT_NAME="" STATE_DIR="/var/lib/heimdall" UPDATE_PUBLIC_KEY="" ALLOW_INSECURE_HTTP=false RUN_MODE=false INSTALL_ONLY=false +CENTRAL_URL="" SITE_TOKEN="" CENTRAL_URL_FILE="" SITE_TOKEN_FILE="" AGENT_NAME="" STATE_DIR="/var/lib/heimdall" UPDATE_PUBLIC_KEY="" ALLOW_INSECURE_HTTP=false RUN_MODE=false INSTALL_ONLY=false INSTALL_ROOT="/opt/heimdall/agent" SERVICE_NAME="heimdall-agent" SERVICE_USER="heimdall" -while [[ $# -gt 0 ]]; do case "$1" in --central-url) CENTRAL_URL="$2"; shift 2;; --site-token) SITE_TOKEN="$2"; shift 2;; --update-public-key) UPDATE_PUBLIC_KEY="$2"; shift 2;; --agent-name) AGENT_NAME="$2"; shift 2;; --state-dir) STATE_DIR="$2"; shift 2;; --allow-insecure-http) ALLOW_INSECURE_HTTP=true; shift;; --run) RUN_MODE=true; shift;; --install-only) INSTALL_ONLY=true; shift;; -h|--help) echo "Usage: $0 --central-url URL --site-token TOKEN [--agent-name NAME] [--run | --install-only] [--update-public-key LOCAL_PEM] [--state-dir PATH] [--allow-insecure-http]"; exit 0;; *) echo "Unknown: $1" >&2; exit 1;; esac; done -[[ -z "$CENTRAL_URL" || -z "$SITE_TOKEN" ]] && { echo "Error: --central-url and --site-token are required" >&2; exit 1; } +while [[ $# -gt 0 ]]; do case "$1" in --central-url-file) CENTRAL_URL_FILE="$2"; shift 2;; --site-token-file) SITE_TOKEN_FILE="$2"; shift 2;; --central-url|--site-token) echo "Error: pass enrollment settings through protected files, not command-line values" >&2; exit 1;; --update-public-key) UPDATE_PUBLIC_KEY="$2"; shift 2;; --agent-name) AGENT_NAME="$2"; shift 2;; --state-dir) STATE_DIR="$2"; shift 2;; --allow-insecure-http) ALLOW_INSECURE_HTTP=true; shift;; --run) RUN_MODE=true; shift;; --install-only) INSTALL_ONLY=true; shift;; -h|--help) echo "Usage: $0 --central-url-file PATH --site-token-file PATH [--agent-name NAME] [--run | --install-only] [--update-public-key LOCAL_PEM] [--state-dir PATH] [--allow-insecure-http]"; exit 0;; *) echo "Unknown: $1" >&2; exit 1;; esac; done +read_protected_value() { + local path="$1" label="$2" mode + [[ -n "$path" && -f "$path" && ! -L "$path" ]] || { echo "Error: $label must reference a regular protected file" >&2; exit 1; } + mode=$(stat -c '%a' "$path") + (( (8#$mode & 077) == 0 )) || { echo "Error: $label file must not be accessible by group or others" >&2; exit 1; } + cat -- "$path" +} +[[ -n "$CENTRAL_URL_FILE" && -n "$SITE_TOKEN_FILE" ]] || { echo "Error: --central-url-file and --site-token-file are required" >&2; exit 1; } +CENTRAL_URL="$(read_protected_value "$CENTRAL_URL_FILE" 'Central URL')" +SITE_TOKEN="$(read_protected_value "$SITE_TOKEN_FILE" 'site token')" +[[ -n "$CENTRAL_URL" && -n "$SITE_TOKEN" ]] || { echo "Error: protected Central URL and site token files must be non-empty" >&2; exit 1; } [[ "$RUN_MODE" == true && "$INSTALL_ONLY" == true ]] && { echo '--run and --install-only cannot be combined' >&2; exit 1; } if [[ -n "$UPDATE_PUBLIC_KEY" && ! -f "$UPDATE_PUBLIC_KEY" ]]; then echo 'Publisher public key file is missing' >&2; exit 1; fi CENTRAL_URL="${CENTRAL_URL%/}" if [[ "$CENTRAL_URL" != https://* && ! ( "$ALLOW_INSECURE_HTTP" == true && "$CENTRAL_URL" == http://* ) ]]; then - echo "Error: --central-url must use HTTPS (or explicitly opt in with --allow-insecure-http on an isolated network)" >&2 + echo "Error: Central URL must use HTTPS (or explicitly opt in with --allow-insecure-http on an isolated network)" >&2 exit 1 fi ARCH=$(uname -m); case "$ARCH" in x86_64|amd64) PLATFORM="linux-x64";; aarch64|arm64) PLATFORM="linux-arm64";; armv7l|armhf) PLATFORM="linux-arm";; *) echo "Unsupported: $ARCH" >&2; exit 1;; esac @@ -45,9 +55,11 @@ RELEASE_METADATA_URL="$CENTRAL_URL/api/updates/latest" for attempt in 1 2 3; do CURL_PROTOCOL=https [[ "$CENTRAL_URL" == https://* ]] || CURL_PROTOCOL=http + printf '%s' "$RELEASE_METADATA_URL" | python3 -c 'import json,sys; open(sys.argv[1],"w").write("url = "+json.dumps(sys.stdin.read())+"\n")' "$TMP_DIR/release-metadata.curl" + chmod 600 "$TMP_DIR/release-metadata.curl" HTTP_STATUS=$(curl -sS --proto "$CURL_PROTOCOL" \ --connect-timeout 10 --max-time 30 \ - -w '%{http_code}' "$RELEASE_METADATA_URL" -o "$TMP_DIR/release.json") && CURL_STATUS=0 || CURL_STATUS=$? + -w '%{http_code}' --config "$TMP_DIR/release-metadata.curl" -o "$TMP_DIR/release.json") && CURL_STATUS=0 || CURL_STATUS=$? if [[ "$CURL_STATUS" -eq 0 && "$HTTP_STATUS" =~ ^2[0-9][0-9]$ ]]; then break fi @@ -109,6 +121,11 @@ with tarfile.open(sys.argv[1], 'r:gz') as archive: shutil.copyfileobj(source,output) PY [[ -f "$TMP_DIR/agent/Heimdall.Agent.dll" ]] || { echo 'Archive has no agent assembly' >&2; exit 1; } +printf '%s' "$CENTRAL_URL" | python3 -c 'import json,pathlib,sys; p=pathlib.Path(sys.argv[1]); raw=p.read_text() if p.exists() else "{}"; +try: d=json.loads(raw) +except json.JSONDecodeError: d={} +d.setdefault("Agent",{})["CentralUrl"]=sys.stdin.read(); p.write_text(json.dumps(d,indent=2)+"\n")' "$TMP_DIR/agent/appsettings.json" +chmod 640 "$TMP_DIR/agent/appsettings.json" id "$SERVICE_USER" &>/dev/null || sudo useradd --system --no-create-home --shell /usr/sbin/nologin "$SERVICE_USER" 2>/dev/null || true sudo mkdir -p "$STATE_DIR" && sudo chown "$SERVICE_USER:$SERVICE_USER" "$STATE_DIR" && sudo chmod 700 "$STATE_DIR" sudo install -d -o "$SERVICE_USER" -g "$SERVICE_USER" -m 750 "$INSTALL_ROOT" "$INSTALL_ROOT/releases" @@ -122,7 +139,9 @@ sudo install -d -o root -g root -m 755 /usr/local/libexec SUPERVISOR_SOURCE="$(dirname "$0")/agent-supervisor.py" if [[ ! -f "$SUPERVISOR_SOURCE" ]]; then SUPERVISOR_SOURCE="$TMP_DIR/agent-supervisor.py" - curl -fsS "$CENTRAL_URL/install/agent-supervisor.py" -o "$SUPERVISOR_SOURCE" || { + printf '%s' "$CENTRAL_URL/install/agent-supervisor.py" | python3 -c 'import json,sys; open(sys.argv[1],"w").write("url = "+json.dumps(sys.stdin.read())+"\n")' "$TMP_DIR/supervisor.curl" + chmod 600 "$TMP_DIR/supervisor.curl" + curl -fsS --config "$TMP_DIR/supervisor.curl" -o "$SUPERVISOR_SOURCE" || { echo 'Failed to download the Heimdall Agent supervisor from Central' >&2; exit 1; } fi @@ -150,7 +169,6 @@ if [[ "$RUN_MODE" == true ]]; then ASPNETCORE_URLS=http://127.0.0.1:8081 \ HEIMDALL_DOTNET="$DOTNET_BIN" \ ASPNETCORE_ENVIRONMENT=Production \ - Agent__CentralUrl="$CENTRAL_URL" \ Agent__AgentName="$AGENT_NAME" \ Agent__AllowInsecureHttp="$ALLOW_INSECURE_HTTP" \ Agent__StateDirectory="$STATE_DIR" \ @@ -173,7 +191,6 @@ RestartSec=5 Environment=ASPNETCORE_URLS=http://127.0.0.1:8081 Environment=HEIMDALL_DOTNET=$DOTNET_BIN Environment=ASPNETCORE_ENVIRONMENT=Production -Environment=Agent__CentralUrl=$CENTRAL_URL Environment=Agent__AllowInsecureHttp=$ALLOW_INSECURE_HTTP Environment=Agent__StateDirectory=$STATE_DIR Environment=Agent__UpdateInstallRoot=$INSTALL_ROOT @@ -183,6 +200,7 @@ $AGENT_NAME_CREDENTIAL [Install] WantedBy=multi-user.target EOF +sudo chmod 600 "/etc/systemd/system/$SERVICE_NAME.service" sudo systemctl daemon-reload && sudo systemctl enable "$SERVICE_NAME" if [[ "$INSTALL_ONLY" == true ]]; then echo "Installed version $VERSION and enabled $SERVICE_NAME. Start it with: sudo systemctl start $SERVICE_NAME" diff --git a/install/install-server.sh b/install/install-server.sh index 38c394d..c133aec 100755 --- a/install/install-server.sh +++ b/install/install-server.sh @@ -110,6 +110,8 @@ copy_source_asset() { say "Installation de Heimdall Central (serveur + PostgreSQL)." destination="$(ask 'Dossier d’installation' "$HOME/heimdall")" +compose_project="$(ask 'Nom isolé du projet Docker Compose' 'heimdall')" +[[ "$compose_project" =~ ^[a-z0-9][a-z0-9_-]{0,62}$ ]] || { echo 'Nom de projet Compose invalide.' >&2; exit 1; } compose_path="$destination/docker-compose.yml" env_path="$destination/.env" is_existing=no @@ -125,7 +127,10 @@ if [[ -e "$compose_path" || -e "$env_path" ]]; then is_existing=yes else web_port="$(ask 'Port HTTP du serveur' '5000')" - cors_origin="$(ask 'Origine(s) autorisée(s) par CORS' '*')" + public_origin="${HEIMDALL_URL:-}" + cors_default='' + if [[ "$public_origin" =~ ^https://[A-Za-z0-9.-]+(:[0-9]{1,5})?$ ]]; then cors_default="$public_origin"; fi + cors_origin="$(ask 'Origine(s) autorisée(s) par CORS' "${cors_default:-https://heimdall.invalid}")" [[ "$web_port" =~ ^[0-9]{1,5}$ ]] && (( web_port >= 1 && web_port <= 65535 )) || { echo "Port invalide." >&2; exit 1; } [[ "$cors_origin" =~ ^[A-Za-z0-9*.,:/_-]+$ ]] || { echo "Origine CORS invalide." >&2; exit 1; } fi @@ -186,8 +191,6 @@ fi compose_tmp="$(mktemp "$destination/.docker-compose.yml.XXXXXX")" trap 'rm -f "${compose_tmp:-}"' EXIT cat > "$compose_tmp" <<'COMPOSE' -name: heimdall - services: postgresql: image: postgres:17-alpine @@ -257,11 +260,10 @@ secrets: networks: heimdall-net: - name: heimdall-net driver: bridge COMPOSE chmod 600 "$compose_tmp" -docker compose --env-file "$env_path" -f "$compose_tmp" config --quiet +docker compose --project-name "$compose_project" --env-file "$env_path" -f "$compose_tmp" config --quiet if [[ "$is_existing" == yes ]]; then backup_path="$compose_path.bak.$(date -u +%Y%m%dT%H%M%SZ)" cp -p "$compose_path" "$backup_path" @@ -291,7 +293,7 @@ say "Variables protégées dans $destination/.env (mode 600), secret PostgreSQL say "Validation du Compose avant démarrage…" start_core=no if [[ "$(ask 'Démarrer PostgreSQL et Heimdall maintenant ?' 'o')" =~ ^([oO]|[oO][uU][iI]|[yY]|[yY][eE][sS])$ ]]; then - docker compose --env-file "$env_path" -f "$compose_path" up -d + docker compose --project-name "$compose_project" --env-file "$env_path" -f "$compose_path" up -d start_core=yes fi @@ -322,7 +324,7 @@ for service in "${selected[@]}"; do ;; esac if [[ "$start_core" == yes ]] && [[ "$(ask "Démarrer le service optionnel ${service} ?" 'o')" =~ ^([oO]|[oO][uU][iI]|[yY]|[yY][eE][sS])$ ]]; then - docker compose --project-directory "$compose_project_directory" --project-name "heimdall-${service}" \ + docker compose --project-directory "$compose_project_directory" --project-name "${compose_project}-${service}" \ --env-file "$destination/.env" \ -f "$destination/optional/docker-compose.${service}.yml" up -d else diff --git a/skills/agent-update-acceptance/SKILL.md b/skills/agent-update-acceptance/SKILL.md index e3a9e36..442e5b1 100644 --- a/skills/agent-update-acceptance/SKILL.md +++ b/skills/agent-update-acceptance/SKILL.md @@ -33,6 +33,28 @@ For Linux systemd installs, preserve the site display name through the existing foreground installer may pass `Agent__AgentName` directly; do not put arbitrary site names in an unescaped systemd `Environment=` assignment. +Linux enrollment values must be passed to `install/install-agent.sh` using +`--central-url-file` and `--site-token-file`, each pointing to a regular file +with no group/other permissions. Reject legacy `--central-url` and +`--site-token` values because they are visible in process listings. The site +token is persisted only in root-owned and Agent-owned mode-0600 credential +files and loaded by systemd `LoadCredential`; generated command text must not +contain either enrollment value. Keep the temporary prompt files mode 0600 in +a mode-0700 directory and remove them on every exit path. Verify generated +Linux command text has no Central URL or site token, both legacy value flags +fail before installation, and unsafe/symlink/empty files are rejected. +Keep the Central URL out of process arguments and unit contents. The Linux +installer stores it in the Agent release's `appsettings.json` with mode 0640 +inside the mode-0750 Agent release tree; a new Agent may alternatively load it +from a systemd `central-url` credential through `CREDENTIALS_DIRECTORY`. +Agent logs must not include the Central URL. + +The server installer Compose project/network must use Compose's project-scoped +resource names rather than fixed global `name:` values. The interactive +installer should default CORS to the configured public HTTPS origin when one +is supplied and otherwise use a restrictive placeholder that the operator +must replace; do not default a new installation to wildcard CORS. + Before accepting a native or Docker install flow, verify that Central's global `updates.forgepublicurl` contains only the HTTPS public Forgejo origin and that Central constructs `api/v1/repos/arnaud.dartois/Heimdall/releases/latest` from @@ -41,6 +63,17 @@ contain the signed manifest, asset checksums, and required image digest. A `main` Docker image build alone cannot supply the signed Agent release metadata used by installers and the IHM. +Forgejo releases may omit the optional `asset.digest` API field. In that case, +Central may fetch the public key, manifest, and signature only from HTTPS URLs +on the configured Forgejo origin, then must verify the ECDSA P-256 signature, +release tag, manifest schema, archive SHA-256 values, and image digests before +returning metadata. Use the hashes from the verified signed manifest for +downloadable archives. Reject cross-origin asset URLs, redirects to another +origin, bad signatures, malformed digests, and tag mismatches. Do not replace +missing API digests with unchecked archive metadata or disable verification. +Validate both an actual release whose API omits `asset.digest` and synthetic +tampered metadata in a source-built Compose acceptance. + ## Linux rollback simulation - Run `python3 -m unittest discover -s scripts/ci -p 'test_*.py' -k supervisor_rolls_back_failed_startup_to_previous_release`. diff --git a/skills/central-auto-updates/SKILL.md b/skills/central-auto-updates/SKILL.md index fb8edc5..0d82061 100644 --- a/skills/central-auto-updates/SKILL.md +++ b/skills/central-auto-updates/SKILL.md @@ -43,10 +43,16 @@ For installer, Compose, image, and documentation work that can proceed independe - When a newer Compose needs an absent env key, append a generated secret or documented default only if that key is missing. Never print secret values. Refuse to continue if the existing database URL or password file needed by PostgreSQL is missing. - If the user declines the Compose refresh, exit without changing the install. If only part of an install is present, stop and explain what is missing instead of creating a second set of credentials. +## Live Linux deployment evidence + +For an explicitly authorized host validation, inspect existing services and data before mutation, use only that environment's protected credentials, and scope reset to the named Heimdall Compose projects. Install Central and Agent through the released `.sh` installers. Record image digest, Agent version/identity/site association, `/healthz`, local Agent version endpoint, heartbeat status, credential modes, listener bindings, and sanitized logs. Restart Central and Agent and verify health and persisted volumes/site identity. Do not infer Windows, GPU, camera, multicast, TURN, backup, or long-load acceptance from a single Linux host. + ## Acceptance -Run `bash -n install/install-server.sh`, validate PowerShell syntax when `pwsh` is available, and run `docker compose config --quiet` for both the installer output and `docker/docker-compose.prod.yml`. Exercise a first install and a second run against an isolated temporary directory: confirm secrets and nondefault `.env` values are byte-for-byte unchanged, the old Compose is backed up, missing new variables are added once, and no volume removal command appears. For the Site Install UI, assert generated CPU/GPU Compose and `docker run` references use the corresponding `:latest` Agent image, Compose sets `pull_policy: always`, Docker Run commands set `--pull always`, all paths mount `/var/run/docker.sock`, and the non-root Agent receives the socket group (`DOCKER_GID` in Compose; detected socket GID for Linux `docker run`). Keep signed digest validation for updates dispatched by Central. Then follow `skills/compose-disposable-recipe/SKILL.md` with a unique project, generated credentials, isolated ports/volumes, and an EXIT cleanup trap installed before build/start. Never connect the recipe to a deployed Docker daemon or production data. +Run `bash -n install/install-server.sh`, validate PowerShell syntax when `pwsh` is available, and run `docker compose config --quiet` for both the installer output and `docker/docker-compose.prod.yml`. Exercise a first install and a second run against an isolated temporary directory: confirm secrets and nondefault `.env` values are byte-for-byte unchanged, the old Compose is backed up, missing new variables are added once, and no volume removal command appears. For the Site Install UI, assert generated CPU/GPU Compose and `docker run` references use their corresponding immutable `repository@sha256:digest` Agent image, Compose sets `pull_policy: always`, Docker Run commands set `--pull always`, all paths mount `/var/run/docker.sock`, and the non-root Agent receives the socket group (`DOCKER_GID` in Compose; detected socket GID for Linux `docker run`). Keep signed digest validation for updates dispatched by Central. A signed Agent manifest always requires the CPU image repository and digest; GPU image metadata is optional for CPU-only releases, and must be present as a valid repository/digest pair when either field is supplied. Unit tests cover CPU-only and CPU+GPU signed manifests plus a malformed half-pair. Source-built Compose acceptance probes Central's latest-release API against the configured public Forgejo source and verifies the returned signature and required CPU digest; record whether the current release also carries GPU metadata. Then follow `skills/compose-disposable-recipe/SKILL.md` with a unique project, generated credentials, isolated ports/volumes, and an EXIT cleanup trap installed before build/start. Never connect the recipe to a deployed Docker daemon or production data. When a runtime Dockerfile changes for OS security updates, source-build and health-check the corresponding Central/Agent image, then scan its saved image archive with the pinned Trivy version and the same `HIGH,CRITICAL` severities used by CI. Record the finding IDs and fixed package versions; do not hide a nonzero scan behind application acceptance. If acceptance builds a local Central/helper image, record its project-unique tag before build and remove/verify that exact tag in the same cleanup trap, including on failure. Do not remove registry/base images or use `--rmi all` or broad image pruning; Watchtower's deployment `--cleanup` behavior is separate from disposable-test cleanup. + +- The Site Install UI must retain the CPU/GPU image digest returned by Central and generate immutable `repository@sha256:digest` references for both Compose and Docker Run. Never reduce a verified release image to a mutable `:latest` tag. Test with distinct CPU/GPU digests and reject malformed/missing digest values by disabling Docker install generation. diff --git a/skills/dependency-security-acceptance/SKILL.md b/skills/dependency-security-acceptance/SKILL.md new file mode 100644 index 0000000..b1eeecb --- /dev/null +++ b/skills/dependency-security-acceptance/SKILL.md @@ -0,0 +1,12 @@ +--- +name: dependency-security-acceptance +description: Update vulnerable NuGet dependencies and prove Heimdall's locked dependency security gate. +--- + +# NuGet dependency security acceptance + +Before changing a dependency after a CI advisory failure, read `AGENTS.md`, `skills/gitea-ticket-workflow/SKILL.md`, and the relevant component skill. Reuse or create a focused Gitea issue before editing; record the advisory IDs, resolved package version, failing CI run, and any behavior changes announced by the upstream fix. Do not suppress an advisory or weaken `scripts/ci/security.sh` thresholds. + +Update the direct `PackageReference` to an upstream patched release, then regenerate every affected `packages.lock.json` using the SDK pinned by `global.json`. Inspect all projects that transitively reference the package, run `dotnet restore --locked-mode`, and run focused tests for the consuming application. Review upstream release notes for compatibility changes and add or adjust regression coverage if the changed behavior reaches Heimdall code. + +Acceptance requires a clean locked restore, passing focused tests, and `scripts/ci/security.sh dependencies` reporting no applicable high or critical advisories. Keep the issue and linked PR open until those checks and the required CI run pass. Document the CI run and exact package version in Gitea without copying credentials or sensitive build output. No disposable Compose project is needed for a library-only dependency update that does not change deployment behavior; when the dependency changes runtime or deployment behavior, also follow `skills/compose-disposable-recipe/SKILL.md`. diff --git a/skills/penpot-design-sync/SKILL.md b/skills/penpot-design-sync/SKILL.md index 0599ed2..d86f636 100644 --- a/skills/penpot-design-sync/SKILL.md +++ b/skills/penpot-design-sync/SKILL.md @@ -27,7 +27,7 @@ Heimdall's connected Penpot file is part of the UI source of truth. Whenever a c ## Installer design reference -The installer should follow the interaction hierarchy represented by `site-agent-installer-ui/SKILL.md`: platform choices, platform-specific method choices, optional configuration, then titled command cards with deliberate copy controls. For the current Agent installer, keep the design aligned with supported Linux, Windows, and Docker options, release signing/update-key gates, Docker installation from the `latest` image tag, signed digest validation for updates dispatched by Central, and the actual command builders. Keep desktop and mobile layouts, plus release-unavailable states, represented. Update the existing installer frame and any relevant variations in the connected file on every behavior or layout change. +The installer should follow the interaction hierarchy represented by `site-agent-installer-ui/SKILL.md`: platform choices, platform-specific method choices, optional configuration, then titled command cards with deliberate copy controls. For the current Agent installer, keep the design aligned with supported Linux, Windows, and Docker options, release signing/update-key gates, Docker installation pinned to the immutable signed `repository@sha256:digest`, signed digest validation for updates dispatched by Central, and the actual command builders. Keep desktop and mobile layouts, plus release-unavailable states, represented. Update the existing installer frame and any relevant variations in the connected file on every behavior or layout change. ## Acceptance evidence diff --git a/skills/site-agent-installer-ui/SKILL.md b/skills/site-agent-installer-ui/SKILL.md index 77a37f4..21cf969 100644 --- a/skills/site-agent-installer-ui/SKILL.md +++ b/skills/site-agent-installer-ui/SKILL.md @@ -11,8 +11,9 @@ Keep the site Agent installer in `src/Heimdall.Web/Components/SiteInstallPanel.r - Offer only Heimdall-supported platforms: Linux, Windows, and Docker. Keep method choices mapped in `AvailableMethods` and reset to that platform's sensible default in `SelectOperatingSystem`. - Keep generated command content in the existing builders and `Commands` projection. Platform selection controls the builders; do not duplicate generated commands in markup. -- Native install commands require a latest signed release with update key, signed manifest, signature, and Agent archive assets. Docker commands additionally require verified CPU/GPU image metadata and the update key, but install the corresponding published `:latest` image. Generated Compose uses `pull_policy: always`; generated Docker Run commands use `--pull always`. Preserve signed digest validation for Agent updates dispatched later by Central. +- Native install commands require a latest signed release with update key, signed manifest, signature, and Agent archive assets. Docker commands additionally require verified CPU/GPU image metadata and the update key, and install the corresponding immutable `repository@sha256:digest` reference. Generated Compose uses `pull_policy: always`; generated Docker Run commands use `--pull always`. Preserve signed digest validation for Agent updates dispatched later by Central. - Treat site tokens and generated configuration as secrets: show them only in the authenticated site's installer view and copy only after a deliberate click. Do not log generated content. +- The Linux generated installer command must not embed Central URL or site token in its text or process arguments. Prompt for both at execution time, hide token input, use protected temporary files and the installer's file-based flags, and clean those files on all exits. - For live installer verification, use the authenticated Orca browser session. Check for the dedicated Heimdall login only in the user secret store at `~/.config/heimdall/credentials.json`; never put account passwords in this skill, repository config, shell arguments, or Orca `fill` commands. The file fallback is owner-only (`0700` directory, `0600` file) and base64-encoded, not encrypted. If it is absent, provide the user-run masked helper `~/.local/bin/store-heimdall-credentials`; do not report the credentials as persisted until that helper succeeds. If Orca has no safe autofill path, ask the user to enter the password in the visible browser. - Keep all visible strings in `SharedResources.resx`, `SharedResources.en.resx`, and `SharedResources.fr.resx`. - Match Pangolin's control hierarchy and compact copy affordance while using Heimdall's MudBlazor theme and supported installation choices. Keep selection and copy feedback accessible with selected styling, tooltips/aria labels, and a check icon after copying. diff --git a/src/Heimdall.Agent/AgentOptions.cs b/src/Heimdall.Agent/AgentOptions.cs index c70d437..7acce8a 100644 --- a/src/Heimdall.Agent/AgentOptions.cs +++ b/src/Heimdall.Agent/AgentOptions.cs @@ -14,7 +14,15 @@ public sealed class AgentOptions /// URL of the Heimdall Central server, supplied by the installation or deployment configuration. [Required, Url] - public string CentralUrl { get; init; } = string.Empty; + public string CentralUrl + { + get => string.IsNullOrWhiteSpace(_centralUrl) + ? ReadSystemdCredential("central-url") ?? string.Empty + : _centralUrl; + init => _centralUrl = value ?? string.Empty; + } + + private string _centralUrl = string.Empty; /// Allow an unencrypted HTTP Central URL for isolated development networks only. public bool AllowInsecureHttp { get; init; } diff --git a/src/Heimdall.Agent/Services/AgentRegistrationService.cs b/src/Heimdall.Agent/Services/AgentRegistrationService.cs index 5425aca..dd48859 100644 --- a/src/Heimdall.Agent/Services/AgentRegistrationService.cs +++ b/src/Heimdall.Agent/Services/AgentRegistrationService.cs @@ -171,7 +171,7 @@ public class AgentRegistrationService : BackgroundService throw new InvalidOperationException( "Agent registration requires Agent:SiteToken or a systemd site-token credential."); - _logger.LogInformation("Registering agent with Central at {CentralUrl}", _options.CentralUrl); + _logger.LogInformation("Registering agent with Central."); var maxRetries = _options.RegistrationMaxRetries; RegisterResponse? registration = null; diff --git a/src/Heimdall.Agent/packages.gpu.lock.json b/src/Heimdall.Agent/packages.gpu.lock.json index 3462760..75dd3be 100644 --- a/src/Heimdall.Agent/packages.gpu.lock.json +++ b/src/Heimdall.Agent/packages.gpu.lock.json @@ -91,8 +91,8 @@ }, "AutoMapper": { "type": "Transitive", - "resolved": "16.1.1", - "contentHash": "VNEky8JA15ci+oIDRGHITOGOpV4dILsf8pnn24QhDl2urtqgJ2IXiS/V2EtGU17P/+f6OeFQPJETaZXV9QOIZg==", + "resolved": "16.3.0", + "contentHash": "wFTqA37e1I4AOEhTTYlxrqDE8BQ4OB3dqhlv2KwYmHv+a4tn7R1JW2n2bzXb8eTBhWVBSl7iTZ0VxEt0a57D4w==", "dependencies": { "Microsoft.IdentityModel.JsonWebTokens": "8.14.0" } @@ -326,7 +326,7 @@ "heimdall.application": { "type": "Project", "dependencies": { - "AutoMapper": "[16.1.1, )", + "AutoMapper": "[16.3.0, )", "FluentValidation": "[11.11.0, )", "FluentValidation.DependencyInjectionExtensions": "[11.11.0, )", "Heimdall.Domain": "[1.0.0, )", diff --git a/src/Heimdall.Agent/packages.lock.json b/src/Heimdall.Agent/packages.lock.json index 82b08cd..6971266 100644 --- a/src/Heimdall.Agent/packages.lock.json +++ b/src/Heimdall.Agent/packages.lock.json @@ -39,8 +39,6 @@ "resolved": "10.0.13", "contentHash": "sk3VNcYEmgwYGPF4ze/112jpaeDKSsKGhmEZ8IlhOR8F6JT+1DYaZUb14jobVXiKhuXWIKcYXV7mkSPeA4dc3g==", "dependencies": { - "Microsoft.Extensions.Hosting": "10.0.13", - "Microsoft.Extensions.Logging.EventLog": "10.0.13", "System.ServiceProcess.ServiceController": "10.0.13" } }, @@ -91,8 +89,8 @@ }, "AutoMapper": { "type": "Transitive", - "resolved": "16.1.1", - "contentHash": "VNEky8JA15ci+oIDRGHITOGOpV4dILsf8pnn24QhDl2urtqgJ2IXiS/V2EtGU17P/+f6OeFQPJETaZXV9QOIZg==", + "resolved": "16.3.0", + "contentHash": "wFTqA37e1I4AOEhTTYlxrqDE8BQ4OB3dqhlv2KwYmHv+a4tn7R1JW2n2bzXb8eTBhWVBSl7iTZ0VxEt0a57D4w==", "dependencies": { "Microsoft.IdentityModel.JsonWebTokens": "8.14.0" } @@ -133,14 +131,6 @@ "resolved": "10.0.13", "contentHash": "r9hlU+te+QWFJlUCt2C22TDKY3oMER8ayC7Qzeq6yJ5toHBKcSqshhyyaLKK1jgBuyNi4ejly0wE8ANV8TyfWQ==" }, - "Microsoft.AspNetCore.Identity.EntityFrameworkCore": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "c6984ahCnqc3zqYgl5KqrBoY+LMKqJW6nZcFdBYNyp3PAA67prA/IgjQ/ySV0t3lEL2LEz3bcx91fbUYr8bRPA==", - "dependencies": { - "Microsoft.EntityFrameworkCore.Relational": "10.0.13" - } - }, "Microsoft.AspNetCore.SignalR.Client.Core": { "type": "Transitive", "resolved": "10.0.13", @@ -202,290 +192,11 @@ "SQLitePCLRaw.core": "2.1.13" } }, - "Microsoft.Extensions.Configuration": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "inhujYI/nikhmLxYI6ZEcaCgZ28ipJsKMPPxxr2XWf3vM0Q2P+E9R3hDHABZOLBxzD3gjpgcbSH/+hd2+gvI2A==", - "dependencies": { - "Microsoft.Extensions.Configuration.Abstractions": "10.0.13", - "Microsoft.Extensions.Primitives": "10.0.13" - } - }, - "Microsoft.Extensions.Configuration.Abstractions": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "DY4C2qzTt2lOIY3VoscBH/TCwTolI5DKOfgJLuI+k1QUvRNT5vTMS58AOerNiihdVRStO0wEpLeRWA8jytzHBQ==", - "dependencies": { - "Microsoft.Extensions.Primitives": "10.0.13" - } - }, - "Microsoft.Extensions.Configuration.Binder": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "yJJl/b0+W+GEWbu+7viw6C3h2BoNkB69Vlz7s/4e+hm4mYbJqfhdcDSi9sCXJw47blsBaiQd3UDPgDtop92+ug==", - "dependencies": { - "Microsoft.Extensions.Configuration": "10.0.13", - "Microsoft.Extensions.Configuration.Abstractions": "10.0.13" - } - }, - "Microsoft.Extensions.Configuration.CommandLine": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "RwdNZ9JdGs8eZmeL5qRe7ugp0Irk3KVkWpC/w1c8kjJwu1R4HvCXYz9kwHZxn45WiaRBG5lphQKtqnBaJOQC+Q==", - "dependencies": { - "Microsoft.Extensions.Configuration": "10.0.13", - "Microsoft.Extensions.Configuration.Abstractions": "10.0.13" - } - }, - "Microsoft.Extensions.Configuration.EnvironmentVariables": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "qJK2dm9/AxyPVfqqBaZtjkUFl2hnBR/CQnMJtSO5LdEoyATMqvZjeQVY+8l0oa6PM6qlVe28iMEyXIRQ0wyZjA==", - "dependencies": { - "Microsoft.Extensions.Configuration": "10.0.13", - "Microsoft.Extensions.Configuration.Abstractions": "10.0.13" - } - }, - "Microsoft.Extensions.Configuration.FileExtensions": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "kwC1DY55CsqPmDtJAz+7alD3G+gJcM+XwHSZrcRO8mJGYB9hRq1qC6ZH8DL0SPW9WtJ/Bae5ikzPic8SxSv6Vw==", - "dependencies": { - "Microsoft.Extensions.Configuration": "10.0.13", - "Microsoft.Extensions.Configuration.Abstractions": "10.0.13", - "Microsoft.Extensions.FileProviders.Abstractions": "10.0.13", - "Microsoft.Extensions.FileProviders.Physical": "10.0.13", - "Microsoft.Extensions.Primitives": "10.0.13" - } - }, - "Microsoft.Extensions.Configuration.Json": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "acCWM2+WR67kBAz6gAhD2zG+IZH9Q2VpKv5le7Msiu0vAMsnnLXpnV3BAzxd8/i+uOEo/dfb2XRYTynRVTDvEg==", - "dependencies": { - "Microsoft.Extensions.Configuration": "10.0.13", - "Microsoft.Extensions.Configuration.Abstractions": "10.0.13", - "Microsoft.Extensions.Configuration.FileExtensions": "10.0.13", - "Microsoft.Extensions.FileProviders.Abstractions": "10.0.13" - } - }, - "Microsoft.Extensions.Configuration.UserSecrets": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "kQ/Tx972unP+ueQL8SSninthIj6w6XP2o0VnJPFC5HQIimPMwEN704MOspEgDkmm4FUL5SuxLEU0bNiW4HEZFA==", - "dependencies": { - "Microsoft.Extensions.Configuration.Abstractions": "10.0.13", - "Microsoft.Extensions.Configuration.Json": "10.0.13", - "Microsoft.Extensions.FileProviders.Abstractions": "10.0.13", - "Microsoft.Extensions.FileProviders.Physical": "10.0.13" - } - }, - "Microsoft.Extensions.DependencyInjection": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "4tnWU9vrU/A8NwYe9Z6wvieZ0EBb/uM82LAT+edNhdepOBWREZ7M7mzb941EIDPJaeOFdbVrDd5+7s9e89U6bQ==", - "dependencies": { - "Microsoft.Extensions.DependencyInjection.Abstractions": "10.0.13" - } - }, - "Microsoft.Extensions.DependencyInjection.Abstractions": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "G2GrGWNAPZBsii2F6AU8n+JT2tC1/I0Ml/e9ZyNCgPjf3hZqronP7o0X91aAynCmVeae8KkSIUNXXeXCNRmdVQ==" - }, "Microsoft.Extensions.DependencyModel": { "type": "Transitive", "resolved": "10.0.13", "contentHash": "6TyllZsToy3S/Ziu67GddljRTttuVJ8bbrbVUrsdHqH5678Oax5MpaEubxLoPoWLvgUBYo4KfcAig0mkBtktXQ==" }, - "Microsoft.Extensions.Diagnostics": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "J9ODOrffj1mK3Et69elNsLGRguesPxvThTdVpFmQX7fLNPhIOgqHQfLdGnTBEwNAV3yf8yiyVlpDZNw2qN87Nw==", - "dependencies": { - "Microsoft.Extensions.Configuration": "10.0.13", - "Microsoft.Extensions.Diagnostics.Abstractions": "10.0.13", - "Microsoft.Extensions.Options.ConfigurationExtensions": "10.0.13" - } - }, - "Microsoft.Extensions.Diagnostics.Abstractions": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "oZzqZze8ed1fLS20HtIrkPxQXGRG/koq09srIw2ptnDHm9RHfwB++d35hosB/cXc55TH7Pshv85O0txongjCIg==", - "dependencies": { - "Microsoft.Extensions.DependencyInjection.Abstractions": "10.0.13", - "Microsoft.Extensions.Options": "10.0.13" - } - }, - "Microsoft.Extensions.FileProviders.Abstractions": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "BZDwtN3uoWRghDi5lRRZPDjMMCg2Ds7J6YEYjqka/TLjqnzquEpXyvchrIMeoubwT1ns23ow6PPeAoBHJO81Rw==", - "dependencies": { - "Microsoft.Extensions.Primitives": "10.0.13" - } - }, - "Microsoft.Extensions.FileProviders.Physical": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "U7HkgGCNPICN5k7NVK6dmLsSPSPeO/EbNcuxOl/5qdC9Ahjp9UZWKOvlnUC+rYurmoxIlwyv9e5j0BaQlTOELA==", - "dependencies": { - "Microsoft.Extensions.FileProviders.Abstractions": "10.0.13", - "Microsoft.Extensions.FileSystemGlobbing": "10.0.13", - "Microsoft.Extensions.Primitives": "10.0.13" - } - }, - "Microsoft.Extensions.FileSystemGlobbing": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "vQVzmAbnzlhXSXA2caYnlxtG9GXxEwtj5bODiWLu06A6iqeJmfBtlfKjuOSJGRy0/CFaNUrm7u9nxEUlljc2Rg==" - }, - "Microsoft.Extensions.Hosting": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "Q+hmPoDqeHipHyJcY7mDCQiLDUcn9jIgjoCThcgaOgjLTTT3ApTe8p6M2+twsDyfKuuCsKhSNlnNjaaggtXxRA==", - "dependencies": { - "Microsoft.Extensions.Configuration": "10.0.13", - "Microsoft.Extensions.Configuration.Abstractions": "10.0.13", - "Microsoft.Extensions.Configuration.Binder": "10.0.13", - "Microsoft.Extensions.Configuration.CommandLine": "10.0.13", - "Microsoft.Extensions.Configuration.EnvironmentVariables": "10.0.13", - "Microsoft.Extensions.Configuration.FileExtensions": "10.0.13", - "Microsoft.Extensions.Configuration.Json": "10.0.13", - "Microsoft.Extensions.Configuration.UserSecrets": "10.0.13", - "Microsoft.Extensions.DependencyInjection": "10.0.13", - "Microsoft.Extensions.DependencyInjection.Abstractions": "10.0.13", - "Microsoft.Extensions.Diagnostics": "10.0.13", - "Microsoft.Extensions.FileProviders.Abstractions": "10.0.13", - "Microsoft.Extensions.FileProviders.Physical": "10.0.13", - "Microsoft.Extensions.Hosting.Abstractions": "10.0.13", - "Microsoft.Extensions.Logging": "10.0.13", - "Microsoft.Extensions.Logging.Abstractions": "10.0.13", - "Microsoft.Extensions.Logging.Configuration": "10.0.13", - "Microsoft.Extensions.Logging.Console": "10.0.13", - "Microsoft.Extensions.Logging.Debug": "10.0.13", - "Microsoft.Extensions.Logging.EventLog": "10.0.13", - "Microsoft.Extensions.Logging.EventSource": "10.0.13", - "Microsoft.Extensions.Options": "10.0.13" - } - }, - "Microsoft.Extensions.Hosting.Abstractions": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "zIrbe9vkIFXxW3mOApIOWXw+xMwX7Cgsptr3ZSlglJt4hW2qp4fB/JU1NHgAevteBNH4PicvU9DsFPHxlnnloA==", - "dependencies": { - "Microsoft.Extensions.Configuration.Abstractions": "10.0.13", - "Microsoft.Extensions.DependencyInjection.Abstractions": "10.0.13", - "Microsoft.Extensions.Diagnostics.Abstractions": "10.0.13", - "Microsoft.Extensions.FileProviders.Abstractions": "10.0.13", - "Microsoft.Extensions.Logging.Abstractions": "10.0.13" - } - }, - "Microsoft.Extensions.Logging": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "fqbiPy4nUp4H2XHKAVQXKN2y3T2h4cFIx1DAAgE6iY9OHkN/OA1cKFi+geJKRWGuX6pS5SFbsjIPWHJqrxE0eg==", - "dependencies": { - "Microsoft.Extensions.DependencyInjection": "10.0.13", - "Microsoft.Extensions.Logging.Abstractions": "10.0.13", - "Microsoft.Extensions.Options": "10.0.13" - } - }, - "Microsoft.Extensions.Logging.Abstractions": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "aSZEhEig4fvNiw2zs8Z6NyDlniKtq6YjcF3DyHuqTEHcZ2VKA/6itMPZ+dW+yWABWExlDcQwwdbqX1Rcb7W8WQ==", - "dependencies": { - "Microsoft.Extensions.DependencyInjection.Abstractions": "10.0.13" - } - }, - "Microsoft.Extensions.Logging.Configuration": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "OyYJOaE9WbBx1Hp+Dd2zrqeFM0JwH5M/x0VL6tNUv3V18vIAVpix8UjhvY9eW/iXpguEHy68JO/Z9YkBOwftIw==", - "dependencies": { - "Microsoft.Extensions.Configuration": "10.0.13", - "Microsoft.Extensions.Configuration.Abstractions": "10.0.13", - "Microsoft.Extensions.Configuration.Binder": "10.0.13", - "Microsoft.Extensions.DependencyInjection.Abstractions": "10.0.13", - "Microsoft.Extensions.Logging": "10.0.13", - "Microsoft.Extensions.Logging.Abstractions": "10.0.13", - "Microsoft.Extensions.Options": "10.0.13", - "Microsoft.Extensions.Options.ConfigurationExtensions": "10.0.13" - } - }, - "Microsoft.Extensions.Logging.Console": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "i9rn0rHkiCxfNVbf4DRG7LOFcKPy/BioAxS07w6daWvIpLNRjskqDJcGGaYVFWndsq0iTRaS8Msry0t5fRYQug==", - "dependencies": { - "Microsoft.Extensions.DependencyInjection.Abstractions": "10.0.13", - "Microsoft.Extensions.Logging": "10.0.13", - "Microsoft.Extensions.Logging.Abstractions": "10.0.13", - "Microsoft.Extensions.Logging.Configuration": "10.0.13", - "Microsoft.Extensions.Options": "10.0.13" - } - }, - "Microsoft.Extensions.Logging.Debug": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "yBig0DNMq+3UgliwxYlUC48dg0fPqvqI5B3ljzmLTrpR6maoKTOO5i9QnPgQUmQoaQWZMgu74fuF6oSDihb6pg==", - "dependencies": { - "Microsoft.Extensions.DependencyInjection.Abstractions": "10.0.13", - "Microsoft.Extensions.Logging": "10.0.13", - "Microsoft.Extensions.Logging.Abstractions": "10.0.13" - } - }, - "Microsoft.Extensions.Logging.EventLog": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "OAK40lXhgMuvyNwvzW3fxLvvucN8yr5XS7dQRcPmtnPf+Pt1lpbMgao5T4Wa6VdFagtIeDZNgPtV5Ig4xstziQ==", - "dependencies": { - "Microsoft.Extensions.DependencyInjection.Abstractions": "10.0.13", - "Microsoft.Extensions.Logging": "10.0.13", - "Microsoft.Extensions.Logging.Abstractions": "10.0.13", - "Microsoft.Extensions.Options": "10.0.13", - "System.Diagnostics.EventLog": "10.0.13" - } - }, - "Microsoft.Extensions.Logging.EventSource": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "SxJu3oczk+TJtHvpgAmCVzEkzx69/obA6GZCbGrbqYqc981YOAyfEprySBdFX7Yc5qatHJKHNTlpGeeBAQkZcA==", - "dependencies": { - "Microsoft.Extensions.DependencyInjection.Abstractions": "10.0.13", - "Microsoft.Extensions.Logging": "10.0.13", - "Microsoft.Extensions.Logging.Abstractions": "10.0.13", - "Microsoft.Extensions.Options": "10.0.13", - "Microsoft.Extensions.Primitives": "10.0.13" - } - }, - "Microsoft.Extensions.Options": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "tmMJgdrE4uhf1JcNs9CV9moAHW+hmDuvgMiPpnQxarKaUxqI2eN33sYK5S4l9Uw+rG9PJvlm4qPxMhvolTDTaQ==", - "dependencies": { - "Microsoft.Extensions.DependencyInjection.Abstractions": "10.0.13", - "Microsoft.Extensions.Primitives": "10.0.13" - } - }, - "Microsoft.Extensions.Options.ConfigurationExtensions": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "xVO5HhATc09WXuS/RaDmx8ZeWS0mTpT1L0tkEDMSBHtAnNpNsDr0ge0wIO2jinCWWqpq5dL1tRTzpYNVlvyqLw==", - "dependencies": { - "Microsoft.Extensions.Configuration.Abstractions": "10.0.13", - "Microsoft.Extensions.Configuration.Binder": "10.0.13", - "Microsoft.Extensions.DependencyInjection.Abstractions": "10.0.13", - "Microsoft.Extensions.Options": "10.0.13", - "Microsoft.Extensions.Primitives": "10.0.13" - } - }, - "Microsoft.Extensions.Primitives": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "ZjTwxzhiw2TMEzIbUDkMF0dfDB2I4NQgIfKD0ELu9/5Mk+SRGdKZcD0/lvBrRCAPo6KN2r0BW86MRancoyJkoA==" - }, "Microsoft.IdentityModel.Abstractions": { "type": "Transitive", "resolved": "8.14.0", @@ -584,11 +295,6 @@ "SQLitePCLRaw.core": "3.0.5" } }, - "System.Diagnostics.EventLog": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "DkNjtQyPR5Ud/zHnWHdsOuKbFRL9nIC92Q76z0NmHVDoQm40toLtsGFTIWq7toBoVa6fo/DInL3PLxY3Asixyw==" - }, "System.Numerics.Tensors": { "type": "Transitive", "resolved": "9.0.0", @@ -602,12 +308,11 @@ "heimdall.application": { "type": "Project", "dependencies": { - "AutoMapper": "[16.1.1, )", + "AutoMapper": "[16.3.0, )", "FluentValidation": "[11.11.0, )", "FluentValidation.DependencyInjectionExtensions": "[11.11.0, )", "Heimdall.Domain": "[1.0.0, )", "MediatR": "[12.5.0, )", - "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "[10.0.13, )", "Microsoft.Data.Sqlite": "[10.0.13, )", "Microsoft.EntityFrameworkCore": "[10.0.13, )", "Microsoft.EntityFrameworkCore.Sqlite": "[10.0.13, )", @@ -620,8 +325,7 @@ "heimdall.domain": { "type": "Project", "dependencies": { - "Heimdall.Domain.Primitives": "[1.0.0, )", - "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "[10.0.13, )" + "Heimdall.Domain.Primitives": "[1.0.0, )" } }, "heimdall.domain.primitives": { @@ -632,4 +336,4 @@ } } } -} +} \ No newline at end of file diff --git a/src/Heimdall.Application/Heimdall.Application.csproj b/src/Heimdall.Application/Heimdall.Application.csproj index 7d8969b..fb649f9 100644 --- a/src/Heimdall.Application/Heimdall.Application.csproj +++ b/src/Heimdall.Application/Heimdall.Application.csproj @@ -5,7 +5,7 @@ - + diff --git a/src/Heimdall.Application/packages.lock.json b/src/Heimdall.Application/packages.lock.json index 0851ebf..f3b05e1 100644 --- a/src/Heimdall.Application/packages.lock.json +++ b/src/Heimdall.Application/packages.lock.json @@ -4,9 +4,9 @@ "net10.0": { "AutoMapper": { "type": "Direct", - "requested": "[16.1.1, )", - "resolved": "16.1.1", - "contentHash": "VNEky8JA15ci+oIDRGHITOGOpV4dILsf8pnn24QhDl2urtqgJ2IXiS/V2EtGU17P/+f6OeFQPJETaZXV9QOIZg==", + "requested": "[16.3.0, )", + "resolved": "16.3.0", + "contentHash": "wFTqA37e1I4AOEhTTYlxrqDE8BQ4OB3dqhlv2KwYmHv+a4tn7R1JW2n2bzXb8eTBhWVBSl7iTZ0VxEt0a57D4w==", "dependencies": { "Microsoft.Extensions.Logging.Abstractions": "10.0.0", "Microsoft.Extensions.Options": "10.0.0", diff --git a/src/Heimdall.Infrastructure/packages.lock.json b/src/Heimdall.Infrastructure/packages.lock.json index ae2863a..9d6cfed 100644 --- a/src/Heimdall.Infrastructure/packages.lock.json +++ b/src/Heimdall.Infrastructure/packages.lock.json @@ -145,8 +145,8 @@ }, "AutoMapper": { "type": "Transitive", - "resolved": "16.1.1", - "contentHash": "VNEky8JA15ci+oIDRGHITOGOpV4dILsf8pnn24QhDl2urtqgJ2IXiS/V2EtGU17P/+f6OeFQPJETaZXV9QOIZg==", + "resolved": "16.3.0", + "contentHash": "wFTqA37e1I4AOEhTTYlxrqDE8BQ4OB3dqhlv2KwYmHv+a4tn7R1JW2n2bzXb8eTBhWVBSl7iTZ0VxEt0a57D4w==", "dependencies": { "Microsoft.Extensions.Logging.Abstractions": "10.0.0", "Microsoft.Extensions.Options": "10.0.0", @@ -791,12 +791,11 @@ "heimdall.application": { "type": "Project", "dependencies": { - "AutoMapper": "[16.1.1, )", + "AutoMapper": "[16.3.0, )", "FluentValidation": "[11.11.0, )", "FluentValidation.DependencyInjectionExtensions": "[11.11.0, )", "Heimdall.Domain": "[1.0.0, )", "MediatR": "[12.5.0, )", - "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "[10.0.13, )", "Microsoft.Data.Sqlite": "[10.0.13, )", "Microsoft.EntityFrameworkCore": "[10.0.13, )", "Microsoft.EntityFrameworkCore.Sqlite": "[10.0.13, )", @@ -806,8 +805,7 @@ "heimdall.domain": { "type": "Project", "dependencies": { - "Heimdall.Domain.Primitives": "[1.0.0, )", - "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "[10.0.13, )" + "Heimdall.Domain.Primitives": "[1.0.0, )" } }, "heimdall.domain.primitives": { diff --git a/src/Heimdall.Web/Components/SiteInstallPanel.razor b/src/Heimdall.Web/Components/SiteInstallPanel.razor index 0e4e04b..83136e7 100644 --- a/src/Heimdall.Web/Components/SiteInstallPanel.razor +++ b/src/Heimdall.Web/Components/SiteInstallPanel.razor @@ -113,6 +113,10 @@ else if (_method == "docker-run") } + @if (_method is "linux-run" or "linux-systemd") + { + @Text["SiteInstallPanel_LinuxSecretPrompt"] + } @foreach (var command in Commands) { @Text[command.Label] @@ -244,12 +248,8 @@ else if (_method == "windows-service") !string.IsNullOrWhiteSpace(release?.SignedManifest) && !string.IsNullOrWhiteSpace(release?.ManifestSignature) && release?.Assets.Count > 0; - if (!string.IsNullOrWhiteSpace(release?.ContainerImage) && - !string.IsNullOrWhiteSpace(release.ContainerImageDigest)) - _agentImageReference = LatestImageReference(release.ContainerImage); - if (!string.IsNullOrWhiteSpace(release?.ContainerImageGpu) && - !string.IsNullOrWhiteSpace(release.ContainerImageGpuDigest)) - _agentGpuImageReference = LatestImageReference(release.ContainerImageGpu); + _agentImageReference = ImmutableImageReference(release?.ContainerImage, release?.ContainerImageDigest); + _agentGpuImageReference = ImmutableImageReference(release?.ContainerImageGpu, release?.ContainerImageGpuDigest); _updatePublicKeyPem = release?.UpdatePublicKeyPem; } catch @@ -262,12 +262,14 @@ else if (_method == "windows-service") } } - private static string LatestImageReference(string image) + private static string? ImmutableImageReference(string? image, string? digest) { - var lastSlash = image.LastIndexOf('/'); - var lastColon = image.LastIndexOf(':'); - var repository = lastColon > lastSlash ? image[..lastColon] : image; - return $"{repository}:latest"; + if (string.IsNullOrWhiteSpace(image) || image.Contains('@', StringComparison.Ordinal) || + string.IsNullOrWhiteSpace(digest) || !System.Text.RegularExpressions.Regex.IsMatch( + digest, "^sha256:[0-9a-fA-F]{64}$", System.Text.RegularExpressions.RegexOptions.CultureInvariant)) + return null; + + return $"{image}@{digest.ToLowerInvariant()}"; } private string ComposeYaml @@ -410,15 +412,16 @@ else if (_method == "windows-service") private string LinuxInstallCommand(bool service) { - var baseUrl = CentralUrl.TrimEnd('/'); - var scriptUrl = ShellQuote(baseUrl + "/install/install-agent.sh"); - var supervisorUrl = ShellQuote(baseUrl + "/install/agent-supervisor.py"); - var args = $"--central-url {ShellQuote(CentralUrl)} --site-token {ShellQuote(SiteToken)} --agent-name {ShellQuote(SiteName)}"; + var args = $"--central-url-file \"$tmp/central-url\" --site-token-file \"$tmp/site-token\" --agent-name {ShellQuote(SiteName)}"; args += service ? " --install-only" : " --run"; - return "tmp=$(mktemp -d) && " + - $"curl -fsSL {scriptUrl} -o \"$tmp/install-agent.sh\" && " + - $"curl -fsSL {supervisorUrl} -o \"$tmp/agent-supervisor.py\" && " + - $"sudo bash \"$tmp/install-agent.sh\" {args}; rc=$?; rm -rf \"$tmp\"; exit $rc"; + return "set -eu\n" + + "tmp=$(mktemp -d)\nchmod 700 \"$tmp\"\n" + + "cleanup() { rc=$?; trap - EXIT; rm -f \"$tmp/install-agent.sh\" \"$tmp/agent-supervisor.py\" \"$tmp/central-url\" \"$tmp/site-token\"; rmdir \"$tmp\"; exit $rc; }\ntrap cleanup EXIT HUP INT TERM\n" + + "printf 'Central HTTPS URL: '; IFS= read -r central_url\n" + + "printf 'Site enrollment token (input hidden): '; IFS= read -r -s site_token; printf '\\n'\n" + + "umask 077\nprintf '%s' \"$central_url\" > \"$tmp/central-url\"\nprintf '%s' \"$site_token\" > \"$tmp/site-token\"\nunset central_url site_token\n" + + "python3 - \"$tmp\" <<'PY'\nimport pathlib, sys, urllib.request\nroot=pathlib.Path(sys.argv[1])\nbase=(root/'central-url').read_text().rstrip('/')\nif not base.startswith('https://'): raise SystemExit('Central URL must use HTTPS')\nfor name in ('install-agent.sh','agent-supervisor.py'):\n request=urllib.request.Request(base+'/install/'+name, headers={'User-Agent':'Heimdall-Agent-Installer'})\n with urllib.request.urlopen(request, timeout=30) as response:\n if response.status != 200: raise SystemExit('Central installer asset request failed')\n (root/name).write_bytes(response.read())\nPY\n" + + $"sudo bash \"$tmp/install-agent.sh\" {args}"; } private string WindowsServiceName => "HeimdallAgent-" + Slugify(SiteName)[..Math.Min(60, Slugify(SiteName).Length)]; diff --git a/src/Heimdall.Web/Controllers/UpdatesController.cs b/src/Heimdall.Web/Controllers/UpdatesController.cs index f26e12b..1ab071b 100644 --- a/src/Heimdall.Web/Controllers/UpdatesController.cs +++ b/src/Heimdall.Web/Controllers/UpdatesController.cs @@ -131,44 +131,41 @@ public class UpdatesController : ControllerBase return null; var release = await ReadForgejoReleaseAsync(response.Content, ct); if (release is null) return null; - var assets = new Dictionary(); - foreach (var asset in release.Assets ?? []) - { - var platform = DetectPlatform(asset.Name); - if (platform is null) continue; - assets[platform] = new PlatformAsset { Url = asset.BrowserDownloadUrl, Sha256 = ExtractSha256(asset.Digest), Size = asset.Size }; - } - var result = new LatestReleaseResponse { Version = release.TagName, ReleaseNotes = release.Body, PublishedAt = release.PublishedAt, Assets = assets }; var publicKeyBytes = await FetchBoundedReleaseAssetAsync(release.Assets, - "agent-release-public.pem", client, 4096, ct); - if (publicKeyBytes is not null) - { - try - { - var publicKeyPem = System.Text.Encoding.UTF8.GetString(publicKeyBytes); - using var verifier = ECDsa.Create(); - verifier.ImportFromPem(publicKeyPem); - if (verifier.KeySize == 256) - result.UpdatePublicKeyPem = publicKeyPem; - } - catch (CryptographicException) { } - catch (ArgumentException) { } - } - var image = await FetchAgentImageManifestAsync(release.Assets, "agent-image.json", client, ct); - result.ContainerImage = image?.Image; - result.ContainerImageDigest = image?.Digest; - var gpuImage = await FetchAgentImageManifestAsync(release.Assets, "agent-image-gpu.json", client, ct); - result.ContainerImageGpu = gpuImage?.Image; - result.ContainerImageGpuDigest = gpuImage?.Digest; + "agent-release-public.pem", client, 4096, sourceUri, ct); var manifestBytes = await FetchBoundedReleaseAssetAsync(release.Assets, - "agent-update-manifest.json", client, 1_048_576, ct); + "agent-update-manifest.json", client, 1_048_576, sourceUri, ct); var signatureBytes = await FetchBoundedReleaseAssetAsync(release.Assets, - "agent-update-manifest.sig", client, 512, ct); - if (manifestBytes is not null && signatureBytes is not null) + "agent-update-manifest.sig", client, 512, sourceUri, ct); + var publicKeyPem = publicKeyBytes is null ? null : System.Text.Encoding.UTF8.GetString(publicKeyBytes); + if (publicKeyPem is null || manifestBytes is null || signatureBytes is null || + !AgentReleaseManifestVerifier.TryVerify(publicKeyPem, manifestBytes, signatureBytes, + release.TagName, out var signedManifest) || signedManifest is null) + return null; + + var assets = new Dictionary(); + foreach (var (platform, sha256) in signedManifest.Assets) { - result.SignedManifest = Convert.ToBase64String(manifestBytes); - result.ManifestSignature = Convert.ToBase64String(signatureBytes); + var asset = release.Assets?.SingleOrDefault(a => DetectPlatform(a.Name) == platform); + if (asset is null || !IsSameHttpsOrigin(asset.BrowserDownloadUrl, sourceUri)) return null; + assets[platform] = new PlatformAsset { Url = asset.BrowserDownloadUrl, Sha256 = sha256, Size = asset.Size }; } + if (assets.Count == 0) return null; + + var result = new LatestReleaseResponse + { + Version = signedManifest.Version, + ReleaseNotes = release.Body, + PublishedAt = release.PublishedAt, + Assets = assets, + ContainerImage = signedManifest.ContainerImage, + ContainerImageDigest = signedManifest.ContainerImageDigest, + ContainerImageGpu = signedManifest.ContainerImageGpu, + ContainerImageGpuDigest = signedManifest.ContainerImageGpuDigest, + UpdatePublicKeyPem = publicKeyPem, + SignedManifest = Convert.ToBase64String(manifestBytes), + ManifestSignature = Convert.ToBase64String(signatureBytes), + }; lock (_cacheLock) { _cache = new LatestReleaseCache(source!, result, DateTime.UtcNow); } return result; } @@ -236,52 +233,19 @@ public class UpdatesController : ControllerBase statusCode is System.Net.HttpStatusCode.RequestTimeout or System.Net.HttpStatusCode.TooManyRequests || (int)statusCode >= 500; - private static async Task FetchAgentImageManifestAsync(List? assets, - string assetName, HttpClient client, CancellationToken ct) - { - var asset = assets?.FirstOrDefault(a => string.Equals(a.Name, assetName, StringComparison.OrdinalIgnoreCase)); - var expectedSha256 = asset is null ? null : ExtractSha256(asset.Digest); - if (asset is null || !IsSha256Digest(expectedSha256)) return null; - try - { - using var response = await client.GetAsync(asset.BrowserDownloadUrl, HttpCompletionOption.ResponseHeadersRead, ct); - if (!response.IsSuccessStatusCode || response.Content.Headers.ContentLength is > 1_048_576) - return null; - await using var stream = await response.Content.ReadAsStreamAsync(ct); - using var buffer = new MemoryStream(); - var chunk = new byte[8192]; - while (true) - { - var read = await stream.ReadAsync(chunk, ct); - if (read == 0) break; - if (buffer.Length + read > 1_048_576) return null; - buffer.Write(chunk, 0, read); - } - var bytes = buffer.ToArray(); - var actualSha256 = Convert.ToHexString(SHA256.HashData(bytes)); - if (!string.Equals(actualSha256, expectedSha256, StringComparison.OrdinalIgnoreCase)) return null; - var manifest = JsonSerializer.Deserialize(bytes, Json); - return manifest is not null && IsValidContainerImageRepository(manifest.Image) && IsValidContainerImageDigest(manifest.Digest) - ? manifest - : null; - } - catch (OperationCanceledException) when (ct.IsCancellationRequested) { throw; } - catch { return null; } - } - - private static bool IsSha256Digest(string? value) => value is { Length: 64 } && value.All(Uri.IsHexDigit); - private static async Task FetchBoundedReleaseAssetAsync(List? assets, - string name, HttpClient client, int maxBytes, CancellationToken ct) + string name, HttpClient client, int maxBytes, Uri sourceUri, CancellationToken ct) { var asset = assets?.FirstOrDefault(a => string.Equals(a.Name, name, StringComparison.Ordinal)); var expected = asset is null ? null : ExtractSha256(asset.Digest); - if (asset is null || !IsSha256Digest(expected)) return null; + if (asset is null || !IsSameHttpsOrigin(asset.BrowserDownloadUrl, sourceUri) || + (asset.Digest is not null && !IsSha256Digest(expected))) return null; try { using var response = await client.GetAsync(asset.BrowserDownloadUrl, HttpCompletionOption.ResponseHeadersRead, ct); - if (!response.IsSuccessStatusCode || response.Content.Headers.ContentLength is long length && length > maxBytes) + if (!response.IsSuccessStatusCode || response.Content.Headers.ContentLength is long length && length > maxBytes || + response.RequestMessage?.RequestUri is not { } finalUri || !IsSameHttpsOrigin(finalUri, sourceUri)) return null; await using var stream = await response.Content.ReadAsStreamAsync(ct); using var buffer = new MemoryStream(); @@ -294,29 +258,23 @@ public class UpdatesController : ControllerBase buffer.Write(chunk, 0, read); } var bytes = buffer.ToArray(); - return string.Equals(Convert.ToHexString(SHA256.HashData(bytes)), expected, + return expected is null || string.Equals(Convert.ToHexString(SHA256.HashData(bytes)), expected, StringComparison.OrdinalIgnoreCase) ? bytes : null; } catch (OperationCanceledException) when (ct.IsCancellationRequested) { throw; } catch { return null; } } - private static bool IsValidContainerImageRepository(string? image) => image is { Length: > 0 and <= 255 } - && char.IsAsciiLetterOrDigit(image[0]) - && image.All(c => char.IsAsciiLetterOrDigit(c) || c is '.' or '_' or ':' or '/' or '-') - && !image.Contains('@') - && !image.Any(char.IsWhiteSpace) - && !image.Split('/').Last().Contains(':'); + private static bool IsSameHttpsOrigin(string candidate, Uri sourceUri) => + Uri.TryCreate(candidate, UriKind.Absolute, out var candidateUri) && IsSameHttpsOrigin(candidateUri, sourceUri); - private static bool IsValidContainerImageDigest(string? digest) => digest is { Length: 71 } - && digest.StartsWith("sha256:", StringComparison.OrdinalIgnoreCase) - && digest[7..].All(Uri.IsHexDigit); + private static bool IsSameHttpsOrigin(Uri candidateUri, Uri sourceUri) => + candidateUri.Scheme == Uri.UriSchemeHttps && + string.Equals(candidateUri.Host, sourceUri.Host, StringComparison.OrdinalIgnoreCase) && + candidateUri.Port == sourceUri.Port && string.IsNullOrEmpty(candidateUri.UserInfo) && + string.IsNullOrEmpty(candidateUri.Fragment); - private sealed class AgentImageManifest - { - [JsonPropertyName("image")] public string Image { get; init; } = string.Empty; - [JsonPropertyName("digest")] public string Digest { get; init; } = string.Empty; - } + private static bool IsSha256Digest(string? value) => value is { Length: 64 } && value.All(Uri.IsHexDigit); private async Task RefreshCacheAsync(string? source, CancellationToken ct) { diff --git a/src/Heimdall.Web/Localization/SharedResources.en.resx b/src/Heimdall.Web/Localization/SharedResources.en.resx index 2f9c4a4..03604c3 100644 --- a/src/Heimdall.Web/Localization/SharedResources.en.resx +++ b/src/Heimdall.Web/Localization/SharedResources.en.resx @@ -4071,6 +4071,9 @@ Install and run + + At runtime, enter the Central HTTPS URL and then the site token (token input is hidden). These values are not included in the copied command. + Run @@ -4078,7 +4081,7 @@ Check - Docker installation uses the latest image. Updates dispatched by Central verify the signed digest before replacing the Agent. Docker mode mounts the host Docker socket, giving the Agent broad control of that host. On Linux, before Compose, set DOCKER_GID to the socket GID: export DOCKER_GID="$(stat -c '%g' /var/run/docker.sock)". + Docker installation pins the CPU or GPU Agent image to the signed repository@sha256:digest. Updates dispatched by Central verify the signed digest before replacing the Agent. Docker mode mounts the host Docker socket, giving the Agent broad control of that host. On Linux, before Compose, set DOCKER_GID to the socket GID: export DOCKER_GID="$(stat -c '%g' /var/run/docker.sock)". The Agent starts in the background so you can check it from this PowerShell session. Choose Windows Service to restart it after logoff or reboot. diff --git a/src/Heimdall.Web/Localization/SharedResources.fr.resx b/src/Heimdall.Web/Localization/SharedResources.fr.resx index e6b4c5e..1ba0b84 100644 --- a/src/Heimdall.Web/Localization/SharedResources.fr.resx +++ b/src/Heimdall.Web/Localization/SharedResources.fr.resx @@ -4071,6 +4071,9 @@ Installer et lancer + + À l’exécution, saisissez l’URL HTTPS de Central puis le token du site (la saisie du token est masquée). Ces valeurs ne sont pas incluses dans la commande copiée. + Lancer diff --git a/src/Heimdall.Web/Localization/SharedResources.resx b/src/Heimdall.Web/Localization/SharedResources.resx index fc768db..bd9709e 100644 --- a/src/Heimdall.Web/Localization/SharedResources.resx +++ b/src/Heimdall.Web/Localization/SharedResources.resx @@ -4071,6 +4071,9 @@ Install and run + + At runtime, enter the Central HTTPS URL and then the site token (token input is hidden). These values are not included in the copied command. + Run @@ -4078,7 +4081,7 @@ Check - Docker installation uses the latest image. Updates dispatched by Central verify the signed digest before replacing the Agent. Docker mode mounts the host Docker socket, giving the Agent broad control of that host. On Linux, before Compose, set DOCKER_GID to the socket GID: export DOCKER_GID="$(stat -c '%g' /var/run/docker.sock)". + Docker installation pins the CPU or GPU Agent image to the signed repository@sha256:digest. Updates dispatched by Central verify the signed digest before replacing the Agent. Docker mode mounts the host Docker socket, giving the Agent broad control of that host. On Linux, before Compose, set DOCKER_GID to the socket GID: export DOCKER_GID="$(stat -c '%g' /var/run/docker.sock)". The Agent starts in the background so you can check it from this PowerShell session. Choose Windows Service to restart it after logoff or reboot. diff --git a/src/Heimdall.Web/Services/AgentReleaseManifestVerifier.cs b/src/Heimdall.Web/Services/AgentReleaseManifestVerifier.cs new file mode 100644 index 0000000..82ed243 --- /dev/null +++ b/src/Heimdall.Web/Services/AgentReleaseManifestVerifier.cs @@ -0,0 +1,68 @@ +using System.Security.Cryptography; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace Heimdall.Web.Services; + +/// Verifies the signed Agent release metadata before Central exposes it to installers. +public static class AgentReleaseManifestVerifier +{ + private static readonly JsonSerializerOptions Json = new() { PropertyNameCaseInsensitive = true }; + + public static bool TryVerify(string publicKeyPem, byte[] manifestBytes, byte[] signatureBytes, + string releaseTag, out AgentReleaseManifest? manifest) + { + manifest = null; + if (string.IsNullOrWhiteSpace(publicKeyPem) || manifestBytes.Length is 0 or > 1_048_576 || + signatureBytes.Length is 0 or > 512 || string.IsNullOrWhiteSpace(releaseTag)) + return false; + + try + { + using var verifier = ECDsa.Create(); + verifier.ImportFromPem(publicKeyPem); + if (verifier.KeySize != 256 || !verifier.VerifyData(manifestBytes, signatureBytes, + HashAlgorithmName.SHA256, DSASignatureFormat.Rfc3279DerSequence)) + return false; + + var parsed = JsonSerializer.Deserialize(manifestBytes, Json); + if (parsed is null || parsed.Assets is null || + !string.Equals(NormalizeVersion(parsed.Version), NormalizeVersion(releaseTag), + StringComparison.Ordinal) || parsed.Assets.Count == 0 || + parsed.Assets.Any(asset => string.IsNullOrWhiteSpace(asset.Key) || asset.Value is null || !IsSha256(asset.Value)) || + !IsValidContainerImageRepository(parsed.ContainerImage) || + !IsValidContainerImageDigest(parsed.ContainerImageDigest) || + ((parsed.ContainerImageGpu is null) != (parsed.ContainerImageGpuDigest is null)) || + (parsed.ContainerImageGpu is not null && + (!IsValidContainerImageRepository(parsed.ContainerImageGpu) || + !IsValidContainerImageDigest(parsed.ContainerImageGpuDigest)))) + return false; + + manifest = parsed; + return true; + } + catch (CryptographicException) { return false; } + catch (ArgumentException) { return false; } + catch (JsonException) { return false; } + } + + private static string NormalizeVersion(string value) => value.Trim().TrimStart('v', 'V'); + private static bool IsSha256(string value) => value.Length == 64 && value.All(Uri.IsHexDigit); + private static bool IsValidContainerImageRepository(string? image) => image is { Length: > 0 and <= 255 } + && char.IsAsciiLetterOrDigit(image[0]) + && image.All(c => char.IsAsciiLetterOrDigit(c) || c is '.' or '_' or ':' or '/' or '-') + && !image.Contains('@') && !image.Any(char.IsWhiteSpace) && !image.Split('/').Last().Contains(':'); + private static bool IsValidContainerImageDigest(string? digest) => digest is { Length: 71 } + && digest.StartsWith("sha256:", StringComparison.OrdinalIgnoreCase) + && digest[7..].All(Uri.IsHexDigit); +} + +public sealed class AgentReleaseManifest +{ + [JsonPropertyName("version")] public string Version { get; init; } = string.Empty; + [JsonPropertyName("assets")] public Dictionary Assets { get; init; } = []; + [JsonPropertyName("containerImage")] public string? ContainerImage { get; init; } + [JsonPropertyName("containerImageDigest")] public string? ContainerImageDigest { get; init; } + [JsonPropertyName("containerImageGpu")] public string? ContainerImageGpu { get; init; } + [JsonPropertyName("containerImageGpuDigest")] public string? ContainerImageGpuDigest { get; init; } +} diff --git a/src/Heimdall.Web/packages.lock.json b/src/Heimdall.Web/packages.lock.json index 398cd61..38b9ccd 100644 --- a/src/Heimdall.Web/packages.lock.json +++ b/src/Heimdall.Web/packages.lock.json @@ -142,8 +142,8 @@ }, "AutoMapper": { "type": "Transitive", - "resolved": "16.1.1", - "contentHash": "VNEky8JA15ci+oIDRGHITOGOpV4dILsf8pnn24QhDl2urtqgJ2IXiS/V2EtGU17P/+f6OeFQPJETaZXV9QOIZg==", + "resolved": "16.3.0", + "contentHash": "wFTqA37e1I4AOEhTTYlxrqDE8BQ4OB3dqhlv2KwYmHv+a4tn7R1JW2n2bzXb8eTBhWVBSl7iTZ0VxEt0a57D4w==", "dependencies": { "Microsoft.IdentityModel.JsonWebTokens": "8.14.0" } @@ -491,7 +491,7 @@ "heimdall.application": { "type": "Project", "dependencies": { - "AutoMapper": "[16.1.1, )", + "AutoMapper": "[16.3.0, )", "FluentValidation": "[11.11.0, )", "FluentValidation.DependencyInjectionExtensions": "[11.11.0, )", "Heimdall.Domain": "[1.0.0, )", diff --git a/tests/Heimdall.Agent.Tests/AgentOptionsTests.cs b/tests/Heimdall.Agent.Tests/AgentOptionsTests.cs new file mode 100644 index 0000000..ccd7bab --- /dev/null +++ b/tests/Heimdall.Agent.Tests/AgentOptionsTests.cs @@ -0,0 +1,31 @@ +namespace Heimdall.Agent.Tests; + +[CollectionDefinition("AgentOptions environment", DisableParallelization = true)] +public sealed class AgentOptionsEnvironmentScope +{ + public const string Name = "AgentOptions environment"; +} + +[Collection(AgentOptionsEnvironmentScope.Name)] +public sealed class AgentOptionsTests +{ + [Fact] + public void CentralUrl_LoadsFromSystemdCredentialWhenNoEnvironmentSettingExists() + { + var previous = Environment.GetEnvironmentVariable("CREDENTIALS_DIRECTORY"); + var directory = Path.Combine(Path.GetTempPath(), $"heimdall-agent-options-{Guid.NewGuid():N}"); + Directory.CreateDirectory(directory); + File.WriteAllText(Path.Combine(directory, "central-url"), "https://central.example.test\n"); + + try + { + Environment.SetEnvironmentVariable("CREDENTIALS_DIRECTORY", directory); + new AgentOptions { }.CentralUrl.ShouldBe("https://central.example.test"); + } + finally + { + Environment.SetEnvironmentVariable("CREDENTIALS_DIRECTORY", previous); + Directory.Delete(directory, recursive: true); + } + } +} diff --git a/tests/Heimdall.Agent.Tests/packages.lock.json b/tests/Heimdall.Agent.Tests/packages.lock.json index 9a35658..2cf8b9c 100644 --- a/tests/Heimdall.Agent.Tests/packages.lock.json +++ b/tests/Heimdall.Agent.Tests/packages.lock.json @@ -82,8 +82,8 @@ }, "AutoMapper": { "type": "Transitive", - "resolved": "16.1.1", - "contentHash": "VNEky8JA15ci+oIDRGHITOGOpV4dILsf8pnn24QhDl2urtqgJ2IXiS/V2EtGU17P/+f6OeFQPJETaZXV9QOIZg==", + "resolved": "16.3.0", + "contentHash": "wFTqA37e1I4AOEhTTYlxrqDE8BQ4OB3dqhlv2KwYmHv+a4tn7R1JW2n2bzXb8eTBhWVBSl7iTZ0VxEt0a57D4w==", "dependencies": { "Microsoft.Extensions.Logging.Abstractions": "10.0.0", "Microsoft.Extensions.Options": "10.0.0", @@ -166,14 +166,6 @@ "resolved": "10.0.13", "contentHash": "INZVBMOPbQC5xj1oTpwhELtokdH9LcY7oCsTVDEavziMpsoGJJPejax5WdFNfPeTMGq9eT6fL8GcVHeobvqORA==" }, - "Microsoft.AspNetCore.Cryptography.KeyDerivation": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "mt935Uji4EdglTPrgJrqHdXkWM2EI6d7V8fEfvlC+KevB16MtHUHGiaKycawlOJgbOMw1D9etbHIfLL2nnWV4Q==", - "dependencies": { - "Microsoft.AspNetCore.Cryptography.Internal": "10.0.13" - } - }, "Microsoft.AspNetCore.DataProtection.Abstractions": { "type": "Transitive", "resolved": "10.0.13", @@ -197,15 +189,6 @@ "Microsoft.AspNetCore.Connections.Abstractions": "10.0.13" } }, - "Microsoft.AspNetCore.Identity.EntityFrameworkCore": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "c6984ahCnqc3zqYgl5KqrBoY+LMKqJW6nZcFdBYNyp3PAA67prA/IgjQ/ySV0t3lEL2LEz3bcx91fbUYr8bRPA==", - "dependencies": { - "Microsoft.EntityFrameworkCore.Relational": "10.0.13", - "Microsoft.Extensions.Identity.Stores": "10.0.13" - } - }, "Microsoft.AspNetCore.SignalR.Client": { "type": "Transitive", "resolved": "10.0.13", @@ -543,27 +526,6 @@ "Microsoft.Extensions.Options": "10.0.0" } }, - "Microsoft.Extensions.Identity.Core": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "76aNRvI7HU9sYjevIlpFuT/VyspRoiREwOZI+RFXM/HRJ3v6nC7gxSZoX881FEBkF+0udKHuFxtsWbRLytqsSA==", - "dependencies": { - "Microsoft.AspNetCore.Cryptography.KeyDerivation": "10.0.13", - "Microsoft.Extensions.Diagnostics": "10.0.13", - "Microsoft.Extensions.Logging": "10.0.13", - "Microsoft.Extensions.Options": "10.0.13" - } - }, - "Microsoft.Extensions.Identity.Stores": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "qNZr9maHa2Kg7mRh+hLEJ59ts2OfYMiJJ5GVjx8BDrmhPxx/V345CTdIrUcZ5FZwwHepITsZY0e9qss7NB2U5A==", - "dependencies": { - "Microsoft.Extensions.Caching.Abstractions": "10.0.13", - "Microsoft.Extensions.Identity.Core": "10.0.13", - "Microsoft.Extensions.Logging": "10.0.13" - } - }, "Microsoft.Extensions.Logging": { "type": "Transitive", "resolved": "10.0.13", @@ -874,7 +836,10 @@ "System.ServiceProcess.ServiceController": { "type": "Transitive", "resolved": "10.0.13", - "contentHash": "0Zh/U/1+hy1MCxx1BTikJi4L5o1Ys6VhB8PKlTNOB4/n2d6ua2+TuoD6T7xN9RV0uiOGod575pQrUSTXg+aYGQ==" + "contentHash": "0Zh/U/1+hy1MCxx1BTikJi4L5o1Ys6VhB8PKlTNOB4/n2d6ua2+TuoD6T7xN9RV0uiOGod575pQrUSTXg+aYGQ==", + "dependencies": { + "System.Diagnostics.EventLog": "10.0.13" + } }, "xunit.abstractions": { "type": "Transitive", @@ -936,12 +901,11 @@ "heimdall.application": { "type": "Project", "dependencies": { - "AutoMapper": "[16.1.1, )", + "AutoMapper": "[16.3.0, )", "FluentValidation": "[11.11.0, )", "FluentValidation.DependencyInjectionExtensions": "[11.11.0, )", "Heimdall.Domain": "[1.0.0, )", "MediatR": "[12.5.0, )", - "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "[10.0.13, )", "Microsoft.Data.Sqlite": "[10.0.13, )", "Microsoft.EntityFrameworkCore": "[10.0.13, )", "Microsoft.EntityFrameworkCore.Sqlite": "[10.0.13, )", @@ -954,8 +918,7 @@ "heimdall.domain": { "type": "Project", "dependencies": { - "Heimdall.Domain.Primitives": "[1.0.0, )", - "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "[10.0.13, )" + "Heimdall.Domain.Primitives": "[1.0.0, )" } }, "heimdall.domain.primitives": { @@ -969,4 +932,4 @@ } } } -} +} \ No newline at end of file diff --git a/tests/Heimdall.Api.Tests/packages.lock.json b/tests/Heimdall.Api.Tests/packages.lock.json index 9547f9f..be3e9d8 100644 --- a/tests/Heimdall.Api.Tests/packages.lock.json +++ b/tests/Heimdall.Api.Tests/packages.lock.json @@ -56,8 +56,8 @@ }, "AutoMapper": { "type": "Transitive", - "resolved": "16.1.1", - "contentHash": "VNEky8JA15ci+oIDRGHITOGOpV4dILsf8pnn24QhDl2urtqgJ2IXiS/V2EtGU17P/+f6OeFQPJETaZXV9QOIZg==", + "resolved": "16.3.0", + "contentHash": "wFTqA37e1I4AOEhTTYlxrqDE8BQ4OB3dqhlv2KwYmHv+a4tn7R1JW2n2bzXb8eTBhWVBSl7iTZ0VxEt0a57D4w==", "dependencies": { "Microsoft.Extensions.Logging.Abstractions": "10.0.0", "Microsoft.Extensions.Options": "10.0.0", @@ -1061,12 +1061,11 @@ "heimdall.application": { "type": "Project", "dependencies": { - "AutoMapper": "[16.1.1, )", + "AutoMapper": "[16.3.0, )", "FluentValidation": "[11.11.0, )", "FluentValidation.DependencyInjectionExtensions": "[11.11.0, )", "Heimdall.Domain": "[1.0.0, )", "MediatR": "[12.5.0, )", - "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "[10.0.13, )", "Microsoft.Data.Sqlite": "[10.0.13, )", "Microsoft.EntityFrameworkCore": "[10.0.13, )", "Microsoft.EntityFrameworkCore.Sqlite": "[10.0.13, )", @@ -1079,8 +1078,7 @@ "heimdall.domain": { "type": "Project", "dependencies": { - "Heimdall.Domain.Primitives": "[1.0.0, )", - "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "[10.0.13, )" + "Heimdall.Domain.Primitives": "[1.0.0, )" } }, "heimdall.domain.primitives": { diff --git a/tests/Heimdall.Application.Tests/packages.lock.json b/tests/Heimdall.Application.Tests/packages.lock.json index 6e146e4..400f339 100644 --- a/tests/Heimdall.Application.Tests/packages.lock.json +++ b/tests/Heimdall.Application.Tests/packages.lock.json @@ -62,8 +62,8 @@ }, "AutoMapper": { "type": "Transitive", - "resolved": "16.1.1", - "contentHash": "VNEky8JA15ci+oIDRGHITOGOpV4dILsf8pnn24QhDl2urtqgJ2IXiS/V2EtGU17P/+f6OeFQPJETaZXV9QOIZg==", + "resolved": "16.3.0", + "contentHash": "wFTqA37e1I4AOEhTTYlxrqDE8BQ4OB3dqhlv2KwYmHv+a4tn7R1JW2n2bzXb8eTBhWVBSl7iTZ0VxEt0a57D4w==", "dependencies": { "Microsoft.Extensions.Logging.Abstractions": "10.0.0", "Microsoft.Extensions.Options": "10.0.0", @@ -115,28 +115,6 @@ "resolved": "2.0.1", "contentHash": "FYv95bNT4UwcNA+G/J1oX5OpRiSUxteXaUt2BJbRSdRNiIUNbggJF69wy6mnk2wYToaanpdXZdCwVylt96MpwQ==" }, - "Microsoft.AspNetCore.Cryptography.Internal": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "INZVBMOPbQC5xj1oTpwhELtokdH9LcY7oCsTVDEavziMpsoGJJPejax5WdFNfPeTMGq9eT6fL8GcVHeobvqORA==" - }, - "Microsoft.AspNetCore.Cryptography.KeyDerivation": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "mt935Uji4EdglTPrgJrqHdXkWM2EI6d7V8fEfvlC+KevB16MtHUHGiaKycawlOJgbOMw1D9etbHIfLL2nnWV4Q==", - "dependencies": { - "Microsoft.AspNetCore.Cryptography.Internal": "10.0.13" - } - }, - "Microsoft.AspNetCore.Identity.EntityFrameworkCore": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "c6984ahCnqc3zqYgl5KqrBoY+LMKqJW6nZcFdBYNyp3PAA67prA/IgjQ/ySV0t3lEL2LEz3bcx91fbUYr8bRPA==", - "dependencies": { - "Microsoft.EntityFrameworkCore.Relational": "10.0.13", - "Microsoft.Extensions.Identity.Stores": "10.0.13" - } - }, "Microsoft.CodeCoverage": { "type": "Transitive", "resolved": "17.14.1", @@ -240,15 +218,6 @@ "Microsoft.Extensions.Primitives": "10.0.13" } }, - "Microsoft.Extensions.Configuration": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "inhujYI/nikhmLxYI6ZEcaCgZ28ipJsKMPPxxr2XWf3vM0Q2P+E9R3hDHABZOLBxzD3gjpgcbSH/+hd2+gvI2A==", - "dependencies": { - "Microsoft.Extensions.Configuration.Abstractions": "10.0.13", - "Microsoft.Extensions.Primitives": "10.0.13" - } - }, "Microsoft.Extensions.Configuration.Abstractions": { "type": "Transitive", "resolved": "10.0.13", @@ -257,15 +226,6 @@ "Microsoft.Extensions.Primitives": "10.0.13" } }, - "Microsoft.Extensions.Configuration.Binder": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "yJJl/b0+W+GEWbu+7viw6C3h2BoNkB69Vlz7s/4e+hm4mYbJqfhdcDSi9sCXJw47blsBaiQd3UDPgDtop92+ug==", - "dependencies": { - "Microsoft.Extensions.Configuration": "10.0.13", - "Microsoft.Extensions.Configuration.Abstractions": "10.0.13" - } - }, "Microsoft.Extensions.DependencyInjection": { "type": "Transitive", "resolved": "10.0.13", @@ -284,46 +244,6 @@ "resolved": "10.0.13", "contentHash": "6TyllZsToy3S/Ziu67GddljRTttuVJ8bbrbVUrsdHqH5678Oax5MpaEubxLoPoWLvgUBYo4KfcAig0mkBtktXQ==" }, - "Microsoft.Extensions.Diagnostics": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "J9ODOrffj1mK3Et69elNsLGRguesPxvThTdVpFmQX7fLNPhIOgqHQfLdGnTBEwNAV3yf8yiyVlpDZNw2qN87Nw==", - "dependencies": { - "Microsoft.Extensions.Configuration": "10.0.13", - "Microsoft.Extensions.Diagnostics.Abstractions": "10.0.13", - "Microsoft.Extensions.Options.ConfigurationExtensions": "10.0.13" - } - }, - "Microsoft.Extensions.Diagnostics.Abstractions": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "oZzqZze8ed1fLS20HtIrkPxQXGRG/koq09srIw2ptnDHm9RHfwB++d35hosB/cXc55TH7Pshv85O0txongjCIg==", - "dependencies": { - "Microsoft.Extensions.DependencyInjection.Abstractions": "10.0.13", - "Microsoft.Extensions.Options": "10.0.13" - } - }, - "Microsoft.Extensions.Identity.Core": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "76aNRvI7HU9sYjevIlpFuT/VyspRoiREwOZI+RFXM/HRJ3v6nC7gxSZoX881FEBkF+0udKHuFxtsWbRLytqsSA==", - "dependencies": { - "Microsoft.AspNetCore.Cryptography.KeyDerivation": "10.0.13", - "Microsoft.Extensions.Diagnostics": "10.0.13", - "Microsoft.Extensions.Logging": "10.0.13", - "Microsoft.Extensions.Options": "10.0.13" - } - }, - "Microsoft.Extensions.Identity.Stores": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "qNZr9maHa2Kg7mRh+hLEJ59ts2OfYMiJJ5GVjx8BDrmhPxx/V345CTdIrUcZ5FZwwHepITsZY0e9qss7NB2U5A==", - "dependencies": { - "Microsoft.Extensions.Caching.Abstractions": "10.0.13", - "Microsoft.Extensions.Identity.Core": "10.0.13", - "Microsoft.Extensions.Logging": "10.0.13" - } - }, "Microsoft.Extensions.Logging": { "type": "Transitive", "resolved": "10.0.13", @@ -351,18 +271,6 @@ "Microsoft.Extensions.Primitives": "10.0.13" } }, - "Microsoft.Extensions.Options.ConfigurationExtensions": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "xVO5HhATc09WXuS/RaDmx8ZeWS0mTpT1L0tkEDMSBHtAnNpNsDr0ge0wIO2jinCWWqpq5dL1tRTzpYNVlvyqLw==", - "dependencies": { - "Microsoft.Extensions.Configuration.Abstractions": "10.0.13", - "Microsoft.Extensions.Configuration.Binder": "10.0.13", - "Microsoft.Extensions.DependencyInjection.Abstractions": "10.0.13", - "Microsoft.Extensions.Options": "10.0.13", - "Microsoft.Extensions.Primitives": "10.0.13" - } - }, "Microsoft.Extensions.Primitives": { "type": "Transitive", "resolved": "10.0.13", @@ -513,12 +421,11 @@ "heimdall.application": { "type": "Project", "dependencies": { - "AutoMapper": "[16.1.1, )", + "AutoMapper": "[16.3.0, )", "FluentValidation": "[11.11.0, )", "FluentValidation.DependencyInjectionExtensions": "[11.11.0, )", "Heimdall.Domain": "[1.0.0, )", "MediatR": "[12.5.0, )", - "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "[10.0.13, )", "Microsoft.Data.Sqlite": "[10.0.13, )", "Microsoft.EntityFrameworkCore": "[10.0.13, )", "Microsoft.EntityFrameworkCore.Sqlite": "[10.0.13, )", @@ -528,8 +435,7 @@ "heimdall.domain": { "type": "Project", "dependencies": { - "Heimdall.Domain.Primitives": "[1.0.0, )", - "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "[10.0.13, )" + "Heimdall.Domain.Primitives": "[1.0.0, )" } }, "heimdall.domain.primitives": { diff --git a/tests/Heimdall.Domain.Tests/packages.lock.json b/tests/Heimdall.Domain.Tests/packages.lock.json index 7272bfe..624866c 100644 --- a/tests/Heimdall.Domain.Tests/packages.lock.json +++ b/tests/Heimdall.Domain.Tests/packages.lock.json @@ -76,208 +76,11 @@ "resolved": "4.4.0", "contentHash": "gwJEfIGS7FhykvtZoscwXj/XwW+mJY6UbAZk+qtLKFUGWC95kfKXnj8VkxsZQnWBxJemM/q664rGLN5nf+OHZw==" }, - "Microsoft.AspNetCore.Cryptography.Internal": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "INZVBMOPbQC5xj1oTpwhELtokdH9LcY7oCsTVDEavziMpsoGJJPejax5WdFNfPeTMGq9eT6fL8GcVHeobvqORA==" - }, - "Microsoft.AspNetCore.Cryptography.KeyDerivation": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "mt935Uji4EdglTPrgJrqHdXkWM2EI6d7V8fEfvlC+KevB16MtHUHGiaKycawlOJgbOMw1D9etbHIfLL2nnWV4Q==", - "dependencies": { - "Microsoft.AspNetCore.Cryptography.Internal": "10.0.13" - } - }, - "Microsoft.AspNetCore.Identity.EntityFrameworkCore": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "c6984ahCnqc3zqYgl5KqrBoY+LMKqJW6nZcFdBYNyp3PAA67prA/IgjQ/ySV0t3lEL2LEz3bcx91fbUYr8bRPA==", - "dependencies": { - "Microsoft.EntityFrameworkCore.Relational": "10.0.13", - "Microsoft.Extensions.Identity.Stores": "10.0.13" - } - }, "Microsoft.CodeCoverage": { "type": "Transitive", "resolved": "17.14.1", "contentHash": "pmTrhfFIoplzFVbhVwUquT+77CbGH+h4/3mBpdmIlYtBi9nAB+kKI6dN3A/nV4DFi3wLLx/BlHIPK+MkbQ6Tpg==" }, - "Microsoft.EntityFrameworkCore": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "u/z4nTQUJ5nJEXAQekgQEQZkh0delp4gL+ESHn7Z6k037c8HC5mSNu1/YdBgxGm7DtLjhOxktNl+aQMzw6wN7A==", - "dependencies": { - "Microsoft.EntityFrameworkCore.Abstractions": "10.0.13", - "Microsoft.EntityFrameworkCore.Analyzers": "10.0.13", - "Microsoft.Extensions.Caching.Memory": "10.0.13", - "Microsoft.Extensions.Logging": "10.0.13" - } - }, - "Microsoft.EntityFrameworkCore.Abstractions": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "ARw+tZ3eiTosnK5nJPUGEzeUQcjyqCqs3qKA3lPtIRH5yJo3qIgxm7AvkZVIT9iWkS2083UsWe3Rj1MysW3p5A==" - }, - "Microsoft.EntityFrameworkCore.Analyzers": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "zBx6VeEz/hkhlm0BJ2V+9xebUuDDIszcKvurJceQHuZPEXuXubrL6Lneo9VZiliRyJbQlB2oNKLkJXd3gHteQA==" - }, - "Microsoft.EntityFrameworkCore.Relational": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "QU/sbTtDR5wVAJRVecC1GwM7mwH8bvKOZNm+lulzMr5rhjdb8DDEFIqqdhF08JIo51DPv5uQdZ1nXoZsD5pTag==", - "dependencies": { - "Microsoft.EntityFrameworkCore": "10.0.13", - "Microsoft.Extensions.Caching.Memory": "10.0.13", - "Microsoft.Extensions.Configuration.Abstractions": "10.0.13", - "Microsoft.Extensions.Logging": "10.0.13" - } - }, - "Microsoft.Extensions.Caching.Abstractions": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "UOJqcdNMoFcV/5RUcOlVKq9pPmbrcmbpLx5iYz9QtrmMcWRQzlL5Q/NZRfbPPLNyIEc1HWjjs5Z7nIwqewU1sg==", - "dependencies": { - "Microsoft.Extensions.Primitives": "10.0.13" - } - }, - "Microsoft.Extensions.Caching.Memory": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "q+At65RACuCtGwUDVI08TmmrC73YFouimMkJAtlhsGhFcU/dVpqYEKpNBOF9TUxkJ6aefEOShqe7StLK7q3NqA==", - "dependencies": { - "Microsoft.Extensions.Caching.Abstractions": "10.0.13", - "Microsoft.Extensions.DependencyInjection.Abstractions": "10.0.13", - "Microsoft.Extensions.Logging.Abstractions": "10.0.13", - "Microsoft.Extensions.Options": "10.0.13", - "Microsoft.Extensions.Primitives": "10.0.13" - } - }, - "Microsoft.Extensions.Configuration": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "inhujYI/nikhmLxYI6ZEcaCgZ28ipJsKMPPxxr2XWf3vM0Q2P+E9R3hDHABZOLBxzD3gjpgcbSH/+hd2+gvI2A==", - "dependencies": { - "Microsoft.Extensions.Configuration.Abstractions": "10.0.13", - "Microsoft.Extensions.Primitives": "10.0.13" - } - }, - "Microsoft.Extensions.Configuration.Abstractions": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "DY4C2qzTt2lOIY3VoscBH/TCwTolI5DKOfgJLuI+k1QUvRNT5vTMS58AOerNiihdVRStO0wEpLeRWA8jytzHBQ==", - "dependencies": { - "Microsoft.Extensions.Primitives": "10.0.13" - } - }, - "Microsoft.Extensions.Configuration.Binder": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "yJJl/b0+W+GEWbu+7viw6C3h2BoNkB69Vlz7s/4e+hm4mYbJqfhdcDSi9sCXJw47blsBaiQd3UDPgDtop92+ug==", - "dependencies": { - "Microsoft.Extensions.Configuration": "10.0.13", - "Microsoft.Extensions.Configuration.Abstractions": "10.0.13" - } - }, - "Microsoft.Extensions.DependencyInjection": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "4tnWU9vrU/A8NwYe9Z6wvieZ0EBb/uM82LAT+edNhdepOBWREZ7M7mzb941EIDPJaeOFdbVrDd5+7s9e89U6bQ==", - "dependencies": { - "Microsoft.Extensions.DependencyInjection.Abstractions": "10.0.13" - } - }, - "Microsoft.Extensions.DependencyInjection.Abstractions": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "G2GrGWNAPZBsii2F6AU8n+JT2tC1/I0Ml/e9ZyNCgPjf3hZqronP7o0X91aAynCmVeae8KkSIUNXXeXCNRmdVQ==" - }, - "Microsoft.Extensions.Diagnostics": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "J9ODOrffj1mK3Et69elNsLGRguesPxvThTdVpFmQX7fLNPhIOgqHQfLdGnTBEwNAV3yf8yiyVlpDZNw2qN87Nw==", - "dependencies": { - "Microsoft.Extensions.Configuration": "10.0.13", - "Microsoft.Extensions.Diagnostics.Abstractions": "10.0.13", - "Microsoft.Extensions.Options.ConfigurationExtensions": "10.0.13" - } - }, - "Microsoft.Extensions.Diagnostics.Abstractions": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "oZzqZze8ed1fLS20HtIrkPxQXGRG/koq09srIw2ptnDHm9RHfwB++d35hosB/cXc55TH7Pshv85O0txongjCIg==", - "dependencies": { - "Microsoft.Extensions.DependencyInjection.Abstractions": "10.0.13", - "Microsoft.Extensions.Options": "10.0.13" - } - }, - "Microsoft.Extensions.Identity.Core": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "76aNRvI7HU9sYjevIlpFuT/VyspRoiREwOZI+RFXM/HRJ3v6nC7gxSZoX881FEBkF+0udKHuFxtsWbRLytqsSA==", - "dependencies": { - "Microsoft.AspNetCore.Cryptography.KeyDerivation": "10.0.13", - "Microsoft.Extensions.Diagnostics": "10.0.13", - "Microsoft.Extensions.Logging": "10.0.13", - "Microsoft.Extensions.Options": "10.0.13" - } - }, - "Microsoft.Extensions.Identity.Stores": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "qNZr9maHa2Kg7mRh+hLEJ59ts2OfYMiJJ5GVjx8BDrmhPxx/V345CTdIrUcZ5FZwwHepITsZY0e9qss7NB2U5A==", - "dependencies": { - "Microsoft.Extensions.Caching.Abstractions": "10.0.13", - "Microsoft.Extensions.Identity.Core": "10.0.13", - "Microsoft.Extensions.Logging": "10.0.13" - } - }, - "Microsoft.Extensions.Logging": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "fqbiPy4nUp4H2XHKAVQXKN2y3T2h4cFIx1DAAgE6iY9OHkN/OA1cKFi+geJKRWGuX6pS5SFbsjIPWHJqrxE0eg==", - "dependencies": { - "Microsoft.Extensions.DependencyInjection": "10.0.13", - "Microsoft.Extensions.Logging.Abstractions": "10.0.13", - "Microsoft.Extensions.Options": "10.0.13" - } - }, - "Microsoft.Extensions.Logging.Abstractions": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "aSZEhEig4fvNiw2zs8Z6NyDlniKtq6YjcF3DyHuqTEHcZ2VKA/6itMPZ+dW+yWABWExlDcQwwdbqX1Rcb7W8WQ==", - "dependencies": { - "Microsoft.Extensions.DependencyInjection.Abstractions": "10.0.13" - } - }, - "Microsoft.Extensions.Options": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "tmMJgdrE4uhf1JcNs9CV9moAHW+hmDuvgMiPpnQxarKaUxqI2eN33sYK5S4l9Uw+rG9PJvlm4qPxMhvolTDTaQ==", - "dependencies": { - "Microsoft.Extensions.DependencyInjection.Abstractions": "10.0.13", - "Microsoft.Extensions.Primitives": "10.0.13" - } - }, - "Microsoft.Extensions.Options.ConfigurationExtensions": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "xVO5HhATc09WXuS/RaDmx8ZeWS0mTpT1L0tkEDMSBHtAnNpNsDr0ge0wIO2jinCWWqpq5dL1tRTzpYNVlvyqLw==", - "dependencies": { - "Microsoft.Extensions.Configuration.Abstractions": "10.0.13", - "Microsoft.Extensions.Configuration.Binder": "10.0.13", - "Microsoft.Extensions.DependencyInjection.Abstractions": "10.0.13", - "Microsoft.Extensions.Options": "10.0.13", - "Microsoft.Extensions.Primitives": "10.0.13" - } - }, - "Microsoft.Extensions.Primitives": { - "type": "Transitive", - "resolved": "10.0.13", - "contentHash": "ZjTwxzhiw2TMEzIbUDkMF0dfDB2I4NQgIfKD0ELu9/5Mk+SRGdKZcD0/lvBrRCAPo6KN2r0BW86MRancoyJkoA==" - }, "Microsoft.TestPlatform.ObjectModel": { "type": "Transitive", "resolved": "17.14.1", @@ -358,8 +161,7 @@ "heimdall.domain": { "type": "Project", "dependencies": { - "Heimdall.Domain.Primitives": "[1.0.0, )", - "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "[10.0.13, )" + "Heimdall.Domain.Primitives": "[1.0.0, )" } }, "heimdall.domain.primitives": { diff --git a/tests/Heimdall.E2E.Tests/Pages/UserManagementTests.cs b/tests/Heimdall.E2E.Tests/Pages/UserManagementTests.cs index 95b8b07..57760ef 100644 --- a/tests/Heimdall.E2E.Tests/Pages/UserManagementTests.cs +++ b/tests/Heimdall.E2E.Tests/Pages/UserManagementTests.cs @@ -104,7 +104,12 @@ public class UserManagementTests : E2ETestBase using var cleanup = new HttpClient { BaseAddress = new Uri(BaseUrl) }; cleanup.DefaultRequestHeaders.Authorization = new("Bearer", token); var deleteResponse = await cleanup.DeleteAsync($"/api/users/{body.GetProperty("user").GetProperty("id").GetString()}"); - deleteResponse.StatusCode.ShouldBeOneOf(HttpStatusCode.OK, HttpStatusCode.NoContent); + var deleteError = await deleteResponse.Content.ReadAsStringAsync(); + deleteError = deleteError.Replace(email, "[email]", StringComparison.Ordinal) + .Replace(password, "[password]", StringComparison.Ordinal); + if (deleteResponse.StatusCode is not (HttpStatusCode.OK or HttpStatusCode.NoContent)) + throw new InvalidOperationException( + $"Viewer/Supervisor cleanup failed with HTTP {(int)deleteResponse.StatusCode}: {deleteError}"); } private static async Task SelectCreateRoleAsync(ILocator dialog, string role) diff --git a/tests/Heimdall.E2E.Tests/packages.lock.json b/tests/Heimdall.E2E.Tests/packages.lock.json index 427dcfd..6b15df6 100644 --- a/tests/Heimdall.E2E.Tests/packages.lock.json +++ b/tests/Heimdall.E2E.Tests/packages.lock.json @@ -74,8 +74,8 @@ }, "AutoMapper": { "type": "Transitive", - "resolved": "16.1.1", - "contentHash": "VNEky8JA15ci+oIDRGHITOGOpV4dILsf8pnn24QhDl2urtqgJ2IXiS/V2EtGU17P/+f6OeFQPJETaZXV9QOIZg==", + "resolved": "16.3.0", + "contentHash": "wFTqA37e1I4AOEhTTYlxrqDE8BQ4OB3dqhlv2KwYmHv+a4tn7R1JW2n2bzXb8eTBhWVBSl7iTZ0VxEt0a57D4w==", "dependencies": { "Microsoft.Extensions.Logging.Abstractions": "10.0.0", "Microsoft.Extensions.Options": "10.0.0", @@ -1335,12 +1335,11 @@ "heimdall.application": { "type": "Project", "dependencies": { - "AutoMapper": "[16.1.1, )", + "AutoMapper": "[16.3.0, )", "FluentValidation": "[11.11.0, )", "FluentValidation.DependencyInjectionExtensions": "[11.11.0, )", "Heimdall.Domain": "[1.0.0, )", "MediatR": "[12.5.0, )", - "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "[10.0.13, )", "Microsoft.Data.Sqlite": "[10.0.13, )", "Microsoft.EntityFrameworkCore": "[10.0.13, )", "Microsoft.EntityFrameworkCore.Sqlite": "[10.0.13, )", @@ -1353,8 +1352,7 @@ "heimdall.domain": { "type": "Project", "dependencies": { - "Heimdall.Domain.Primitives": "[1.0.0, )", - "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "[10.0.13, )" + "Heimdall.Domain.Primitives": "[1.0.0, )" } }, "heimdall.domain.primitives": { diff --git a/tests/Heimdall.Infrastructure.Tests/packages.lock.json b/tests/Heimdall.Infrastructure.Tests/packages.lock.json index 78614ca..2abb35b 100644 --- a/tests/Heimdall.Infrastructure.Tests/packages.lock.json +++ b/tests/Heimdall.Infrastructure.Tests/packages.lock.json @@ -77,8 +77,8 @@ }, "AutoMapper": { "type": "Transitive", - "resolved": "16.1.1", - "contentHash": "VNEky8JA15ci+oIDRGHITOGOpV4dILsf8pnn24QhDl2urtqgJ2IXiS/V2EtGU17P/+f6OeFQPJETaZXV9QOIZg==", + "resolved": "16.3.0", + "contentHash": "wFTqA37e1I4AOEhTTYlxrqDE8BQ4OB3dqhlv2KwYmHv+a4tn7R1JW2n2bzXb8eTBhWVBSl7iTZ0VxEt0a57D4w==", "dependencies": { "Microsoft.Extensions.Logging.Abstractions": "10.0.0", "Microsoft.Extensions.Options": "10.0.0", @@ -876,12 +876,11 @@ "heimdall.application": { "type": "Project", "dependencies": { - "AutoMapper": "[16.1.1, )", + "AutoMapper": "[16.3.0, )", "FluentValidation": "[11.11.0, )", "FluentValidation.DependencyInjectionExtensions": "[11.11.0, )", "Heimdall.Domain": "[1.0.0, )", "MediatR": "[12.5.0, )", - "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "[10.0.13, )", "Microsoft.Data.Sqlite": "[10.0.13, )", "Microsoft.EntityFrameworkCore": "[10.0.13, )", "Microsoft.EntityFrameworkCore.Sqlite": "[10.0.13, )", @@ -905,8 +904,7 @@ "heimdall.domain": { "type": "Project", "dependencies": { - "Heimdall.Domain.Primitives": "[1.0.0, )", - "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "[10.0.13, )" + "Heimdall.Domain.Primitives": "[1.0.0, )" } }, "heimdall.domain.primitives": { diff --git a/tests/Heimdall.IntegrationTests/packages.lock.json b/tests/Heimdall.IntegrationTests/packages.lock.json index 132821b..fc7b8db 100644 --- a/tests/Heimdall.IntegrationTests/packages.lock.json +++ b/tests/Heimdall.IntegrationTests/packages.lock.json @@ -67,8 +67,8 @@ }, "AutoMapper": { "type": "Transitive", - "resolved": "16.1.1", - "contentHash": "VNEky8JA15ci+oIDRGHITOGOpV4dILsf8pnn24QhDl2urtqgJ2IXiS/V2EtGU17P/+f6OeFQPJETaZXV9QOIZg==", + "resolved": "16.3.0", + "contentHash": "wFTqA37e1I4AOEhTTYlxrqDE8BQ4OB3dqhlv2KwYmHv+a4tn7R1JW2n2bzXb8eTBhWVBSl7iTZ0VxEt0a57D4w==", "dependencies": { "Microsoft.Extensions.Logging.Abstractions": "10.0.0", "Microsoft.Extensions.Options": "10.0.0", @@ -1310,12 +1310,11 @@ "heimdall.application": { "type": "Project", "dependencies": { - "AutoMapper": "[16.1.1, )", + "AutoMapper": "[16.3.0, )", "FluentValidation": "[11.11.0, )", "FluentValidation.DependencyInjectionExtensions": "[11.11.0, )", "Heimdall.Domain": "[1.0.0, )", "MediatR": "[12.5.0, )", - "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "[10.0.13, )", "Microsoft.Data.Sqlite": "[10.0.13, )", "Microsoft.EntityFrameworkCore": "[10.0.13, )", "Microsoft.EntityFrameworkCore.Sqlite": "[10.0.13, )", @@ -1328,8 +1327,7 @@ "heimdall.domain": { "type": "Project", "dependencies": { - "Heimdall.Domain.Primitives": "[1.0.0, )", - "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "[10.0.13, )" + "Heimdall.Domain.Primitives": "[1.0.0, )" } }, "heimdall.domain.primitives": { diff --git a/tests/Heimdall.Web.Tests/Components/Pages/SiteDetailTests.cs b/tests/Heimdall.Web.Tests/Components/Pages/SiteDetailTests.cs index 023ff7e..af4bc24 100644 --- a/tests/Heimdall.Web.Tests/Components/Pages/SiteDetailTests.cs +++ b/tests/Heimdall.Web.Tests/Components/Pages/SiteDetailTests.cs @@ -82,7 +82,7 @@ public class SiteDetailTests : PageTestBase cut.Markup.ShouldContain("Agent__SiteToken"); cut.Markup.ShouldContain("Régénérer"); var compose = cut.Find("pre code").TextContent; - compose.ShouldContain("image: registry.example/heimdall-agent:latest"); + compose.ShouldContain("image: registry.example/heimdall-agent@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); compose.ShouldContain("pull_policy: always"); compose.ShouldContain("network_mode: host"); compose.ShouldContain("Agent__CentralUrl: \"http://localhost\""); @@ -95,7 +95,7 @@ public class SiteDetailTests : PageTestBase var agent = GetAgentService(ParseCompose(compose)); agent.Children.ShouldNotContainKey(new YamlScalarNode("deploy")); ((YamlScalarNode)agent.Children[new YamlScalarNode("image")]).Value - .ShouldBe("registry.example/heimdall-agent:latest"); + .ShouldBe("registry.example/heimdall-agent@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); ((YamlScalarNode)agent.Children[new YamlScalarNode("pull_policy")]).Value.ShouldBe("always"); var volumes = (YamlSequenceNode)agent.Children[new YamlScalarNode("volumes")]; volumes.Children.Select(node => ((YamlScalarNode)node).Value) @@ -112,12 +112,12 @@ public class SiteDetailTests : PageTestBase { var commands = cut.FindAll("pre code").Select(code => code.TextContent).ToArray(); commands.Length.ShouldBe(6); - commands[0].ShouldContain("docker pull registry.example/heimdall-agent:latest"); + commands[0].ShouldContain("docker pull registry.example/heimdall-agent@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); commands[1].ShouldContain("--pull always"); - commands[1].ShouldContain("registry.example/heimdall-agent:latest"); - commands[3].ShouldContain("docker pull 'registry.example/heimdall-agent:latest'"); + commands[1].ShouldContain("registry.example/heimdall-agent@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); + commands[3].ShouldContain("docker pull 'registry.example/heimdall-agent@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'"); commands[4].ShouldContain("'--pull','always'"); - commands[4].ShouldContain("'registry.example/heimdall-agent:latest'"); + commands[4].ShouldContain("'registry.example/heimdall-agent@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'"); }); } @@ -140,6 +140,29 @@ public class SiteDetailTests : PageTestBase cut.Markup.ShouldNotContain("install-agent.ps1"); } + [Fact] + public void SiteDetail_CommandeLinuxNeContientNiUrlCentralNiToken() + { + Handler.OnGet("api/updates/latest", AgentRelease()); + Handler.OnGet("api/sites/", new SiteItem( + SiteId, "Site Principal", null, "UTC", null, true, false, DateTime.UtcNow)); + Handler.On(HttpMethod.Post, "api/sites/", new TokenResult("tok-linux-private-42", DateTime.UtcNow.AddHours(24))); + LoginAs(); + + var cut = RenderPage(p => p.Add(x => x.Id, SiteId)); + cut.WaitForAssertion(() => cut.Markup.ShouldContain("Générer un token")); + cut.FindAll("button").Single(b => b.TextContent.Contains("Générer un token")).Click(); + cut.WaitForAssertion(() => cut.Markup.ShouldContain("tok-linux-private-42")); + + var command = cut.Find("pre code").TextContent; + command.ShouldContain("--central-url-file"); + command.ShouldContain("--site-token-file"); + command.ShouldContain("read -r -s site_token"); + command.ShouldNotContain("tok-linux-private-42"); + command.ShouldNotContain("http://localhost"); + cut.Markup.ShouldContain("saisie du token est masquée"); + } + [Fact] public void SiteDetail_ChoisirImageNvidia_GenereComposeAvecGpuEtProviderCuda() { @@ -160,7 +183,7 @@ public class SiteDetailTests : PageTestBase cut.WaitForAssertion(() => { var compose = cut.Find("pre code").TextContent; - compose.ShouldContain("image: registry.example/heimdall-agent-gpu:latest"); + compose.ShouldContain("image: registry.example/heimdall-agent-gpu@sha256:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"); compose.ShouldContain("pull_policy: always"); compose.ShouldContain("Agent__InferenceExecutionProvider: CUDA"); compose.ShouldContain("driver: nvidia"); @@ -168,7 +191,7 @@ public class SiteDetailTests : PageTestBase compose.ShouldContain("\n deploy:\n resources:\n reservations:"); var agent = GetAgentService(ParseCompose(compose)); ((YamlScalarNode)agent.Children[new YamlScalarNode("image")]).Value.ShouldBe( - "registry.example/heimdall-agent-gpu:latest"); + "registry.example/heimdall-agent-gpu@sha256:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"); ((YamlScalarNode)agent.Children[new YamlScalarNode("pull_policy")]).Value.ShouldBe("always"); var deploy = (YamlMappingNode)agent.Children[new YamlScalarNode("deploy")]; var resources = (YamlMappingNode)deploy.Children[new YamlScalarNode("resources")]; @@ -185,11 +208,33 @@ public class SiteDetailTests : PageTestBase run.ShouldContain("--gpus all"); run.ShouldContain("Agent__InferenceExecutionProvider=CUDA"); run.ShouldContain("--pull always"); - run.ShouldContain("registry.example/heimdall-agent-gpu:latest"); + run.ShouldContain("registry.example/heimdall-agent-gpu@sha256:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"); run.ShouldContain("--group-add \"$(stat -c '%g' /var/run/docker.sock)\""); run.ShouldContain("-v /var/run/docker.sock:/var/run/docker.sock"); commands[4].ShouldContain("'--pull','always'"); - commands[4].ShouldContain("'registry.example/heimdall-agent-gpu:latest'"); + commands[4].ShouldContain("'registry.example/heimdall-agent-gpu@sha256:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'"); + }); + } + + [Fact] + public void SiteDetail_RefuseDockerComposeQuandDigestImageInvalide() + { + Handler.OnGet("api/updates/latest", AgentRelease("sha256:not-a-digest")); + Handler.OnGet("api/sites/", new SiteItem( + SiteId, "Site Principal", null, "UTC", null, true, false, DateTime.UtcNow.AddDays(-10))); + Handler.On(HttpMethod.Post, "api/sites/", new TokenResult("tok-invalid-digest", DateTime.UtcNow.AddHours(24))); + LoginAs(); + + var cut = RenderPage(p => p.Add(x => x.Id, SiteId)); + cut.WaitForAssertion(() => cut.Markup.ShouldContain("Générer un token")); + cut.FindAll("button").Single(b => b.TextContent.Contains("Générer un token")).Click(); + cut.WaitForAssertion(() => cut.Markup.ShouldContain("tok-invalid-digest")); + cut.FindAll("button").Single(b => b.TextContent.Contains("Docker", StringComparison.OrdinalIgnoreCase)).Click(); + + cut.WaitForAssertion(() => + { + cut.Markup.ShouldContain("Le manifeste d’image de l’agent fourni par Central est indisponible"); + cut.FindAll(".installer-copy-box").ShouldBeEmpty(); }); } @@ -250,11 +295,11 @@ public class SiteDetailTests : PageTestBase LastUsedAt = lastUsed, }; - private static LatestReleaseInfo AgentRelease() => new() + private static LatestReleaseInfo AgentRelease(string? imageDigest = null) => new() { Version = "1.0.0", ContainerImage = "registry.example/heimdall-agent", - ContainerImageDigest = "sha256:" + new string('a', 64), + ContainerImageDigest = imageDigest ?? "sha256:" + new string('a', 64), UpdatePublicKeyPem = "test-public-key", SignedManifest = "eyJ2ZXJzaW9uIjoiMS4wLjAifQ==", ManifestSignature = "c2lnbmF0dXJl", diff --git a/tests/Heimdall.Web.Tests/Controllers/UpdatesControllerRetryTests.cs b/tests/Heimdall.Web.Tests/Controllers/UpdatesControllerRetryTests.cs index 2c7ce8a..8a32a8c 100644 --- a/tests/Heimdall.Web.Tests/Controllers/UpdatesControllerRetryTests.cs +++ b/tests/Heimdall.Web.Tests/Controllers/UpdatesControllerRetryTests.cs @@ -9,6 +9,26 @@ namespace Heimdall.Web.Tests.Controllers; public sealed class UpdatesControllerRetryTests { + [Fact] + public async Task FetchBoundedReleaseAssetAsync_allowsMissingForgejoDigestForSignedMetadata() + { + using var client = new HttpClient(new StaticResponseHandler("verified-by-release-signature")); + var result = await FetchAssetAsync("https://forgejo.example/attachments/release-key", digest: null, client); + + Assert.Equal("verified-by-release-signature", Encoding.UTF8.GetString(result!)); + } + + [Fact] + public async Task FetchBoundedReleaseAssetAsync_rejectsCrossOriginUrls() + { + var handler = new StaticResponseHandler("unexpected"); + using var client = new HttpClient(handler); + var result = await FetchAssetAsync("https://other.example/asset", digest: null, client); + + Assert.Null(result); + Assert.Equal(0, handler.RequestCount); + } + [Theory] [InlineData("Proxy error")] [InlineData("{not-json")] @@ -63,6 +83,40 @@ public sealed class UpdatesControllerRetryTests return task.GetType().GetProperty("Result")?.GetValue(task); } + private static async Task FetchAssetAsync(string url, string? digest, HttpClient client) + { + var assetType = typeof(UpdatesController).GetNestedType("ForgejoAsset", BindingFlags.NonPublic); + Assert.NotNull(assetType); + var asset = Activator.CreateInstance(assetType)!; + assetType.GetProperty("Name")!.SetValue(asset, "agent-release-public.pem"); + assetType.GetProperty("BrowserDownloadUrl")!.SetValue(asset, url); + assetType.GetProperty("Digest")!.SetValue(asset, digest); + var listType = typeof(List<>).MakeGenericType(assetType); + var assets = (System.Collections.IList)Activator.CreateInstance(listType)!; + assets.Add(asset); + var method = typeof(UpdatesController).GetMethod("FetchBoundedReleaseAssetAsync", + BindingFlags.NonPublic | BindingFlags.Static); + Assert.NotNull(method); + var task = (Task)method.Invoke(null, + [assets, "agent-release-public.pem", client, 4096, new Uri("https://forgejo.example/api/v1/releases/latest"), CancellationToken.None])!; + return await task; + } + + private sealed class StaticResponseHandler(string body) : HttpMessageHandler + { + public int RequestCount { get; private set; } + + protected override Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) + { + RequestCount++; + return Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK) + { + RequestMessage = request, + Content = new StringContent(body, Encoding.UTF8), + }); + } + } + [Theory] [InlineData(HttpStatusCode.RequestTimeout, true)] [InlineData(HttpStatusCode.TooManyRequests, true)] diff --git a/tests/Heimdall.Web.Tests/Services/AgentReleaseManifestVerifierTests.cs b/tests/Heimdall.Web.Tests/Services/AgentReleaseManifestVerifierTests.cs new file mode 100644 index 0000000..47b0bdd --- /dev/null +++ b/tests/Heimdall.Web.Tests/Services/AgentReleaseManifestVerifierTests.cs @@ -0,0 +1,100 @@ +using System.Security.Cryptography; +using System.Text.Json; +using Heimdall.Web.Services; +using Xunit; + +namespace Heimdall.Web.Tests.Services; + +public sealed class AgentReleaseManifestVerifierTests +{ + [Fact] + public void TryVerify_AcceptsSignedManifestWhenForgejoAssetDigestIsUnavailable() + { + using var key = ECDsa.Create(ECCurve.NamedCurves.nistP256); + var bytes = ManifestBytes(); + var signature = key.SignData(bytes, HashAlgorithmName.SHA256, DSASignatureFormat.Rfc3279DerSequence); + + var valid = AgentReleaseManifestVerifier.TryVerify( + key.ExportSubjectPublicKeyInfoPem(), bytes, signature, "1.0.7", out var manifest); + + Assert.True(valid); + Assert.NotNull(manifest); + Assert.Equal("1.0.7", manifest.Version); + Assert.True(manifest.Assets.ContainsKey("portable")); + } + + [Fact] + public void TryVerify_AcceptsCpuOnlySignedManifest() + { + using var key = ECDsa.Create(ECCurve.NamedCurves.nistP256); + var bytes = ManifestBytes(includeGpuImage: false); + var signature = key.SignData(bytes, HashAlgorithmName.SHA256, DSASignatureFormat.Rfc3279DerSequence); + + var valid = AgentReleaseManifestVerifier.TryVerify( + key.ExportSubjectPublicKeyInfoPem(), bytes, signature, "1.0.7", out var manifest); + + Assert.True(valid); + Assert.NotNull(manifest); + Assert.Null(manifest.ContainerImageGpu); + Assert.Null(manifest.ContainerImageGpuDigest); + } + + [Fact] + public void TryVerify_RejectsIncompleteGpuImageMetadata() + { + using var key = ECDsa.Create(ECCurve.NamedCurves.nistP256); + var bytes = ManifestBytes(invalidGpuPair: true); + var signature = key.SignData(bytes, HashAlgorithmName.SHA256, DSASignatureFormat.Rfc3279DerSequence); + + Assert.False(AgentReleaseManifestVerifier.TryVerify(key.ExportSubjectPublicKeyInfoPem(), bytes, signature, + "1.0.7", out _)); + } + + [Fact] + public void TryVerify_RejectsModifiedManifest() + { + using var key = ECDsa.Create(ECCurve.NamedCurves.nistP256); + var bytes = ManifestBytes(); + var signature = key.SignData(bytes, HashAlgorithmName.SHA256, DSASignatureFormat.Rfc3279DerSequence); + bytes[^2] ^= 1; + + Assert.False(AgentReleaseManifestVerifier.TryVerify(key.ExportSubjectPublicKeyInfoPem(), bytes, signature, + "1.0.7", out _)); + } + + [Fact] + public void TryVerify_RejectsTagMismatchAndMalformedArchiveDigest() + { + using var key = ECDsa.Create(ECCurve.NamedCurves.nistP256); + var bytes = ManifestBytes(); + var signature = key.SignData(bytes, HashAlgorithmName.SHA256, DSASignatureFormat.Rfc3279DerSequence); + + Assert.False(AgentReleaseManifestVerifier.TryVerify(key.ExportSubjectPublicKeyInfoPem(), bytes, signature, + "1.0.8", out _)); + + bytes = ManifestBytes(invalidArchiveHash: true); + signature = key.SignData(bytes, HashAlgorithmName.SHA256, DSASignatureFormat.Rfc3279DerSequence); + Assert.False(AgentReleaseManifestVerifier.TryVerify(key.ExportSubjectPublicKeyInfoPem(), bytes, signature, + "1.0.7", out _)); + } + + private static byte[] ManifestBytes(bool invalidArchiveHash = false, bool includeGpuImage = true, + bool invalidGpuPair = false) + { + var manifest = new Dictionary + { + ["version"] = "1.0.7", + ["assets"] = new Dictionary + { + ["portable"] = invalidArchiveHash ? "not-a-sha256" : new string('c', 64) + }, + ["containerImage"] = "eltruncho/heimdall-agent", + ["containerImageDigest"] = "sha256:" + new string('a', 64), + }; + if (includeGpuImage || invalidGpuPair) + manifest["containerImageGpu"] = "eltruncho/heimdall-agent-gpu"; + if (includeGpuImage && !invalidGpuPair) + manifest["containerImageGpuDigest"] = "sha256:" + new string('b', 64); + return JsonSerializer.SerializeToUtf8Bytes(manifest); + } +} diff --git a/tests/Heimdall.Web.Tests/packages.lock.json b/tests/Heimdall.Web.Tests/packages.lock.json index f62cf2c..aea24f5 100644 --- a/tests/Heimdall.Web.Tests/packages.lock.json +++ b/tests/Heimdall.Web.Tests/packages.lock.json @@ -131,8 +131,8 @@ }, "AutoMapper": { "type": "Transitive", - "resolved": "16.1.1", - "contentHash": "VNEky8JA15ci+oIDRGHITOGOpV4dILsf8pnn24QhDl2urtqgJ2IXiS/V2EtGU17P/+f6OeFQPJETaZXV9QOIZg==", + "resolved": "16.3.0", + "contentHash": "wFTqA37e1I4AOEhTTYlxrqDE8BQ4OB3dqhlv2KwYmHv+a4tn7R1JW2n2bzXb8eTBhWVBSl7iTZ0VxEt0a57D4w==", "dependencies": { "Microsoft.Extensions.Logging.Abstractions": "10.0.0", "Microsoft.Extensions.Options": "10.0.0", @@ -1188,7 +1188,7 @@ "heimdall.application": { "type": "Project", "dependencies": { - "AutoMapper": "[16.1.1, )", + "AutoMapper": "[16.3.0, )", "FluentValidation": "[11.11.0, )", "FluentValidation.DependencyInjectionExtensions": "[11.11.0, )", "Heimdall.Domain": "[1.0.0, )",