4

DevSecOps Practices: Securing Infrastructure as Code (IaC)

 1 year ago
source link: https://hackernoon.com/devsecops-practices-securing-infrastructure-as-code-iac/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

DevSecOps Practices: Securing Infrastructure as Code (IaC)

June 12th 2023 New Story
4min
by @andreyg

Andrey Glukhov

@andreyg

Security Engineering Lead

Open TLDRtldt arrow
Read on Terminal Reader
Read this story in a terminal
Print this story
Print this story
Read this story w/o Javascript
Read this story w/o Javascript

Too Long; Didn't Read

CI/CD configuration for Checkov and KICS, two Infrastructure as Code (IaC) analysis tools. These tools support various languages, including Terraform, CloudFormation, Kubernetes, ARM and others. I will use GitHub Actions and Gitlab CI to utilize them.
featured image - DevSecOps Practices: Securing Infrastructure as Code (IaC)
Your browser does not support theaudio element.
Read by Dr. One (en-US)
Audio Presented by

@andreyg

Andrey Glukhov

Security Engineering Lead


Receive Stories from @andreyg


Credibility

In my previous article, I highlighted the key steps and important solutions with regard to the security of CI/CD pipelines. In this article, I would like to share the basic CI/CD configuration for Checkov and KICS, two Infrastructure as Code (IaC) analysis tools that can look through your IaC templates for potential vulnerabilities or misconfigurations. These tools support various languages, including Terraform, CloudFormation, Kubernetes, ARM, and others. I will use GitHub Actions and Gitlab CI to utilize them.

Please keep in mind that all configuration files should be adapted to your environment and project requirements.

Checkov

https://github.com/bridgecrewio/checkov

1. Configuration with GitHub Actions:

In your GitHub repository, create a new file named . Add the following configuration to the file:

name: IaC scanning stage
on:
 push:
   branches: [ "main", "master" ]
 pull_request:
   branches: [ "main", "master" ]
jobs:
 IaC_scan:
   runs-on: ubuntu-latest
   steps:
     # Checks-out your repository under $GITHUB_WORKSPACE, so follow-up steps can access it
     - name: Checkout repository
       uses: actions/checkout@v3

     - name: Set up Python
       uses: actions/setup-python@v2
       with:
         python-version: 3.9

     - name: Install Checkov
       run: pip install checkov

     - name: Run Checkov
       run: checkov --directory .

This GitHub Actions workflow triggers a Checkov scan on every push and pull request to the repository.

2. Configuration with Gitlab CI:

In your Gitlab repository, create a new file named . Add the following configuration to the file:

stages:
  - IaC_scan

Checkov:
  stage: IaC_scan
  image: python:3.9
  allow_failure: true
  before_script:
    - pip install checkov
  script:
    - checkov -d .

In the GitLab CI pipeline configuration, an IaC_scan stage is defined with a job named Checkov. It uses the Python Docker image to set up a Python environment, installs Checkov, and runs Checkov to scan the IaC code.

https://kics.io/

1. Configuration with GitHub Actions:

In your GitHub repository, create a new file named . Add the following configuration to the file:

name: IaC scanning stage
on:
 push:
   branches: [ "main", "master" ]
 pull_request:
   branches: [ "main", "master" ]
jobs:
 kics:
   runs-on: ubuntu-latest
   steps:
     # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
     - name: Checkout repository
       uses: actions/checkout@v3
    # Scan Iac with kics
     - name: Run KICS scan
       uses: checkmarx/[email protected]
       with:
         path: "."

This GitHub Actions workflow triggers a KICS scan on every push and pull request to the repository.

  1. Configuration with Gitlab CI:

    In your Gitlab repository, create a new file named (or update it if you already have one). Add the following configuration to the file:

stages:
  - IaC_scan

kics:
 stage: IaC_scan
 image:
   name: checkmarx/kics:latest
   entrypoint: [""]
 script:
   - kics scan -p ${PWD} -o ${PWD} --report-formats json --output-name kics-results
 artifacts:
     name: kics-results.json
     paths:
         - kics-results.json

In the GitLab CI pipeline configuration, an IaC_scan stage is defined with a job named kics. This job uses the KICS Docker image to run the KICS scan against the IaC code.


As a closing remark, I strongly suggest using Infrastructure as Code (IaC) scanner tools at an early stage to enhance your security measures. With this proactive approach, misconfigurations can be prevented. This preemptive tactic allows you to detect and address potential security risks early in the lifecycle, thus mitigating the threat of these risks infiltrating your live infrastructure.

by Andrey Glukhov @andreyg.Security Engineering Lead
Read my stories
L O A D I N G
. . . comments & more!

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK