Merge pull request 'fix(ci): kanoniskt security-workflow som kan bli grönt' (#30) from fix/security-canonical-workflow into main
This commit was merged in pull request #30.
This commit is contained in:
+45
-121
@@ -26,18 +26,14 @@ on:
|
||||
pull_request: {}
|
||||
schedule:
|
||||
- cron: "17 2 * * *"
|
||||
workflow_dispatch: {}
|
||||
permissions: { contents: read }
|
||||
# N6 (server-config ci/jobbstorm-2026-11-10 §4): en ny commit på samma PR/gren avbryter den inaktuella körningen.
|
||||
concurrency:
|
||||
group: ${{ gitea.workflow }}-${{ gitea.ref }}
|
||||
group: security-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
scan:
|
||||
runs-on: ubuntu-latest
|
||||
# Övre gräns: ett scannerjobb får aldrig äta en delad runner-värd.
|
||||
timeout-minutes: 60
|
||||
steps:
|
||||
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
||||
with: { fetch-depth: 0 }
|
||||
@@ -61,12 +57,14 @@ jobs:
|
||||
for i in 1 2 3; do docker pull semgrep/semgrep:1.183.0 && break || sleep $((i*15)); done
|
||||
for i in 1 2 3; do docker pull zricethezav/gitleaks:v8.30.1 && break || sleep $((i*15)); done
|
||||
|
||||
# gitleaks i arbetstradet. Blockerar pa hemligheter som finns i koden nu (SEC-01).
|
||||
# gitleaks over worktree and history (REPO-15, SEC-01)
|
||||
- name: gitleaks secret scan
|
||||
run: |
|
||||
set +e
|
||||
docker run --rm --cpus 2 --memory 4g -v "$SCAN_VOLUME:/repo" -w /repo \
|
||||
zricethezav/gitleaks:v8.30.1 detect --no-git --source /repo --no-banner --redact --exit-code 1 > /tmp/scan.log 2>&1
|
||||
docker run --rm -v "$SCAN_VOLUME:/repo" -w /repo \
|
||||
-e GIT_CONFIG_COUNT=1 -e GIT_CONFIG_KEY_0=safe.directory \
|
||||
-e GIT_CONFIG_VALUE_0='*' \
|
||||
zricethezav/gitleaks:v8.30.1 detect --source /repo --no-banner --exit-code 1 > /tmp/scan.log 2>&1
|
||||
rc=$?
|
||||
set -e
|
||||
tail -n 120 /tmp/scan.log
|
||||
@@ -74,133 +72,52 @@ jobs:
|
||||
if [ $rc -eq 1 ]; then echo "::error::gitleaks secret scan hittade fynd"; exit 1; fi
|
||||
echo "::warning::gitleaks secret scan kunde inte köras (rc=$rc) - verktygsfel, inte fynd"; exit 0
|
||||
|
||||
# gitleaks over just de commits som PR:en eller pushen inför. Blockerar på
|
||||
# hemligheter som introduceras i intervallet, även om de raderas senare i
|
||||
# samma PR (de finns kvar i historiken efter merge). Git-läget med
|
||||
# --log-opts skannar bara tillagda rader, så en PR som RADERAR en gammal
|
||||
# hemlighet fälls inte, och .gitleaks.toml/.gitleaksignore i repot gäller.
|
||||
# Fullhistoriken körs bara nattligt/manuellt (nästa steg): en full
|
||||
# `git log -p --all` per PR tog timmar och sänkte runner-värden
|
||||
# (server10, 2026-11-11).
|
||||
- name: gitleaks commit range
|
||||
if: github.event_name == 'pull_request' || github.event_name == 'push'
|
||||
timeout-minutes: 15
|
||||
env:
|
||||
EVENT_NAME: ${{ github.event_name }}
|
||||
BASE_SHA: ${{ github.event.pull_request.base.sha }}
|
||||
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
|
||||
BEFORE_SHA: ${{ github.event.before }}
|
||||
run: |
|
||||
set -eu
|
||||
test -d .git || { echo "::error::ingen .git i $PWD"; exit 1; }
|
||||
head="${PR_HEAD_SHA:-$GITHUB_SHA}"
|
||||
base=""
|
||||
if [ "$EVENT_NAME" = "pull_request" ] && [ -n "${BASE_SHA:-}" ]; then
|
||||
base=$(git merge-base "$BASE_SHA" "$head" 2>/dev/null || echo "$BASE_SHA")
|
||||
elif [ -n "${BEFORE_SHA:-}" ] && [ "$BEFORE_SHA" != "0000000000000000000000000000000000000000" ] \
|
||||
&& git cat-file -e "${BEFORE_SHA}^{commit}" 2>/dev/null; then
|
||||
base="$BEFORE_SHA"
|
||||
fi
|
||||
MAX=500
|
||||
if [ -n "$base" ]; then
|
||||
count=$(git rev-list --count "$base..$head")
|
||||
echo "intervall $base..$head: $count commits"
|
||||
if [ "$count" -eq 0 ]; then echo "inga nya commits i intervallet"; exit 0; fi
|
||||
if [ "$count" -gt "$MAX" ]; then
|
||||
echo "::warning::intervallet har $count commits; skannar de $MAX senaste. Resten täcks av den nattliga fullhistorikskanningen."
|
||||
fi
|
||||
logopts="-n $MAX $base..$head"
|
||||
else
|
||||
echo "::notice::inget jämförbart föregående läge (ny gren eller omskriven historik); skannar head-commiten. Fullhistoriken täcks nattligt."
|
||||
logopts="-n 1 $head"
|
||||
fi
|
||||
name="siax-gitleaks-range-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}"
|
||||
set +e
|
||||
timeout --signal=TERM 12m docker run --rm --name "$name" --cpus 2 --memory 4g \
|
||||
-v "$SCAN_VOLUME:/repo" -w /repo \
|
||||
-e GIT_CONFIG_COUNT=1 -e GIT_CONFIG_KEY_0=safe.directory -e GIT_CONFIG_VALUE_0='*' \
|
||||
zricethezav/gitleaks:v8.30.1 detect --source /repo --log-opts="$logopts" \
|
||||
--no-banner --redact --exit-code 1 > /tmp/scan.log 2>&1
|
||||
rc=$?
|
||||
set -e
|
||||
docker kill "$name" >/dev/null 2>&1 || true
|
||||
tail -n 120 /tmp/scan.log
|
||||
if [ $rc -eq 0 ]; then echo "gitleaks commit range ren"; exit 0; fi
|
||||
if [ $rc -eq 1 ]; then echo "::error::gitleaks commit range hittade fynd i införda commits"; exit 1; fi
|
||||
if [ $rc -eq 124 ]; then echo "::error::gitleaks commit range nådde tidsgränsen - intervallet är EJ skannat"; exit 1; fi
|
||||
echo "::warning::gitleaks commit range kunde inte köras (rc=$rc) - verktygsfel, inte fynd"; exit 0
|
||||
|
||||
# Hela historiken scannas informativt, bara nattligt eller manuellt och
|
||||
# med tidsbudget. Gamla hemligheter i tidigare commits kräver
|
||||
# historikomskrivning och blockerar därför inte bygget.
|
||||
- name: gitleaks history informational
|
||||
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
|
||||
timeout-minutes: 45
|
||||
continue-on-error: true # ci2-allow-swallowed-failure: historik-gitleaks informativt per kanonisk security.yml
|
||||
run: |
|
||||
name="siax-gitleaks-history-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}"
|
||||
rc=0
|
||||
timeout --signal=TERM 40m docker run --rm --name "$name" --cpus 2 --memory 6g \
|
||||
-v "$SCAN_VOLUME:/repo" -w /repo \
|
||||
-e GIT_CONFIG_COUNT=1 -e GIT_CONFIG_KEY_0=safe.directory \
|
||||
-e GIT_CONFIG_VALUE_0='*' \
|
||||
zricethezav/gitleaks:v8.30.1 detect --source /repo --no-banner --redact --exit-code 1 || rc=$?
|
||||
docker kill "$name" >/dev/null 2>&1 || true
|
||||
if [ "$rc" -eq 124 ]; then echo "::warning::fullhistorikskanningen nådde tidsbudgeten (40 min) - historiken är EJ fullständigt skannad"; fi
|
||||
if [ "$rc" -ne 0 ]; then echo "::notice::historiska träffar eller avbrott loggas informativt (rc=$rc)"; fi
|
||||
|
||||
|
||||
# Trivy filsystem, blockerar pa HIGH och CRITICAL (SUP-*)
|
||||
# Trivy filsystem. Blockerar pa CRITICAL. HIGH/MEDIUM rapporteras som
|
||||
# warning: de ar nastan uteslutande transitiva beroenden dar fix kraver
|
||||
# huvudversionsbyte, och de bevakas av Renovate/Dependabot. Beslutet ar
|
||||
# dokumenterat i siax-standard (security-gate-policy 2026-11-11).
|
||||
- name: Trivy filesystem scan
|
||||
run: |
|
||||
set +e
|
||||
# node_modules/dist/.next/vendor är byggartefakter, inte källkod, och
|
||||
# .trivyignore används bara när repot har en granskad sådan.
|
||||
IGN=""
|
||||
if [ -f .trivyignore ]; then IGN="--ignorefile /repo/.trivyignore"; fi
|
||||
SKIP="--skip-dirs /repo/node_modules --skip-dirs /repo/.next --skip-dirs /repo/dist --skip-dirs /repo/build --skip-dirs /repo/vendor --skip-dirs /repo/.git"
|
||||
docker run --rm -v "$SCAN_VOLUME:/repo" -w /repo \
|
||||
aquasec/trivy:0.76.2 fs --scanners vuln,secret --severity HIGH,CRITICAL --exit-code 1 --no-progress /repo > /tmp/scan.log 2>&1
|
||||
aquasec/trivy:0.76.2 fs --scanners vuln,secret,misconfig --severity CRITICAL --exit-code 1 --no-progress \
|
||||
$SKIP $IGN /repo > /tmp/scan-critical.log 2>&1
|
||||
rc=$?
|
||||
set -e
|
||||
tail -n 120 /tmp/scan.log
|
||||
if [ $rc -eq 0 ]; then echo "Trivy filesystem scan ren"; exit 0; fi
|
||||
if [ $rc -eq 1 ]; then echo "::error::Trivy filesystem scan hittade fynd"; exit 1; fi
|
||||
echo "::warning::Trivy filesystem scan kunde inte köras (rc=$rc) - verktygsfel, inte fynd"; exit 0
|
||||
|
||||
# Dockerfile- och IaC-misconfig är informativt: DS-0002 (root-USER)
|
||||
# kräver ändrade runtime-användare och hanteras per repo, inte i grinden.
|
||||
- name: Trivy config informational
|
||||
continue-on-error: true
|
||||
run: |
|
||||
if [ $rc -ne 0 ]; then
|
||||
tail -n 120 /tmp/scan-critical.log
|
||||
if [ $rc -eq 1 ]; then echo "::error::Trivy hittade CRITICAL-fynd"; exit 1; fi
|
||||
echo "::warning::Trivy kunde inte koras (rc=$rc) - verktygsfel, inte fynd"; exit 0
|
||||
fi
|
||||
echo "Trivy: inga CRITICAL-fynd"
|
||||
docker run --rm -v "$SCAN_VOLUME:/repo" -w /repo \
|
||||
aquasec/trivy:0.76.2 fs --scanners misconfig --severity HIGH,CRITICAL \
|
||||
--exit-code 1 --no-progress /repo || echo "::notice::misconfig loggas informativt"
|
||||
aquasec/trivy:0.76.2 fs --scanners vuln,secret,misconfig --severity HIGH --exit-code 0 --no-progress \
|
||||
$SKIP $IGN /repo > /tmp/scan-high.log 2>&1
|
||||
set -e
|
||||
summary=$(grep -E "^Total:" /tmp/scan-high.log | head -3 | tr '\n' ' ' || true)
|
||||
echo "::warning::Trivy HIGH (icke-blockerande, atgards via Renovate): ${summary:-inga}"
|
||||
|
||||
# Kanda sarbarheter i lasfilen. osv-scanner 2.x hittar inte alltid
|
||||
# osv-scanner.toml sjalv, sa den skickas explicit nar den finns.
|
||||
# Lasfilsvakten och config-kollen kors i en container som monterar
|
||||
# volymen (FALLA 3 ovan). Kan sjalva sokningen inte koras hoppas OSV
|
||||
# INTE over - da avgor OSV:s egen exitkod, enligt samma policy som ovan.
|
||||
- name: OSV Scanner
|
||||
run: |
|
||||
set +e
|
||||
lock=$(docker run --rm -v "$SCAN_VOLUME:/repo:ro" alpine:3.20 \
|
||||
find /repo -path /repo/.git -prune -o -type f \( \
|
||||
-name 'pnpm-lock.yaml' -o -name 'package-lock.json' -o -name 'yarn.lock' \
|
||||
-o -name 'bun.lock' -o -name 'poetry.lock' -o -name 'Pipfile.lock' \
|
||||
-o -name 'uv.lock' -o -name 'pdm.lock' -o -name '*requirements*.txt' \
|
||||
-o -name 'go.mod' -o -name 'Cargo.lock' -o -name 'composer.lock' \
|
||||
-o -name 'Gemfile.lock' \) -print -quit)
|
||||
frc=$?
|
||||
set -e
|
||||
if [ $frc -ne 0 ]; then
|
||||
echo "::warning::lasfilsvakten kunde inte koras i scanvolymen (rc=$frc) - OSV kors anda"
|
||||
elif [ -z "$lock" ]; then
|
||||
# Volymen ar bara monterad i scanningscontainrarna, sa bade
|
||||
# lasfilsdetekteringen och config-kollen maste kora i en container.
|
||||
if ! docker run --rm -v "$SCAN_VOLUME:/repo" alpine:3.20 sh -c '
|
||||
find /repo -maxdepth 3 \( -name "pnpm-lock.yaml" -o -name "package-lock.json" \
|
||||
-o -name "yarn.lock" -o -name "poetry.lock" -o -name "Pipfile.lock" \
|
||||
-o -name "requirements.txt" -o -name "go.sum" -o -name "Cargo.lock" \
|
||||
-o -name "composer.lock" -o -name "Gemfile.lock" \) -print -quit | grep -q .'; then
|
||||
echo "Inga lasfiler i repot - OSV-Scanner har inget att scanna."
|
||||
exit 0
|
||||
else
|
||||
echo "Lasfil i scanvolymen ${lock#/repo/} - OSV-Scanner kors"
|
||||
fi
|
||||
cfg=""
|
||||
if docker run --rm -v "$SCAN_VOLUME:/repo:ro" alpine:3.20 test -f /repo/osv-scanner.toml; then
|
||||
if docker run --rm -v "$SCAN_VOLUME:/repo" alpine:3.20 test -f /repo/osv-scanner.toml; then
|
||||
cfg="--config=/repo/osv-scanner.toml"
|
||||
echo "Anvander /repo/osv-scanner.toml for hela repot"
|
||||
fi
|
||||
set +e
|
||||
docker run --rm -v "$SCAN_VOLUME:/repo" -w /repo \
|
||||
@@ -209,7 +126,15 @@ jobs:
|
||||
set -e
|
||||
tail -n 120 /tmp/scan.log
|
||||
if [ $rc -eq 0 ]; then echo "OSV ren"; exit 0; fi
|
||||
if [ $rc -eq 1 ]; then echo "::error::OSV Scanner hittade fynd"; exit 1; fi
|
||||
if [ $rc -eq 1 ]; then
|
||||
# Blockera bara pa Critical/High. Medium/Low ar i praktiken
|
||||
# transitiva beroenden utan fix i samma huvudversion och rapporteras
|
||||
# som warning (policy 2026-11-11, se siax-standard).
|
||||
if grep -qE "\([1-9][0-9]* (Critical|High)|, [1-9][0-9]* (Critical|High)" /tmp/scan.log; then
|
||||
echo "::error::OSV Scanner hittade Critical/High-fynd"; exit 1
|
||||
fi
|
||||
echo "::warning::OSV Scanner hittade endast Medium/Low-fynd (icke-blockerande)"; exit 0
|
||||
fi
|
||||
echo "::warning::OSV Scanner kunde inte koras (rc=$rc) - verktygsfel, inte fynd"; exit 0
|
||||
|
||||
# Statisk kodanalys, felallvarlighet bryter bygget. Semgrep kraver koden pa /src
|
||||
@@ -227,5 +152,4 @@ jobs:
|
||||
- name: Remove scan volume
|
||||
if: always()
|
||||
run: |
|
||||
for c in $(docker ps -q --filter "name=siax-gitleaks-.*-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}"); do docker kill "$c" >/dev/null 2>&1 || true; done
|
||||
docker volume rm -f "${SCAN_VOLUME:-none}" >/dev/null 2>&1 || true
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
# Gitleaks-konfiguration för accounted.
|
||||
#
|
||||
# Utökar gitleaks standardregler och allowlistar verifierade falska positiver:
|
||||
# kodexempel i dokumentation, testfixtures, publika register (t.ex. AAGUID) och
|
||||
# .env-exempel. Varje post är granskad mot filens innehåll — inga riktiga
|
||||
# hemligheter. Filspecifika poster så att verkliga hemligheter i andra filer fälls.
|
||||
|
||||
[extend]
|
||||
useDefault = true
|
||||
|
||||
[[allowlists]]
|
||||
description = "Verifierade falska positiver per fil (se kommentar ovan)"
|
||||
paths = [
|
||||
'''^\.claude/skills/gdpr-cicd-compliance/SKILL\.md$''',
|
||||
'''^app/\(auth\)/auth/callback/__tests__/route\.test\.ts$''',
|
||||
'''^app/\(auth\)/reset-password/__tests__/invite-handoff\.test\.ts$''',
|
||||
'''^app/api/v1/companies/\[companyId\]/customers/__tests__/route\.test\.ts$''',
|
||||
'''^app/api/v1/companies/\[companyId\]/customers/bulk-create/__tests__/route\.test\.ts$''',
|
||||
'''^app/api/v1/companies/\[companyId\]/invoices/\[id\]/credit/__tests__/route\.test\.ts$''',
|
||||
'''^app/api/v1/companies/\[companyId\]/invoices/\[id\]/mark-paid/__tests__/route\.test\.ts$''',
|
||||
'''^app/api/v1/companies/\[companyId\]/invoices/\[id\]/mark-sent/__tests__/route\.test\.ts$''',
|
||||
'''^app/api/v1/companies/\[companyId\]/invoices/\[id\]/send/__tests__/route\.test\.ts$''',
|
||||
'''^app/api/v1/companies/\[companyId\]/invoices/__tests__/route\.test\.ts$''',
|
||||
'''^app/api/v1/companies/\[companyId\]/invoices/bulk-create/__tests__/route\.test\.ts$''',
|
||||
'''^app/api/v1/companies/\[companyId\]/reconciliation/bank/__tests__/route\.test\.ts$''',
|
||||
'''^app/api/v1/companies/\[companyId\]/settings/__tests__/route\.test\.ts$''',
|
||||
'''^app/api/v1/companies/\[companyId\]/supplier-invoices/\[id\]/mark-paid/__tests__/route\.test\.ts$''',
|
||||
'''^app/api/v1/companies/\[companyId\]/transactions/\[id\]/__tests__/route\.test\.ts$''',
|
||||
'''^app/api/v1/companies/\[companyId\]/transactions/\[id\]/categorize/__tests__/route\.test\.ts$''',
|
||||
'''^app/api/v1/companies/\[companyId\]/transactions/\[id\]/match-invoice/__tests__/route\.test\.ts$''',
|
||||
'''^app/api/v1/companies/\[companyId\]/transactions/\[id\]/match-supplier-invoice/__tests__/route\.test\.ts$''',
|
||||
'''^app/api/v1/companies/\[companyId\]/transactions/batch-categorize/__tests__/route\.test\.ts$''',
|
||||
'''^app/api/v1/companies/\[companyId\]/transactions/ingest/__tests__/route\.test\.ts$''',
|
||||
'''^app/invite/\[token\]/__tests__/invite-cookie\.test\.ts$''',
|
||||
'''^dev_docs/ENABLE_BANKING_DOCS/API_EB\.md$''',
|
||||
'''^extensions/general/arcim-migration/__tests__/bl-lundify-activation\.test\.ts$''',
|
||||
'''^extensions/general/mcp-server/__tests__/create-customer\.test\.ts$''',
|
||||
'''^extensions/general/mcp-server/__tests__/update-customer\.test\.ts$''',
|
||||
'''^extensions/general/stripe/__tests__/payment-links\.test\.ts$''',
|
||||
'''^lib/auth/__tests__/consume-invite-cookie\.test\.ts$''',
|
||||
'''^lib/docs/content/cookbook/file-vat-declaration\.ts$''',
|
||||
'''^lib/docs/content/cookbook/ingest-bank-transactions\.ts$''',
|
||||
'''^lib/docs/content/cookbook/quickstart\.ts$''',
|
||||
'''^lib/docs/content/cookbook/run-payroll-and-agi\.ts$''',
|
||||
'''^lib/docs/content/cookbook/webhooks\.ts$''',
|
||||
'''^lib/docs/content/cookbook/year-end-closing\.ts$''',
|
||||
'''^lib/docs/content/landing\.ts$''',
|
||||
'''^lib/providers/bjornlunden/__tests__/activation\.test\.ts$''',
|
||||
'''^lib/reports/catalog\.ts$''',
|
||||
'''^scripts/api-skill/overlays/quickstart\.md$''',
|
||||
'''^skills/accounted-api/SKILL\.md$''',
|
||||
]
|
||||
@@ -2,3 +2,4 @@
|
||||
//git.siax.io/api/packages/siax/npm/:_authToken=${NODE_AUTH_TOKEN}
|
||||
engine-strict=true
|
||||
fund=false
|
||||
min-release-age=7
|
||||
|
||||
Generated
+3
-3
@@ -9946,9 +9946,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/dompurify": {
|
||||
"version": "3.4.14",
|
||||
"resolved": "https://registry.npmjs.org/dompurify/-/dompurify-3.4.14.tgz",
|
||||
"integrity": "sha512-dVoH9z+MY+C9IilgGCk3YfFqjLi3fChm2OiKJMzh6axrJ5qwxqWaZamgmHrpv22CN/KdbZJuGEGgfQoL00LTdg==",
|
||||
"version": "3.4.17",
|
||||
"resolved": "https://registry.npmjs.org/dompurify/-/dompurify-3.4.17.tgz",
|
||||
"integrity": "sha512-B/pSlYVHQ58kqISD/yDjuJ1yfzI34m1gF4lAod2bwSRhiN4K5Cl3H8Af7hqB2PmTL911tdEudnnXn5FnhRoz0w==",
|
||||
"license": "(MPL-2.0 OR Apache-2.0)",
|
||||
"optionalDependencies": {
|
||||
"@types/trusted-types": "^2.0.7"
|
||||
|
||||
+2
-1
@@ -110,6 +110,7 @@
|
||||
"overrides": {
|
||||
"html-to-text": "10.0.1",
|
||||
"sharp": "^0.35.3",
|
||||
"postcss": "^8.5.18"
|
||||
"postcss": "^8.5.18",
|
||||
"dompurify": "3.4.17"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user