Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a0ef30f
changed go-ci.yml to use a script to check searchLine
cx-ricardo-jesus Mar 10, 2026
bd0d688
.
cx-ricardo-jesus Mar 10, 2026
823d88c
fixed print to not use f when is missing placeholders
cx-ricardo-jesus Mar 10, 2026
6d64470
removed unnecessary action
cx-ricardo-jesus Mar 10, 2026
b8986d7
fixed typo
cx-ricardo-jesus Mar 10, 2026
8040087
fixing issues from codacy
cx-ricardo-jesus Mar 10, 2026
2b517c5
updated go image in Dockerfile
cx-ricardo-jesus Mar 10, 2026
e18bee3
update go images
cx-ricardo-jesus Mar 10, 2026
2312cda
changed git image
cx-ricardo-jesus Mar 10, 2026
09a2cb0
changing positive expected results
cx-ricardo-jesus Mar 10, 2026
a64ba82
added requests to requirements file
cx-ricardo-jesus Mar 10, 2026
cc2b2ef
changed searchLine to get -1 value
cx-ricardo-jesus Mar 11, 2026
2c99993
added debug prints
cx-ricardo-jesus Mar 11, 2026
e46f8ff
added exception type
cx-ricardo-jesus Mar 11, 2026
8a6e905
fixing error in script
cx-ricardo-jesus Mar 11, 2026
b869010
removed trailing whitespace
cx-ricardo-jesus Mar 16, 2026
989adfe
changed to run the other script
cx-ricardo-jesus Mar 16, 2026
cdb60a5
debugging test directory path
cx-ricardo-jesus Mar 16, 2026
d37f8c5
changed scripts that run on the action
cx-ricardo-jesus Mar 16, 2026
5ee1892
removed f-string without placeholders
cx-ricardo-jesus Mar 16, 2026
ee9a137
inverted changes on the query
cx-ricardo-jesus Mar 16, 2026
8ed8261
changed positive_expected_result
cx-ricardo-jesus Mar 16, 2026
4e92c36
changed filename to fileName
cx-ricardo-jesus Mar 16, 2026
c1942b4
added print for debugging processes
cx-ricardo-jesus Mar 16, 2026
f714b7e
added print to see content value
cx-ricardo-jesus Mar 16, 2026
6a74250
changed script
cx-ricardo-jesus Mar 17, 2026
dcff885
testing searchLine != searchLine
cx-ricardo-jesus Mar 17, 2026
4d48c0e
removed unnecessary sorting on the results in execution context
cx-ricardo-jesus Mar 17, 2026
b3d85ab
removed unused requirements.txt file
cx-ricardo-jesus Mar 17, 2026
c374d8d
reverter changes on positie_expected_results
cx-ricardo-jesus Mar 17, 2026
6606dbb
Merge branch 'master' into AST-139912--searchLine-validation
cx-ricardo-jesus Mar 18, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
166 changes: 166 additions & 0 deletions .github/scripts/validate-search-line/validate-search-line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
#!/usr/bin/env python3

import json
import os
import subprocess
import sys
from pathlib import Path

REPO_ROOT = Path(__file__).resolve().parent.parent.parent.parent


def get_changed_queries():
"""Parse CHANGED_QUERIES env var (JSON array from dorny/paths-filter) to get query directories."""
raw = os.getenv("CHANGED_QUERIES", "")
if not raw:
print("::error::CHANGED_QUERIES environment variable is empty or not set")
sys.exit(1)

try:
files = json.loads(raw)
except json.JSONDecodeError:
print(f"::error::CHANGED_QUERIES is not valid JSON: {raw}")
sys.exit(1)

dirs = []
for f in files:
if f.endswith("/query.rego"):
dirs.append(REPO_ROOT / Path(f).parent)
return dirs


def has_search_line_defined(query_dir):
"""Check if query.rego defines searchLine in its result object."""
rego_file = query_dir / "query.rego"
if not rego_file.exists():
return False
return "searchLine" in rego_file.read_text()


def run_kics_scan(query_dir):
"""Run KICS scan for a single query and return True if it completed successfully."""
query_id = json.loads((query_dir / "metadata.json").read_text())["id"]

results_dir = query_dir / "results"
results_dir.mkdir(exist_ok=True)

payloads_dir = query_dir / "payloads"
payloads_dir.mkdir(exist_ok=True)

cmd = [
"go", "run", str(REPO_ROOT / "cmd" / "console" / "main.go"),
"scan",
"-p", str(query_dir / "test"),
"-o", str(results_dir),
"--output-name", "all_results.json",
"-i", query_id,
"-d", str(payloads_dir / "all_payloads.json"),
"-v",
"--experimental-queries",
"--bom",
"--enable-openapi-refs",
"--ignore-on-exit", "results",
]

print(f" Running scan with query ID: {query_id}")

proc = subprocess.run(cmd, capture_output=True, text=True, cwd=str(REPO_ROOT))

if proc.returncode != 0:
print(f" ::error::Scan failed (exit code {proc.returncode})")
if proc.stdout:
print(f" stdout (last 500 chars): ...{proc.stdout[-500:]}")
if proc.stderr:
print(f" stderr (last 500 chars): ...{proc.stderr[-500:]}")
return False

return True


def validate_scan_results(query_dir):
"""
Validate scan results:
- Sort results by: file_name, line, search_key, search_value, resource_type,
resource_name, query_name, expected_value, actual_value
- Fail if any search_line != line
- Fail if any search_line == -1
"""
results_file = query_dir / "results" / "all_results.json"
rel_dir = query_dir.relative_to(REPO_ROOT)

if not results_file.exists():
print(f" ::error file={rel_dir}::Results file not generated by scan")
return False

data = json.loads(results_file.read_text())

# Flatten results from all queries
all_results = []
for query in data.get("queries", []):
for entry in query.get("files", []):
all_results.append({
"file_name": entry.get("file_name", ""),
"line": entry.get("line", 0),
"search_line": entry.get("search_line", 0),
})

if not all_results:
print(" [OK] No results to validate")
return True

# Validate each result
valid = True
for idx, r in enumerate(all_results):
sl = r["search_line"]
ln = r["line"]
fn = r["file_name"]

if sl == -1:
print(f" ::error::Result [{idx}] {fn}: search_line is -1")
valid = False
elif sl != ln:
print(f" ::error::Result [{idx}] {fn}: search_line ({sl}) != line ({ln})")
valid = False
else:
print(f" [OK] Result [{idx}] {fn}: search_line={sl} == line={ln}")

return valid


def validate_query(query_dir):
"""Validate a single query directory."""

if not has_search_line_defined(query_dir):
print(" [SKIP] searchLine not defined in query.rego - PASS")
return True

print(" searchLine is defined in query.rego - running scan...")

if not run_kics_scan(query_dir):
return False

return validate_scan_results(query_dir)


def main():
query_dirs = get_changed_queries()

if not query_dirs:
print("No query.rego were changes - nothing to validate")
sys.exit(0)

all_valid = True
for qd in query_dirs:
if not validate_query(qd):
all_valid = False

if all_valid:
print("All searchLine validations passed!")
sys.exit(0)
else:
print("::error::Some searchLine validations failed. See errors above.")
sys.exit(1)


if __name__ == "__main__":
main()
34 changes: 34 additions & 0 deletions .github/workflows/go-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,40 @@ jobs:
with:
name: unit-test-${{ runner.os }}-${{ github.event.pull_request.head.sha }}.log
path: unit-test.log
validate-search-line:
name: validate-search-line
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
fetch-depth: 0
- name: Detect changed query.rego files
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
id: filter
with:
list-files: json
filters: |
queries:
- 'assets/queries/**/query.rego'
- name: Set up Python
if: steps.filter.outputs.queries == 'true'
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: '3.13'
- name: Set up Go
if: steps.filter.outputs.queries == 'true'
run: make build
- name: Validate searchLine in modified queries
if: steps.filter.outputs.queries == 'true'
env:
CHANGED_QUERIES: ${{ steps.filter.outputs.queries_files }}
KICS_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
KICS_PR_NUMBER: ${{ github.event.number }}
working-directory: .github/scripts/validate-search-line/
run: python3 validate-search-line.py

security-scan:
name: security-scan
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.25.7-alpine AS build_env
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.25.8-alpine AS build_env

# Install build dependencies
RUN apk add --no-cache git
Expand Down Expand Up @@ -51,7 +51,7 @@
USER checkmarx

# Add kics to PATH
ENV PATH $PATH:/app/bin

Check warning on line 54 in docker/Dockerfile.alpine

View workflow job for this annotation

GitHub Actions / e2e-tests (1.25.x, ubuntu-latest, docker/Dockerfile.alpine)

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/

# Healthcheck the container (consistent with Debian variant)
HEALTHCHECK CMD wget -q --method=HEAD localhost/system-status.txt
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.debian
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# it does not define an ENTRYPOINT as this is a requirement described here:
# https://docs.microsoft.com/en-us/azure/devops/pipelines/process/container-phases?view=azure-devops#linux-based-containers
#
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.25.7-bookworm as build_env
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.25.8-bookworm as build_env

Check warning on line 6 in docker/Dockerfile.debian

View workflow job for this annotation

GitHub Actions / e2e-debian-tests (1.25.x, ubuntu-latest)

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/
# Create a group and user
RUN groupadd checkmarx && useradd -g checkmarx -M -s /bin/bash checkmarx
USER checkmarx
Expand Down Expand Up @@ -45,7 +45,7 @@

RUN groupadd checkmarx && useradd -g checkmarx -M -s /bin/bash checkmarx

ENV PATH /app/bin:/usr/bin/git:$PATH

Check warning on line 48 in docker/Dockerfile.debian

View workflow job for this annotation

GitHub Actions / e2e-debian-tests (1.25.x, ubuntu-latest)

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/

RUN apt-get update -yq \
&& apt-get install git wget unzip zip jq -y \
Expand All @@ -60,7 +60,7 @@

WORKDIR /app/bin

ENV PATH $PATH:/app/bin

Check warning on line 63 in docker/Dockerfile.debian

View workflow job for this annotation

GitHub Actions / e2e-debian-tests (1.25.x, ubuntu-latest)

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/
# Healthcheck the container

HEALTHCHECK CMD wget -q --method=HEAD localhost/system-status.txt
6 changes: 3 additions & 3 deletions docker/Dockerfile.ubi8
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

ENV PATH=$PATH:/usr/local/go/bin

ADD https://golang.org/dl/go1.25.7.linux-amd64.tar.gz .
ADD https://golang.org/dl/go1.25.8.linux-amd64.tar.gz .
RUN yum install git gcc -y \
&& rm -rf /usr/local/go && tar -C /usr/local -xzf go1.25.7.linux-amd64.tar.gz \
&& rm -f go1.25.7.linux-amd64.tar.gz
&& rm -rf /usr/local/go && tar -C /usr/local -xzf go1.25.8.linux-amd64.tar.gz \
&& rm -f go1.25.8.linux-amd64.tar.gz

ENV GOPRIVATE=github.com/Checkmarx/*
ARG VERSION="development"
Expand Down Expand Up @@ -36,7 +36,7 @@

FROM registry.access.redhat.com/ubi8:latest

ENV RELEASE=$RELEASE \

Check warning on line 39 in docker/Dockerfile.ubi8

View workflow job for this annotation

GitHub Actions / e2e-tests (1.25.x, ubuntu-latest, docker/Dockerfile.ubi8)

Variables should be defined before their use

UndefinedVar: Usage of undefined variable '$VERSION' More info: https://docs.docker.com/go/dockerfile/rule/undefined-var/

Check warning on line 39 in docker/Dockerfile.ubi8

View workflow job for this annotation

GitHub Actions / e2e-tests (1.25.x, ubuntu-latest, docker/Dockerfile.ubi8)

Variables should be defined before their use

UndefinedVar: Usage of undefined variable '$RELEASE' More info: https://docs.docker.com/go/dockerfile/rule/undefined-var/
VERSION=$VERSION

LABEL name="KICS" \
Expand Down Expand Up @@ -75,7 +75,7 @@
COPY --chown=${KUSER}:${KGROUP} --from=build_env /build/bin/kics /app/bin/kics
COPY --chown=${KUSER}:${KGROUP} --from=build_env /build/assets/ /app/bin/assets/

ENV PATH $PATH:/app/bin

Check warning on line 78 in docker/Dockerfile.ubi8

View workflow job for this annotation

GitHub Actions / e2e-tests (1.25.x, ubuntu-latest, docker/Dockerfile.ubi8)

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/

# Command to run the executable
ENTRYPOINT ["/app/bin/kics"]
Loading