Coder Social home page Coder Social logo

jeff-snyk / iac-tfplan-demo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from benlaplanche/iac-tfplan-demo

0.0 0.0 0.0 309 KB

Snyk IaC - Demo application scanning Terraform Plan as part of a deployment workflow

HCL 43.03% Shell 29.77% Open Policy Agent 27.21%

iac-tfplan-demo's Introduction

Snyk Infrastructure as Code - Terraform Cloud Demo

This demo app shows Snyk Infrastructure as Code integrated with Terraform Cloud.

When you create a pull_request the Terraform Plan workflow will kick off and perform:

  • Plan creation using Terraform Cloud
  • Scan for security issues using the Snyk IaC CLI against that plan file
  • Run user-provided custom rules to ensure tagging standards
  • Uploads the results to GitHub Security

You can see the output of this in your GitHub Actions build run.

Setup

Setup a GitHub secret called SNYK_TOKEN which is your API token for Snyk. Setup a GitHub secret called TF_API_TOKEN which is your Terraform Cloud API Token. Change the organization and workspaces in the s3.tf file to match your setup. These are your Terraform Cloud settings.

Based on https://learn.hashicorp.com/tutorials/terraform/github-actions

In Detail

You can find the full GitHub action in .github/workflows/terraform.yaml

Image detailing the github workflow

Custom Rule

In custom.rego you can see we've written a custom rule which enforces the addition of a tag called Team If this isn't present the check will fail and return the message as defined here.

deny[msg] {
	resource := input.resource.aws_s3_bucket[name]
	not resource.tags.Team

	msg := {
		"id": "124",
		"publicId": "CUSTOM-123",
		"title": "Missing a tag for owning team",
		"type": "custom",
		"subType": "S3",
		"severity": "critical",
		"policyEngineType": "opa",
		"issue": "There is no defined tag for the owning team",
		"impact": "Deployment will be blocked until this is resolved.",
		"resolve": "Set `aws_s3_bucket.tags.Team`",
		"msg": sprintf("input.resource.aws_s3_bucket[%s].tags", [name]),
		"references": [],
	}
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.