Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tflint to Terraform Lint, Add trivy workflow #74

Merged
merged 1 commit into from
Mar 11, 2023
Merged

Conversation

reedloden
Copy link
Contributor

@reedloden reedloden commented Feb 19, 2023

@reedloden reedloden self-assigned this Feb 19, 2023
@reedloden reedloden requested review from a team February 19, 2023 04:19
Copy link
Contributor

@wadells wadells left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of using trivy. I don't like the currently proposed rollout strategy. Per https://aquasecurity.github.io/trivy/v0.19.2/misconfiguration/comparison/tfsec/:

tfsec is designed for Terraform. People who use only Terraform should use tfsec. People who want to scan a wide range of configuration files should use Trivy.

This implies to me that trivy isn't a 1-1 replacement for tfsec, and may flag issues much more broadly than tfsec would. As such, I recommend put trivy in its own independent, new workflow, in parallel with the current tfsec workflow.

A separate workflow has the advantage of a staged rollout, where trivy can be enabled without being required immediately. This gives us a chance identify and address any new failures it reports without scatterblasting the actual work of trivy compliance onto unsuspecting employees who happen to touch the files next.

Once we're happy with Trivy, we can then remove tfsec.

.github/workflows/terraform-lint.yaml Outdated Show resolved Hide resolved
@reedloden
Copy link
Contributor Author

I like the idea of using trivy. I don't like the currently proposed rollout strategy. Per https://aquasecurity.github.io/trivy/v0.19.2/misconfiguration/comparison/tfsec/:

tfsec is designed for Terraform. People who use only Terraform should use tfsec. People who want to scan a wide range of configuration files should use Trivy.

My understanding is that this is outdated. They just announced two days ago that tfsec is deprecated and that everybody should move to trivy. See aquasecurity/tfsec#1994 (forgot to include this URL earlier).

As such, I recommend put trivy in its own independent, new workflow, in parallel with the current tfsec workflow.

A separate workflow has the advantage of a staged rollout, where trivy can be enabled without being required immediately. This gives us a chance identify and address any new failures it reports without scatterblasting the actual work of trivy compliance onto unsuspecting employees who happen to touch the files next.

Can definitely add it as a new workflow on cloud-terraform for testing for a bit. I don't think it's worth adding it in every repository that uses this shared workflow just for testing.

If it works the same way as tfsec, existing failures should be fine. It should only be complaining about new failures.

We've been having lots of issues with tfsec not catching stuff lately, so I'm hopeful that trivy will solve that. From the local testing I did, it does seem to correctly look into terraform modules and test things there as well, which is what we want.

@wadells
Copy link
Contributor

wadells commented Feb 20, 2023

Can definitely add it as a new workflow on cloud-terraform for testing for a bit. I don't think it's worth adding it in every repository that uses this shared workflow just for testing.

I care the most about teleport, cloud, cloud-terraform and github-terraform in that order. These are where blocking will have the most impact and thus where we should check with non-blocking trivvy before enabling enforcement.

If it works the same way as tfsec, existing failures should be fine. It should only be complaining about new failures.

It isn't the terraform I'm as worried about. It is the various other things that trivy lints that (afaik) have had little no prior linting. For instance, will it block PRs that touch non-compliant dockerfiles or helm charts? I know it should be ok if that infra is untouched, but I don't yet trust it to be smart enough to handle the various edge cases. I'd like to see it run for a week or two first before becoming blocking.

@wadells
Copy link
Contributor

wadells commented Feb 20, 2023

I care the most about teleport, cloud, cloud-terraform and github-terraform in that order. These are where blocking will have the most impact and thus where we should check with non-blocking trivvy before enabling enforcement.

Upon further investigation, it doesn't look like tfsec is enforced in teleport or cloud. This allays some of my worry, but also creates different ones. Especially for cloud this is surprising to me.

@jentfoo
Copy link
Contributor

jentfoo commented Feb 21, 2023

it doesn't look like tfsec is enforced in teleport or cloud

Does teleport have any HCL that needs enforcement? I did not notice any so it was not listed as needing to be included for tfsec.

cloud

It does look like requirements for cloud were missed somehow (my fault). I just submitted a PR to add these jobs as required: https://github.com/gravitational/github-terraform/pull/434 Thank you!

@adaadb6
Copy link
Contributor

adaadb6 commented Feb 21, 2023

Does teleport have any HCL that needs enforcement? I did not notice any so it was not listed as needing to be included for tfsec.

I'm assuming for the Terraform modules: https://github.com/gravitational/teleport/tree/master/examples/aws/terraform.

@jof jof force-pushed the reed/terraform-lint-v2 branch from ba35116 to edf4063 Compare March 3, 2023 23:16
@jof jof self-assigned this Mar 3, 2023
@jof
Copy link
Contributor

jof commented Mar 4, 2023

Test scan against gravitational/teleport: https://github.com/gravitational/teleport/actions/runs/4328529117/jobs/7558312852

@jof jof requested a review from wadells March 7, 2023 19:25
Copy link
Contributor

@wadells wadells left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this removes the tfsec job. We can't have tfsec required if we're going to remove it:

https://github.com/gravitational/github-terraform/search?q=terraform-lint+%2F+tfsec&type=code

I'd recommend we leave tfsec alone in this PR, and keep the changes purely additive. We can come back and remove tfsec later, once repos no longer rely on it. Right now if this merges, there will be a bunch of folks who are blocked -- unable to merge because an expected check isn't running.

@wadells
Copy link
Contributor

wadells commented Mar 8, 2023

Test scan against gravitational/teleport: https://github.com/gravitational/teleport/actions/runs/4328529117/jobs/7558312852

Can you also introduce a failure in a run? Our issue with tfsec was that it wasn't flagging errors. I'd like to see some confirmation that trivy won't commit similar type I errors.

Why do I say this? When I run trivy against teleport, I'm getting a range of high and critical errors in the repo. I know we won't detect latent stuff on PR runs, but I would like to make sure we detect new stuff.

Related: should we run a one-off sarif import of issues that trivy flags that are latent in the repo?

assets/backport/go.mod (gomod)

Total: 1 (UNKNOWN: 0, LOW: 0, MEDIUM: 0, HIGH: 1, CRITICAL: 0)

┌──────────────────┬────────────────┬──────────┬───────────────────────────────────┬───────────────────────────────────┬─────────────────────────────────────────────────────────┐
│     Library      │ Vulnerability  │ Severity │         Installed Version         │           Fixed Version           │                          Title                          │
├──────────────────┼────────────────┼──────────┼───────────────────────────────────┼───────────────────────────────────┼─────────────────────────────────────────────────────────┤
│ gopkg.in/yaml.v3 │ CVE-2022-28948 │ HIGH     │ 3.0.0-20200313102051-9f266ea9e77c │ 3.0.0-20220521103104-8f96da9f5d5e │ golang-gopkg-yaml: crash when attempting to deserialize │
│                  │                │          │                                   │                                   │ invalid input                                           │
│                  │                │          │                                   │                                   │ https://avd.aquasec.com/nvd/cve-2022-28948              │
└──────────────────┴────────────────┴──────────┴───────────────────────────────────┴───────────────────────────────────┴─────────────────────────────────────────────────────────┘

build.assets/tooling/go.mod (gomod)

Total: 5 (UNKNOWN: 0, LOW: 2, MEDIUM: 2, HIGH: 1, CRITICAL: 0)

┌───────────────────────────┬────────────────┬──────────┬───────────────────┬─────────────────────────────────────┬────────────────────────────────────────────────────────────┐
│          Library          │ Vulnerability  │ Severity │ Installed Version │            Fixed Version            │                           Title                            │
├───────────────────────────┼────────────────┼──────────┼───────────────────┼─────────────────────────────────────┼────────────────────────────────────────────────────────────┤
│ github.com/aws/aws-sdk-go │ CVE-2020-8911  │ MEDIUM   │ 1.44.47           │                                     │ aws/aws-sdk-go: CBC padding oracle issue in AWS S3 Crypto  │
│                           │                │          │                   │                                     │ SDK for golang...                                          │
│                           │                │          │                   │                                     │ https://avd.aquasec.com/nvd/cve-2020-8911                  │
│                           ├────────────────┼──────────┤                   ├─────────────────────────────────────┼────────────────────────────────────────────────────────────┤
│                           │ CVE-2020-8912  │ LOW      │                   │                                     │ aws-sdk-go: In-band key negotiation issue in AWS S3 Crypto │
│                           │                │          │                   │                                     │ SDK for golang...                                          │
│                           │                │          │                   │                                     │ https://avd.aquasec.com/nvd/cve-2020-8912                  │
├───────────────────────────┼────────────────┼──────────┼───────────────────┼─────────────────────────────────────┼────────────────────────────────────────────────────────────┤
│ golang.org/x/net          │ CVE-2022-41721 │ HIGH     │ 0.1.0             │ 0.1.1-0.20221104162952-702349b0e862 │ x/net/http2/h2c: request smuggling                         │
│                           │                │          │                   │                                     │ https://avd.aquasec.com/nvd/cve-2022-41721                 │
│                           ├────────────────┼──────────┤                   ├─────────────────────────────────────┼────────────────────────────────────────────────────────────┤
│                           │ CVE-2022-41717 │ MEDIUM   │                   │ 0.4.0                               │ golang: net/http: An attacker can cause excessive memory   │
│                           │                │          │                   │                                     │ growth in a Go...                                          │
│                           │                │          │                   │                                     │ https://avd.aquasec.com/nvd/cve-2022-41717                 │
│                           ├────────────────┼──────────┤                   ├─────────────────────────────────────┼────────────────────────────────────────────────────────────┤
│                           │ CVE-2022-41723 │ LOW      │                   │ 0.7.0                               │ A maliciously crafted HTTP/2 stream could cause excessive  │
│                           │                │          │                   │                                     │ CPU consumpt ...                                           │
│                           │                │          │                   │                                     │ https://avd.aquasec.com/nvd/cve-2022-41723                 │
└───────────────────────────┴────────────────┴──────────┴───────────────────┴─────────────────────────────────────┴────────────────────────────────────────────────────────────┘

examples/desktop-registration/go.mod (gomod)

Total: 1 (UNKNOWN: 0, LOW: 1, MEDIUM: 0, HIGH: 0, CRITICAL: 0)

┌──────────────────┬────────────────┬──────────┬───────────────────┬───────────────┬───────────────────────────────────────────────────────────┐
│     Library      │ Vulnerability  │ Severity │ Installed Version │ Fixed Version │                           Title                           │
├──────────────────┼────────────────┼──────────┼───────────────────┼───────────────┼───────────────────────────────────────────────────────────┤
│ golang.org/x/net │ CVE-2022-41723 │ LOW      │ 0.5.0             │ 0.7.0         │ A maliciously crafted HTTP/2 stream could cause excessive │
│                  │                │          │                   │               │ CPU consumpt ...                                          │
│                  │                │          │                   │               │ https://avd.aquasec.com/nvd/cve-2022-41723                │
└──────────────────┴────────────────┴──────────┴───────────────────┴───────────────┴───────────────────────────────────────────────────────────┘

go.mod (gomod)

Total: 2 (UNKNOWN: 0, LOW: 1, MEDIUM: 1, HIGH: 0, CRITICAL: 0)

┌───────────────────────────┬───────────────┬──────────┬───────────────────┬───────────────┬────────────────────────────────────────────────────────────┐
│          Library          │ Vulnerability │ Severity │ Installed Version │ Fixed Version │                           Title                            │
├───────────────────────────┼───────────────┼──────────┼───────────────────┼───────────────┼────────────────────────────────────────────────────────────┤
│ github.com/aws/aws-sdk-go │ CVE-2020-8911 │ MEDIUM   │ 1.44.210          │               │ aws/aws-sdk-go: CBC padding oracle issue in AWS S3 Crypto  │
│                           │               │          │                   │               │ SDK for golang...                                          │
│                           │               │          │                   │               │ https://avd.aquasec.com/nvd/cve-2020-8911                  │
│                           ├───────────────┼──────────┤                   ├───────────────┼────────────────────────────────────────────────────────────┤
│                           │ CVE-2020-8912 │ LOW      │                   │               │ aws-sdk-go: In-band key negotiation issue in AWS S3 Crypto │
│                           │               │          │                   │               │ SDK for golang...                                          │
│                           │               │          │                   │               │ https://avd.aquasec.com/nvd/cve-2020-8912                  │
└───────────────────────────┴───────────────┴──────────┴───────────────────┴───────────────┴────────────────────────────────────────────────────────────┘

yarn.lock (yarn)

Total: 7 (UNKNOWN: 0, LOW: 0, MEDIUM: 0, HIGH: 6, CRITICAL: 1)

┌──────────────┬────────────────┬──────────┬───────────────────┬─────────────────────┬──────────────────────────────────────────────────────────────┐
│   Library    │ Vulnerability  │ Severity │ Installed Version │    Fixed Version    │                            Title                             │
├──────────────┼────────────────┼──────────┼───────────────────┼─────────────────────┼──────────────────────────────────────────────────────────────┤
│ glob-parent  │ CVE-2020-28469 │ HIGH     │ 3.1.0             │ 5.1.2               │ nodejs-glob-parent: Regular expression denial of service     │
│              │                │          │                   │                     │ https://avd.aquasec.com/nvd/cve-2020-28469                   │
├──────────────┼────────────────┼──────────┼───────────────────┼─────────────────────┼──────────────────────────────────────────────────────────────┤
│ loader-utils │ CVE-2022-37601 │ CRITICAL │ 2.0.2             │ 1.4.1, 2.0.3        │ loader-utils: prototype pollution in function parseQuery in  │
│              │                │          │                   │                     │ parseQuery.js                                                │
│              │                │          │                   │                     │ https://avd.aquasec.com/nvd/cve-2022-37601                   │
│              ├────────────────┼──────────┤                   ├─────────────────────┼──────────────────────────────────────────────────────────────┤
│              │ CVE-2022-37599 │ HIGH     │                   │ 3.2.1, 2.0.4, 1.4.2 │ A Regular expression denial of service (ReDoS) flaw was      │
│              │                │          │                   │                     │ found in Funct...                                            │
│              │                │          │                   │                     │ https://avd.aquasec.com/nvd/cve-2022-37599                   │
│              ├────────────────┤          │                   │                     ├──────────────────────────────────────────────────────────────┤
│              │ CVE-2022-37603 │          │                   │                     │ loader-utils:Regular expression denial of service            │
│              │                │          │                   │                     │ https://avd.aquasec.com/nvd/cve-2022-37603                   │
├──────────────┼────────────────┤          ├───────────────────┼─────────────────────┼──────────────────────────────────────────────────────────────┤
│ minimatch    │ CVE-2022-3517  │          │ 3.0.4             │ 3.0.5               │ nodejs-minimatch: ReDoS via the braceExpand function         │
│              │                │          │                   │                     │ https://avd.aquasec.com/nvd/cve-2022-3517                    │
├──────────────┼────────────────┤          ├───────────────────┼─────────────────────┼──────────────────────────────────────────────────────────────┤
│ terser       │ CVE-2022-25858 │          │ 5.10.0            │ 5.14.2, 4.8.1       │ terser: insecure use of regular expressions leads to ReDoS   │
│              │                │          │                   │                     │ https://avd.aquasec.com/nvd/cve-2022-25858                   │
├──────────────┼────────────────┤          ├───────────────────┼─────────────────────┼──────────────────────────────────────────────────────────────┤
│ trim         │ CVE-2020-7753  │          │ 0.0.1             │ 0.0.3               │ nodejs-trim: Regular Expression Denial of Service (ReDoS) in │
│              │                │          │                   │                     │ trim function                                                │
│              │                │          │                   │                     │ https://avd.aquasec.com/nvd/cve-2020-7753                    │
└──────────────┴────────────────┴──────────┴───────────────────┴─────────────────────┴──────────────────────────────────────────────────────────────┘

...

For context -- it was errors like the above that trivy flags and tfsec doesn't that caused me to pump the breaks in #74 (review). Swapping from tfsec to trivy means this isn' a terraform specific check anymore. I'd recommend putting it in its own workflow file instead of nested under terraform-lint. Why would a terraform-lint check be nagging me about yarn.lock? Its a misnomer.

@jof jof force-pushed the reed/terraform-lint-v2 branch 4 times, most recently from 2dc132a to bb1ea08 Compare March 8, 2023 23:32
@jof jof force-pushed the reed/terraform-lint-v2 branch 2 times, most recently from 96e21a6 to 22a4a8a Compare March 9, 2023 22:18
@jof
Copy link
Contributor

jof commented Mar 9, 2023

Renamed as trivy in the workflow, as the scope of what this flags is much greater than just Terraform stuff.

I made some test runs against PRs in gravitational/cloud-terraform and gravitational/teleport. These workflows seem to work, but Trivy flags a whole bunch of latent issues, and also comments about things in PRs that weren't touched in the PR, which is a bit of a behavior change as compared to the aquasecurity/tfsec-pr-commenter-action Action.

I'm thinking that we should keep using a test branch like these testing PRs to see the latent issues, and then iterate on adding ignore lines or fixes to reduce the latent issue backlog.

We can also just land in this change which makes a bunch of findings in the Trivy workflow, then work repo by repo to apply the Workflow into the repo, and accept/wontfix the findings it generates. Then, at least, we can flag new issues reliably while still having a backlog of latent issues we can go back and address.

@jof jof requested a review from wadells March 9, 2023 23:23
@jof jof force-pushed the reed/terraform-lint-v2 branch from 22a4a8a to b6175a9 Compare March 10, 2023 00:15
@jof jof requested a review from a team March 10, 2023 21:41
@jof
Copy link
Contributor

jof commented Mar 10, 2023

I think this is in a mergable state where it sets up the workflow we can start pointing to, without changing downstream users of terraform-lint.yaml too much. However, this does add in tflint into the existing workflow.

Once merged, we can then work, repo-by-repo in increasing order of visibility/impact/publicness to add this new workflow, triage the findings and set that state in GitHub, and then once in a good and steady state, set this new workflow as a requirement before merging.

@jof jof changed the title Update Terraform Lint to use tflint and trivy Add tflint to Terraform Lint, Add trivy workflow Mar 10, 2023
Copy link
Contributor

@wadells wadells left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, this does add in tflint into the existing workflow.

No concerns here. Thanks for adding it.

@jof jof merged commit 9fcbac6 into main Mar 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants