Pulse Beta

User guide

How-to guide

GitHub Actions

Scan each push and each pull request of a GitHub repository, and fail the job when a high or critical finding is open.

Before you start #

Add the job #

Store the token in the secret store of GitHub with the name TUXCARE_PORTAL_TOKEN. The CLI reads it from that variable and writes it nowhere.

Add the token under Settings › Secrets and variables › Actions › New repository secret. Then add .github/workflows/tuxcarectl.yml:

name: tuxcarectl
on:
  push:
    branches: [main]
  pull_request:
jobs:
  tuxcarectl:
    runs-on: ubuntu-latest
    env:
      TUXCARE_PORTAL_TOKEN: ${{ secrets.TUXCARE_PORTAL_TOKEN }}
    steps:
      - uses: actions/checkout@v4
      - run: |
          curl -fsSL https://securechain.tuxcare.com/get/tuxcarectl | sh
          echo "$HOME/.local/bin" >> "$GITHUB_PATH"
      - run: tuxcarectl guard check
      - run: tuxcarectl guard setup --ci
      - run: npm ci              # the install step of your project, through the guard
      - run: tuxcarectl sca --fail-on high

GitHub gives no secret to a pull request from a fork, so that job stops with exit code 3.

Fail a pull request only on new findings #

compare --fail-on-new fails a pull request only on the findings that it adds, not on the old findings of the base branch. The job scans the base branch on each push, and compares each pull request with it. See Pull and merge requests.

name: tuxcarectl
on:
  push:
    branches: [main]
  pull_request:
jobs:
  tuxcarectl:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm ci              # the install step of your project
      - name: Scan the branch
        if: github.event_name == 'push'
        uses: TuxCare/tuxcarectl-action@v0
        with:
          command: sca
          args: --fail-on high
          portal-token: ${{ secrets.TUXCARE_PORTAL_TOKEN }}
          registry-login: none
      - name: Fail on new findings
        if: github.event_name == 'pull_request'
        uses: TuxCare/tuxcarectl-action@v0
        with:
          command: compare
          args: --base ${{ github.base_ref }} --fail-on-new
          portal-token: ${{ secrets.TUXCARE_PORTAL_TOKEN }}
          registry-login: none

Sign in with no stored token #

GitHub Actions gives each job a signed OIDC token. With a trust rule of an admin (CI sign-in), the job trades it for a portal token of one hour, and the repository stores no portal token. Change the job as below. PORTAL_URL is the address of your workspace, with no slash at the end. The audience of the OIDC token must be this address.

permissions:
  id-token: write
  contents: read
steps:
  - name: Sign in to the portal
    env:
      PORTAL_URL: https://acme.example.com
    run: |
      oidc=$(curl -sS -H "Authorization: Bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
        "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=$PORTAL_URL" | jq -r .value)
      token=$(jq -n --arg t "$oidc" '{token: $t}' | curl -sS --fail-with-body -X POST \
        --data-binary @- "$PORTAL_URL/securechain/v1/ci-token" | jq -r .access_token)
      echo "::add-mask::$token"
      echo "TUXCARE_PORTAL_TOKEN=$token" >> "$GITHUB_ENV"

More #

Next: GitLab CI