Skip to content

Commit ce5d213

Browse files
committed
Add support for custom base registry in Checkmarx AST GitHub Action
- Introduced new input parameters: `base_registry`, `base_registry_username`, and `base_registry_password` for authenticating with a custom container registry. - Updated action logic to build and run the Docker image from a specified base registry if provided, defaulting to Docker Hub otherwise. - Enhanced documentation in README.md to include configuration details for using a custom base registry. - Added a new workflow to test the custom registry feature, ensuring proper functionality and integration. - Updated Dockerfile to support the new base registry argument.
1 parent 21c9298 commit ce5d213

7 files changed

Lines changed: 312 additions & 45 deletions

File tree

.github/workflows/release.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@ jobs:
2323
- name: Extract full CLI version from Dockerfile
2424
id: extract_cli_version
2525
run: |
26-
IMAGE_LINE=$(grep -m 1 '^FROM' Dockerfile | awk '{print $2}') # Extract the full image reference
26+
# Extract the image reference (supports optional BASE_REGISTRY variable in FROM)
27+
IMAGE_LINE=$(grep -m 1 'checkmarx/ast-cli:' Dockerfile | grep -oP 'checkmarx/ast-cli:[^[:space:]]+')
2728
IMAGE_TAG=$(echo "$IMAGE_LINE" | cut -d':' -f2-) # Get everything after the first colon
2829
2930
echo "Extracted CLI version: $IMAGE_TAG"
3031
3132
echo "CLI_VERSION=$IMAGE_TAG" >> $GITHUB_ENV
32-
echo "::set-output name=CLI_VERSION::$IMAGE_TAG"
33+
echo "CLI_VERSION=$IMAGE_TAG" >> $GITHUB_OUTPUT
3334
3435
3536
- name: Tag
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
name: Test Custom Registry Feature
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
base_registry:
7+
description: 'Custom registry URL (e.g., your-artifactory.jfrog.io)'
8+
required: true
9+
default: ''
10+
skip_scan:
11+
description: 'Skip actual scan (just test Docker build)'
12+
type: boolean
13+
default: false
14+
15+
jobs:
16+
test-custom-registry:
17+
runs-on: ubuntu-latest
18+
name: Test with Custom Registry
19+
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v4
23+
24+
# Step 1: Verify Docker is available
25+
- name: Verify Docker
26+
run: |
27+
echo "Docker version:"
28+
docker --version
29+
echo ""
30+
echo "Docker info:"
31+
docker info
32+
33+
# Step 2: Test registry login (standalone test)
34+
- name: Test Registry Login
35+
run: |
36+
echo "Testing login to: ${{ inputs.base_registry }}"
37+
echo "${{ secrets.ARTIFACTORY_PASSWORD }}" | docker login "${{ inputs.base_registry }}" -u "${{ secrets.ARTIFACTORY_USERNAME }}" --password-stdin
38+
echo "✅ Registry login successful!"
39+
40+
# Step 3: Test image pull (standalone test)
41+
- name: Test Image Pull
42+
run: |
43+
echo "Testing image pull from custom registry..."
44+
REGISTRY="${{ inputs.base_registry }}"
45+
# Ensure registry ends with /
46+
[[ "$REGISTRY" != */ ]] && REGISTRY="${REGISTRY}/"
47+
48+
IMAGE="${REGISTRY}checkmarx/ast-cli:2.3.41"
49+
echo "Pulling: $IMAGE"
50+
51+
docker pull "$IMAGE"
52+
echo "✅ Image pull successful!"
53+
54+
echo ""
55+
echo "Image details:"
56+
docker inspect "$IMAGE" | jq '.[0].RepoTags, .[0].Created, .[0].Size'
57+
58+
# Step 4: Test Docker build with build-arg
59+
- name: Test Docker Build
60+
run: |
61+
echo "Testing Docker build with custom base registry..."
62+
REGISTRY="${{ inputs.base_registry }}"
63+
[[ "$REGISTRY" != */ ]] && REGISTRY="${REGISTRY}/"
64+
65+
echo "Building with BASE_REGISTRY=${REGISTRY}"
66+
67+
docker build \
68+
--build-arg BASE_REGISTRY="${REGISTRY}" \
69+
-t checkmarx-ast-action:test \
70+
.
71+
72+
echo "✅ Docker build successful!"
73+
74+
echo ""
75+
echo "Built image details:"
76+
docker images checkmarx-ast-action:test
77+
78+
# Step 5: Test full action (optional - if not skipping scan)
79+
- name: Run Full Checkmarx Scan
80+
if: ${{ inputs.skip_scan == false }}
81+
uses: ./
82+
with:
83+
base_registry: ${{ inputs.base_registry }}
84+
base_registry_username: ${{ secrets.ARTIFACTORY_USERNAME }}
85+
base_registry_password: ${{ secrets.ARTIFACTORY_PASSWORD }}
86+
base_uri: ${{ secrets.CX_BASE_URI }}
87+
cx_tenant: ${{ secrets.CX_TENANT }}
88+
cx_client_id: ${{ secrets.CX_CLIENT_ID }}
89+
cx_client_secret: ${{ secrets.CX_CLIENT_SECRET }}
90+
project_name: ${{ github.repository }}-custom-registry-test
91+
scan_params: --scan-types sast --sast-incremental
92+
93+
# Step 6: Summary
94+
- name: Test Summary
95+
run: |
96+
echo "## Test Results" >> $GITHUB_STEP_SUMMARY
97+
echo "" >> $GITHUB_STEP_SUMMARY
98+
echo "| Test | Status |" >> $GITHUB_STEP_SUMMARY
99+
echo "|------|--------|" >> $GITHUB_STEP_SUMMARY
100+
echo "| Registry Login | ✅ Passed |" >> $GITHUB_STEP_SUMMARY
101+
echo "| Image Pull | ✅ Passed |" >> $GITHUB_STEP_SUMMARY
102+
echo "| Docker Build | ✅ Passed |" >> $GITHUB_STEP_SUMMARY
103+
if [ "${{ inputs.skip_scan }}" == "false" ]; then
104+
echo "| Full Scan | ✅ Passed |" >> $GITHUB_STEP_SUMMARY
105+
else
106+
echo "| Full Scan | ⏭️ Skipped |" >> $GITHUB_STEP_SUMMARY
107+
fi
108+
echo "" >> $GITHUB_STEP_SUMMARY
109+
echo "**Registry Used:** \`${{ inputs.base_registry }}\`" >> $GITHUB_STEP_SUMMARY
110+

.github/workflows/update-docker-image.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ jobs:
3838
DIGEST=$(curl -s -I -H "Authorization: Bearer $TOKEN" -H "Accept: application/vnd.docker.distribution.manifest.v2+json" \
3939
"https://registry.hub.docker.com/v2/${REPO}/manifests/${RELEASE_TAG}" | grep -i "Docker-Content-Digest" | awk '{print $2}' | tr -d '\r')
4040
41-
# Get the current tag from the Dockerfile
42-
CURRENT_TAG=$(grep -oP '(?<=FROM checkmarx/ast-cli:)[^@]+' Dockerfile)
41+
# Get the current tag from the Dockerfile (supports optional BASE_REGISTRY variable)
42+
CURRENT_TAG=$(grep -oP '(?<=checkmarx/ast-cli:)[^@]+' Dockerfile)
4343
4444
echo "RELEASE_TAG=$RELEASE_TAG" >> $GITHUB_ENV
4545
echo "DIGEST=$DIGEST" >> $GITHUB_ENV
@@ -48,7 +48,8 @@ jobs:
4848
- name: Update Dockerfile
4949
if: env.CURRENT_TAG != env.RELEASE_TAG
5050
run: |
51-
sed -i "s|FROM checkmarx/ast-cli:.*@sha256:[a-f0-9]*|FROM checkmarx/ast-cli:${RELEASE_TAG}@${DIGEST}|" Dockerfile
51+
# Update the base image tag (supports optional BASE_REGISTRY variable in FROM)
52+
sed -i "s|checkmarx/ast-cli:.*@sha256:[a-f0-9]*|checkmarx/ast-cli:${RELEASE_TAG}@${DIGEST}|" Dockerfile
5253
5354
- name: Commit Changes
5455
if: env.CURRENT_TAG != env.RELEASE_TAG

Dockerfile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1+
# Build-time argument for custom base registry
2+
# If BASE_REGISTRY is provided, it should be in format: my-registry.example.com/
3+
# If not provided, defaults to Docker Hub
4+
ARG BASE_REGISTRY=""
5+
16
# Use AST Base image
2-
FROM checkmarx/ast-cli:2.3.41@sha256:6eb696e1a1bcc45d7f980763f08f97ab7780e447604f34e83145ad064752ab72
7+
# When BASE_REGISTRY is empty, this resolves to checkmarx/ast-cli:...
8+
# When BASE_REGISTRY is set (e.g., "my-registry.example.com/"), this resolves to my-registry.example.com/checkmarx/ast-cli:...
9+
FROM ${BASE_REGISTRY}checkmarx/ast-cli:2.3.41@sha256:6eb696e1a1bcc45d7f980763f08f97ab7780e447604f34e83145ad064752ab72
310

411
# Docker actions must be run by the default Docker user (root).
512
USER root

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,46 @@ Cloud](https---checkmarx-com-resource-documents-en-34965-68678-github-cloud.html
9898

9999
- You have a Checkmarx One account and you have an OAuth **Client ID** and **Client Secret** for that account. To create an OAuth client, see [Creating an OAuth Client for Checkmarx One Integrations](https://checkmarx.com/resource/documents/en/34965-118315-authentication-for-checkmarx-one-cli.html#UUID-a4e31a96-1f36-6293-e95a-97b4b9189060_UUID-4123a2ff-32d0-2287-8dd2-3c36947f675e).
100100

101+
## Custom Base Registry
102+
103+
For environments with restricted access to public Docker registries (e.g., Docker Hub), you can configure the action to pull the `checkmarx/ast-cli` base image from an internal/enterprise registry.
104+
105+
### Configuration
106+
107+
Use the following input parameters:
108+
109+
| Parameter | Required | Description |
110+
|-----------|----------|-------------|
111+
| `base_registry` | No | Base container registry URL (e.g., `my-registry.example.com`). If not provided, defaults to Docker Hub. |
112+
| `base_registry_username` | No | Username for authenticating with the base container registry. |
113+
| `base_registry_password` | No | Password/token for authenticating with the base container registry. |
114+
115+
### Example Usage
116+
117+
```yaml
118+
- name: Checkmarx AST CLI Action
119+
uses: checkmarx/ast-github-action@main
120+
with:
121+
# Custom base registry configuration
122+
base_registry: my-enterprise-registry.example.com
123+
base_registry_username: ${{ secrets.REGISTRY_USERNAME }}
124+
base_registry_password: ${{ secrets.REGISTRY_PASSWORD }}
125+
126+
# Standard Checkmarx One configuration
127+
base_uri: https://ast.checkmarx.net/
128+
cx_tenant: your_tenant
129+
cx_client_id: ${{ secrets.CX_CLIENT_ID }}
130+
cx_client_secret: ${{ secrets.CX_CLIENT_SECRET }}
131+
```
132+
133+
### Setting Up Your Enterprise Registry
134+
135+
1. Mirror or proxy the `checkmarx/ast-cli` image from Docker Hub to your internal registry
136+
2. Ensure the image is available at `<your-registry>/checkmarx/ast-cli:<tag>`
137+
3. Configure the action with your registry URL and credentials
138+
139+
For a complete example workflow, see [`sample-yml/checkmarx-ast-scan-custom-registry.yml`](sample-yml/checkmarx-ast-scan-custom-registry.yml).
140+
101141

102142
## Getting Started
103143

action.yml

Lines changed: 119 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@ name: 'Checkmarx AST Github Action'
22
description: 'Simplify Checkmarx Scanning of source code along with Result consumption leveraging Checkmarx AST solution.'
33
author: 'Checkmarx'
44
inputs:
5+
base_registry:
6+
required: false
7+
default: ''
8+
description: 'Base container registry for pulling checkmarx/ast-cli image (e.g., my-registry.example.com). If not provided, defaults to Docker Hub (docker.io).'
9+
base_registry_username:
10+
required: false
11+
default: ''
12+
description: 'Username for authenticating with the base container registry'
13+
base_registry_password:
14+
required: false
15+
default: ''
16+
description: 'Password/token for authenticating with the base container registry'
517
base_uri:
618
required: true
719
description: 'Provide the AST portal URL'
@@ -62,51 +74,119 @@ inputs:
6274
required: false
6375
default: .
6476
description: "Source directory"
65-
outputs:
77+
outputs:
6678
cxcli:
6779
description: output from cli
80+
value: ${{ steps.run-scan.outputs.cxcli }}
6881
cxScanID:
6982
description: scan ID output from cli
83+
value: ${{ steps.run-scan.outputs.cxScanID }}
7084
runs:
71-
using: 'docker'
72-
image: 'Dockerfile'
73-
args:
74-
- ${{ inputs.base_uri }}
75-
- ${{ inputs.cx_tenant }}
76-
- ${{ inputs.cx_client_id }}
77-
- ${{ inputs.cx_client_secret }}
78-
- ${{ inputs.github_token }}
79-
- ${{ inputs.project_name }}
80-
- ${{ inputs.additional_params }}
81-
- ${{ inputs.global_params }}
82-
- ${{ inputs.scan_params }}
83-
- ${{ inputs.utils_params }}
84-
- ${{ inputs.results_params }}
85-
- ${{ inputs.repo_name }}
86-
- ${{ inputs.namespace }}
87-
- ${{ inputs.pr_number }}
88-
- ${{ inputs.source_dir }}
89-
entrypoint: '/app/entrypoint.sh'
90-
post-if: cancelled()
91-
post-entrypoint: '/app/cleanup.sh'
85+
using: 'composite'
86+
steps:
87+
# Step 1: Login to base registry if credentials are provided
88+
- name: Login to base registry
89+
if: ${{ inputs.base_registry != '' && inputs.base_registry_username != '' && inputs.base_registry_password != '' }}
90+
shell: bash
91+
run: |
92+
echo "Logging into base registry: ${{ inputs.base_registry }}"
93+
echo "${{ inputs.base_registry_password }}" | docker login "${{ inputs.base_registry }}" -u "${{ inputs.base_registry_username }}" --password-stdin
94+
95+
# Step 2: Build Docker image with custom base registry
96+
- name: Build Docker image
97+
shell: bash
98+
run: |
99+
# Prepare the base registry argument
100+
BASE_REGISTRY_ARG=""
101+
if [ -n "${{ inputs.base_registry }}" ]; then
102+
# Ensure registry ends with a slash
103+
REGISTRY="${{ inputs.base_registry }}"
104+
if [[ ! "$REGISTRY" == */ ]]; then
105+
REGISTRY="${REGISTRY}/"
106+
fi
107+
BASE_REGISTRY_ARG="$REGISTRY"
108+
echo "Using custom base registry: ${BASE_REGISTRY_ARG}"
109+
else
110+
echo "Using default Docker Hub registry"
111+
fi
112+
113+
# Build the Docker image
114+
docker build \
115+
--build-arg BASE_REGISTRY="${BASE_REGISTRY_ARG}" \
116+
-t checkmarx-ast-action:local \
117+
"${{ github.action_path }}"
118+
119+
# Step 3: Run the scan
120+
- name: Run Checkmarx scan
121+
id: run-scan
122+
shell: bash
123+
env:
124+
CX_BASE_URI: ${{ inputs.base_uri }}
125+
CX_TENANT: ${{ inputs.cx_tenant }}
126+
CX_CLIENT_ID: ${{ inputs.cx_client_id }}
127+
CX_CLIENT_SECRET: ${{ inputs.cx_client_secret }}
128+
GITHUB_TOKEN: ${{ inputs.github_token }}
129+
BRANCH: ${{ inputs.branch }}
130+
PROJECT_NAME: ${{ inputs.project_name }}
131+
ADDITIONAL_PARAMS: ${{ inputs.additional_params }}
132+
GLOBAL_PARAMS: ${{ inputs.global_params }}
133+
SCAN_PARAMS: ${{ inputs.scan_params }}
134+
UTILS_PARAMS: ${{ inputs.utils_params }}
135+
RESULTS_PARAMS: ${{ inputs.results_params }}
136+
REPO_NAME: ${{ inputs.repo_name }}
137+
NAMESPACE: ${{ inputs.namespace }}
138+
PR_NUMBER: ${{ inputs.pr_number }}
139+
SOURCE_DIR: ${{ inputs.source_dir }}
140+
run: |
141+
# Create temporary files for outputs
142+
OUTPUT_FILE=$(mktemp)
143+
SUMMARY_FILE=$(mktemp)
144+
145+
# Run the Docker container with --rm flag for automatic cleanup
146+
docker run --rm \
147+
-e CX_BASE_URI="${CX_BASE_URI}" \
148+
-e CX_TENANT="${CX_TENANT}" \
149+
-e CX_CLIENT_ID="${CX_CLIENT_ID}" \
150+
-e CX_CLIENT_SECRET="${CX_CLIENT_SECRET}" \
151+
-e GITHUB_TOKEN="${GITHUB_TOKEN}" \
152+
-e BRANCH="${BRANCH}" \
153+
-e PROJECT_NAME="${PROJECT_NAME}" \
154+
-e ADDITIONAL_PARAMS="${ADDITIONAL_PARAMS}" \
155+
-e GLOBAL_PARAMS="${GLOBAL_PARAMS}" \
156+
-e SCAN_PARAMS="${SCAN_PARAMS}" \
157+
-e UTILS_PARAMS="${UTILS_PARAMS}" \
158+
-e RESULTS_PARAMS="${RESULTS_PARAMS}" \
159+
-e REPO_NAME="${REPO_NAME}" \
160+
-e NAMESPACE="${NAMESPACE}" \
161+
-e PR_NUMBER="${PR_NUMBER}" \
162+
-e SOURCE_DIR="${SOURCE_DIR}" \
163+
-e GITHUB_SERVER_URL="${GITHUB_SERVER_URL}" \
164+
-e GITHUB_OUTPUT="/github/file_commands/output" \
165+
-e GITHUB_STEP_SUMMARY="/github/file_commands/summary" \
166+
-v "${OUTPUT_FILE}:/github/file_commands/output" \
167+
-v "${SUMMARY_FILE}:/github/file_commands/summary" \
168+
-v "${GITHUB_WORKSPACE}:/github/workspace" \
169+
-w /github/workspace \
170+
checkmarx-ast-action:local \
171+
/app/entrypoint.sh
172+
173+
EXIT_CODE=$?
174+
175+
# Copy outputs to GitHub outputs file
176+
if [ -f "${OUTPUT_FILE}" ]; then
177+
cat "${OUTPUT_FILE}" >> $GITHUB_OUTPUT
178+
fi
179+
180+
# Copy summary to GitHub step summary
181+
if [ -f "${SUMMARY_FILE}" ]; then
182+
cat "${SUMMARY_FILE}" >> $GITHUB_STEP_SUMMARY
183+
fi
184+
185+
# Cleanup temp files
186+
rm -f "${OUTPUT_FILE}" "${SUMMARY_FILE}"
187+
188+
exit $EXIT_CODE
92189
93-
env:
94-
CX_BASE_URI: "${{ inputs.base_uri }}"
95-
CX_TENANT: ${{ inputs.cx_tenant }}
96-
CX_CLIENT_ID: ${{ inputs.cx_client_id }}
97-
CX_CLIENT_SECRET: ${{ inputs.cx_client_secret }}
98-
GITHUB_TOKEN: ${{ inputs.github_token }}
99-
BRANCH: ${{ inputs.branch }}
100-
PROJECT_NAME: ${{ inputs.project_name }}
101-
ADDITIONAL_PARAMS: ${{ inputs.additional_params }}
102-
GLOBAL_PARAMS: ${{ inputs.global_params }}
103-
SCAN_PARAMS: ${{ inputs.scan_params }}
104-
UTILS_PARAMS: ${{ inputs.utils_params }}
105-
RESULTS_PARAMS: ${{ inputs.results_params }}
106-
REPO_NAME: ${{ inputs.repo_name }}
107-
NAMESPACE: ${{ inputs.namespace }}
108-
PR_NUMBER: ${{ inputs.pr_number }}
109-
SOURCE_DIR: ${{ inputs.source_dir }}
110190
branding:
111191
icon: 'check'
112192
color: 'green'

0 commit comments

Comments
 (0)