Azure / ResourceModules

This repository includes a CI platform for and collection of mature and curated Bicep modules. The platform supports both ARM and Bicep and can be leveraged using GitHub actions as well as Azure DevOps pipelines.
https://aka.ms/carml
MIT License
726 stars 457 forks source link

[Feature Request]: Integrate PSRule PoC #2026

Closed eriqua closed 1 year ago

eriqua commented 2 years ago

Description

Related issues #1186 #1580

Leveraging this issue as a starting point for a PoC to integrate PSRule with the CARML CI environment pipelines. The goal is to enable and test it for at least 3 modules already converted to the new dependencies approach (see issue #1791)

Workstreams and goals

Pre-flight - Test before resources are deployed from templates.

The goals of this workstream are:

Stretch goals

Cross platform

Custom rules

In-flight

References

eriqua commented 2 years ago

Day 1

Challenges

  1. Token replacement: needs to run before the PSRule check, otherwise rules checking correct naming will fail. Token <<namePrefix>> is seen as an intended parameter value and normally not compliant with any resource name.
    1. Group 1 implemented and integrated a fix in the ResourceGroup workflow.
    2. PR merged to the dev branch #2068
  2. Run subset of rules: how to exclude specific rules from the default baseline?
    1. Group 2 looked into customizing general settings in ps-rule.yaml. Here we can ignore specific files/patterns, add exclusion of specific rules, add suppression of specific rules for specific resources. Tested in the KeyVault workflow.
    2. PR merged to the dev branch #2067

PSRule feedback

Start collecting possible feedback to discuss with the PSRule team:

Next steps

eriqua commented 2 years ago

Day 2

Ref Vnet Workflow run

PSRule feedback

Next steps

eriqua commented 2 years ago

Day 3

Ref #2094 running on pull request

PSRule feedback

Next steps

eriqua commented 2 years ago

Day 4

Ref Vnet run workflow

PSRule feedback

Next steps

eriqua commented 2 years ago

Failing rules and target resources before adding suppression groups:

image

Next steps

BernieWhite commented 2 years ago

Logs show a WARNING: Target object 'modules/Microsoft.Resources/resourceGroups/.test/common/deploy.test.bicep' has not been processed because no matching rules were found. although the file is then checked successfully

Currently this is by design, although we are aware that it is a common point of confusion and may change this behvaiour for PSRule v3. microsoft/PSRule#1179

However you can disable this warning by setting Execution.NotProcessedWarning.

https://microsoft.github.io/PSRule/v2/concepts/PSRule/en-US/about_PSRule_Options/#executionnotprocessedwarning

BernieWhite commented 2 years ago

PSRule VSC extension: cannot be used due to tokenized parameters.

Interested in finding more about this one.

BernieWhite commented 2 years ago

SuppressionGroups do not allow the use of wildcards for rule names Example: skip Azure.KeyVault.*

Interested in more detail about this or a feature request.

AlexanderSehr commented 1 year ago

Can be closed in favor of #2151 . Next steps such as the ADO extension should be adressed seperatly as we're blocked until that becomes available.