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

Include local not automatically being enabled for default module baseline #1506

Closed
BernieWhite opened this issue Apr 22, 2023 · 3 comments · Fixed by #1545
Closed

Include local not automatically being enabled for default module baseline #1506

BernieWhite opened this issue Apr 22, 2023 · 3 comments · Fixed by #1545
Assignees
Labels
bug Something isn't working feature: baselines Issues that affect baselines
Milestone

Comments

@BernieWhite
Copy link
Member

Description of the issue

When using a module, if the module specifies a default baseline local rules should automatically be included based on the principal of least surprise (Customers would expect local rules to be automatically processed).

However currently when using a module such as PSRule for Azure which specifies a default baseline, local rules are not automatically included.

Local rules are included when the Rule.IncludeLocal option is explicitly set to true.

Additional context

Related to discussion here #1504.

@BernieWhite BernieWhite added bug Something isn't working feature: baselines Issues that affect baselines labels Apr 22, 2023
@tstooke
Copy link

tstooke commented Apr 24, 2023

When we do not add Rules.IncludeLocal to the options, we have found that adding the GA tag to our custom rules does allow them to show up in the assertion run. Since we're not explicitly setting the baseline in the assertion run, this seems to be counter to the documentation for PSRule.Rules.Azure, which mentions "When you specify a baseline...."

image

Based on that statement, we would expect our custom rules to be included because we're not specifying a baseline in the command. We're letting the Module select the Azure.Default baseline for us.

So, to get our custom rules included when using a module, we either need to tag all of our custom rules so that they match the default baseline in the module, or we need to include Rules.IncludeLocal in the options for the assertion run. Of course, it would be great to get an update to have custom rules included automatically when not explicitly selecting a baseline.

@BernieWhite
Copy link
Member Author

@tstooke Looking at this issue. Testing locally, trying to reproduce.

Are you able to advise if you have any configuration set within ps-rule.yaml under the rule: option except for the previously mentioned Rule.IncludeLocal option. Such as Rule.Include?

@tstooke
Copy link

tstooke commented May 2, 2023

@BernieWhite We do have a handful of Azure rules listed under Rule.Exclude. Here's our ps-rule.yaml file (shortened list of exclusions).

# Require minimum versions of modules.
requires:
  PSRule: '>=2.8.1'
  PSRule.Rules.Azure: '>=1.26.1'

output:
  culture:
    - 'en-US'

binding:
  targetType:
    - 'resourceType'
    - 'type'

rule:
  exclude:
  - Azure.Resource.UseTags
  - Azure.Redis.MinSku
  # others, as well

When we execute Assert-PSRule, we have the following in a PS script:

$config = @{
    AZURE_BICEP_FILE_EXPANSION = $True
    AZURE_BICEP_CHECK_TOOL = $True
    AZURE_BICEP_MINIMUM_VERSION = "0.16.2"
    AZURE_BICEP_FILE_EXPANSION_TIMEOUT = 120
}

$options = New-PSRuleOption `
    -NotProcessedWarning $False `
    -InputPathIgnore @("*", "!**/*.tests.bicep") `
    -RuleIncludeLocal $True `
    -Configuration $config

Assert-PSRule -Module "PSRule.Rules.Azure" -Path "./.ps-rule/" -Format File -InputPath '.' -Option $options

@BernieWhite BernieWhite self-assigned this Jun 6, 2023
@BernieWhite BernieWhite added this to the v2.9.0 milestone Jun 6, 2023
BernieWhite added a commit to BernieWhite/PSRule that referenced this issue Jun 6, 2023
This was referenced Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working feature: baselines Issues that affect baselines
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants