v1.31.0
conocimientocicd-architecttemplates/4063 B

action.yml.template

Fichero que /hv:cicd-architect usa o materializa en el proyecto. Se muestra tal cual está en el plugin.

cicd-architectskill
templatescarpeta
4063 Btamaño
2026-10-02último cambio del pack
# =============================================================================
# .github/actions/security-scan/action.yml — composite action
# G8: gate de ciberseguridad (patron verdict-file). Corre UNA vez en el job de build y publica el artefacto
# `security-report`; los jobs de deploy lo leen con .github/actions/security-gate (dev = warn, pre/pro = block).
# NUNCA tumba el build (continue-on-error): la asimetria con el gate de cobertura es deliberada.
# El script .NET vive en ops/cicd/scripts/security-scan.ps1 (materializado por /cicd-init desde
# skills/cicd-architect/templates/security-scan.ps1; CI no puede leer el plugin).
# Ovillo cicd-architect github-action-security-scan @ {{TEMPLATE_STAMP}}
# =============================================================================
name: Security scan (Ovillo G8)
description: Analiza dependencias, secretos, hardening y SAST y publica el verdict-file security-report

inputs:
  stack:
    description: dotnet | spa
    required: false
    default: dotnet
  solution-path:
    description: .sln o .slnx (stack dotnet)
    required: false
    default: ''
  api-project:
    description: csproj del entrypoint (stack dotnet)
    required: false
    default: ''
  working-dir:
    description: carpeta con package.json (stack spa)
    required: false
    default: '.'
  enable-sast:
    required: false
    default: 'true'

runs:
  using: composite
  steps:
    - name: Security scan
      shell: pwsh
      continue-on-error: true
      env:
        STACK: ${{ inputs.stack }}
        SOLUTION_PATH: ${{ inputs.solution-path }}
        API_PROJECT: ${{ inputs.api-project }}
        WORKING_DIR: ${{ inputs.working-dir }}
        ENABLE_SAST: ${{ inputs.enable-sast }}
      run: |
        $out = Join-Path $env:RUNNER_TEMP 'security-report'
        New-Item -ItemType Directory -Force -Path $out | Out-Null
        if ($env:STACK -eq 'dotnet') {
          & "$env:GITHUB_WORKSPACE/ops/cicd/scripts/security-scan.ps1" `
            -SolutionPath $env:SOLUTION_PATH `
            -ApiProject   $env:API_PROJECT `
            -SourceRoot   $env:GITHUB_WORKSPACE `
            -OutputDir    $out `
            -EnableSast   $env:ENABLE_SAST
        } else {
          # Variante SPA: npm audit en el check 1; hardening/SAST/secretos = skipped. Mismo shape de verdict.
          Push-Location $env:WORKING_DIR
          $raw = (npm audit --json 2>$null | Out-String)
          Pop-Location
          $v = @{ critical = 0; high = 0; moderate = 0; low = 0 }
          try { $a = $raw | ConvertFrom-Json; if ($a.metadata.vulnerabilities) { $v = $a.metadata.vulnerabilities } } catch { Write-Warning "npm audit sin JSON valido (sin red?): verdict inconclusive" }
          $report = [ordered]@{
            schema = 'ovillo-security-report/v1'; buildId = $env:GITHUB_RUN_NUMBER; stack = 'spa'
            summary          = [ordered]@{ Critical = [int]$v.critical; High = [int]$v.high; Moderate = [int]$v.moderate; Low = [int]$v.low; secrets = 0 }
            effectiveSummary = [ordered]@{ Critical = [int]$v.critical; High = [int]$v.high; Moderate = [int]$v.moderate; Low = [int]$v.low; secrets = 0 }
            checks = [ordered]@{ vulnerableDependencies = 'npm audit'; configHardening = 'skipped'; sast = 'skipped'; secrets = 'skipped' }
          }
          ($report | ConvertTo-Json -Depth 8) | Out-File -LiteralPath (Join-Path $out 'security-report.json') -Encoding UTF8
        }
        Write-Host "security-report generado en $out"

    - name: Ensure verdict folder (fail-safe)
      # El gate NUNCA debe tumbar el build por una carpeta inexistente; sin verdict, el deploy a pre/pro bloquea igual.
      shell: pwsh
      run: New-Item -ItemType Directory -Force -Path (Join-Path $env:RUNNER_TEMP 'security-report') | Out-Null

    - name: Upload security-report
      uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
      with:
        name: security-report
        path: ${{ runner.temp }}/security-report
        if-no-files-found: warn
        retention-days: 14

← Volver a la ficha de cicd-architect