متقدم
البحث فيأدلة التثبيت
طريقة البحث
  • الصق رسالة الخطأ بين علامتي تنصيص، مثل "permission denied"، لتجد جدول الحل.
  • اختر مجالًا وجزءًا من الدليل (التثبيت، أول الإعدادات، الاستخدام اليومي، الأمان، الحلول) لتصل مباشرة إلى الخطوة الصحيحة.
  • "كلمتان" تجد العبارة بالضبط.
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث
جرّب:

الدليل 67Checkov · Security

Install and set up Checkov (IaC security scanner)

Checkov scans infrastructure as code for bad security settings before anything is deployed: public S3 buckets, open security groups, unencrypted disks, privileged Kubernetes Pods, Dockerfiles running as root, GitHub Actions with too many permissions. It knows 1,000+ built-in checks for Terraform/OpenTofu, CloudFormation, Kubernetes, Helm, Kustomize, Dockerfile, ARM/Bicep and CI files. This guide installs Checkov, scans code and Terraform plans, sets up skips with reasons and a baseline, and adds a CI gate.

  • 9 الدروس
  • 7 الأوامر

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

$ مستخدم عادي# بصلاحية root (أو مع sudo)

67.1

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.

ItemValue
Installpipx install checkov (Python) or the bridgecrew/checkov container
Commandcheckov -d DIR / checkov -f FILE
Config.checkov.yaml in the repo
Skipsinline checkov:skip=CHECK_ID:reason, or --skip-check
Outputscli, json, sarif, junitxml, cyclonedx

67.2

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.

الأوامر في هذا الدرس

67.3

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_actions

Scan 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_plan

A config file so every run is the same:

.checkov.yaml
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
SettingWhy
frameworkOnly the file types you use (faster, less noise).
quiet + compactShow only failures, without code blocks.
download-external-modulesAlso scan modules from the registry or Git.
output: sarifA report for GitHub/GitLab security views.

الأوامر في هذا الدرس

67.4

Skips with reasons and a baseline

Skip a check for one resource, inside the code, with the reason:

main.tf
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.baseline

67.5

Daily 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-fail

A CI job (GitLab; the same command works in GitHub Actions and Jenkins):

.gitlab-ci.yml
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.

67.6

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.

67.7

Update and remove

pipx upgrade checkov
pipx uninstall checkov

67.8

Fix common problems

ProblemCauseFix
Hundreds of failures at the startAn old codebase.--create-baseline; fix the high/critical checks first.
A failure for a variable that is set correctlyCheckov sees the code, not the final value.Scan the plan JSON (terraform_plan).
Module resources not scannedExternal modules not downloaded.--download-external-modules true (with Git access).
ModuleNotFoundError / install failsOld Python.Use a supported Python 3 with pipx, or the container.
A skip comment is ignoredWrong place or format.Put #checkov:skip=ID:reason inside the resource block.
CI fails although you only want a reportDefault exit code on failures.--soft-fail (or --soft-fail-on LOW).

67.9

Next steps

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.

الأوامر في هذا الدرس

كل الأوامر في هذا الفصل