-
Notifications
You must be signed in to change notification settings - Fork 312
Description
Describe the bug
When using Build-PolicyDocumentation.ps1 with the -PacSelector parameter in a multi-tenant environment (where each tenant has separate pipelines with isolated access), the script processes all documentation files in the policyDocumentations folder, regardless of the -PacSelector value. This causes authentication failures when a pipeline tries to process documentation for environments it cannot access.
The -PacSelector parameter currently only filters entries within documentAllAssignments in a given file, but does not:
- Skip entire documentation files that don't match the selector
- Filter
documentPolicySetsentries based on the selector
This makes it impossible to maintain a single repository with documentation definitions for multiple isolated tenants without implementing workarounds in the pipeline.
To Reproduce
-
Configure EPAC with two PAC environments in
global-settings.jsoncrepresenting separate tenants:stage(Tenant A with Service Connection A)main(Tenant B with Service Connection B)
-
Create two documentation files in
Definitions/policyDocumentations/:stage-documentation.jsoncwith"pacEnvironment": "stage"main-documentation.jsoncwith"pacEnvironment": "main"
-
Set up separate Azure DevOps pipelines:
- Stage pipeline: authenticated to Tenant A only, triggered on
stagebranch - Main pipeline: authenticated to Tenant B only, triggered on
mainbranch
- Stage pipeline: authenticated to Tenant A only, triggered on
-
In the stage pipeline, run:
Build-PolicyDocumentation -PacSelector "stage" -Interactive $false
-
Observe that the script attempts to process both documentation files, including
main-documentation.jsonc, which requires authentication to Tenant B.
Expected behavior
When -PacSelector is specified, the script should:
- Skip entire documentation files where none of the
pacEnvironmentvalues indocumentAllAssignmentsordocumentPolicySetsmatch the selector - Filter
documentPolicySetsentries to only process entries wherepacEnvironmentmatches the selector (similar to howdocumentAllAssignmentsis filtered) - Allow a single documentation file with multiple environments defined, processing only the sections matching the selector
This would enable:
- Multi-tenant setups with isolated pipelines to use a shared repository
- Each pipeline to generate documentation only for its accessible tenant
- Maintaining all documentation definitions in a single file or folder structure without manual file filtering in pipelines
Screenshots
Error output when stage pipeline attempts to process main documentation:
===================================================================================================
Processing documentation definitions in folder './Definitions/policyDocumentations'
===================================================================================================
Number of documentation definition files = 2
Reading and Processing 'main-documentation.jsonc'
The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Wrong cloud or tenant logged in by SPN:
Required cloud = AzureCloud, tenantId = <tenant-b-id>
If you are running this script interactive, specify script parameter -Interactive $true.
EPAC Version
Version: 10.12.0
Environment
- Azure DevOps Pipelines
- Ubuntu-latest agent
- PowerShell 7.x