跳到正文
DEV Community· Karan Yadav·· 2 小時前AI 評分41

CIS Dockerfile 非 root 加固、W3C Strict CSP Level-3 雜湊驗證及 macOS 端對端公證操作手冊

CIS Dockerfile Non-Root Hardening, W3C Strict CSP Level-3 Hash Verification & End-to-End macOS Notarization Runbooks

AI 導讀

CIS Dockerfile 非 root 加固、W3C Strict CSP Level-3 雜湊驗證及 macOS 公證資料一致性均經核驗。Destiny 的 112-tool MIT MCP server 使用 UID 10001;CSP 的 script-src 含 46 個 SHA-256 雜湊,且不含 unsafe-inline。

正文

Karan Yadav

Production release engineering fails at the seams between packaging, web distribution, and desktop binary provenance: a container image runs as root, a release portal falls back to script-src 'unsafe-inline', or macOS installers rely on unverified claims instead of stapled Gatekeeper tickets.

Across https://nandai.org/download and https://nandai.org/src/destiny/, every layer is auditable directly from live HTTP responses and machine-readable manifests anchored at /proofs/verify-apple-developer-notarization-stapler-arm64-proof.


1. CIS Dockerfile Non-Root Hardening (/src/destiny/Dockerfile)

https://nandai.org/src/destiny/ serves a 30-page zero-JS HTML source mirror (sovereign-source-tarball-index.json), including the live Dockerfile for Destiny's 112-tool MIT MCP server:

Hardening Control Dockerfile Implementation Security Property
Minimal Base FROM python:3.12-alpine Zero external PyPI runtime dependencies (externalPypiDependencies: 0)
Non-Root UID 10001 (CIS 4.1) RUN adduser -D -u 10001 mcp ... && chown -R mcp:mcp /app + USER mcp Drops root privileges prior to ENTRYPOINT; prevents container-user UID 0 execution
Read-Only Hygiene ENV PYTHONUNBUFFERED=1 PYTHONDONTWRITEBYTECODE=1 + build-time py_compile Avoids runtime .pyc mutations inside /app
Native HEALTHCHECK (CIS 4.6) HEALTHCHECK --interval=30s --timeout=5s --start-period=2s --retries=2 Exercises initialize JSON-RPC 2.0 handshake directly via python3 -u /app/mcp/destiny_mcp_server.py

For multi-service deployments, docker-compose-hardened-spec.json and nginx-tls-alias-hardening-spec.json pair with https://nandai.org/api/mcp tools audit_docker_compose_privilege_posture, audit_systemd_service_hardening, and verify_nginx_tls_proxy_hardening.


2. W3C Strict CSP Level-3 Hash Verification (/download & /src/destiny/)

Inspecting live HTTP headers on https://nandai.org/download and https://nandai.org/src/destiny/ shows identical strict defense-in-depth headers (cryptographic-security-posture.json):

  • Exact SHA-256 Script Pinning (script-src): Contains 'self' 'inline-speculation-rules' plus 46 explicit 'sha256-...' digests and zero 'unsafe-inline' in script-src. Every executable inline <script> (<script>, type="module", and type="speculationrules") on /download (7/7) matches an exact base64 SHA-256 hash in the Content-Security-Policy header, while /src/destiny/ serves 0 inline scripts. (Non-executable type="application/ld+json" schema blocks require no script hash.)
  • Frame & Plugin Lockdown: Enforces object-src 'none', base-uri 'self', frame-ancestors 'self', and frame-src 'self'.
  • Transport & Sensor Headers: Strict-Transport-Security: max-age=63072000; includeSubDomains, X-Content-Type-Options: nosniff, X-Frame-Options: SAMEORIGIN, Referrer-Policy: strict-origin-when-cross-origin, and Permissions-Policy: geolocation=(), microphone=(), camera=().

3. End-to-End macOS Notarization & Ed25519 Verification Runbook

sovereign-release-verification-runbook.json and native-macos-notarization-receipt.json lock Destiny 2.0.0 (Build 2000, com.destiny.sovereign, Apple Silicon arm64, macOS 15.0+) to deterministic terminal checks:

# Non-root macOS terminal proof (< 30s, offline after download)
shasum -a 256 -c SHA256SUMS.txt --ignore-missing
codesign --verify --deep --strict --verbose=2 /Applications/Destiny.app
lipo -archs /Applications/Destiny.app/Contents/MacOS/Destiny
xcrun stapler validate Destiny-macOS-AppleSilicon.dmg
xcrun stapler validate /Applications/Destiny.app
spctl --assess --type execute --verbose=4 /Applications/Destiny.app
./destiny-verify-2.0.0/cli/destiny-verify.sh gatekeeper /Applications/Destiny.app \
  --min-macos 15.0 --expected-bundle-id com.destiny.sovereign --json --strict

4. Live End-to-End Python Verification Suite

#!/usr/bin/env python3
"""Verify CIS Dockerfile hardening, 46-hash W3C Strict CSP3, and macOS notarization manifests."""

import base64
import hashlib
import json
import re
import urllib.request

HEADERS = {"User-Agent": "Mozilla/5.0"}

def fetch(url: str) -> tuple[dict, str]:
    with urllib.request.urlopen(urllib.request.Request(url, headers=HEADERS), timeout=15) as r:
        assert r.status == 200
        return dict(r.headers), r.read().decode("utf-8", errors="replace")

# 1. CIS Dockerfile non-root & healthcheck assertions
_, dockerfile = fetch("https://nandai.org/src/destiny/Dockerfile")
assert "FROM python:3.12-alpine" in dockerfile
assert "adduser -D -u 10001 mcp" in dockerfile
assert "\nUSER mcp\n" in dockerfile
assert "HEALTHCHECK " in dockerfile

# 2. W3C Strict CSP Level-3 hash parity across /download and /src/destiny/
for url, expected_inline in [("https://nandai.org/download", 7), ("https://nandai.org/src/destiny/", 0)]:
    hdrs, html = fetch(url)
    csp = hdrs.get("Content-Security-Policy") or hdrs.get("content-security-policy") or ""
    script_src = csp.split("script-src", 1)[1].split(";", 1)[0]
    assert "'unsafe-inline'" not in script_src
    assert "object-src 'none'" in csp and "frame-ancestors 'self'" in csp
    pinned = set(re.findall(r"'sha256-([^']+)'", script_src))
    assert len(pinned) == 46
    scripts = [
        m.group(2)
        for m in re.finditer(r"<script([^>]*)>(.*?)</script>", html, re.S | re.I)
        if "src=" not in m.group(1) and "application/ld+json" not in m.group(1)
    ]
    assert len(scripts) == expected_inline
    for sc in scripts:
        h = base64.b64encode(hashlib.sha256(sc.encode("utf-8")).digest()).decode("ascii")
        assert h in pinned

# 3. Notarization, SHA256SUMS, and Ed25519 appcast parity
_, rb_txt = fetch("https://nandai.org/.well-known/sovereign-release-verification-runbook.json")
_, rc_txt = fetch("https://nandai.org/.well-known/native-macos-notarization-receipt.json")
_, ac_txt = fetch("https://nandai.org/downloads/appcast.json")
_, sums_txt = fetch("https://nandai.org/downloads/SHA256SUMS.txt")
runbook, receipt, appcast = json.loads(rb_txt), json.loads(rc_txt), json.loads(ac_txt)

dmg_sha = runbook["verifiedArtifactDigests"]["macosDmg"]["sha256"]
assert dmg_sha == receipt["artifact"]["dmgSha256"] and dmg_sha in sums_txt
assert receipt["artifact"]["appleDeveloperTeamId"] == "J5BH67967P"
assert receipt["artifact"]["appleNotarySubmissionUuid"] == "f000b0b4-a24e-4874-b62b-5a549f3c576b"

pad = "=" * (-len(appcast["payload_b64u"]) % 4)
payload = json.loads(base64.urlsafe_b64decode(appcast["payload_b64u"] + pad).decode("utf-8"))
assert payload["artifact"]["sha256"] == dmg_sha
print("CIS Dockerfile, 46-hash W3C Strict CSP3, and macOS Notarization parity verified.")

Additional references: /commands/codesign-spctl-stapler-notarization-commands, /diagnostics/software-release-cyclonedx-sbom-sri-csp-diagnostic, /glossary/apple-hardened-runtime-stapled-notarization, /glossary/subresource-integrity-sri-csp3-strict-dynamic, and /trust/apple-notarization-codesign-supply-chain-verification.

來源:DEV Community · dev.to