هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
$ مستخدم عادي# بصلاحية root (أو مع sudo)
Know it before you install
Each check has an ID (CKV_AWS_20 = S3 bucket not public, CKV_K8S_16 = no privileged containers …) and passes or fails per resource. Frameworks are the file types to scan. Scanning a Terraform plan sees the real values after variables and modules.
| Item | Value |
|---|---|
| Install | pipx install checkov (Python) or the bridgecrew/checkov container |
| Command | checkov -d DIR / checkov -f FILE |
| Config | .checkov.yaml in the repo |
| Skips | inline checkov:skip=CHECK_ID:reason, or --skip-check |
| Outputs | cli, json, sarif, junitxml, cyclonedx |
Install on RHEL and Ubuntu
dnf -y install python3 pipx
apt-get install -y pipx
pipx ensurepath
pipx install checkov
checkov --version(First line RHEL, second Ubuntu.) Or: docker run --rm -v "$PWD:/tf" bridgecrew/checkov -d /tf.
First configuration: scan your code
checkov -d ./terraform --framework terraform --compact
Passed checks: 41, Failed checks: 6, Skipped checks: 0
Check: CKV_AWS_20: "S3 Bucket has an ACL defined which allows public READ access."
FAILED for resource: aws_s3_bucket.assets
File: /main.tf:12-20
checkov -d ./k8s --framework kubernetes
checkov -f Dockerfile
checkov -d .github/workflows --framework github_actionsScan the plan to see the final values (modules and variables resolved):
terraform init && terraform plan -out tfplan
terraform show -json tfplan > tfplan.json
checkov -f tfplan.json --framework terraform_planA config file so every run is the same:
directory:
- terraform
- k8s
framework:
- terraform
- kubernetes
- dockerfile
compact: true
quiet: true
download-external-modules: true
skip-path:
- examples/
output:
- cli
- sarif
output-file-path: console,results| Setting | Why |
|---|---|
framework | Only the file types you use (faster, less noise). |
quiet + compact | Show only failures, without code blocks. |
download-external-modules | Also scan modules from the registry or Git. |
output: sarif | A report for GitHub/GitLab security views. |
Skips with reasons and a baseline
Skip a check for one resource, inside the code, with the reason:
resource "aws_s3_bucket" "public_site" {
#checkov:skip=CKV_AWS_20:Public static website by design, approved in SEC-301
bucket = "acme-public-site"
}Start on an old repository without failing on all old findings — make a baseline and fail only on new ones:
checkov -d . --create-baseline
checkov -d . --baseline .checkov.baselineDaily use: the commands and the real uses
checkov -d . --check CKV_AWS_20,CKV_AWS_145
checkov -d . --skip-check CKV_AWS_18
checkov -d . --check HIGH,CRITICAL
checkov -d . -o json | jq '.summary'
checkov --list | grep -i encrypt | head
checkov -d . --soft-failA CI job (GitLab; the same command works in GitHub Actions and Jenkins):
iac-scan:
stage: test
image:
name: bridgecrew/checkov:latest
entrypoint: [""]
script:
- checkov -d . --config-file .checkov.yaml --output sarif --output-file-path results
artifacts:
when: always
paths: [results/](Pin the image tag in production.)
Real uses at work:
- Stop insecure cloud settings in merge requests (before
terraform apply). - Check Kubernetes YAML and Helm output against Pod Security best practice.
- Compliance evidence (CIS benchmarks, internal rules) with custom checks in YAML or Python.
Make it safe
Security checklist:
- Run on every merge request and before every apply (scan the plan).
- Every skip has a reason and a ticket; review skips in code review.
- Use a baseline for old repos, then reduce it over time.
- Pin the Checkov version; review new checks after upgrades (they can add failures).
- Combine with policy at deploy time (Kyverno/OPA) — scanners can be bypassed, admission can not.
Update and remove
pipx upgrade checkov
pipx uninstall checkovFix common problems
| Problem | Cause | Fix |
|---|---|---|
| Hundreds of failures at the start | An old codebase. | --create-baseline; fix the high/critical checks first. |
| A failure for a variable that is set correctly | Checkov sees the code, not the final value. | Scan the plan JSON (terraform_plan). |
| Module resources not scanned | External modules not downloaded. | --download-external-modules true (with Git access). |
ModuleNotFoundError / install fails | Old Python. | Use a supported Python 3 with pipx, or the container. |
| A skip comment is ignored | Wrong place or format. | Put #checkov:skip=ID:reason inside the resource block. |
| CI fails although you only want a report | Default exit code on failures. | --soft-fail (or --soft-fail-on LOW). |
Next steps
- Quick how-tos: Create a safe S3 bucket with Terraform, Keep secrets out of Terraform, Scan Terraform code.
- Write safe Terraform: Install and set up Terraform, Terraform — Secrets.
- The other IaC scanner: Trivy (
trivy config). Deploy-time policies: Kyverno. - All scanners together: One pipeline.
1Why scan the Terraform plan JSON and not only the .tf files?
The plan has the final values after variables and modules, so the checks see what will really be built.
2How do you skip one check for one resource the right way?
An inline #checkov:skip=CHECK_ID:reason comment in that resource.