Skip to content

Commit 632956e

Browse files
authored
Merge pull request #11 from Vickydew1/clean-pr
Updated and cleaned
2 parents e5b5326 + 545211e commit 632956e

File tree

2 files changed

+70
-127
lines changed

2 files changed

+70
-127
lines changed

README.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ Before using this GitHub Action, ensure the following:
3636

3737
To authenticate with **AccuKnox Console**, retrieve the required credentials from the **AccuKnox Console**:
3838

39-
1️⃣ **Go to Settings** → Navigate to the **Tokens** section in the **AccuKnox Console**.
40-
2️⃣ **Create a New Token** → Click on **Create Token** to generate `accuknox_token` and `tenant_id`.
39+
1️⃣ **Go to Settings** → Navigate to the **Tokens** section in the **AccuKnox Console**.
40+
41+
2️⃣ **Create a New Token** → Click on **Create Token** to generate `accuknox_token`.
42+
4143
3️⃣ **Store Securely** → Copy and securely store these credentials for workflow usage.
4244

4345
### **Step 3: Implement the Workflow YAML**
@@ -61,15 +63,15 @@ jobs:
6163
- name: Run AccuKnox SAST
6264
uses: accuknox/sast-scan-action@v1.0.2
6365
with:
66+
skip_sonar_scan: false
67+
sonar_project_key: ${{ secrets.SONAR_PROJECT_KEY }}
6468
sonar_token: ${{ secrets.SONAR_TOKEN }}
6569
sonar_host_url: ${{ secrets.SONAR_HOST_URL }}
70+
sonar_organization_id: ${{ secrets.SONAR_ORG_ID }}
6671
accuknox_endpoint: ${{ secrets.ACCUKNOX_ENDPOINT }}
67-
accuknox_token: ${{ secrets.ACCUKNOX_DEV_TOKEN }}
68-
tenant_id: ${{ secrets.TENANT_ID }}
69-
label: "my-sast-scan"
70-
sonar_project_key: "my-project-key"
71-
input_soft_fail: false
72-
skip_sonar_scan: false
72+
accuknox_token: ${{ secrets.ACCUKNOX_TOKEN }}
73+
accuknox_label: ${{ secrets.ACCUKNOX_LABEL }}
74+
soft_fail: false
7375
```
7476
7577
## ⚙️ **Configuration Options (Inputs)**
@@ -79,14 +81,13 @@ jobs:
7981
| `sonar_token` | Personal access token for authenticating with SonarQube. | Required | None |
8082
| `sonar_host_url` | URL of the SonarQube server to run the SAST. | Required | None |
8183
| `accuknox_endpoint`| AccuKnox API endpoint URL to upload the scan results. | Required | None |
82-
| `tenant_id` | Unique ID of the tenant for AccuKnox CSPM panel. | Required | None |
8384
| `accuknox_token` | Token for authenticating with AccuKnox API. | Required | None |
84-
| `label` | Label in AccuKnox SaaS for tagging scan results. | Required | None |
85+
| `accuknox_label` | Label in AccuKnox SaaS for tagging scan results. | Required | None |
8586
| `sonar_project_key`| Project key in SonarQube for identifying the project. | Required | None |
86-
| `sonar_organization_id`| Organization ID for SonarQube (For cloud user only). | Optional | None |
87+
| `sonar_organization_id`| Organisation ID for SonarQube (For cloud user only). | Optional | None |
8788
| `skip_sonar_scan` | Skip SonarQube scan, for advanced users | Optional | false |
88-
| `input_soft_fail` | Do not return an error code if there are failed checks. | Optional | false |
89-
| `upload_artifact` | Upload scan results as artifact | Optional | false |
89+
| `soft_fail` | Do not return an error code if there are failed checks. | Optional | false |
90+
9091

9192
## 🔍 **How It Works?**
9293

action.yaml

Lines changed: 56 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -1,139 +1,81 @@
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+
38
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 }}'
249
skip_sonar_scan:
2510
description: 'Whether to skip the SonarQube scan.'
2611
required: false
2712
default: 'false'
2813
sonar_project_key:
29-
description: 'The SonarQube project key.'
14+
description: 'SonarQube project key'
3015
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)'
3318
required: false
3419
sonar_token:
35-
description: "Token for authenticating with SonarQube."
20+
description: 'SonarQube authentication token'
3621
required: true
3722
sonar_host_url:
38-
description: "The SonarQube host URL."
23+
description: 'SonarQube host URL'
3924
required: true
25+
soft_fail:
26+
description: 'Do not fail the pipeline if scan finds issues'
27+
required: false
28+
default: 'false'
4029
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'
4531
required: true
4632
accuknox_token:
47-
description: "The token for authenticating with AccuKnox SaaS."
33+
description: 'AccuKnox authentication token'
4834
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'
5137
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'
6038

6139
runs:
6240
using: "composite"
6341
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
9360
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
10264
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"
10470
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"
10873
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

Comments
 (0)