Open trevorvoncannon opened 1 year ago
I noticed this recently as well. The worst part about it is that anyone could be having this issue and they will just assume everything is fine because the tfsec check passes and we trust it.
Looked into this a little more today and was able to pull out the error that is triggering the ignore statement:
Here is the results.json file and the errors:
{
"results": [
{
"rule_id": "AVD-AWS-0099",
"long_id": "aws-ec2-add-description-to-security-group",
"rule_description": "Missing description for security group.",
"rule_provider": "aws",
"rule_service": "ec2",
"impact": "Descriptions provide context for the firewall rule reasons",
"resolution": "Add descriptions for all security groups",
"links": [
"https://aquasecurity.github.io/tfsec/v1.28.1/checks/aws/ec2/add-description-to-security-group/",
"https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group",
"https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule"
],
"description": "Security group explicitly uses the default description.",
"severity": "LOW",
"warning": false,
"status": 0,
"resource": "aws_security_group.terratest-sg",
"location": {
"filename": "/github/workspace/terratest-poc/main.tf",
"start_line": 9,
"end_line": 18
}
},
{
"rule_id": "AVD-AWS-0124",
"long_id": "aws-ec2-add-description-to-security-group-rule",
"rule_description": "Missing description for security group rule.",
"rule_provider": "aws",
"rule_service": "ec2",
"impact": "Descriptions provide context for the firewall rule reasons",
"resolution": "Add descriptions for all security groups rules",
"links": [
"https://aquasecurity.github.io/tfsec/v1.28.1/checks/aws/ec2/add-description-to-security-group-rule/",
"https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group",
"https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule"
],
"description": "Security group rule does not have a description.",
"severity": "LOW",
"warning": false,
"status": 0,
"resource": "aws_security_group.terratest-sg",
"location": {
"filename": "/github/workspace/terratest-poc/main.tf",
"start_line": 12,
"end_line": 17
}
},
{
"rule_id": "AVD-AWS-0131",
"long_id": "aws-ec2-enable-at-rest-encryption",
"rule_description": "Instance with unencrypted block device.",
"rule_provider": "aws",
"rule_service": "ec2",
"impact": "The block device could be compromised and read from",
"resolution": "Turn on encryption for all block devices",
"links": [
"https://aquasecurity.github.io/tfsec/v1.28.1/checks/aws/ec2/enable-at-rest-encryption/",
"https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/instance#ebs-ephemeral-and-root-block-devices"
],
"description": "Root block device is not encrypted.",
"severity": "HIGH",
"warning": false,
"status": 0,
"resource": "aws_instance.terratest-ec2-instance",
"location": {
"filename": "/github/workspace/terratest-poc/main.tf",
"start_line": 1,
"end_line": 7
}
},
{
"rule_id": "AVD-AWS-0028",
"long_id": "aws-ec2-enforce-http-token-imds",
"rule_description": "aws_instance should activate session tokens for Instance Metadata Service.",
"rule_provider": "aws",
"rule_service": "ec2",
"impact": "Instance metadata service can be interacted with freely",
"resolution": "Enable HTTP token requirement for IMDS",
"links": [
"https://aquasecurity.github.io/tfsec/v1.28.1/checks/aws/ec2/enforce-http-token-imds/",
"https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/instance#metadata-options"
],
"description": "Instance does not require IMDS access to require a token",
"severity": "HIGH",
"warning": false,
"status": 0,
"resource": "aws_instance.terratest-ec2-instance",
"location": {
"filename": "/github/workspace/terratest-poc/main.tf",
"start_line": 1,
"end_line": 7
}
}
]
}
starting the github commenter Working in repository terraform Working in PR 1337 TFSec found 4 issues Working in GITHUB_WORKSPACE /github/workspace/ Preparing comment for violation of rule aws-ec2-add-description-to-security-group in terratest-poc/terratest-poc/main.tf There is nothing to comment on at line [9] in file [terratest-poc/terratest-poc/main.tf] Preparing comment for violation of rule aws-ec2-add-description-to-security-group-rule in terratest-poc/terratest-poc/main.tf There is nothing to comment on at line [12] in file [terratest-poc/terratest-poc/main.tf] Preparing comment for violation of rule aws-ec2-enable-at-rest-encryption in terratest-poc/terratest-poc/main.tf There is nothing to comment on at line [1] in file [terratest-poc/terratest-poc/main.tf] Preparing comment for violation of rule aws-ec2-enforce-http-token-imds in terratest-poc/terratest-poc/main.tf There is nothing to comment on at line [1] in file [terratest-poc/terratest-poc/main.tf]
I'm seeing the same error, and to my horror realised recently it's been happening silently for a while and I've just been assuming all is good with the sec scan!
+1
any updates on this?
just add working_directory empty:
- name: tfsec
uses: aquasecurity/tfsec-pr-commenter-action@main
with:
working_directory: ''
This works for me!
I was also facing the same issue.
Thanks @mario-fernandez-mm , it seems that adding an empty working_directory does works.
The suggested fix of adding a blank working_directory
doesn't work when using --force-all-dirs
.
@sysophost It seems to be working with --force-all-dirs
with my setup. I already have --force-all-dirs
in my workflow.
@mandeeps13k I'm still getting the behaviour described by the OP.
Starting the github commenter
Working in repository my-repo
Working in PR 12
TFSec found 1 issues
Working in GITHUB_WORKSPACE /github/workspace/
Preparing comment for violation of rule custom-custom-001 in modules/security_group/rules.tf
Ignoring - change not part of the current PR
With this action definition
name: Run tfsec and comment on PR
on:
- pull_request
jobs:
tfsec:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.ref }}
- name: tfsec
uses: aquasecurity/tfsec-pr-commenter-action@main
with:
github_token: ${{ github.token }}
working_directory: ''
tfsec_args: --concise-output --config-file=.tfsec.yml --custom-check-dir=.tfsec --force-all-dirs
.tfsec.yml
contains a few entries in the exclude
block. There is a single custom rule in .tfsec
which is the rule that is being picked up for violation (custom-custom-001
).
I am seeing the same issue,
I checked the code and the problem is related with commenter. Commenter checks if the comment line fits the changed lines. If the changed file contains multiple changed locations (ie changes -> from line 3 to line 10 and line 20 to line 30) commenter only checks the first hunk. And the tfsec problem is in between line 20 and line 30 it throws the exception Ignoring - change not part of the current PR
If you fix this that would be awesome.
@sysophost @ahmetrehaseker
What version of the tfsec-commenter-action are you guys using?
Try forcing the use of the 1.2.0
version, it might solve this problem.
A similar error was described here.
Thanks for the suggestion @saerosV, I had tried pinning to an older version but was getting the same behaviour. I think my issue comes from the fact I'm creating a resource from a module where the templated module is not being changed in the PR, just the place where it's instantiated.
Preparing comment for violation of rule custom-001 in modules/security_group/rules.tf
Ignoring - change not part of the current PR
In this case my tf is in a totally separate dir to the module, but as the resource is referencing the template in modules
I assume it's being treated as a resource that is actually created in the modules
dir rather than the dir where I'm creating an instance of the module.
@sysophost @ahmetrehaseker
What version of the tfsec-commenter-action are you guys using?
Try forcing the use of the
1.2.0
version, it might solve this problem.A similar error was described here.
I did not test with that version but checked out the repo and debugged it myself, the problem is with the library you are using for commenting on the pr, as I wrote in the comment if you have multiple changed parts in the file library only checks for first hunk and ignores the other changes because of that return change is not part of the current PR
I created an issue for that repository Issue
Having the same this issue here. Certainly was working on these files in my PR.
Starting the github commenter
Working in repository terraform-modules
Working in PR 18
TFSec found 108 issues
Working in GITHUB_WORKSPACE /github/workspace/
Preparing comment for violation of rule aws-iam-no-policy-wildcards in ./global/iam/iam_groups/main.tf
Ignoring - change not part of the current PR
Preparing comment for violation of rule aws-iam-no-policy-wildcards in ./global/iam/iam_groups/main.tf
Ignoring - change not part of the current PR
Preparing comment for violation of rule aws-iam-no-policy-wildcards in ./global/iam/iam_groups/main.tf
Ignoring - change not part of the current PR
Preparing comment for violation of rule aws-iam-no-policy-wildcards in ./global/iam/iam_groups/main.tf
Ignoring - change not part of the current PR
Preparing comment for violation of rule aws-iam-no-policy-wildcards in ./global/iam/iam_groups/main.tf
Ignoring - change not part of the current PR
My actions file:
- name: Run tfsec and write pull request comments
uses: aquasecurity/tfsec-pr-commenter-action@main
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
tfsec_args: --force-all-dirs
I am also having this issue on v1.3.1. My workflow:
name: tfsec
on:
pull_request:
paths:
- 'terraform/modules/**'
workflow_dispatch:
inputs:
environment:
description: 'Environment'
required: true
default: 'dev'
type: choice
options:
- dev
- staging
- preprod
refToBuild:
description: 'Branch, tag or commit SHA1 to build (default HEAD)'
required: false
default: ""
type: string
jobs:
tfsec:
name: tfsec PR commenter
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Clone repo
uses: actions/checkout@v3
- name: tfsec
uses: aquasecurity/tfsec-pr-commenter-action@v1.3.1
with:
github_token: ${{ github.token }}
working_directory: terraform/modules
I downgraded to v1.2.0 and still got this error.
+1
I am also experiencing this issue, even when using the --no-ignores
argument.
+1
+1
+1
+1
similar issue here I did changes to test it , it recognize the "error" in the change but say that it does not belong to PR , when it does.
`name: tfsec-pr-commenter
on:
pull_request:
permissions:
pull-requests: write
actions: write
contents: write
id-token: write
jobs:
tfsec:
name: tfsec PR commenter
runs-on: ubuntu-latest
steps:
- name: Clone repo
uses: actions/checkout@v3
- name: tfsec
uses: aquasecurity/tfsec-pr-commenter-action@v1.2.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
tfsec_args: --force-all-dirs`
just add working_directory empty:
- name: tfsec uses: aquasecurity/tfsec-pr-commenter-action@main with: working_directory: ''
This works for me!
Thank you so much. Its save me week
Also hitting this issue. A fix has been suggested on the commenter action that is used but has not yet been merged https://github.com/owenrumney/go-github-pr-commenter/issues/14
The repository go-github-pr-commenter
has been archived :(
I have a workflow (below) that correctly parses my .tf files in a PR, but never actually comments on it. Already looked into permissions issues - no problem here. I have also cycle through various arguments to see if they would yield the result I wanted, but again I've had no luck.
I just get this output at the end of my run
I can see where this error is coming from, but I am not able to see what the exact issue with the results.json file is.
Action command output
Based on this, it looks like there is an issue with my PR and the results.json file syncing up