Documentation
Guides
GitHub Action

GitHub Action

The nat-testing/nat-action GitHub Action runs a NAT security scan as part of your CI/CD workflow. It integrates directly with your NAT Cloud account using an API key stored as a GitHub secret, and supports SARIF upload to GitHub Code Scanning and automatic PR comments.

Quick start

name: NAT Security Scan
 
on:
  pull_request:
  push:
    branches: [main]
 
permissions:
  contents: read
  security-events: write
  pull-requests: write
 
jobs:
  nat-scan:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
 
      - uses: nat-testing/nat-action@v1
        with:
          api-url: ${{ vars.STAGING_API_URL }}   # replace with your staging API URL
          api-key: ${{ secrets.NAT_API_KEY }}
          spec: ./openapi.yaml
          fail-on: high
          upload-sarif: true
          comment-on-pr: true

Setup

  1. Sign up at app.nat-testing.io (opens in a new tab) and generate an API key from Settings β†’ API Keys.
  2. Add the key as a secret named NAT_API_KEY in your repository's Settings β†’ Secrets and variables β†’ Actions.
  3. Add the workflow step shown above to your CI configuration.

Inputs reference

InputRequiredDescriptionDefault
api-urlβœ…Base URL of the target APIβ€”
api-keyβœ…NAT API key (store as a secret)β€”
specPath or URL to OpenAPI/Swagger specAuto-discover
auth-typebearer, header, basic, oauth2, nonenone
tokenAuth token valueβ€”
fail-onSeverity level that fails the build (critical, high, medium, low)high
max-findingsFail if total findings exceed this countβ€”
output-formathtml, json, sarif, markdownsarif
output-fileReport output file pathnat-results.sarif
excludeComma-separated glob patterns to exclude from scanningβ€”
concurrencyParallel request count5
upload-sarifAuto-upload SARIF results to GitHub Code Scanningfalse
comment-on-prPost a scan summary comment on the pull requestfalse

Outputs reference

OutputDescription
scan-idUnique identifier for the scan
finding-countTotal number of findings
critical-countNumber of critical severity findings
high-countNumber of high severity findings
report-urlURL to the full report in the NAT dashboard
sarif-filePath to the SARIF output file
summary-filePath to the scan summary markdown file
pr-comment-filePath to the PR comment markdown file

Workflow examples

Minimal configuration β€” scan on every push to main:

name: NAT Security Scan
on:
  push:
    branches: [main]
 
permissions:
  contents: read
  security-events: write
 
jobs:
  nat-scan:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: nat-testing/nat-action@v1
        with:
          api-url: ${{ vars.STAGING_API_URL }}
          api-key: ${{ secrets.NAT_API_KEY }}

Permissions

Declare only the permissions your workflow needs:

PermissionRequired for
contents: readChecking out the repository
security-events: writeUploading SARIF to GitHub Code Scanning (upload-sarif: true)
pull-requests: writePosting a PR comment (comment-on-pr: true)

Troubleshooting

API key not set

Symptom: Error: NAT_API_KEY is not set

Fix: Add NAT_API_KEY as a repository secret in Settings β†’ Secrets and variables β†’ Actions, then reference it as ${{ secrets.NAT_API_KEY }} in the workflow.

Target API unreachable

Symptom: Error: connection refused or Error: timeout reaching <url>

Fix: Ensure the target API is running and reachable from GitHub-hosted runners. Use a staging environment URL rather than localhost. If your API is on a private network, use a self-hosted runner inside the same network.

SARIF upload fails

Symptom: Error: advanced-security is not enabled for this repository

Fix: GitHub Code Scanning requires GitHub Advanced Security. It is available on all public repositories and on GitHub Enterprise Cloud / GitHub Enterprise Server. Verify the security-events: write permission is declared on the job.

PR comment not appearing

Symptom: Scan completes but no comment is posted on the pull request.

Fix: Ensure:

  1. comment-on-pr: true is set in the action inputs.
  2. The workflow is triggered on pull_request events.
  3. The pull-requests: write permission is declared.

Next steps

  • CI/CD Integration β€” GitLab CI, CircleCI, Jenkins, and other platforms
  • AI Assistant β€” use nat ai in CI for compliance reports and audit trails
  • Compliance β€” generate compliance badges in CI with nat badge
Was this helpful?