|
1 | | -name: AccuKnox SAST |
2 | | -description: Run SAST analysis and upload reports to AccuKnox Panel. |
| 1 | +name: "AccuKnox SQ-SAST Scanner" |
| 2 | +description: "Run SonarQube-based SAST scan and upload results to AccuKnox Panel." |
| 3 | + |
| 4 | +branding: |
| 5 | + icon: "shield" |
| 6 | + color: "purple" |
| 7 | + |
3 | 8 | inputs: |
4 | | - repository_url: |
5 | | - description: 'Repository URL' |
6 | | - required: false |
7 | | - default: '${{ github.repositoryUrl }}' |
8 | | - commit_sha: |
9 | | - description: 'Commit SHA' |
10 | | - required: false |
11 | | - default: '${{ github.sha }}' |
12 | | - commit_ref: |
13 | | - description: 'Commit Reference' |
14 | | - required: false |
15 | | - default: '${{ github.ref_name }}' |
16 | | - pipeline_id: |
17 | | - description: 'Github Run ID' |
18 | | - required: false |
19 | | - default: '${{ github.run_id }}' |
20 | | - job_url: |
21 | | - description: 'Github Job URL' |
22 | | - required: false |
23 | | - default: '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}' |
24 | 9 | skip_sonar_scan: |
25 | 10 | description: 'Whether to skip the SonarQube scan.' |
26 | 11 | required: false |
27 | 12 | default: 'false' |
28 | 13 | sonar_project_key: |
29 | | - description: 'The SonarQube project key.' |
| 14 | + description: 'SonarQube project key' |
30 | 15 | required: true |
31 | | - sonar_organization_id: |
32 | | - description: 'Organization ID for SonarQube (cloud only).' |
| 16 | + sonar_org_id: |
| 17 | + description: 'SonarQube organisation ID (cloud only)' |
33 | 18 | required: false |
34 | 19 | sonar_token: |
35 | | - description: "Token for authenticating with SonarQube." |
| 20 | + description: 'SonarQube authentication token' |
36 | 21 | required: true |
37 | 22 | sonar_host_url: |
38 | | - description: "The SonarQube host URL." |
| 23 | + description: 'SonarQube host URL' |
39 | 24 | required: true |
| 25 | + soft_fail: |
| 26 | + description: 'Do not fail the pipeline if scan finds issues' |
| 27 | + required: false |
| 28 | + default: 'false' |
40 | 29 | accuknox_endpoint: |
41 | | - description: "The URL of the CSPM panel to push the scan results to." |
42 | | - required: true |
43 | | - tenant_id: |
44 | | - description: "The ID of the tenant associated with the CSPm dashboard." |
| 30 | + description: 'AccuKnox CSPM panel endpoint URL' |
45 | 31 | required: true |
46 | 32 | accuknox_token: |
47 | | - description: "The token for authenticating with AccuKnox SaaS." |
| 33 | + description: 'AccuKnox authentication token' |
48 | 34 | required: true |
49 | | - label: |
50 | | - description: "Label created in AccuKnox SaaS for associating the scan results." |
| 35 | + accuknox_label: |
| 36 | + description: 'Label for associating scan results in AccuKnox' |
51 | 37 | required: true |
52 | | - input_soft_fail: |
53 | | - description: 'Do not return an error code if there are failed checks.' |
54 | | - required: false |
55 | | - default: 'false' |
56 | | - upload_artifact: |
57 | | - description: 'Upload the scan results as a GitHub artifact' |
58 | | - required: true |
59 | | - default: 'true' |
60 | 38 |
|
61 | 39 | runs: |
62 | 40 | using: "composite" |
63 | 41 | steps: |
64 | | - - name: Run SonarQube Scan |
65 | | - shell: bash |
66 | | - env: |
67 | | - SKIP_SONAR_SCAN: ${{ inputs.skip_sonar_scan }} |
68 | | - SONAR_PROJECT_KEY: ${{ inputs.sonar_project_key }} |
69 | | - SONAR_TOKEN: ${{ inputs.sonar_token }} |
70 | | - SONAR_HOST_URL: ${{ inputs.sonar_host_url }} |
71 | | - SONAR_ORG_ID: ${{ inputs.sonar_organization_id }} |
72 | | - REPOSITORY_URL: ${{ inputs.repository_url }} |
73 | | - COMMIT_SHA: ${{ inputs.commit_sha }} |
74 | | - COMMIT_REF: ${{ inputs.commit_ref }} |
75 | | - JOB_URL: ${{ inputs.job_url }} |
76 | | - PIPELINE_ID: ${{ inputs.pipeline_id }} |
77 | | - ACCUKNOX_ENDPOINT: ${{ inputs.accuknox_endpoint }} |
78 | | - ACCUKNOX_TENANT: ${{ inputs.tenant_id }} |
79 | | - ACCUKNOX_TOKEN: ${{ inputs.accuknox_token }} |
80 | | - ACCUKNOX_LABEL: ${{ inputs.label }} |
81 | | - INPUT_SOFT_FAIL: ${{ inputs.input_soft_fail }} |
82 | | - id: scan_check |
83 | | - run: | |
84 | | - curl -sSL -o accuknox-aspm-scanner \ |
85 | | - https://github.com/accuknox/aspm-scanner-cli/releases/download/v0.9.1/accuknox-aspm-scanner_linux_x86_64 |
86 | | - chmod +x accuknox-aspm-scanner |
87 | | - mv accuknox-aspm-scanner /usr/local/bin/ |
88 | | -
|
89 | | - set +e # Allow script to continue even if a command fails |
90 | | - |
91 | | - [ "$INPUT_SOFT_FAIL" = "true" ] && SOFT_FAIL_ARG="--softfail" || SOFT_FAIL_ARG="" |
92 | | - export PIPELINE_URL="$JOB_URL" |
| 42 | + - name: Run AccuKnox SQ-SAST Scan |
| 43 | + shell: bash |
| 44 | + env: |
| 45 | + SKIP_SONAR_SCAN: ${{ inputs.skip_sonar_scan }} |
| 46 | + SONAR_PROJECT_KEY: ${{ inputs.sonar_project_key }} |
| 47 | + SONAR_ORG_ID: ${{ inputs.sonar_org_id }} |
| 48 | + SONAR_TOKEN: ${{ inputs.sonar_token }} |
| 49 | + SONAR_HOST_URL: ${{ inputs.sonar_host_url }} |
| 50 | + SOFT_FAIL: ${{ inputs.soft_fail }} |
| 51 | + ACCUKNOX_ENDPOINT: ${{ inputs.accuknox_endpoint }} |
| 52 | + ACCUKNOX_TOKEN: ${{ inputs.accuknox_token }} |
| 53 | + ACCUKNOX_LABEL: ${{ inputs.accuknox_label }} |
| 54 | + run: | |
| 55 | + SOFT_FAIL="${SOFT_FAIL//[$'\t\r\n ']}" |
| 56 | + SOFT_FAIL_ARG="" |
| 57 | + if [ "$SOFT_FAIL" = "true" ]; then |
| 58 | + SOFT_FAIL_ARG="--softfail" |
| 59 | + fi |
93 | 60 |
|
94 | | - # Build arguments array |
95 | | - ARGS=() |
96 | | - [ "$SKIP_SONAR_SCAN" = "1" ] && ARGS+=("--skip-sonar-scan") |
97 | | - [ -n "$SONAR_PROJECT_KEY" ] && ARGS+=("-Dsonar.projectKey=$SONAR_PROJECT_KEY") |
98 | | - [ -n "$SONAR_TOKEN" ] && ARGS+=("-Dsonar.token=$SONAR_TOKEN") |
99 | | - [ -n "$SONAR_HOST_URL" ] && ARGS+=("-Dsonar.host.url=$SONAR_HOST_URL") |
100 | | - [ -n "$SONAR_ORG_ID" ] && ARGS+=("-Dsonar.organization=$SONAR_ORG_ID") |
101 | | - ARGS+=("-Dsonar.qualitygate.wait=true") |
| 61 | + echo "Downloading AccuKnox ASPM Scanner..." |
| 62 | + curl -L https://github.com/accuknox/aspm-scanner-cli/releases/download/v0.13.4/accuknox-aspm-scanner -o accuknox-aspm-scanner |
| 63 | + chmod +x accuknox-aspm-scanner |
102 | 64 |
|
103 | | - CMD_STRING="${ARGS[@]}" |
| 65 | + # Build SonarQube command string |
| 66 | + CMD_ARGS="-Dsonar.projectKey=$SONAR_PROJECT_KEY \ |
| 67 | + -Dsonar.token=$SONAR_TOKEN \ |
| 68 | + -Dsonar.host.url=$SONAR_HOST_URL \ |
| 69 | + -Dsonar.qualitygate.wait=true" |
104 | 70 |
|
105 | | - echo "Running: accuknox-aspm-scanner scan $SOFT_FAIL_ARG sq-sast --command \"${CMD_STRING}\" --pipeline-url \"$PIPELINE_URL\" --container-mode" |
106 | | - accuknox-aspm-scanner scan $SOFT_FAIL_ARG sq-sast --command "${CMD_STRING}" --pipeline-url "$PIPELINE_URL" --container-mode |
107 | | - AK_EXIT_CODE=$? |
| 71 | + [ -n "$SONAR_ORG_ID" ] && CMD_ARGS="$CMD_ARGS -Dsonar.organization=$SONAR_ORG_ID" |
| 72 | + [ "$SKIP_SONAR_SCAN" = "true" ] && CMD_ARGS="--skip-sonar-scan $CMD_ARGS" |
108 | 73 |
|
109 | | - if ls SQ-*.json 1> /dev/null 2>&1; then |
110 | | - upload_artifact=true |
111 | | - else |
112 | | - upload_artifact=false |
113 | | - fi |
114 | | -
|
115 | | - echo "upload_artifact=$upload_artifact" >> $GITHUB_OUTPUT |
116 | | -
|
117 | | - echo "AK_EXIT_CODE=$AK_EXIT_CODE" >> $GITHUB_ENV |
118 | | -
|
119 | | - - name: Upload Scan Results as Artifact |
120 | | - if: inputs.upload_artifact == 'true' && steps.scan_check.outputs.upload_artifact == 'true' |
121 | | - uses: actions/upload-artifact@v4 |
122 | | - with: |
123 | | - name: scan-results-${{ github.sha }} |
124 | | - path: SQ-*.json |
125 | | - if-no-files-found: ignore |
126 | | - |
127 | | - - name: Fail pipeline if scan fails |
128 | | - shell: bash |
129 | | - run: | |
130 | | - if [ "$AK_EXIT_CODE" -ne 0 ]; then |
131 | | - echo "Vulnerabilities detected and soft fail is disabled. Exiting with failure." |
132 | | - exit 1 |
133 | | - else |
134 | | - echo "Scan completed successfully." |
135 | | - fi |
136 | | - |
137 | | -branding: |
138 | | - icon: "shield" |
139 | | - color: "purple" |
| 74 | + # Run the scanner (AccuKnox env variables now used instead of CLI args) |
| 75 | + echo "./accuknox-aspm-scanner scan $SOFT_FAIL_ARG sq-sast --command \"$CMD_ARGS\" --repo-url \"$GITHUB_REPOSITORY\" --branch \"${GITHUB_REF#refs/heads/}\" --commit-sha \"$GITHUB_SHA\" --pipeline-url \"$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID\" --container-mode" |
| 76 | + ./accuknox-aspm-scanner scan $SOFT_FAIL_ARG sq-sast --command "$CMD_ARGS" \ |
| 77 | + --repo-url "$GITHUB_REPOSITORY" \ |
| 78 | + --branch "${GITHUB_REF#refs/heads/}" \ |
| 79 | + --commit-sha "$GITHUB_SHA" \ |
| 80 | + --pipeline-url "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" \ |
| 81 | + --container-mode |
0 commit comments