Jenkins Integration (Example)
Jenkins's default content security policies don't allow Jenkins to serve the HTML generated by IaC without some configuration in advance. We require you to modify the content security policy if you want to serve the HTML directly from Jenkins. This integration is provided as an example setup and may vary based on your specific environment.
To temporarily relax these policies, run
System.setProperty("hudson.model.DirectoryBrowserSupport.CSP", "default-src 'self'; style-src 'self' 'unsafe-inline'; font-src *; img-src *;")
in the Jenkins Console.
Changing content security policies
Changing content security policies in this way will only be effective until Jenkins's next startup.
- To relax these policies automatically at startup, you can run the above command in a post-initialization script.
Product name to be replaced
You may observe that some components, screen captures, or examples use our former product name, DivvyCloud. This doesn't affect the configuration or the product's functionality, and we will notify you as we replace these component names.
Create a Jenkins Project
To configure a freeform Jenkins project to scan a template with IaC Security, you will need to set up a project using the steps below:
Click the New Item button.
Click Freestyle Project and enter a name.
Configure the integration with your version control system using the Source Code Management portion of the Project configuration page.
Configure Build Triggers as desired.If your InsightCloudSec installation or script requires authentication to run IaC Security scans, choose credentials and bind them to environment variables in your build environment.
- For our provided tool
mimics
, the expected flag is--api-key
. You'll need to generate an API Key prior to setting up this integration. - IaC will require authentication to initiate scans if it is configured with the
iac_auth_required
variable set to1
in theSystemSettings
table.
- For our provided tool
Configure an
Execute Shell
build step with the following command callingmimics
.
If using Terraform:
text
1# Generate a Terraform plan and convert it to JSON2terraform plan -out tf.plan3terraform show -json tf.plan > tf.plan.json45# Run our IaC tool.6docker run \7-v $WORKSPACE:/data \8-e MIMICS_BASE_URL=$ICS_BASE_URL \9-e MIMICS_API_KEY=$ICS_API_KEY \10public.ecr.aws/rapid7-insightcloudsec/ics/mimics:latest scan \11data/tf.plan.json \12-c "My IaC Config Name" \13--report-formats all \14--report-path "/data/reports" \15--no-progress
If using AWS CloudFormation:
text
1# Run our IaC tool.2docker run \3-v $WORKSPACE:/data \4-e MIMICS_BASE_URL=$ICS_BASE_URL \5-e MIMICS_API_KEY=$ICS_API_KEY \6public.ecr.aws/rapid7-insightcloudsec/ics/mimics:latest scan \7data/my_cft.yml \8-c "My IaC Config Name" \9--report-formats all \10--report-path "/data/reports" \11--no-progress
- Configure a post-build action to archive the HTML and/or JSON output created by the command above.
- Click Save.
Jenkins Pipeline
If you use Jenkins pipelines for configuration-as-code and repeatability benefits, check out the following example pipeline configurations for reference and modify to fit your needs.
AWS CloudFormation (Jenkins)
Jenkins Pipeline Example - CFT
text
1pipeline {2agent any34stages {5stage('Submit CloudFormation Template to InsightCloudSec') {6environment {7ICS_BASE_URL = "https://<ICS Base URL>/"8ICS_API_KEY = credentials("ics-api-key")9WORKSPACE = "${env.WORKSPACE}"10}11steps {12script {13try {14sh 'docker run -v $WORKSPACE:/data -e MIMICS_BASE_URL=$ICS_BASE_URL -e MIMICS_API_KEY=$ICS_API_KEY public.ecr.aws/rapid7-insightcloudsec/ics/mimics:latest scan data/my_cft.yml -c "My IaC Config Name" --report-formats all --report-path "/data/reports" --no-progress'15} catch (e) {16throw e17} finally {18archiveArtifacts 'reports/scan_output.*'19}20}21}22}23}24}
Terraform (Jenkins)
Jenkins Pipeline Example - TF
text
1pipeline {2agent any34stages {5stage('Generate Terraform Plan') {6steps {7sh 'terraform plan -out tf.plan'8sh 'terraform show -json tf.plan > tf.plan.json'9stash includes: 'tf.plan.json', name: 'cloudsec-iac-security-stash'10}11}12stage('Submit Terraform Plan to InsightCloudSec') {13environment {14ICS_BASE_URL = "https://<ICS Base URL>/"15ICS_API_KEY = credentials("ics-api-key")16WORKSPACE = "${env.WORKSPACE}"17}18steps {19unstash 'cloudsec-iac-security-stash'20script {21try {22sh 'docker run -v $WORKSPACE:/data -e MIMICS_BASE_URL=$ICS_BASE_URL -e MIMICS_API_KEY=${{ ICS_API_KEY }} public.ecr.aws/rapid7-insightcloudsec/ics/mimics:latest scan data/tf.plan.json -c "My IaC Config Name" --report-formats all --report-path "/data/reports" --no-progress'23} catch (e) {24throw e25} finally {26archiveArtifacts 'scan_output.html'27}28}29}30}31}32}