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

Pulumi: Add update AAD sync script #1605

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,14 @@ Configuration DownloadInstallers {
}

xRemoteFile DisconnectAD { # from xPSDesiredStateConfiguration
Uri = "https://raw.githubusercontent.com/alan-turing-institute/data-safe-haven/python-migration/data_safe_haven/resources/active_directory/disconnect_ad.ps1"
Uri = "https://raw.githubusercontent.com/alan-turing-institute/data-safe-haven/python-migration/data_safe_haven/resources/desired_state_configuration/DisconnectAD.ps1"
DestinationPath = Join-Path $DIInstallerBasePath "DisconnectAD.ps1"
}

xRemoteFile UpdateAADSyncRule { # from xPSDesiredStateConfiguration
Uri = "https://raw.githubusercontent.com/alan-turing-institute/data-safe-haven/python-migration/data_safe_haven/resources/desired_state_configuration/UpdateAADSyncRule.ps1"
DestinationPath = Join-Path $DIInstallerBasePath "UpdateAADSyncRule.ps1"
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Import-Module -Name "C:\Program Files\Microsoft Azure AD Sync\Bin\ADSync" -Force -ErrorAction Stop

# Create a new rule that is a copy of the default rule
$defaultRule = Get-ADSyncRule | Where-Object { $_.Name -eq "Out to AAD - User Join" }
$newRule = New-ADSyncRule `
-Name 'Out to AAD - User Join' `
-Description $defaultRule.Description `
-Direction 'Outbound' `
-Precedence $defaultRule.Precedence `
-PrecedenceAfter $defaultRule.PrecedenceAfter `
-PrecedenceBefore $defaultRule.PrecedenceBefore `
-SourceObjectType $defaultRule.SourceObjectType `
-TargetObjectType $defaultRule.TargetObjectType `
-Connector $defaultRule.Connector `
-LinkType $defaultRule.LinkType `
-SoftDeleteExpiryInterval $defaultRule.SoftDeleteExpiryInterval `
-ImmutableTag '' `
-EnablePasswordSync

# Copy all flow mappings except the usage location one
foreach ($flow in ($defaultRule.AttributeFlowMappings | Where-Object { $_.Destination -ne "usageLocation" })) {
$params = @{
Destination = $flow.Destination
FlowType = $flow.FlowType
ValueMergeType = $flow.ValueMergeType
}
if ($flow.Source) { $params["Source"] = $flow.Source }
if ($flow.Expression) { $params["Expression"] = $flow.Expression }
$null = Add-ADSyncAttributeFlowMapping -SynchronizationRule $newRule @params
}

# Set the usage location flow mapping manually
$null = Add-ADSyncAttributeFlowMapping -SynchronizationRule $newRule -Source @('c') -Destination 'usageLocation' -FlowType 'Direct' -ValueMergeType 'Update'

# Add appropriate scope and join conditions
$newRule.JoinFilter = $defaultRule.JoinFilter
$newRule.ScopeFilter = $defaultRule.ScopeFilter

# Remove the old rule and add the new one
$null = Remove-ADSyncRule -SynchronizationRule $defaultRule
Add-ADSyncRule -SynchronizationRule $newRule