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

Treat "remediate" stack policies as "mandatory" #339

Merged
merged 2 commits into from
Mar 7, 2024

Conversation

justinvp
Copy link
Member

@justinvp justinvp commented Mar 6, 2024

Stack policies cannot be remediated (resource policies can). And yet, it's possible to configure a policy pack such that all or certain policies have a certain enforcement level (enforcement levels can be configured externally, such as from a file or Pulumi Cloud). This means it's possible to specify an enforcement level of "remediate" for a stack policy, even though stack policies do not support being remediated.

Currently, if a stack policy has a level of "remediate" and a violation is reported, a panic occurs in the CLI.

This commit addresses this by treating stack policies with a level of "remediate" as "mandatory", similar to how "remediate" resource policies are treated as "mandatory" if the policy is still in violation after a remediation for the policy has run:

if (enforcementLevel === "remediate") {
// If we ran a remediation, but we are still somehow triggering a violation,
// "downgrade" the level we report from remediate to mandatory.
enforcementLevel = "mandatory";
}

if enforcement_level == EnforcementLevel.REMEDIATE:
# If we ran a remediation, but we are still somehow triggering a violation,
# "downgrade" the level we report from remediate to mandatory.
enforcement_level = EnforcementLevel.MANDATORY

Related: pulumi/pulumi#15618

Part of #332

justinvp added 2 commits March 6, 2024 14:34
Stack policies cannot be remediated (resource policies can). It's possible to configure a policy pack such that all or certain policies have a certain enforcement level. This means it's currently possible to specify an enforcement level of "remediate" for a stack policy even though stack policies do not support being remediated.

Currently, if a stack policy has a level of "remediate" and a violation is reported, a panic occurs in the CLI.

This commit addresses this by treating stack policies with a level of "remediate" as "mandatory", similar to how "remediate" resource policies are treated as "mandatory" if the policy is still in violation after a remediation has run.
@justinvp justinvp requested a review from a team March 6, 2024 23:10
@Frassle
Copy link
Member

Frassle commented Mar 7, 2024

I feel like this ought to have an engine side fix as well. If a stack policy can't be "remediate" the engine should auto-downgrade that as well.

@justinvp
Copy link
Member Author

justinvp commented Mar 7, 2024

@Frassle, here is the engine change: pulumi/pulumi#15618

github-merge-queue bot pushed a commit to pulumi/pulumi that referenced this pull request Mar 7, 2024
Policy violations should not have a remediate enforcement level. The
Policy SDK currently downgrades the level from remediate to mandatory
for resource policy violations, but isn't currently doing that for stack
policies. A change to the Policy SDK is in-progress to do that.

This change applies the same behavior to the engine. If a resource
policy still has a violation after running remediations and the level is
remediate, "downgrade" the level to mandatory. Similarly, if a stack
policy has a violation with a remediate level, downgrade it to
mandatory.

This avoids a panic when getting a policy violation from a stack policy
and the enforcement level is remediate.

Related: pulumi/pulumi-policy#339

Fixes pulumi/pulumi-policy#332
@justinvp justinvp merged commit be4ed4e into master Mar 7, 2024
5 checks passed
@justinvp justinvp deleted the justin/stack_remediate branch March 7, 2024 15:10
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.

2 participants