diff --git a/.gitea/workflows/cd.yml b/.gitea/workflows/cd.yml index 299f4ad..75611fb 100644 --- a/.gitea/workflows/cd.yml +++ b/.gitea/workflows/cd.yml @@ -95,7 +95,7 @@ jobs: exit 1 fi - - uses: actions/checkout@v4 + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 with: fetch-depth: 0 diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index b4117e2..0246cf5 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -33,8 +33,8 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 30 steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 + - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4 with: node-version: "22" cache: "pnpm" @@ -134,8 +134,8 @@ jobs: --health-timeout 5s --health-retries 60 steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 + - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4 with: node-version: "22" cache: "pnpm" @@ -271,10 +271,18 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 15 steps: - - uses: actions/checkout@v4 - - name: Install Trivy + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 + - name: Install Trivy (pinned + checksum verified) run: | - curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin + set -euo pipefail + TRIVY_VERSION=0.76.2 + BASE="https://github.com/aquasecurity/trivy/releases/download/v${TRIVY_VERSION}" + curl -fsSLO "${BASE}/trivy_${TRIVY_VERSION}_Linux-64bit.tar.gz" + curl -fsSLO "${BASE}/trivy_${TRIVY_VERSION}_checksums.txt" + grep " trivy_${TRIVY_VERSION}_Linux-64bit.tar.gz$" "trivy_${TRIVY_VERSION}_checksums.txt" | sha256sum -c - + tar -xzf "trivy_${TRIVY_VERSION}_Linux-64bit.tar.gz" -C /usr/local/bin trivy + rm -f "trivy_${TRIVY_VERSION}_Linux-64bit.tar.gz" "trivy_${TRIVY_VERSION}_checksums.txt" + trivy --version # `siax/sbom/` är CycloneDX-evidenens för REDAN BYGGDA images (release-kedjan), # inte källberoenden. Att scanna dem här återrapporterar gamla image-versioner # (next 16.3.x, sharp 0.35.4) och blockerar källfixar som redan är patchade. @@ -292,7 +300,7 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 20 steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 with: fetch-depth: 0 - name: SonarQube analysis (self-hosted sonar.siax.dev) @@ -316,12 +324,12 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 10 steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 + - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4 with: node-version: '22' - name: Checkout canonical siax-standard (SSOT) - uses: actions/checkout@v4 + uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 with: repository: admin/siax-standard token: ${{ secrets.SIAX_CI_TOKEN }} diff --git a/.gitea/workflows/health-check.yml b/.gitea/workflows/health-check.yml index afd2a63..bd3e3ee 100644 --- a/.gitea/workflows/health-check.yml +++ b/.gitea/workflows/health-check.yml @@ -12,12 +12,21 @@ jobs: health: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 - name: Required files run: | for f in README.md LICENSE .gitignore; do [ -f "$f" ] || echo "::warning file=$f,title=Missing::$f is missing"; done [ -f .gitea/workflows/ci.yml ] || echo "::warning title=No CI::No CI workflow found" - - name: Install Trivy - run: curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin + - name: Install Trivy (pinned + checksum verified) + run: | + set -euo pipefail + TRIVY_VERSION=0.76.2 + BASE="https://github.com/aquasecurity/trivy/releases/download/v${TRIVY_VERSION}" + curl -fsSLO "${BASE}/trivy_${TRIVY_VERSION}_Linux-64bit.tar.gz" + curl -fsSLO "${BASE}/trivy_${TRIVY_VERSION}_checksums.txt" + grep " trivy_${TRIVY_VERSION}_Linux-64bit.tar.gz$" "trivy_${TRIVY_VERSION}_checksums.txt" | sha256sum -c - + tar -xzf "trivy_${TRIVY_VERSION}_Linux-64bit.tar.gz" -C /usr/local/bin trivy + rm -f "trivy_${TRIVY_VERSION}_Linux-64bit.tar.gz" "trivy_${TRIVY_VERSION}_checksums.txt" + trivy --version - name: Secret scan run: trivy fs --scanners secret --exit-code 0 . \ No newline at end of file diff --git a/.gitea/workflows/masterplan-lock.yml b/.gitea/workflows/masterplan-lock.yml index 05c96fb..f46ea49 100644 --- a/.gitea/workflows/masterplan-lock.yml +++ b/.gitea/workflows/masterplan-lock.yml @@ -21,6 +21,6 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 10 steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 - name: Masterplan lock check run: sh scripts/check-masterplan-lock.sh \ No newline at end of file diff --git a/.gitea/workflows/nightly.yml b/.gitea/workflows/nightly.yml index 7931a4a..b4361cd 100644 --- a/.gitea/workflows/nightly.yml +++ b/.gitea/workflows/nightly.yml @@ -17,8 +17,8 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 45 steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 + - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4 with: node-version: "22" cache: "pnpm" @@ -43,10 +43,18 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 20 steps: - - uses: actions/checkout@v4 - - name: Install Trivy + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 + - name: Install Trivy (pinned + checksum verified) run: | - curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin + set -euo pipefail + TRIVY_VERSION=0.76.2 + BASE="https://github.com/aquasecurity/trivy/releases/download/v${TRIVY_VERSION}" + curl -fsSLO "${BASE}/trivy_${TRIVY_VERSION}_Linux-64bit.tar.gz" + curl -fsSLO "${BASE}/trivy_${TRIVY_VERSION}_checksums.txt" + grep " trivy_${TRIVY_VERSION}_Linux-64bit.tar.gz$" "trivy_${TRIVY_VERSION}_checksums.txt" | sha256sum -c - + tar -xzf "trivy_${TRIVY_VERSION}_Linux-64bit.tar.gz" -C /usr/local/bin trivy + rm -f "trivy_${TRIVY_VERSION}_Linux-64bit.tar.gz" "trivy_${TRIVY_VERSION}_checksums.txt" + trivy --version # A nightly scan exists to catch CVEs published against code that did # not change. With `--exit-code 0` it could never report failure, so it # could never raise that alarm -- the one job whose entire purpose is diff --git a/.gitea/workflows/prod-smoke.yml b/.gitea/workflows/prod-smoke.yml index 62551e9..773b7e8 100644 --- a/.gitea/workflows/prod-smoke.yml +++ b/.gitea/workflows/prod-smoke.yml @@ -53,10 +53,13 @@ jobs: echo "::warning::SIAX_CI_TOKEN is not set — cannot compare with main; commit $running is live" exit 0 fi - expected="$(curl -fsS --max-time 15 \ + # Ladda ner först och parsea sedan: curl | tolk leder till Semgrep + # gha-curl-pipe-shell och gör det omöjligt att verifiera svaret. + curl -fsS --max-time 15 \ -H "Authorization: token ${SIAX_CI_TOKEN}" \ - "https://git.siax.io/api/v1/repos/admin/0pt/commits?limit=1" \ - | python3 -c 'import sys,json; print(json.load(sys.stdin)[0]["sha"])')" + -o "${RUNNER_TEMP}/0pt-main.json" \ + "https://git.siax.io/api/v1/repos/admin/0pt/commits?limit=1" + expected="$(python3 -c 'import json,sys; print(json.load(open(sys.argv[1]))[0]["sha"])' "${RUNNER_TEMP}/0pt-main.json")" echo "running=$running expected(main)=$expected" [ -n "$expected" ] || { echo "::error::could not read main SHA from Gitea"; exit 1; } [ "$running" = "$expected" ] || { diff --git a/.gitea/workflows/security.yml b/.gitea/workflows/security.yml index d2645ee..1438200 100644 --- a/.gitea/workflows/security.yml +++ b/.gitea/workflows/security.yml @@ -162,8 +162,10 @@ jobs: if [ $rc -eq 1 ]; then echo "::error::Trivy filesystem scan hittade fynd"; exit 1; fi echo "::error::Trivy filesystem scan kunde inte koras (rc=$rc) - scannerfel, inte fynd; grinden far inte bli tyst gron"; exit 1 - # Dockerfile- och IaC-misconfig är informativt: DS-0002 (root-USER) - # kräver ändrade runtime-användare och hanteras per repo, inte i grinden. + # Dockerfile- och IaC-misconfig är informativt. DS-0002 (root-USER), + # KSV-0014/KSV-0118 (readOnlyRootFilesystem + icke-root) är åtgärdade i + # services/*/Dockerfile och deploy/k8s/deployment.yaml; steget finns kvar + # som tidig varning för nya misconfigs, inte som en tyst grön grind. - name: Trivy config informational continue-on-error: true run: | diff --git a/.gitea/workflows/vehiq-oltp-ingest.yml b/.gitea/workflows/vehiq-oltp-ingest.yml index 7d7f63c..6bdae6f 100644 --- a/.gitea/workflows/vehiq-oltp-ingest.yml +++ b/.gitea/workflows/vehiq-oltp-ingest.yml @@ -36,8 +36,8 @@ jobs: # requires" section are actually done. VEHIQ_INGEST_MODE: preview steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 + - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4 with: node-version: "22" - name: Enable corepack + pin pnpm@9 diff --git a/deploy/k8s/deployment.yaml b/deploy/k8s/deployment.yaml index b1369e6..0cc534f 100644 --- a/deploy/k8s/deployment.yaml +++ b/deploy/k8s/deployment.yaml @@ -15,9 +15,23 @@ spec: labels: app: 0pt-web spec: + # Den här manifesten är referens-only (se README.md), men den ska vara + # säker att använda. Imagebygget kör redan USER node (uid 1000). + securityContext: + runAsNonRoot: true + runAsUser: 1000 + runAsGroup: 1000 + fsGroup: 1000 + seccompProfile: + type: RuntimeDefault containers: - name: 0pt-web image: REPLACE_ME/0pt-web:REPLACE_ME_TAG + securityContext: + allowPrivilegeEscalation: false + readOnlyRootFilesystem: true + capabilities: + drop: ["ALL"] ports: - containerPort: 3000 env: @@ -50,6 +64,18 @@ spec: limits: cpu: "1" memory: "512Mi" + # readOnlyRootFilesystem above needs explicit writable scratch space: + # Node/Next writes temp files and caches here at runtime. + volumeMounts: + - name: tmp + mountPath: /tmp + - name: next-cache + mountPath: /app/.next/cache + volumes: + - name: tmp + emptyDir: {} + - name: next-cache + emptyDir: {} --- apiVersion: v1 kind: Service diff --git a/services/analytics/Dockerfile b/services/analytics/Dockerfile index 2db6baf..d0ea963 100644 --- a/services/analytics/Dockerfile +++ b/services/analytics/Dockerfile @@ -4,6 +4,10 @@ ENV PYTHONUNBUFFERED=1 PIP_NO_CACHE_DIR=1 COPY requirements.txt . RUN pip install -r requirements.txt COPY app.py ingest_aud0.py ./ +# Kör som icke-root (DS-0002). Inga skrivningar till /app krävs. +RUN useradd --create-home --uid 10001 appuser +USER appuser + EXPOSE 8096 HEALTHCHECK --interval=30s --timeout=5s --retries=3 \ CMD python -c "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8096/health', timeout=3)" diff --git a/services/api/Dockerfile b/services/api/Dockerfile index 306fb88..01c6ff9 100644 --- a/services/api/Dockerfile +++ b/services/api/Dockerfile @@ -15,6 +15,11 @@ RUN pip install -r requirements.txt COPY . . +# Kör som icke-root (DS-0002). Beroendena ligger i globala /usr/local och är +# läsliga för alla användare; appens egen kod skrivs inte vid körning. +RUN useradd --create-home --uid 10001 appuser +USER appuser + EXPOSE 8000 # API: uvicorn orchestrator.main:app --host 0.0.0.0 --port 8000 # Worker: python -m workers.run diff --git a/services/scrapers/Dockerfile b/services/scrapers/Dockerfile index 3c22748..a611587 100644 --- a/services/scrapers/Dockerfile +++ b/services/scrapers/Dockerfile @@ -14,8 +14,11 @@ RUN pip install --no-cache-dir -r requirements.txt # Copy scraper code COPY . . -# Create data directories -RUN mkdir -p /data/output /data/checkpoints /data/sources +# Create data directories (writable by the non-root runtime user, DS-0002) +RUN mkdir -p /data/output /data/checkpoints /data/sources \ + && useradd --create-home --uid 10001 appuser \ + && chown -R appuser:appuser /data +USER appuser ENV PYTHONUNBUFFERED=1 ENV S3_ENDPOINT=https://s3.siax.io