tfsec

aquasecurityMIT更新放缓

静态扫描 Terraform 等基础设施即代码文件,提前发现云资源配置中的安全风险和合规问题,可接入 CI 流程。

Tfsec is now part of Trivy

v1.28.14发布于 2025-05-02 04:22 UTC7,061star +1 / 7 天559fork同步于 2026-11-10 17:34 UTC

怎么上手

由 README 提炼,执行前请确认
brew install tfsec
docker run --rm -it -v "$(pwd):/src" aquasec/tfsec /src
硬件要求按 README 说明

README 未说明,纯静态分析工具,无需 GPU

有 Docker 镜像
下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

静态扫描 Terraform 代码找出云资源配置中的安全隐患,现已并入 Trivy

静态扫描 Terraform 等基础设施即代码文件,提前发现云资源配置中的安全风险和合规问题,可接入 CI 流程。

核心能力

  • 内置数百条规则覆盖主流云厂商配置检查
  • 扫描本地与远程 Terraform 模块
  • 可求值 HCL 表达式、函数及资源间关系
  • 支持 Rego 自定义策略与多种输出格式
  • 可用 tfsec:ignore 注释按规则忽略告警

容易踩的坑

项目已并入 Trivy,官方后续工程投入转向 Trivy,新项目建议直接用 Trivy;用 go install 安装会直接取 master 分支且 --version 不显示版本号;扫描发现问题时退出码非零,接入 CI 需注意处理

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v1.28.14
  1. v1.28.14最新正式版2025-05-02 · 2025-05-02 04:22 UTC

    What's Changed

    New Contributors

    Full Changelog: https://github.com/aquasecurity/tfsec/compare/v1.28.13...v1.28.14

  2. v1.28.132025-01-11 · 2025-01-11 04:22 UTC
    查看更新说明

    Changelog

    • 1ade1215f chore(deps): bump github.com/go-git/go-git/v5 from 5.11.0 to 5.13.0 (#2164)
  3. v1.28.122025-01-03 · 2025-01-03 02:08 UTC
    查看更新说明

    Changelog

    • 7f016e798 CVE-2024-45337: Misuse of ServerConfig.PublicKeyCallback may cause authorization bypass (#2162)
  4. v1.28.112024-10-03 · 2024-10-03 17:59 UTC
    查看更新说明

    What's Changed

    Full Changelog: https://github.com/aquasecurity/tfsec/compare/v1.28.10...v1.28.11

  5. v1.28.102024-07-03 · 2024-07-03 00:05 UTC
    查看更新说明

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

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

    📣 tfsec 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, tfsec 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 tfsec 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 Aqua as well as by a the passionate Trivy community. tfsec will continue to remain available for the time being, although our engineering attention will be directed at Trivy going forward.

    tfsec to Trivy migration guide

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

    Overview

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

    Features

    • :cloud: Checks for misconfigurations across all major (and some minor) cloud providers
    • :no_entry: Hundreds of built-in rules
    • :nesting_dolls: Scans modules (local and remote)
    • :heavy_plus_sign: Evaluates HCL expressions as well as literal values
    • :arrow_right_hook: Evaluates Terraform functions e.g. concat()
    • :link: Evaluates relationships between Terraform resources
    • :toolbox: Compatible with the Terraform CDK
    • :no_good: Applies (and embellishes) user-defined Rego policies
    • :page_with_curl: Supports multiple output formats: lovely (default), JSON, SARIF, CSV, CheckStyle, JUnit, text, Gif.
    • :hammer_and_wrench: Configurable (via CLI flags and/or config file)
    • :zap: Very fast, capable of quickly scanning huge repositories
    • :electric_plug: Plugins for popular IDEs available (JetBrains, VSCode and Vim)
    • :house_with_garden: Community-driven - come and chat with us on Slack!

    Recommended by Thoughtworks

    Rated Adopt by the Thoughtworks Tech Radar:

    For our projects using Terraform, tfsec 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 tfsec could be a good addition to any Terraform project.

    Example Output

    Example screenshot

    Installation

    Install with brew/linuxbrew

    brew install tfsec
    

    Install with Chocolatey

    choco install tfsec
    

    Install with Scoop

    scoop install tfsec
    

    Bash script (Linux):

    curl -s https://raw.githubusercontent.com/aquasecurity/tfsec/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/aquasecurity/tfsec/cmd/tfsec@latest
    

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

    Signing

    The binaries on the releases page are signed with the tfsec signing key D66B222A3EA4C25D5D1A097FC34ACEFB46EC39CE

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

    Usage

    tfsec 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 tfsec finds problems, otherwise the exit status will be zero.

    tfsec .
    

    Use with Docker

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

    There are a number of Docker options available

    Image NameBaseComment
    aquasec/tfsecalpineNormal tfsec image
    aquasec/tfsec-alpinealpineExactly the same as aquasec/tfsec, but for those whole like to be explicit
    aquasec/tfsec-cialpinetfsec with no entrypoint - useful for CI builds where you want to override the command
    aquasec/tfsec-scratchscratchAn image built on scratch - nothing frilly, just runs tfsec

    To run:

    docker run --rm -it -v "$(pwd):/src" aquasec/tfsec /src
    

    Use with Visual Studio Code

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

    Use as GitHub Action

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

    Use as an Azure DevOps Pipelines Task

    You can now install the official tfsec 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 tfsec: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"] #tfsec:ignore:aws-vpc-no-public-ingress-sgr
    }
    

    ...or...

    resource "aws_security_group_rule" "my-rule" {
        type = "ingress"
        #tfsec: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 tfsec output for the line number of the discovered problem.

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

    #tfsec:ignore:aws-s3-enable-bucket-encryption tfsec: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.

    #tfsec: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

    tfsec . -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

    tfsec 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

    tfsec is designed for running in a CI pipeline. You may wish to run tfsec 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 tfsec 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 tfsec checks you can use the tfsec-sarif-action Github action to run the static analysis then upload the results to the security alerts tab.

    The alerts generated for tfsec-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 tfsec, 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.

    tfsec is an Aqua 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.