-
Notifications
You must be signed in to change notification settings - Fork 31
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
NewResourceName: AdcsAiaExtension. A feature to add/remove AIA URI extensions - New Resource Issue #78. #79
Closed
Closed
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
117cbb9
Update to add AdcsAiaExtension
alsitton 2b9ee1a
Update with code fixes
alsitton d315112
Update
alsitton 1cedd9e
Update to manifest and help files
alsitton d1b3d31
Update for formatting corrections and parameters
alsitton 1bcfece
Updated changelog with AiaExtension
alsitton 4770a0b
Update to fix errors
alsitton 36854db
Updated module, test and strings
alsitton 1e5fc56
Updated unit test to improve code coverage
alsitton 624774d
Update to unit test formatting
alsitton d9aaf44
Update with changes
alsitton 9c524fb
Update to tests
alsitton cc87089
Updated parameters and test
alsitton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
254 changes: 254 additions & 0 deletions
254
DSCResources/MSFT_AdcsAiaExtension/MSFT_AdcsAiaExtension.psm1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,254 @@ | ||
$modulePath = Join-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) -ChildPath 'Modules' | ||
|
||
# Import the ADCS Deployment Resource Common Module. | ||
Import-Module -Name (Join-Path -Path $modulePath ` | ||
-ChildPath (Join-Path -Path 'ActiveDirectoryCSDsc.CommonHelper' ` | ||
-ChildPath 'ActiveDirectoryCSDsc.CommonHelper.psm1')) | ||
|
||
# Import the ADCS Deployment Resource Helper Module. | ||
Import-Module -Name (Join-Path -Path $modulePath ` | ||
-ChildPath (Join-Path -Path 'ActiveDirectoryCSDsc.ResourceHelper' ` | ||
-ChildPath 'ActiveDirectoryCSDsc.ResourceHelper.psm1')) | ||
|
||
# Import Localization Strings. | ||
$LocalizedData = Get-LocalizedData ` | ||
-ResourceName 'MSFT_AdcsAiaExtension' ` | ||
-ResourcePath (Split-Path -Parent $script:MyInvocation.MyCommand.Path) | ||
|
||
<# | ||
.SYNOPSIS | ||
Gets the current certification authority AddToCertificateAia (boolean) and Uniform Resource Identifiers (URI) | ||
settings. | ||
|
||
.PARAMETER IsSingleInstance | ||
Specifies the resource is a single instance, the value must be 'Yes'. | ||
|
||
.PARAMETER AiaUriPath | ||
Specifies the URI location where issuer of certificate is located. | ||
|
||
.PARAMETER RestartService | ||
Specifies if the service should be restarted. | ||
|
||
.PARAMETER Ensure | ||
Ensures that the Authority Information Access (AIA) Uniform Resource Identifiers (URI) is Present or Absent. | ||
#> | ||
function Get-TargetResource | ||
{ | ||
[CmdletBinding()] | ||
[OutputType([System.Collections.Hashtable])] | ||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[ValidateSet('Yes')] | ||
[System.String] | ||
$IsSingleInstance, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[System.String[]] | ||
$AiaUriPath, | ||
|
||
[Parameter()] | ||
[System.Boolean] | ||
$RestartService, | ||
|
||
[Parameter()] | ||
[ValidateSet('Present', 'Absent')] | ||
[System.String] | ||
$Ensure = 'Present' | ||
) | ||
|
||
Write-Verbose -Message $localizedData.GetAiaUriPaths | ||
|
||
[System.Array] $currentAiaUriPathList = (Get-CAAuthorityInformationAccess).Where( { | ||
$_.AddToCertificateAia -eq $true | ||
} ).Uri | ||
|
||
return @{ | ||
AiaUriPath = $currentAiaUriPathList | ||
Ensure = $Ensure | ||
IsSingleInstance = $IsSingleInstance | ||
RestartService = $RestartService | ||
} | ||
} | ||
|
||
<# | ||
.SYNOPSIS | ||
Configures the current Authority Information Access (AIA) settings for the certification authority. | ||
|
||
.PARAMETER IsSingleInstance | ||
Specifies the resource is a single instance, the value must be 'Yes'. | ||
|
||
.PARAMETER AiaUriPath | ||
Specifies the URI location where issuer of certificate is located. | ||
|
||
.PARAMETER RestartService | ||
Specifies if the service should be restarted. | ||
|
||
.PARAMETER Ensure | ||
Specifies if the AIA responder URI should be present or absent. | ||
#> | ||
function Set-TargetResource | ||
{ | ||
[CmdletBinding()] | ||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[ValidateSet('Yes')] | ||
[System.String] | ||
$IsSingleInstance, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[System.String[]] | ||
$AiaUriPath, | ||
|
||
[Parameter()] | ||
[System.Boolean] | ||
$RestartService, | ||
|
||
[Parameter()] | ||
[ValidateSet('Present', 'Absent')] | ||
[System.String] | ||
$Ensure = 'Present' | ||
) | ||
|
||
$currentState = Get-TargetResource @PSBoundParameters | ||
|
||
if ($Ensure -eq 'Present') | ||
{ | ||
foreach ($oldField in $currentState.AiaUriPath) | ||
{ | ||
Write-Verbose -Message ($localizedData.RemoveAiaUriPaths -f $oldField) | ||
Remove-CAAuthorityInformationAccess -Uri $oldField -Force -ErrorAction Stop | ||
} | ||
|
||
foreach ($newField in $AiaUriPath) | ||
{ | ||
Write-Verbose -Message ($localizedData.AddAiaUriPaths -f $newField) | ||
Add-CAAuthorityInformationAccess -Uri $newField -AddToCertificateAia -Force -ErrorAction Stop | ||
} | ||
} | ||
else { | ||
foreach ($field in $AiaUriPath) | ||
{ | ||
Write-Verbose -Message ($localizedData.RemoveAiaUriPaths -f $field) | ||
Remove-CAAuthorityInformationAccess -Uri $field -Force -ErrorAction Stop | ||
} | ||
} | ||
|
||
if ($RestartService) | ||
{ | ||
Write-Verbose -Message $localizedData.RestartService | ||
Restart-ServiceIfExists -Name CertSvc | ||
} | ||
} | ||
|
||
<# | ||
.SYNOPSIS | ||
Tests the current certification authority AddToCertificateAia (boolean) and Uniform Resource Identifiers (URI) | ||
settings. | ||
|
||
.PARAMETER IsSingleInstance | ||
Specifies the resource is a single instance, the value must be 'Yes'. | ||
|
||
.PARAMETER AiaUriPath | ||
Specifies the URI location where issuer of certificate is located. | ||
|
||
.PARAMETER RestartService | ||
Specifies if the service should be restarted. | ||
|
||
.PARAMETER Ensure | ||
Ensures that the Authority Information Access (AIA) Uniform Resource Identifiers (URI) is Present or Absent. | ||
#> | ||
function Test-TargetResource | ||
{ | ||
[CmdletBinding()] | ||
[OutputType([System.Boolean])] | ||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[ValidateSet('Yes')] | ||
[System.String] | ||
$IsSingleInstance, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[System.String[]] | ||
$AiaUriPath, | ||
|
||
[Parameter()] | ||
[System.Boolean] | ||
$RestartService, | ||
|
||
[Parameter()] | ||
[ValidateSet('Present', 'Absent')] | ||
[System.String] | ||
$Ensure = 'Present' | ||
) | ||
|
||
$currentState = Get-TargetResource @PSBoundParameters | ||
|
||
$inDesiredState = $true | ||
|
||
if ($Ensure -eq 'Present') | ||
{ | ||
if ($currentState.AiaUriPath.Count -ne $AiaUriPath.Count) | ||
{ | ||
if ($null -ne $currentState.AiaUriPath) | ||
{ | ||
$compareAiaUriPaths = Compare-Object -ReferenceObject $AiaUriPath -DifferenceObject $currentState.AiaUriPath -PassThru | ||
|
||
# Desired state AIA URI path(s) not found in reference set. | ||
$desiredAiaUriPathsMissing = $compareAiaUriPaths.Where( { | ||
$_.SideIndicator -eq '<=' | ||
} ) -join ', ' | ||
|
||
# AIA URI path(s) found in $currentState that do not match $AiaUriPath desired state. | ||
$notDesiredAiaUriPathsFound = $compareAiaUriPaths.Where( { | ||
$_.SideIndicator -eq '=>' | ||
} ) -join ', ' | ||
|
||
if ($desiredAiaUriPathsMissing) | ||
{ | ||
Write-Verbose -Message ($localizedData.DesiredAiaPathsMissing -f $desiredAiaUriPathsMissing) | ||
$inDesiredState = $false | ||
} | ||
|
||
if ($notDesiredAiaUriPathsFound) | ||
{ | ||
Write-Verbose -Message ($localizedData.AdditionalAiaPathsFound -f $notDesiredAiaUriPathsFound) | ||
$inDesiredState = $false | ||
} | ||
} | ||
else | ||
{ | ||
$aiaUriPathList = $AiaUriPath -join ', ' | ||
|
||
Write-Verbose -Message ($localizedData.AiaPathsNull -f $aiaUriPathList) | ||
$inDesiredState = $false | ||
} | ||
} | ||
|
||
foreach ($uri in $currentState.AiaUriPath) | ||
{ | ||
if ($uri -notin $AiaUriPath) | ||
{ | ||
Write-Verbose -Message ($localizedData.IncorrectAiaUriFound -f $uri) | ||
$inDesiredState = $false | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
foreach ($uri in $AiaUriPath) | ||
{ | ||
if ($uri -in $currentState.AiaUriPath) | ||
{ | ||
Write-Verbose -Message ($localizedData.EnsureAbsentButUriPathsExist -f $uri) | ||
$inDesiredState = $false | ||
} | ||
} | ||
} | ||
|
||
return $inDesiredState | ||
} | ||
|
||
Export-ModuleMember -Function Get-TargetResource, Test-TargetResource, Set-TargetResource |
8 changes: 8 additions & 0 deletions
8
DSCResources/MSFT_AdcsAiaExtension/MSFT_AdcsAiaExtension.schema.mof
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[ClassVersion("1.0.0"), FriendlyName("AdcsAiaExtension")] | ||
class MSFT_AdcsAiaExtension : OMI_BaseResource | ||
{ | ||
[Key, Description("Specifies the resource is a single instance, the value must be 'Yes'."), ValueMap{"Yes"}, Values{"Yes"}] String IsSingleInstance; | ||
[Required, Description("Specifies the URI location where issuer of certificate is located.")] String AiaUriPath[]; | ||
[Write, Description("Specifies if the service should be restarted.")] Boolean RestartService; | ||
[Write, Description("Ensures that the Authority Information Access (AIA) Uniform Resource Identifiers (URI) is Present or Absent."), ValueMap{"Present", "Absent"}, Values{"Present", "Absent"}] String Ensure; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Description | ||
|
||
This resource can be used to configure the AIA URI extensions on the | ||
Certificate Authority after the feature has been installed on the server. | ||
Using this DSC Resource to configure an ADCS Certificate Authority assumes that | ||
the `ADCS-Cert-Authority` feature has already been installed. |
11 changes: 11 additions & 0 deletions
11
DSCResources/MSFT_AdcsAiaExtension/en-US/MSFT_AdcsAiaExtension.strings.psd1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
ConvertFrom-StringData @' | ||
AdditionalAiaPathsFound = Not in desired state, additional AIA URI paths found, "{0}", running Set. | ||
AddAiaUriPaths = Adding "{0}" to desired AIA URI paths. | ||
DesiredAiaPathsMissing = Not in desired state, missing desired AIA URI paths, "{0}", running Set. | ||
EnsureAbsentButUriPathsExist = Not in desired state, AIA URI paths should be Absent, but found "{0}". | ||
GetAiaUriPaths = Getting all AIA URI paths. | ||
AiaPathsNull = Not in desired state, AIA URI paths empty, missing "{0}", running Set. | ||
RemoveAiaUriPaths = Removing "{0}" AIA URI paths. | ||
RestartService = Preparing to restart the CertSvc for changes to take affect. | ||
IncorrectAiaUriFound = Not in desired state, AIA URI path incorrect, found "{0}", running Set. | ||
'@ |
43 changes: 43 additions & 0 deletions
43
Examples/Resources/AdcsAiaExtension/1-AdcsAiaExtension_AddAiaPath_Config.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<#PSScriptInfo | ||
.VERSION 1.0.0 | ||
.GUID 93c71497-c4ac-452e-baf1-aff17bd4ecac | ||
.AUTHOR Microsoft Corporation | ||
.COMPANYNAME Microsoft Corporation | ||
.COPYRIGHT | ||
.TAGS DSCConfiguration | ||
.LICENSEURI https://github.com/PowerShell/ActiveDirectoryCSDsc/blob/master/LICENSE | ||
.PROJECTURI https://github.com/PowerShell/ActiveDirectoryCSDsc | ||
.ICONURI | ||
.EXTERNALMODULEDEPENDENCIES | ||
.REQUIREDSCRIPTS | ||
.EXTERNALSCRIPTDEPENDENCIES | ||
.RELEASENOTES First version. | ||
.PRIVATEDATA 2016-Datacenter,2016-Datacenter-Server-Core | ||
#> | ||
|
||
#Requires -module ActiveDirectoryCSDsc | ||
|
||
<# | ||
.DESCRIPTION | ||
A DSC configuration script to add desired AIA URI path extensions for a Certificate Authority. | ||
This will remove all existing AIA URI paths from the Certificate Authority. | ||
#> | ||
configuration AdcsAiaExtension_AddAiaPath_Config | ||
{ | ||
Import-DscResource -ModuleName ActiveDirectoryCSDsc | ||
|
||
node localhost | ||
{ | ||
AdcsAiaExtension AddAiaUriPath | ||
{ | ||
IsSingleInstance = 'Yes' | ||
AiaUriPath = @( | ||
'http://setAIAPathTest1/Certs/<CATruncatedName>.cer' | ||
'http://setAIAPathTest2/Certs/<CATruncatedName>.cer' | ||
'http://setAIAPathTest3/Certs/<CATruncatedName>.cer' | ||
) | ||
RestartService = $true | ||
Ensure = 'Present' | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might want to reword this. If the DSC configuration is set to Apply and Monitor it would not run Set if the setting is change to an incorrect setting.