Skip to content

Commit 6233374

Browse files
authored
Minor README.md and Build-PolicyAssignmentDocumentation.ps1 improvements
Minor README.md and Build-PolicyAssignmentDocumentation.ps1 improvements.
2 parents 6202f3e + a5694db commit 6233374

6 files changed

+91
-64
lines changed

Pipeline/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ Create service connections for each of your environments and require minimum rol
6262
| :--- | :--- | :--- | :--- | :--- | :--- |
6363
| sc-pac-dev | devAllStage | Owner ||||
6464
| sc-pac-test | testAllStage || Owner |||
65-
| sc-pac-plan-1 | prodPlanFeatureStage <br/> prodPlanMainStage ||| Policy Reader ||
66-
| sc-pac-plan-2 | prodPlanFeatureStage <br/> prodPlanMainStage |||| Policy Reader |
67-
| sc-pac-prod-1 | prodDeployStage-1 ||| Policy Contributor ||
68-
| sc-pac-prod-2 | prodDeployStage-2 |||| Policy Contributor |
69-
| sc-pac-roles-1 | prodRolesStage-1 ||| User Administrator ||
70-
| sc-pac-roles-2 | prodRolesStage-2 |||| User Administrator |
65+
| sc-pac-plan-1 | prodPlanFeatureStage <br/> prodPlanMainStage ||| Policy Reader<br/>Security Reader ||
66+
| sc-pac-plan-2 | prodPlanFeatureStage <br/> prodPlanMainStage |||| Policy Reader<br/>Security Reader |
67+
| sc-pac-prod-1 | prodDeployStage-1 ||| Policy Contributor<br/>Security Reader ||
68+
| sc-pac-prod-2 | prodDeployStage-2 |||| Policy Contributor<br/>Security Reader |
69+
| sc-pac-roles-1 | prodRolesStage-1 ||| User Administrator<br/>Security Reader ||
70+
| sc-pac-roles-2 | prodRolesStage-2 |||| User Administrator<br/>Security Reader |
7171
| none | prodNoPolicyStage-1 <br/> prodNoRoleStage-1 <br/> prodNoPolicyStage-2 </br> prodNoRoleStage-2 |||||
7272

7373
<br/>

README.md

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ More details:
3333
- [Operational Scripts](Scripts/Operations/README.md)
3434

3535
<br/><p style="background-color:Yellow;color:Black;border:5px solid Red;padding-left: 10px;padding-right: 10px;padding-top: 10px;padding-bottom: 10px;">
36-
<b><u>Warning:</u> If you have a existing Policies, Initiatives and Assignments in your environment, do not forget to change the "brownfield" variable in the pipeline to true.<br/><br/><u>Why?</u> This solution uses the desired state strategy. It will remove any custom Policies, Initiatives or Policy Assignments not duplicated in the definition files. The Build-AzPoliciesInitiativesAssignmentsPlan.ps1 script's switch parameter SuppressDeletes changes this behavior. Set the "brownfield" variable in the pipeline to true; it will set the switch parameter preventing deletions of existing Policies, Initiatives and Policy Assignments while transitioning to Enterprise Policy as Code.</b>
36+
<b><u>Warning:</u> If you have a existing Policies, Initiatives and Assignments in your environment, you have not transferred to EPAC, do not forget to change the "brownfield" variable in the pipeline to true.<br/><br/><u>Why?</u> This solution uses the desired state strategy. It will remove any custom Policies, Initiatives or Policy Assignments not duplicated in the definition files. The Build-AzPoliciesInitiativesAssignmentsPlan.ps1 script's switch parameter SuppressDeletes changes this behavior. Set the "brownfield" variable in the pipeline to true; it will set the switch parameter preventing deletions of existing Policies, Initiatives and Policy Assignments. This allows for a gradual transition from your existing Policy management to Enterprise Policy as Code.</b>
3737
</p><br/>
3838

3939
## Security & Compliance for Cloud Infrastructure
@@ -69,10 +69,10 @@ Git lacks a capability to ignore files/directories during a PR only. This repo h
6969
- You may add additional folders, such as a folder for your own operational scripts.
7070
- Syncing from GitHub repo.
7171
- Fetch changes from GitHub to `MyForkRepo`.
72-
- Execute `Sync-Repo.ps1` to copy files from `MyForkRepo` to `MyWorkingRepo` feature branch.
72+
- Execute [`Sync-Repo.ps1`](#sync-repops1) to copy files from `MyForkRepo` to `MyWorkingRepo` feature branch.
7373
- PR `MyWorkingRepo` feature branch.
7474
- Contribute to GitHub
75-
- Execute `Sync-Repo.ps1` to copy files from `MyWorkingRepo` to `MyForkRepo` feature branch
75+
- Execute [`Sync-Repo.ps1`](#sync-repops1) to copy files from `MyWorkingRepo` to `MyForkRepo` feature branch
7676
- PR `MyForkRepo` feature branch.
7777
- PR changes in your fork (`MyForkRepo`) to GitHub.
7878
- GitHub maintainers will review PR.
@@ -173,19 +173,26 @@ Explanations
173173
- `cloud` is used to select clouds (e.g., `AzureCloud`, `AzureUSGovernment`, `AzureGermanCloud`, ...).
174174
- `tenantId` is the GUID of your Azure AD tenant
175175
- `defaultSubscriptionId` is required to resolve Azure scopes correctly.
176-
- `rootScope` defines the location of your custom Policy and Initiative definitions. It also denotes the highest scope for an assignment. The roles for the CI/CD SPNs must assigned here.
176+
- `rootScope` defines the location of your custom Policy and Initiative definitions. It also denotes the highest scope for an assignment. The roles for the CI/CD SPNs must be assigned here.
177177

178178
We explain the `managedIdentityLocations` and `globalNotScopes` elements in `global-settings.jsonc` [here](Definitions/README.md).
179179

180+
<p style="background-color:Yellow;color:Black;border:5px solid Red;padding-left: 10px;padding-right: 10px;padding-top: 10px;padding-bottom: 10px;"><b><u>Note:</u>&nbsp;&nbsp;If the default output for az cli is configured wrong then you will encounter an unexpected error from ConvertFrom-Json in Invoke-AzCli. The initial default in az cli out-of-box is correct. You can set it back to the correct default with "az config set core.output=json"
181+
</b></p><br/>
182+
183+
```ps1
184+
az config set core.output=json
185+
```
186+
180187
<br/>
181188

182189
### Azure DevOps CI/CD Pipeline
183190

184191
Setup your pipeline based on the provided starter kit pipeline. The yml file contains commented out sections to run in a IaaS Azure DevOps server (it requires a different approach to artifact storage) and for 2 additional tenants. Uncomment or delete the commented sections to fit your environment.
185192

186193
<p style="background-color:Yellow;color:Black;border:5px solid Red;padding-left: 10px;padding-right: 10px;padding-top: 10px;padding-bottom: 10px;">
187-
<b><u>Warning:</u> If you have a existing Policies, Initiatives and Policy Assignments in your environment, do not forget to change the "brownfield" variable in the pipeline to true.</b>
188-
</p><br/>
194+
<b><u>Warning:</u>&nbsp;&nbsp;If you have a existing Policies, Initiatives and Policy Assignments in your environment you have not transferred to EPAC, do not forget to change the "brownfield" variable in the pipeline to true.
195+
</b></p><br/>
189196

190197
Pipelines can customized to fit your needs:
191198

@@ -200,10 +207,14 @@ Pipelines can customized to fit your needs:
200207

201208
### Edit and create Policies, Initiatives and Assignments
202209

203-
Using the sttarter kit edit the directories in the `Definitions` folder
210+
Using the starter kit edit the directories in the `Definitions` folder. To simplify entering parameters, you can use the [Initiative documenting feature](Definitions/DocumentationSpecs/README.md#documenting-assignments-and-initiatives) which creates Markdown, CSV and a Json parameter file. You need to specify your initiatives to be documented (folder [`Definitions\DocumentationSpecs`](Definitions/DocumentationSpecs/README.md#specifying-initiative-documentation)) and execute script [`./Scripts/Operations/Build-PolicyAssignmentDocumentation.ps1`](Scripts/Operations/README.md#build-policyassignmentdocumentationps1)
204211

205212
<br/>
206213

214+
### Document your Assignments
215+
216+
This solution can generate [documentation in markdown and csv formats](Definitions/DocumentationSpecs/README.md).
217+
207218
## GitHub Folder Structure
208219

209220
<br/>

Scripts/Helpers/Convert-EffectToString.ps1

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,33 @@
22

33
function Convert-EffectToString {
44
param (
5-
[string] $effect,
5+
[string] $effect,
66
[array] $allowedValues,
7-
[bool] $isParameterized,
87
[switch] $Markdown
98
)
109

1110
[string] $text = ""
1211
$effectShort = Convert-EffectToShortForm -effect $effect
1312
if ($Markdown.IsPresent) {
14-
$text = "**$effectShort**"
15-
if ($isParameterized) {
16-
foreach ($allowed in $allowedValues) {
17-
if ($allowed -ne $effect) {
18-
$effectShort = Convert-EffectToShortForm -effect $allowed
19-
$text += "<br/>*$effectShort*"
20-
}
13+
if ($allowedValues.Count -eq 1) {
14+
$text = "***$effectShort***"
15+
}
16+
else {
17+
$text = "**$effectShort**"
18+
}
19+
foreach ($allowed in $allowedValues) {
20+
if ($allowed -cne $effect) {
21+
$effectShort = Convert-EffectToShortForm -effect $allowed
22+
$text += "<br/>*$effectShort*"
2123
}
2224
}
2325
}
2426
else {
2527
$text += $effectShort
26-
if ($isParameterized) {
27-
foreach ($allowed in $allowedValues) {
28-
if ($allowed -ne $effect) {
29-
$effectShort = Convert-EffectToShortForm -effect $allowed
30-
$text += "\n$effectShort"
31-
}
28+
foreach ($allowed in $allowedValues) {
29+
if ($allowed -cne $effect) {
30+
$effectShort = Convert-EffectToShortForm -effect $allowed
31+
$text += "\n$effectShort"
3232
}
3333
}
3434
}

Scripts/Helpers/Out-InitiativeDocumentationToFile.ps1

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ function Out-InitiativeDocumentationToFile {
125125
$text = Convert-EffectToString `
126126
-effect $effectValue `
127127
-allowedValues $effectAllowedValues `
128-
-isParameterized $isEffectParameterized `
129128
-Markdown
130129
$addedEffectColumns += " $text |"
131130

@@ -191,11 +190,9 @@ function Out-InitiativeDocumentationToFile {
191190
$perInitiative = $initiativeList.$shortName
192191
$effectValue = $perInitiative.effectValue
193192
$effectAllowedValues = $perInitiative.effectAllowedValues
194-
$isEffectParameterized = $perInitiative.isEffectParameterized
195193
$text = Convert-EffectToString `
196194
-effect $effectValue `
197-
-allowedValues $effectAllowedValues `
198-
-isParameterized $isEffectParameterized
195+
-allowedValues $effectAllowedValues
199196
$null = $cells.Add($text)
200197
}
201198
else {

Scripts/Helpers/Out-PolicyAssignmentDocumentationAcrossEnvironmentsToFile.ps1

Lines changed: 50 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -62,31 +62,34 @@ function Out-PolicyAssignmentDocumentationAcrossEnvironmentsToFile {
6262
foreach ($id in $flatPolicyList.Keys) {
6363
$flatPolicyEntry = $flatPolicyList.$id
6464

65-
[hashtable] $policyEffectsFlatEntry = @{}
65+
[hashtable] $policyEffectsFlatEntry = $null
6666
if ($policyEffectsFlatList.ContainsKey($id)) {
6767
$policyEffectsFlatEntry = $policyEffectsFlatList.$id
68-
$effectAllowedValuesCurrent = $policyEffectsFlatEntry.effectAllowedValues
69-
$effectAllowedValuesNew = $flatPolicyEntry.effectAllowedValues
70-
if ($effectAllowedValuesNew.Count -gt $effectAllowedValuesCurrent.Count) {
71-
$policyEffectsFlatEntry.effectAllowedValue = $effectAllowedValuesNew
72-
}
7368
}
7469
else {
7570

7671
$policyEffectsFlatEntry = @{
77-
category = $flatPolicyEntry.category
78-
displayName = $flatPolicyEntry.displayName
79-
description = $flatPolicyEntry.description
80-
effectByEnvironment = @{}
81-
effectAllowedValues = $flatPolicyEntry.effectAllowedValues
72+
category = $flatPolicyEntry.category
73+
displayName = $flatPolicyEntry.displayName
74+
description = $flatPolicyEntry.description
75+
byEnvironment = @{}
8276
}
8377
$policyEffectsFlatList.Add($id, $policyEffectsFlatEntry)
8478
}
8579

8680
$effectiveAssignment = $flatPolicyEntry.effectiveAssignment
8781
$effect = $effectiveAssignment.effect
88-
$effectByEnvironment = $policyEffectsFlatEntry.effectByEnvironment
89-
$effectByEnvironment.Add($environmentCategory, $effect)
82+
$effectAllowedValues = $effectiveAssignment.effectAllowedValues
83+
$parameters = $effectiveAssignment.parameters
84+
$byEnvironment = $policyEffectsFlatEntry.byEnvironment
85+
if (!$byEnvironment.ContainsKey($environmentCategory)) {
86+
$byEnvironment.Add($environmentCategory, @{
87+
effect = $effect
88+
effectAllowedValues = $effectAllowedValues
89+
parameters = $parameters
90+
}
91+
)
92+
}
9093
}
9194
}
9295

@@ -132,21 +135,36 @@ function Out-PolicyAssignmentDocumentationAcrossEnvironmentsToFile {
132135
$policyEffectsFlatList.Values | Sort-Object -Property { $_.category }, { $_.displayName } | ForEach-Object -Process {
133136
# Build additional columns
134137
$addedEffectColumns = ""
135-
$effectByEnvironment = $_.effectByEnvironment
138+
$byEnvironment = $_.byEnvironment
139+
$parameterFragment = ""
136140
foreach ($environmentCategory in $environmentCategories) {
137-
if ($effectByEnvironment.ContainsKey($environmentCategory)) {
138-
$effect = Convert-EffectToShortForm -effect $effectByEnvironment.$environmentCategory
139-
$addedEffectColumns += " $effect |"
141+
if ($byEnvironment.ContainsKey($environmentCategory)) {
142+
$environmentCategoryValues = $byEnvironment.$environmentCategory
143+
$effectValue = $environmentCategoryValues.effect
144+
$effectAllowedValues = $environmentCategoryValues.effectAllowedValues
145+
# $parameters = $environmentCategoryValues.parameters
146+
147+
$text = Convert-EffectToString `
148+
-effect $effectValue `
149+
-allowedValues $effectAllowedValues `
150+
-Markdown
151+
$addedEffectColumns += " $text |"
152+
153+
# if ($null -ne $parameters -and $parameters.Count -gt 0) {
154+
# $parameterFragment += "<br/>**$($environmentCategory):**"
155+
# $text = Convert-ParametersToString -parameters $parameters -Markdown
156+
# $parameterFragment += $text
157+
# }
140158
}
141159
else {
142160
$addedEffectColumns += " |"
143161
}
144162
}
145-
$null = $body.Add("| $($_.category) | **$($_.displayName)**<br/>$($_.description) | $addedEffectColumns")
163+
$null = $body.Add("| $($_.category) | **$($_.displayName)**<br/>$($_.description)$($parameterFragment) | $addedEffectColumns")
146164
}
147165
$null = $allLines.AddRange($headerAndToc)
148166
$null = $allLines.AddRange($body)
149-
167+
150168
# Output file
151169
$outputFilePath = "$($outputPath -replace '[/\\]$', '')/$fileNameStem.md"
152170
$allLines | Out-File $outputFilePath -Force
@@ -162,26 +180,33 @@ function Out-PolicyAssignmentDocumentationAcrossEnvironmentsToFile {
162180
foreach ($environmentCategory in $environmentCategories) {
163181
$null = $cells.Add($environmentCategory)
164182
}
165-
$headerString = Convert-ListToToCsvRow($cells)
183+
$headerString = Convert-ListToToCsvRow($cells)
166184
$null = $allLines.Add($headerString)
167185

168186
$policyEffectsFlatList.Values | Sort-Object -Property { $_.category }, { $_.displayName } | ForEach-Object -Process {
169187
# Build common columns
170188
$cells.Clear()
171189
$null = $cells.AddRange(@($_.category, $_.displayName, $_.description))
172190

173-
$effectByEnvironment = $_.effectByEnvironment
191+
$byEnvironment = $_.byEnvironment
174192
# Build effect by environmentCategory columns
175193
foreach ($environmentCategory in $environmentCategories) {
176-
if ($effectByEnvironment.ContainsKey($environmentCategory)) {
177-
$effect = Convert-EffectToShortForm -effect $effectByEnvironment.$environmentCategory
178-
$null = $cells.Add($effect)
194+
if ($byEnvironment.ContainsKey($environmentCategory)) {
195+
$environmentCategoryValues = $byEnvironment.$environmentCategory
196+
$effectValue = $environmentCategoryValues.effect
197+
$effectAllowedValues = $environmentCategoryValues.effectAllowedValues
198+
# $parameters = $environmentCategoryValues.parameters
199+
200+
$text = Convert-EffectToString `
201+
-effect $effectValue `
202+
-allowedValues $effectAllowedValues
203+
$null = $cells.Add($text)
179204
}
180205
else {
181206
$null = $cells.Add("n/a")
182207
}
183208
}
184-
$row = Convert-ListToToCsvRow($cells)
209+
$row = Convert-ListToToCsvRow($cells)
185210
$null = $allLines.Add($row)
186211
}
187212

Scripts/Helpers/Out-PolicyAssignmentDocumentationPerEnvironmentToFile.ps1

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,9 @@ function Out-PolicyAssignmentDocumentationPerEnvironmentToFile {
9292
$assignmentFlat = $allAssignments.$shortName
9393
$effectValue = $assignmentFlat.effect
9494
$effectAllowedValues = $assignmentFlat.effectAllowedValues
95-
$effectReason = $assignmentFlat.effectReason
96-
$isParameterized = $effectReason -ne "PolicyFixed" -and $effectReason -ne "InitiativeFixed" -and $effectReason -ne "PolicyDefault"
9795
$text = Convert-EffectToString `
9896
-effect $effectValue `
9997
-allowedValues $effectAllowedValues `
100-
-isParameterized $isParameterized `
10198
-Markdown
10299
$addedEffectColumns += " $text |"
103100

@@ -158,12 +155,9 @@ function Out-PolicyAssignmentDocumentationPerEnvironmentToFile {
158155
$assignmentFlat = $allAssignments.$shortName
159156
$effectValue = $assignmentFlat.effect
160157
$effectAllowedValues = $assignmentFlat.effectAllowedValues
161-
$effectReason = $assignmentFlat.effectReason
162-
$isParameterized = $effectReason -ne "PolicyFixed" -and $effectReason -ne "InitiativeFixed" -and $effectReason -ne "PolicyDefault"
163158
$text = Convert-EffectToString `
164159
-effect $effectValue `
165-
-allowedValues $effectAllowedValues `
166-
-isParameterized $isParameterized
160+
-allowedValues $effectAllowedValues
167161
$null = $cells.Add($text)
168162
}
169163
else {

0 commit comments

Comments
 (0)