Integrate KICS with Codefresh

February 1, 2024 · View on GitHub

Find security vulnerabilities, compliance issues, and infrastructure misconfigurations early in the development cycle of your infrastructure-as-code with KICS Codefresh step by Checkmarx.

You can find the KICS Codefresh step here.

Please, be aware that the KICS Codefresh step can require MEDIUM instances.

ARGUMENTS

VariableExample Value  Description  TypeRequiredDefault
PROJECT_PATHterraform/main.tf,Dockerfilepaths to a file or directories to scan, comma separated liststringYesN/A
IGNORE_ON_EXITresultsdefines which kind of non-zero exits code should be ignored (all, results, errors, none)stringNoN/A
FAIL_ONhigh,mediumwhich kind of results should return an exit code different from 0stringNocritical,high,medium,low,info
TIME_OUT75number of seconds the query has to execute before being canceledstringNo60
PROFILINGCPUenables performance profiler that prints resource consumption metrics in the logs during the execution (CPU, MEM)stringNoN/A
TYPESAnsible,Terraformcase insensitive list of platform types to scan (Ansible, AzureResourceManager, CloudFormation, Dockerfile, Docker Compose, GRPC, GoogleDeploymentManager, Kubernetes, OpenAPI, Terraform)stringNoAll
EXCLUDE_PATHS./shouldNotScan/*,somefile.txtexclude paths from scanstringNoN/A
EXCLUDE_QUERIESe69890e6-fce5-461d-98ad-cb98318dfc96,4728cd65-a20c-49da-8b31-9c08b423e4dbexclude queries by providing the query ID; cannot be provided with query inclusion flagsstringNoN/A
EXCLUDE_CATEGORIESAccess control,Best practicesexclude categories by providing its name; cannot be provided with query inclusion flagsstringNoN/A
EXCLUDE_SEVERETIESinfo,lowexclude results by providing the severity of a resultstringNoN/A
EXCLUDE_RESULTSd4a1fa80-d9d8-450f-87c2-e1f6669c41f8exclude results by providing the similarity ID of a resultstringNoN/A
INCLUDE_QUERIESa227ec01-f97a-4084-91a4-47b350c1db54include queries by providing the query ID; cannot be provided with query exclusion flagsstringNoN/A
OUTPUT_FORMATSjson,sarifformats in which the results will be exported (all, asff, csv, cyclonedx, glsast, html, json, junit, pdf, sarif, sonarqube)stringNojson
OUTPUT_PATHmyResults/directory path to store reportsstringNoN/A
PAYLOAD_PATH/tmp/mypayload.jsonpath to store internal representation JSON filestringNoN/A
QUERIES_PATHquery"example": "/tmp/mypayload.json"stringNo./assets/queries downloaded with the binaries
VERBOSEtruewrite logs to stdout too (mutually exclusive with silent)booleanNofalse
BOMtrueinclude bill of materials (BoM) in results output;booleanNofalse
DISABLE_FULL_DESCRIPTIONStruedisable request for full descriptions and use default vulnerability descriptionsbooleanNofalse
DISABLE_SECRETStruedisable secrets scanningbooleanNofalse
SECRETS_REGEXES_PATH./mydir/secrets-config.jsonpath to secrets regex rules configuration filestringNoN/A
LIBRARIES_PATH./myLibsDirpath to directory with librariesstringNoN/A

EXAMPLES

RUNNING KICS

steps:
    clone:
      title: Clone a project
      type: git-clone
      repo: 'rafaela-soares/query'
      git: github
    run_kics:
          title: Scanning IaC files
          type: checkmarx/kics
          arguments:
              PROJECT_PATH: ./query

RUNNING KICS AND SAVING KICS REPORTS

🚨 Be aware that you should set IGNORE_ON_EXIT: results to be able to avoid the KICS exit code and run the step that saves the report.

GITHUB REPOSITORY

steps:
    clone:
      title: Clone a project
      type: git-clone
      repo: 'rafaela-soares/query'
      git: github
    run_kics:
          title: Scanning IaC files
          type: checkmarx/kics
          arguments:
              PROJECT_PATH: ./query
              QUERIES_PATH: ./query/alb_listening_on_http
              OUTPUT_PATH: /codefresh/volume/query/reports
              OUTPUT_FORMATS: all
              VERBOSE: true
              EXCLUDE_PATHS: ./query/alb_listening_on_http/test/negative.yaml
              TYPES: Ansible
              LOG_LEVEL: DEBUG
              PAYLOAD_PATH: /codefresh/volume/query/payload.json
              IGNORE_ON_EXIT: results
    save_reports_and_payload:
          title: Saving KICS payload and KICS reports
          type: git-commit
        arguments:
              repo: 'rafaela-soares/query'
              git: github
              working_directory: '/codefresh/volume/query'
              commit_message: saved payload and reports
              git_user_name: git-user-name
              git_user_email: git-user@email.com
              allow_empty: false
              add:
                - payload.json
                - ./reports

S3 BUCKET

steps:
    clone:
      title: Clone a project
      type: git-clone
      repo: 'rafaela-soares/query'
      git: github
    run_kics:
          title: Scanning IaC files
          type: checkmarx/kics
          arguments:
              PROJECT_PATH: ./query
              QUERIES_PATH: ./query/alb_listening_on_http
              OUTPUT_PATH: /codefresh/volume/query/reports
              OUTPUT_FORMATS: all
              VERBOSE: true
              EXCLUDE_PATHS: ./query/alb_listening_on_http/test/negative.yaml
              TYPES: Ansible
              LOG_LEVEL: DEBUG
              IGNORE_ON_EXIT: results
    save_reports_in_s3_bucket:
             title: Saving KICS reports
             image: 'amazon/aws-cli'
             working_directory: '/codefresh/volume/query'
             commands:
                 - mkdir ~/.aws
                 - touch ~/.aws/config
                 - chmod 600 ~/.aws/config
                 - echo "[default]" > ~/.aws/config
                 - echo "aws_access_key_id=${AWS_ACCESS_KEY_ID}" >> ~/.aws/config
                 - echo "aws_secret_access_key=${AWS_SECRET_ACCESS_KEY}" >> ~/.aws/config
                 - echo "aws_session_token=${AWS_SESSION_TOKEN}" >> ~/.aws/config
                 - echo "region=${AWS_REGION}" >> ~/.aws/config
                 - aws s3 cp ./reports s3://${{BUCKET_NAME}}/ --recursive