runatlantis / atlantis

Terraform Pull Request Automation
https://www.runatlantis.io
Other
7.68k stars 1.05k forks source link

[Bug] unable to unmarshal conftest output or Anyone able to approve Atlantis policy failures #4243

Open kumaresh0 opened 7 months ago

kumaresh0 commented 7 months ago

Community Note


Overview of the Issue

  1. Anyone ( non policy owners ) able to approve Atlantis policy failures ( seems major bug ) I am using below server config with custom_policy_check: true & policy_check: true

  2. if I use custom_policy_check: flase & policy_check: true i get the unable to unmarshal conftest output error

But based on this documentation https://www.runatlantis.io/docs/policy-checking.html#step-2-define-the-policy-configuration we tried the config as i mentioned below

Reproduction Steps

Nothing special just used Alpine image and added the below server-side workflow and repo side workflow then triggered policy failure, if anyone comments the atlantis approve_policies policy failures are fixed with approval

Logs

Issue screen shot

image

Environment details

If not already included, please provide the following:

Atlantis server-side config file:

repos:
- id: "/.*/"
  branch: "/master/"
  pre_workflow_hooks:
    - description: Pull the Atlantis policies.
  post_workflow_hooks:
    - run: python3 /home/atlantis/review.py 
  allow_custom_workflows: false
  custom_policy_check: true
  policy_check: true
  allowed_overrides: [workflow, apply_requirements, delete_source_branch_on_merge]
  apply_requirements: [approved, mergeable]
  import_requirements: [approved, mergeable]

metrics:
  prometheus:
    endpoint: /metrics

policies:
    conftest_version: 0.45.0
    owners:
      users:
        - user1
        - user2
        - user3
    policy_sets:
        - name: audit_policy
          path: /home/atlantis/policy/security
          source: local
          approve_count: 2
          owners:
            users:
              - securityuser1
        - name: comman_policy
          path: /home/atlantis/policy/regula
          source: local

workflows:
  default:
    plan:
      steps:
      - init:
          extra_args: [ "-reconfigure"]
      - run: TF_WORKSPACE=$WORKSPACE tflint --config /home/atlantis/.tflint.hcl
      - plan
      - run: terraform$ATLANTIS_TERRAFORM_VERSION show -no-color -json $PLANFILE > tfplan.json
    apply:
      steps:
      - apply
    policy_check: &policy_check
      steps:
      - run: |
          aws sts get-caller-identity --output json | jq '{"aws": .}' | jq '{"external": .}' > external-data.json
      - run: conftest test tfplan.json --namespace main --namespace security -o table --policy /home/atlantis/policy -d external-data.json
    import:
      steps:
      - import

Repo atlantis.yaml file:

version: 3
automerge: true
delete_source_branch_on_merge: true

projects:
- name: test-case/default-workflow
  dir: test-case/default-workflow
  workspace: default
  autoplan:
    when_modified: ["*.tf", "../modules/**.tf", "Terrafile"]
    enabled: true
  workflow: default

Our Atlantis is deployed in ECS fargate with ghcr.io/runatlantis/atlantis:v0.27-alpine

Additional Context

kumaresh0 commented 6 months ago

similar issuer reported here : https://github.com/runatlantis/atlantis/issues/4308

kumaresh0 commented 6 months ago

Adding some update on this:

From console, i can see policy test results

example

Resources: {"aws_security_group.inline_invalid_security_group"}

4 tests, 2 passed, 0 warnings, 2 failures, 0 exceptions

But in PR it show unable to unmarshal conftest output and anyone able to approve the policy failures

image