Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 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
63e3406
Merge branch 'master' into AST-139912--searchLine-validation
cx-ricardo-jesus Mar 24, 2026
d5e7348
changes on the script and removed unnecessary go setup
cx-ricardo-jesus Mar 24, 2026
ded7ad2
changed query to get errors on go-ci action
cx-ricardo-jesus Mar 24, 2026
bf3939b
parsing json data into objects
cx-ricardo-jesus Mar 25, 2026
135d8f9
small change to test if this is the root of the problem
cx-ricardo-jesus Mar 25, 2026
cf22572
reverted changes
cx-ricardo-jesus Mar 25, 2026
2bef2ed
fixing misspelled directory name
cx-ricardo-jesus Mar 25, 2026
4475b51
fixing some errors in the script used in the validate-search-line job…
cx-ricardo-jesus Mar 25, 2026
78bad5f
fixed misspelled field in validate_scan_results function
cx-ricardo-jesus Mar 25, 2026
bd289fd
simplifying code
cx-ricardo-jesus Mar 25, 2026
972a039
using pymarshal to use models that unmarshal json content directly
cx-ricardo-jesus Mar 25, 2026
1576282
fixing errors in results_models pymarshal import
cx-ricardo-jesus Mar 25, 2026
581fa12
testing searchLine defined to '-1' hardcoded value
cx-ricardo-jesus Mar 25, 2026
0504c8b
convert line and searchLine to int
cx-ricardo-jesus Mar 25, 2026
df27dd2
adding print's for debug purposes
cx-ricardo-jesus Mar 25, 2026
1a1cf97
adding print's for debug purposes
cx-ricardo-jesus Mar 25, 2026
0ece437
fixing cases where searchLine is defined to an hardcoded value of -1
cx-ricardo-jesus Mar 25, 2026
7d6d715
added prints for debug purposes
cx-ricardo-jesus Mar 25, 2026
28c3dff
debug prints
cx-ricardo-jesus Mar 25, 2026
290acf3
debug prints
cx-ricardo-jesus Mar 25, 2026
d0dab72
debug prints
cx-ricardo-jesus Mar 25, 2026
1416d96
changes for debug purposes
cx-ricardo-jesus Mar 25, 2026
216c56f
.
cx-ricardo-jesus Mar 25, 2026
f3038c4
changes
cx-ricardo-jesus Mar 25, 2026
01ebac7
trying to fix cases with -1 hardcoded on searchLine
cx-ricardo-jesus Mar 25, 2026
be3f72c
changes
cx-ricardo-jesus Mar 25, 2026
411f4f3
more changes
cx-ricardo-jesus Mar 25, 2026
c623658
trying type_assert
cx-ricardo-jesus Mar 25, 2026
51eb564
trying type_assert
cx-ricardo-jesus Mar 25, 2026
27b1798
trying type_assert
cx-ricardo-jesus Mar 25, 2026
a20d193
trying type_assert
cx-ricardo-jesus Mar 25, 2026
f56d8cf
trying type_assert
cx-ricardo-jesus Mar 25, 2026
39f673e
testing new scenario
cx-ricardo-jesus Mar 25, 2026
e975f6c
testing test3 case from artur test branch
cx-ricardo-jesus Mar 25, 2026
ef20b51
testing test3 case from artur test branch
cx-ricardo-jesus Mar 25, 2026
b29765c
back to the other scenario
cx-ricardo-jesus Mar 25, 2026
3cfcdf4
back to the other scenario again
cx-ricardo-jesus Mar 25, 2026
4f2b0ab
used unmarshal_json from pumarshal to unmarshal the json with the res…
cx-ricardo-jesus Mar 25, 2026
afbd895
testing hardcoded .1 again
cx-ricardo-jesus Mar 25, 2026
496648e
trying case - common_lib.build_search_line([shdfosdhfoisdhf], []),
cx-ricardo-jesus Mar 25, 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
31 changes: 31 additions & 0 deletions .github/scripts/validate-search-line/results_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from pymarshal.json import type_assert, type_assert_iter


class ScanFile:
def __init__(self, file_name, similarity_id, line,
resource_type, resource_name, issue_type,
search_key, search_line, search_value,
expected_value, actual_value):
self.file_name = type_assert(file_name, str)
self.similarity_id = type_assert(similarity_id, str)
self.line = type_assert(line, int)
self.resource_type = type_assert(resource_type, str)
self.resource_name = type_assert(resource_name, str)
self.issue_type = type_assert(issue_type, str)
self.search_key = type_assert(search_key, str)
self.search_line = type_assert(search_line, int)
self.search_value = type_assert(search_value, str)
self.expected_value = type_assert(expected_value, str)
self.actual_value = type_assert(actual_value, str)


class Query:
def __init__(self, query_name="", query_id="", files=None):
self.query_name = type_assert(query_name, str)
self.query_id = type_assert(query_id, str)
self.files = type_assert_iter(files, ScanFile)


class ScanResults:
def __init__(self, queries=None):
self.queries = type_assert_iter(queries, Query)
160 changes: 160 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,160 @@
#!/usr/bin/env python3

import json
import os
import subprocess
import sys
from pathlib import Path
from pymarshal.json import unmarshal_json
from results_models import ScanResults

REPO_ROOT = Path(__file__).resolve().parents[3]

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",
"--kics_compute_new_simid"
]

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 not in {0, 60, 50, 40, 30, 20}:
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:
- 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())
scan_results = unmarshal_json(data, ScanResults)

# Flatten results from all queries
all_results = []
for query in scan_results.queries:
all_results.extend(query.files)

if not all_results:
print(" [OK] No results to validate")
return True
# Validate each result
valid = True
for idx, f in enumerate(all_results):
sl = int(f.search_line)
ln = int(f.line)
fn = f.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 changed - 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: Install Python dependencies
if: steps.filter.outputs.queries == 'true'
run: pip install pymarshal
- 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 assets/queries/dockerCompose/cpus_not_limited/query.rego
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ CxPolicy[result] {
"issueType": "MissingAttribute",
"keyExpectedValue": "'deploy.resources' should be defined",
"keyActualValue": "'deploy.resources' is not defined",
"searchLine": common_lib.build_search_line(["services", name, "deploy"], []),
"searchLine": common_lib.build_search_line(["shdfosdhfoisdhf"], []),
}
}

Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.alpine
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change the dockerfiles go version?

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