aquasecurity/tfsec

GitHub: aquasecurity/tfsec

Tfsec 是一款针对 Terraform 的静态安全扫描工具,现已并入 Trivy,提供规则驱动的配置合规检查。

Stars: 6983 | Forks: 557

[![GoReportCard](https://goreportcard.com/badge/github.com/aquasecurity/tfsec)](https://goreportcard.com/report/github.com/aquasecurity/tfsec) [![Join Our Slack](https://img.shields.io/badge/Slack-Join-green)](https://slack.aquasec.com/) [![Docker Build](https://img.shields.io/docker/v/tfsec/tfsec?label=docker)](https://hub.docker.com/r/tfsec/tfsec) [![Homebrew](https://img.shields.io/badge/dynamic/json.svg?url=https://formulae.brew.sh/api/formula/tfsec.json&query=$.versions.stable&label=homebrew)](https://formulae.brew.sh/formula/tfsec) [![Chocolatey](https://img.shields.io/chocolatey/v/tfsec)](https://chocolatey.org/packages/tfsec) [![AUR version](https://img.shields.io/aur/version/tfsec-bin)](https://aur.archlinux.org/packages/tfsec-bin) [![VScode Extension](https://img.shields.io/visual-studio-marketplace/v/tfsec.tfsec?label=vscode)](https://marketplace.visualstudio.com/items?itemName=tfsec.tfsec) ## 📣 tfsec 到 Trivy 迁移 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](https://github.com/aquasecurity/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 到 Trivy 迁移指南 For further information on how Trivy compares to tfsec and moving from tfsec to Trivy, do have a look at the [migration guide.](https://github.com/aquasecurity/tfsec/blob/master/tfsec-to-trivy-migration-guide.md) ## 概述 tfsec uses static analysis of your terraform code to spot potential misconfigurations. ### 功能 - :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](https://plugins.jetbrains.com/plugin/18687-tfsec-findings-explorer), [VSCode](https://marketplace.visualstudio.com/items?itemName=tfsec.tfsec) and [Vim](https://github.com/aquasecurity/vim-tfsec)) - :house_with_garden: Community-driven - come and chat with us [on Slack](https://slack.aquasec.com/)! ## Thoughtworks 推荐 Rated _Adopt_ by the [Thoughtworks Tech Radar](https://www.thoughtworks.com/en-gb/radar/tools/tfsec): ## 示例输出 ![Example screenshot](https://static.pigsec.cn/wp-content/uploads/repos/2026/04/02a47bacdb184917.png) ## 安装 Install with [brew/linuxbrew](https://brew.sh) ``` brew install tfsec ``` Install with [Chocolatey](https://chocolatey.org/) ``` choco install tfsec ``` Install with [Scoop](https://scoop.sh/) ``` 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](https://github.com/aquasecurity/tfsec/releases). 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`. ### 签名 The binaries on the [releases page](https://github.com/aquasecurity/tfsec/releases) are signed with the tfsec signing key `D66B222A3EA4C25D5D1A097FC34ACEFB46EC39CE` Form more information check the [signing page](SIGNING.md) for instructions on verification. ## 用法 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 . ``` ## 与 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 Name | Base | Comment | |------------|------|---------| |[aquasec/tfsec](https://hub.docker.com/r/aquasec/tfsec)|alpine|Normal tfsec image| |[aquasec/tfsec-alpine](https://hub.docker.com/r/aquasec/tfsec-alpine)|alpine|Exactly the same as aquasec/tfsec, but for those whole like to be explicit| |[aquasec/tfsec-ci](https://hub.docker.com/r/aquasec/tfsec-ci)|alpine|tfsec with no entrypoint - useful for CI builds where you want to override the command| |[aquasec/tfsec-scratch](https://hub.docker.com/r/aquasec/tfsec-scratch)|scratch|An image built on scratch - nothing frilly, just runs tfsec| To run: ``` docker run --rm -it -v "$(pwd):/src" aquasec/tfsec /src ``` ## 与 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](https://marketplace.visualstudio.com/items?itemName=tfsec.tfsec) ## 作为 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](https://github.com/aquasecurity/tfsec-pr-commenter-action). ## 作为 Azure DevOps 管道任务使用 You can now install the [official tfsec task](https://marketplace.visualstudio.com/items?itemName=AquaSecurityOfficial.tfsec-official). Please raise any issues/feature requests on the [task repository](https://github.com/aquasecurity/tfsec-azure-pipelines-task). ## 忽略警告 You may wish to ignore some warnings. If you'd like to do so, you can simply add a comment containing `tfsec:ignore:` 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" } ``` ### 过期日期 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. ## 禁用检查 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 ``` ## 包含 .tfvars 中的值 You can include values from a tfvars file in the scan, using, for example: `--tfvars-file terraform.tfvars`. ## 包含的检查 tfsec supports many popular cloud and platform providers | Checks | |:----------------------------------------------------------------------------------------| | [AWS Checks](https://aquasecurity.github.io/tfsec/latest/checks/aws/) | | [Azure Checks](https://aquasecurity.github.io/tfsec/latest/checks/azure/) | | [GCP Checks](https://aquasecurity.github.io/tfsec/latest/checks/google/) | | [CloudStack Checks](https://aquasecurity.github.io/tfsec/latest/checks/cloudstack/) | | [DigitalOcean Checks](https://aquasecurity.github.io/tfsec/latest/checks/digitalocean/) | | [GitHub Checks](https://aquasecurity.github.io/tfsec/latest/checks/github/) | | [Kubernetes Checks](https://aquasecurity.github.io/tfsec/latest/checks/kubernetes/) | | [OpenStack Checks](https://aquasecurity.github.io/tfsec/latest/checks/openstack/) | | [Oracle Checks](https://aquasecurity.github.io/tfsec/latest/checks/oracle/) | ## 在 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). ## 输出选项 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 安全警报 If you want to integrate with Github Security alerts and include the output of your tfsec checks you can use the [tfsec-sarif-action](https://github.com/marketplace/actions/run-tfsec-with-sarif-upload) Github action to run the static analysis then upload the results to the security alerts tab. The alerts generated for [tfsec-example-project](https://github.com/tfsec/tfsec-example-project) look like this. ![github security alerts](https://static.pigsec.cn/wp-content/uploads/repos/2026/04/122f124895184918.png) When you click through the alerts for the branch, you get more information about the actual issue. ![github security alerts](https://static.pigsec.cn/wp-content/uploads/repos/2026/04/567c83f443184919.png) For more information about adding security alerts, check [the GitHub documentation](https://docs.github.com/en/code-security/repository-security-advisories/about-github-security-advisories-for-repositories) ## 对旧版本 Terraform 的支持 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. ### 一些贡献者 Made with [contributors-img](https://contrib.rocks). `tfsec` is an [Aqua Security](https://aquasec.com) open source project. Learn about our open source work and portfolio [here](https://www.aquasec.com/products/open-source-projects/). Join the community, and talk to us about any matter in [GitHub Discussion](https://github.com/aquasecurity/tfsec/discussions) or [Slack](https://slack.aquasec.com).
标签:AUR, Chocolatey, DevSecOps, Docker, EVTX分析, Go 语言, Homebrew, IaC 安全, SAST, TCP/UDP协议, Terraform 扫描, Tfsec, VS Code 扩展, Web截图, 上游代理, 商业支持, 安全防御评估, 容器安全, 开源安全工具, 日志审计, 生态整合, 盲注攻击, 请求拦截, 迁移, 逆向工程平台, 静态应用安全测试