Skip to content

khulnasoft/tfsecurity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

51 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

GoReportCard Join Our Slack Docker Build Homebrew Chocolatey AUR version VScode Extension

πŸ“£ tfsecurity to Trivy Migration

As part of our goal to provide a comprehensive open source security solution for all, we have been consolidating all of our scanning-related efforts in one place, and that is Trivy.

Over the past year, tfsecurity has laid the foundations to Trivy's IaC & misconfigurations scanning capabilities, including Terraform scanning, which has been natively supported in Trivy for a long time now.

Going forward we want to encourage the tfsecurity community to transition over to Trivy. Moving to Trivy gives you the same excellent Terraform scanning engine, with some extra benefits:

  1. Access to more languages and features in the same tool.
  2. Access to more integrations with tools and services through the rich ecosystem around Trivy.
  3. Commercially supported by KhulnaSoft as well as by a the passionate Trivy community. tfsecurity will continue to remain available for the time being, although our engineering attention will be directed at Trivy going forward.

tfsecurity to Trivy migration guide

For further information on how Trivy compares to tfsecurity and moving from tfsecurity to Trivy, do have a look at the migration guide.

Overview

tfsecurity uses static analysis of your terraform code to spot potential misconfigurations.

Features

  • ☁️ Checks for misconfigurations across all major (and some minor) cloud providers
  • β›” Hundreds of built-in rules
  • πŸͺ† Scans modules (local and remote)
  • βž• Evaluates HCL expressions as well as literal values
  • β†ͺ️ Evaluates Terraform functions e.g. concat()
  • πŸ”— Evaluates relationships between Terraform resources
  • 🧰 Compatible with the Terraform CDK
  • πŸ™… Applies (and embellishes) user-defined Rego policies
  • πŸ“ƒ Supports multiple output formats: lovely (default), JSON, SARIF, CSV, CheckStyle, JUnit, text, Gif.
  • πŸ› οΈ Configurable (via CLI flags and/or config file)
  • ⚑ Very fast, capable of quickly scanning huge repositories
  • πŸ”Œ Plugins for popular IDEs available (JetBrains, VSCode and Vim)
  • 🏑 Community-driven - come and chat with us on Slack!

Recommended by Thoughtworks

Rated Adopt by the Thoughtworks Tech Radar:

For our projects using Terraform, tfsecurity has quickly become a default static analysis tool to detect potential security risks. It's easy to integrate into a CI pipeline and has a growing library of checks against all of the major cloud providers and platforms like Kubernetes. Given its ease of use, we believe tfsecurity could be a good addition to any Terraform project.

Example Output

Example screenshot

Installation

Install with brew/linuxbrew

brew install tfsecurity

Install with Chocolatey

choco install tfsecurity

Install with Scoop

scoop install tfsecurity

Bash script (Linux):

curl -s https://raw.githubusercontent.com/khulnasoft/tfsecurity/master/scripts/install_linux.sh | bash

You can also grab the binary for your system from the releases page.

Alternatively, install with Go:

go install github.com/khulnasoft/tfsecurity/cmd/tfsecurity@latest

Please note that using go install will install directly from the master branch and version numbers will not be reported via tfsecurity --version.

Signing

The binaries on the releases page are signed with the tfsecurity signing key CF64D06A1E6F774769DF7F4F612D823DECB96A43

Form more information check the signing page for instructions on verification.

Usage

tfsecurity will scan the specified directory. If no directory is specified, the current working directory will be used.

The exit status will be non-zero if tfsecurity finds problems, otherwise the exit status will be zero.

tfsecurity .

Use with Docker

As an alternative to installing and running tfsecurity on your system, you may run tfsecurity in a Docker container.

There are a number of Docker options available

Image Name Base Comment
khulnasoft/tfsecurity alpine Normal tfsecurity image
khulnasoft/tfsecurity-alpine alpine Exactly the same as khulnasoft/tfsecurity, but for those whole like to be explicit
khulnasoft/tfsecurity-ci alpine tfsecurity with no entrypoint - useful for CI builds where you want to override the command
khulnasoft/tfsecurity-scratch scratch An image built on scratch - nothing frilly, just runs tfsecurity

To run:

docker run --rm -it -v "$(pwd):/src" khulnasoft/tfsecurity /src

Use with Visual Studio Code

A Visual Studio Code extension is being developed to integrate with tfsecurity results. More information can be found on the tfsecurity Marketplace page

Use as GitHub Action

If you want to run tfsecurity on your repository as a GitHub Action, you can use https://github.com/khulnasoft/tfsecurity-pr-commenter-action.

Use as an Azure DevOps Pipelines Task

You can now install the official tfsecurity task. Please raise any issues/feature requests on the task repository.

Ignoring Warnings

You may wish to ignore some warnings. If you'd like to do so, you can simply add a comment containing tfsecurity:ignore:<rule> to the offending line in your templates. Alternatively, you can add the comment to the line above the block containing the issue, or to the module block to ignore all occurrences of an issue inside the module.

For example, to ignore an open security group rule:

resource "aws_security_group_rule" "my-rule" {
    type = "ingress"
    cidr_blocks = ["0.0.0.0/0"] #tfsecurity:ignore:aws-vpc-no-public-ingress-sgr
}

...or...

resource "aws_security_group_rule" "my-rule" {
    type = "ingress"
    #tfsecurity:ignore:aws-vpc-no-public-ingress-sgr
    cidr_blocks = ["0.0.0.0/0"]
}

If you're not sure which line to add the comment on, just check the tfsecurity output for the line number of the discovered problem.

You can ignore multiple rules by concatenating the rules on a single line:

#tfsecurity:ignore:aws-s3-enable-bucket-encryption tfsecurity:ignore:aws-s3-enable-bucket-logging
resource "aws_s3_bucket" "my-bucket" {
  bucket = "foobar"
  acl    = "private"
}

Expiration Date

You can set expiration date for ignore with yyyy-mm-dd format. This is a useful feature when you want to ensure ignored issue won't be forgotten and should be revisited in the future.

#tfsecurity:ignore:aws-s3-enable-bucket-encryption:exp:2025-01-02

Ignore like this will be active only till 2025-01-02, after this date it will be deactivated.

Disable checks

You may wish to exclude some checks from running. If you'd like to do so, you can simply add new argument -e check1,check2,etc to your cmd command

tfsecurity . -e general-secrets-sensitive-in-variable,google-compute-disk-encryption-customer-keys

Including values from .tfvars

You can include values from a tfvars file in the scan, using, for example: --tfvars-file terraform.tfvars.

Included Checks

tfsecurity supports many popular cloud and platform providers

Checks
AWS Checks
Azure Checks
GCP Checks
CloudStack Checks
DigitalOcean Checks
GitHub Checks
Kubernetes Checks
OpenStack Checks
Oracle Checks

Running in CI

tfsecurity is designed for running in a CI pipeline. You may wish to run tfsecurity as part of your build without coloured output. You can do this using --no-colour (or --no-color for our American friends).

Output options

You can output tfsecurity results as JSON, CSV, Checkstyle, Sarif, JUnit or just plain old human-readable format. Use the --format flag to specify your desired format.

GitHub Security Alerts

If you want to integrate with Github Security alerts and include the output of your tfsecurity checks you can use the tfsecurity-sarif-action Github action to run the static analysis then upload the results to the security alerts tab.

The alerts generated for tfsecurity-example-project look like this.

github security alerts

When you click through the alerts for the branch, you get more information about the actual issue.

github security alerts

For more information about adding security alerts, check the GitHub documentation

Support for older terraform versions

If you need to support versions of terraform which use HCL v1 (terraform <0.12), you can use v0.1.3 of tfsecurity, though support is very limited and has fewer checks.

Contributing

We always welcome contributions; big or small, it can be documentation updates, adding new checks or something bigger. Please check the Contributing Guide for details on how to help out.

Some People who have contributed

Made with contributors-img.

tfsecurity is an KhulnaSoft Security open source project. Learn about our open source work and portfolio here. Join the community, and talk to us about any matter in GitHub Discussion or Slack.