kics icon indicating copy to clipboard operation
kics copied to clipboard

Support data sources for queries related with policies

Open cx-joao-reigota opened this issue 6 years ago • 1 comments

Expected Behavior

When Parsing a Terraform file with a policy it should be able to unmarshall the policy even if its given by a variable.

Actual Behavior

4:31PM | ERROR | inspector. query executed with error, query=assets\queries\terraform\aws\iam_role_with_full_privileges ERROR:"failed to evaluate query: assets\queries\terraform\aws\iam_role_with_full_privileges:5: eval_builtin_error: json.unmarshal: invalid character '$' looking for beginning of value" scanID:CONSOLE

Query fails since it isn't able to unmarshall the policy which after parsed stays this way :

"assume_role_policy":${data.aws_iam_policy_document.iam_policy_eks.json }

Using the example below.

(Other queries are not being executed for the same reason)

Steps to Reproduce the Problem

  1. Create a terraform file where the policy file is given by a variable ex: data aws_iam_policy_document "iam_policy_eks" { statement { effect = "Allow" actions = ["sts:AssumeRole"] principals { type = "Service" identifiers = ["eks.amazonaws.com"] } } }

    resource aws_iam_role "iam_for_eks" { name = "${local.resource_prefix.value}-iam-for-eks" assume_role_policy = data.aws_iam_policy_document.iam_policy_eks.json }

  2. Run the application specifying the -p flag with the path to the terraform file and using -v or -l flag to see the logs

Specifications

  • Platform: Terraform
  • Provider: AWS

cx-joao-reigota avatar Dec 03 '20 17:12 cx-joao-reigota

This will need more work, looking to implement this together with the evaluation of HCL functions

rogeriopeixotocx avatar May 26 '21 13:05 rogeriopeixotocx