Azure / Azure/Azure-Landing-Zones

Non Compliance message for kubernetes policies

Open
#491 5 comments 1 reaction 0 assignees View on GitHub
Transfer From: caf-enterprise-scale :arrow_right:
Dominant language
PowerShell
Stars
96
Forks
70
Avg merge
3d 1h
Merged PRs (30d)
7

Description

### Community Note

- Please vote on this issue by adding a 👍 [reaction](https://blog.github.com/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/) to the original issue to help the community and maintainers prioritize this request
- Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
- If you are interested in working on this issue or have submitted a pull request, please leave a comment

### Versions

**terraform**:2.239.1

**azure provider**:">= 3.0.2"

**module**:latest

### Description
While using the kubernetes policy https://www.azadvertizer.net/azpolicyadvertizer/1c6e92c9-99f0-4e55-9cf2-0c234dc48f99.html,
the module puts in a non complaint message which is not supported by the policy
+ non_compliance_message {
+ content = "This resource must be compliant with the assigned policy."
}
}

#### Describe the bug

As per the documentation and support **policy_non_compliance_message_not_supported_definitions** variable is to be used for skipping the list of policies that are to be excluded from the non complaint message. But the conditional block in **resources.policy_assignments.tf** checks for only **policy_non_compliance_message_enabled** and non_compliance_message_supported_policy_modes to assign compliance message. There is no way to override the **non_compliance_message_supported_policy_modes** for kubernetes as it is not defined as a variable in vars and any overriding from local to module too wont work. IN this case the **policy_non_compliance_message_not_supported_definitions** variable should be part of the conditional variable checking in the above code.

The dynamic code block for non compliance message says
dynamic "non_compliance_message" {
for_each = local.policy_non_compliance_message_enabled ? (contains(local.non_compliance_message_supported_policy_modes, lookup(local.all_policy_modes, each.value.template.properties.policyDefinitionId, local.policy_set_mode)) ? lookup(each.value.template.properties, "nonComplianceMessages", local.default_non_compliance_message_list) : local.empty_list) : local.empty_list
content {
content = replace(lookup(non_compliance_message.value, "message", local.policy_non_compliance_message_default), local.non_compliance_message_enforcement_mode_placeholder, each.value.enforcement_mode ? local.non_compliance_message_enforcement_mode_replacements.default : local.non_compliance_message_enforcement_mode_replacements.donotenforce)
policy_definition_reference_id = lookup(non_compliance_message.value, "policyDefinitionReferenceId", null)
}
}

#### Steps to Reproduce

1. Add the policy_non_compliance_message_not_supported_definitions in vars file
1

2. Call it in the main file to refer the variable
2

4. And the plan shows non compliant message to add and the apply fails

4
3

#### Screenshots

#### Additional context

Contributor guide

Open the contributing guide

Research direction

Start in resources.policy_assignments.tf and inspect the policy_non_compliance_message_not_supported_definitions variable alongside the non_compliance_message dynamic block. Reproduce the issue with the Kubernetes policy and a Terraform plan/apply; done means the unsupported non-compliance message is not added for that excluded policy.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, kubernetes, terraform
Domain
cloud, infrastructure, security
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.