Code Monkey home page Code Monkey logo

frediana / terrascan Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tenable/terrascan

0.0 0.0 0.0 13.82 MB

Detect compliance and security violations across Infrastructure as Code to mitigate risk before provisioning cloud native infrastructure.

Home Page: https://docs.accurics.com/projects/accurics-terrascan/en/latest/

License: Apache License 2.0

Makefile 0.21% Dockerfile 0.14% Shell 0.95% Go 70.91% Open Policy Agent 14.75% HCL 0.93% CSS 0.19% JavaScript 11.42% HTML 0.19% Smarty 0.30%

terrascan's Introduction

Terrascan

GitHub release License: Apache 2.0 PRs Welcome CI codecov community Documentation Status Contributor Covenant

Introduction

Terrascan is a static code analyzer for Infrastructure as Code. Terrascan allow you to:

  • seamlessly scan infrastructure as code for misconfigurations
  • monitor provisioned cloud infrastructure for configuration changes that introduce posture drift, and enables reverting to a secure posture.
  • Detect security vulnerabilities and compliance violations.
  • Mitigate risks before provisioning cloud native infrastructure.
  • Offers flexibility to run locally or integrate with your CI\CD.

Resources

Key features

  • 500+ Policies for security best practices
  • Scanning of Terraform (HCL2)
  • Scanning of Kubernetes (JSON/YAML), Helm v3, and Kustomize v3
  • Support for AWS, Azure, GCP, Kubernetes and GitHub

Quick Start

  1. Install
  2. Scan
  3. Integrate

Step 1: Install

Terrascan's supports multiple ways to install and is also available as a Docker image. See Terrascan's releases page for latest version of builds in all supported platforms. Select the correct binary for your platform.

Install as a native executable

$ curl -L "$(curl -s https://api.github.com/repos/accurics/terrascan/releases/latest | grep -o -E "https://.+?_Darwin_x86_64.tar.gz")" > terrascan.tar.gz
$ tar -xf terrascan.tar.gz terrascan && rm terrascan.tar.gz
$ install terrascan /usr/local/bin && rm terrascan
$ terrascan

Install via brew

Homebrew users can install by:

$ brew install terrascan

Docker image

Terrascan is also available as a Docker image and can be used as follows

$ docker run accurics/terrascan

Refer to documentation for information.

Step 2: Scan

To scan your code for security issues you can run the following (defaults to scanning Terraform).

$ terrascan scan

Note: Terrascan will exit with an error code 3 if any issues are found during a scan.

Step 3: Integrate with CI\CD

Terrascan can be integrated into CI/CD pipelines to enforce security best practices. Please refer to our documentation to integrate with your pipeline.

Terrascan Commands

You can use terrascan command with the following options:

$ terrascan
Terrascan

Usage:
  terrascan [command]

Available Commands:
  help        Help about any command
  init        Initialize Terrascan
  scan        Detect compliance and security violations across Infrastructure as Code.
  server      Run Terrascan as an API server
  version     Terrascan version

Flags:
  -c, --config-path string   config file path
  -h, --help                 help for terrascan
  -l, --log-level string     log level (debug, info, warn, error, panic, fatal) (default "info")
  -x, --log-type string      log output type (console, json) (default "console")
  -o, --output string        output type (human, json, yaml, xml) (default "human")

Use "terrascan [command] --help" for more information about a command.

Policies

Terrascan policies are written using the Rego policy language. Every rego includes a JSON "rule" file which defines metadata for the policy. By default, Terrascan downloads policies from Terrascan repositories while scanning for the first time. However if you want to download the latest policies, you need to run the Initialization process. See Usage for information about the Initialization process.

Note: The scan command will implicitly run the initialization process there are no policies found.

Customizing scans

By default, Terrascan scans your entire configuration against all policies. However, Terrascan supports granular configuration of policies and resources.

Read more about in-file instrumentation and the config file on our documentation site.

For now, some quick tips:

How to exclude a policy while scanning a resource

You can configure Terrascan to skip a particular policy (rule) while scanning a resource. Follow these steps depending on your platform:

Terraform

Use Terraform scripts to configure Terrascan to skip rules by inserting a comment with the phrase "ts:skip=<RULENAME><SKIP_REASON>". The comment should be included inside the resource as shown in the example below.

tf

Kubernetes

In Kubernetes yamls, you can configure Terrascan to skip policies by adding an annotation as seen in the snippet below.

k8s

How to include or exclude specific policies or resources from being scanned

Use the Terrascan config file to manually select the policies which should be included or excluded from the entire scan. This is suitable for edge use cases. Use the "in-file" suppression option to specify resources that should be excluded from being tested against selected policies. This ensures that the policies are skipped only for particular resources, rather than all of the resources.

config

Sample scan output

Terrascan's default output is a list of violations present in the scanned IaC. A sample output:

Screenshot 2021-01-19 at 10 52 47 PM

Building Terrascan

Terrascan can be built locally. This is helpful if you want to be on the latest version or when developing Terrascan.

$ git clone [email protected]:accurics/terrascan.git
$ cd terrascan
$ make build
$ ./bin/terrascan

To build your own docker, refer to this example (Alpine Linux):

FROM golang:alpine AS build-env

RUN apk add --update git

RUN git clone https://github.com/accurics/terrascan && cd terrascan \
  && CGO_ENABLED=0 GO111MODULE=on go build -o /go/bin/terrascan cmd/terrascan/main.go

Developing Terrascan

To learn more about developing and contributing to Terrascan refer to the contributing guide.

Code of Conduct

We believe having an open and inclusive community benefits all of us. Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

License

Terrascan is licensed under the Apache 2.0 License.

terrascan's People

Contributors

cesar-rodriguez avatar patilpankaj212 avatar pyup-bot avatar kanchwala-yusuf avatar amirbenv avatar harkirat22 avatar jjarboe avatar acc-jon avatar gaurav-gogia avatar dependabot[bot] avatar sbalbach avatar rchanger avatar jlk avatar horizonnet avatar zachzeid avatar shreyas-phansalkar-189 avatar kklin avatar chenrui333 avatar avanti19 avatar jdyke avatar rahulchheda avatar menzbua avatar matt-slalom avatar upa-acc avatar xortim avatar nasir-rabbani avatar lucas-giaco avatar gliptak avatar gauravgahlot avatar nathannaveen avatar

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.