Skip to content
Open
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
@@ -1,27 +1,33 @@
# Load thescript
. "$PSScriptRoot\..\Common\EnvironmentEnterprisePolicyOperations.ps1"
<#
SAMPLE CODE NOTICE

function AddCustomerManagedKeyToEnvironment
THIS SAMPLE CODE IS MADE AVAILABLE AS IS. MICROSOFT MAKES NO WARRANTIES, WHETHER EXPRESS OR IMPLIED,
OF FITNESS FOR A PARTICULAR PURPOSE, OF ACCURACY OR COMPLETENESS OF RESPONSES, OF RESULTS, OR CONDITIONS OF MERCHANTABILITY.
THE ENTIRE RISK OF THE USE OR THE RESULTS FROM THE USE OF THIS SAMPLE CODE REMAINS WITH THE USER.
NO TECHNICAL SUPPORT IS PROVIDED. YOU MAY NOT DISTRIBUTE THIS CODE UNLESS YOU HAVE A LICENSE AGREEMENT WITH MICROSOFT THAT ALLOWS YOU TO DO SO.
#>

param(
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[String]$EnvironmentId,

[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[String]$PolicyArmId,

[Parameter(Mandatory=$false)]
[BAPEndpoint]$Endpoint = "prod"

)

$ErrorActionPreference = "Stop"

Import-Module "$PSScriptRoot\..\Common\EnterprisePolicies" -Force

if (-not(Connect-Azure))
{
param(
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[String]$environmentId,

[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[String]$policyArmId,

[Parameter(Mandatory=$false)]
[ValidateSet("tip1", "tip2", "prod")]
[String]$endpoint

)

if (![bool]$endpoint) {
$endpoint = "prod"
}

LinkPolicyToEnv -policyType cmk -environmentId $environmentId -policyArmId $policyArmId -endpoint $endpoint
return
}
AddCustomerManagedKeyToEnvironment

New-PolicyToEnvLink -PolicyType [PolicyType]::Encryption -EnvironmentId $EnvironmentId -PolicyArmId $PolicyArmId -Endpoint $Endpoint
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
param(
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[String]$policyArmId,
[String]$PolicyArmId,

[Parameter(Mandatory=$false)]
[ValidateSet("tip1", "tip2", "prod")]
[String]$endpoint
[BAPEndpoint]$Endpoint = "prod"
)

# Load thescript
. "$PSScriptRoot\..\Common\EnvironmentEnterprisePolicyOperations.ps1"
$ErrorActionPreference = "Stop"

if (![bool]$endpoint) {
$endpoint = "prod"
Import-Module "$PSScriptRoot\..\Common\EnterprisePolicies" -Force

if (-not(Connect-Azure))
{
return
}

LinkPolicyToPlatformAppsData -policyType cmk -policyArmId $policyArmId -endpoint $endpoint
New-PolicyToPlatformAppsDataLink -PolicyType [PolicyType]::Encryption -PolicyArmId $PolicyArmId -Endpoint $Endpoint
111 changes: 45 additions & 66 deletions powershell/enterprisePolicies/Cmk/CreateCMKEnterprisePolicy.ps1
Original file line number Diff line number Diff line change
@@ -1,81 +1,60 @@
# Load the environment script
. "$PSScriptRoot\..\Common\EnterprisePolicyOperations.ps1"
<#
SAMPLE CODE NOTICE

function CreateCMKEnterprisePolicy
{
param(
[Parameter(
Mandatory=$true,
HelpMessage="The Policy subscription"
)]
[string]$subscriptionId,
THIS SAMPLE CODE IS MADE AVAILABLE AS IS. MICROSOFT MAKES NO WARRANTIES, WHETHER EXPRESS OR IMPLIED,
OF FITNESS FOR A PARTICULAR PURPOSE, OF ACCURACY OR COMPLETENESS OF RESPONSES, OF RESULTS, OR CONDITIONS OF MERCHANTABILITY.
THE ENTIRE RISK OF THE USE OR THE RESULTS FROM THE USE OF THIS SAMPLE CODE REMAINS WITH THE USER.
NO TECHNICAL SUPPORT IS PROVIDED. YOU MAY NOT DISTRIBUTE THIS CODE UNLESS YOU HAVE A LICENSE AGREEMENT WITH MICROSOFT THAT ALLOWS YOU TO DO SO.
#>

[Parameter(
Mandatory=$true,
HelpMessage="The Policy resource group"
)]
[string]$resourceGroup,
param(
[Parameter(Mandatory, HelpMessage="The Policy subscription")]
[string]$subscriptionId,

[Parameter(
Mandatory=$true,
HelpMessage="The Policy name"
)]
[string]$enterprisePolicyName,
[Parameter(Mandatory, HelpMessage="The Policy resource group")]
[string]$resourceGroup,

[Parameter(
Mandatory=$true,
HelpMessage="The Policy location"
)]
[string]$enterprisePolicyLocation,
[Parameter(Mandatory, HelpMessage="The Policy name")]
[string]$enterprisePolicyName,

[Parameter(
Mandatory=$true,
HelpMessage="The KeyVault ARM Id"
)]
[string]$keyVaultId,
[Parameter(Mandatory, HelpMessage="The Policy location")]
[string]$enterprisePolicyLocation,

[Parameter(
Mandatory=$true,
HelpMessage="The Key name"
)]
[string]$keyName,
[Parameter(Mandatory, HelpMessage="The KeyVault ARM Id")]
[string]$keyVaultId,

[Parameter(
Mandatory=$true,
HelpMessage="The Key version"
)]
[string]$keyVersion
[Parameter(Mandatory, HelpMessage="The Key name")]
[string]$keyName,

)
[Parameter(Mandatory, HelpMessage="The Key version")]
[string]$keyVersion
)

Write-Host "Logging In..." -ForegroundColor Green
$connect = AzureLogin
if ($false -eq $connect)
{
return
}
$ErrorActionPreference = "Stop"

Write-Host "Logged In..." -ForegroundColor Green
Import-Module "$PSScriptRoot\..\Common\EnterprisePolicies" -Force

if ($keyVersion -eq "N/A")
{
$keyVersion = $null
}

$body = GenerateEnterprisePolicyBody -policyType "cmk" -policyLocation $enterprisePolicyLocation -policyName $enterprisePolicyName -keyVaultId $keyVaultId -keyName $keyName -keyVersion $keyVersion
if (-not(Connect-Azure))
{
return
}

$result = PutEnterprisePolicy $resourceGroup $body
if ($result -eq $false)
{
return
}
Write-Host "CMK Enterprise policy created" -ForegroundColor Green
if ($keyVersion -eq "N/A")
{
$keyVersion = $null
}

$policyArmId = "/subscriptions/$subscriptionId/resourceGroups/$resourceGroup/providers/Microsoft.PowerPlatform/enterprisePolicies/$enterprisePolicyName"
$policy = GetEnterprisePolicy $policyArmId
$policyString = $policy | ConvertTo-Json -Depth 7
Write-Host "Policy created"
Write-Host $policyString
$body = New-EnterprisePolicyBody -PolicyType [PolicyType]::Encryption -PolicyLocation $enterprisePolicyLocation -PolicyName $enterprisePolicyName -KeyVaultId $keyVaultId -KeyName $keyName -KeyVersion $keyVersion

$result = Set-EnterprisePolicy -ResourceGroup $resourceGroup -Body $body
if ($result -eq $false)
{
return
}
CreateCMKEnterprisePolicy
Write-Host "CMK Enterprise policy created" -ForegroundColor Green

$policyArmId = "/subscriptions/$subscriptionId/resourceGroups/$resourceGroup/providers/Microsoft.PowerPlatform/enterprisePolicies/$enterprisePolicyName"
$policy = Get-EnterprisePolicy -PolicyArmId $policyArmId
$policyString = $policy | ConvertTo-Json -Depth 7
Write-Host "Policy created"
Write-Host $policyString
Original file line number Diff line number Diff line change
@@ -1,32 +1,28 @@
# Load the environment script
. "$PSScriptRoot\..\Common\EnterprisePolicyOperations.ps1"
<#
SAMPLE CODE NOTICE

function GetCMKEnterprisePoliciesInResourceGroup
{
param(
[Parameter(
Mandatory=$true,
HelpMessage="The subscriptionId"
)]
[string]$subscriptionId,
THIS SAMPLE CODE IS MADE AVAILABLE AS IS. MICROSOFT MAKES NO WARRANTIES, WHETHER EXPRESS OR IMPLIED,
OF FITNESS FOR A PARTICULAR PURPOSE, OF ACCURACY OR COMPLETENESS OF RESPONSES, OF RESULTS, OR CONDITIONS OF MERCHANTABILITY.
THE ENTIRE RISK OF THE USE OR THE RESULTS FROM THE USE OF THIS SAMPLE CODE REMAINS WITH THE USER.
NO TECHNICAL SUPPORT IS PROVIDED. YOU MAY NOT DISTRIBUTE THIS CODE UNLESS YOU HAVE A LICENSE AGREEMENT WITH MICROSOFT THAT ALLOWS YOU TO DO SO.
#>

param(
[Parameter(Mandatory, HelpMessage="The subscriptionId")]
[string]$subscriptionId,

[Parameter(
Mandatory=$true,
HelpMessage="The resource group"
)]
[string]$resourceGroup
)
[Parameter(Mandatory, HelpMessage="The resource group")]
[string]$resourceGroup
)

Write-Host "Logging In..." -ForegroundColor Green
$connect = AzureLogin
if ($false -eq $connect)
{
return
}
$ErrorActionPreference = "Stop"

Write-Host "Logged In..." -ForegroundColor Green
$cmkPolicies = GetEnterprisePoliciesInResourceGroup $subscriptionId "Encryption" $resourceGroup
$cmkPolicies | Select-Object -Property ResourceId, Location, Name
Import-Module "$PSScriptRoot\..\Common\EnterprisePolicies" -Force

if (-not(Connect-Azure))
{
return
}
GetCMKEnterprisePoliciesInResourceGroup

$cmkPolicies = Get-EnterprisePoliciesInResourceGroup -SubscriptionId $subscriptionId -PolicyType [PolicyType]::Encryption -ResourceGroup $resourceGroup
$cmkPolicies | Select-Object -Property ResourceId, Location, Name
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
# Load the environment script
. "$PSScriptRoot\..\Common\EnterprisePolicyOperations.ps1"
<#
SAMPLE CODE NOTICE

function GetCMKEnterprisePoliciesInSubscription
{
param(
[Parameter(
Mandatory=$true,
HelpMessage="The subscriptionId"
)]
[string]$subscriptionId
)
THIS SAMPLE CODE IS MADE AVAILABLE AS IS. MICROSOFT MAKES NO WARRANTIES, WHETHER EXPRESS OR IMPLIED,
OF FITNESS FOR A PARTICULAR PURPOSE, OF ACCURACY OR COMPLETENESS OF RESPONSES, OF RESULTS, OR CONDITIONS OF MERCHANTABILITY.
THE ENTIRE RISK OF THE USE OR THE RESULTS FROM THE USE OF THIS SAMPLE CODE REMAINS WITH THE USER.
NO TECHNICAL SUPPORT IS PROVIDED. YOU MAY NOT DISTRIBUTE THIS CODE UNLESS YOU HAVE A LICENSE AGREEMENT WITH MICROSOFT THAT ALLOWS YOU TO DO SO.
#>

param(
[Parameter(Mandatory, HelpMessage="The subscriptionId")]
[string]$SubscriptionId
)

Write-Host "Logging In..." -ForegroundColor Green
$connect = AzureLogin
if ($false -eq $connect)
{
return
}
$ErrorActionPreference = "Stop"

Write-Host "Logged In..." -ForegroundColor Green
$cmkPolicies = GetEnterprisePoliciesInSubscription $subscriptionId "Encryption"
$cmkPolicies | Select-Object -Property ResourceId, Location, Name
Import-Module "$PSScriptRoot\..\Common\EnterprisePolicies" -Force

if (-not(Connect-Azure))
{
return
}
GetCMKEnterprisePoliciesInSubscription

$cmkPolicies = Get-EnterprisePoliciesInSubscription -SubscriptionId $SubscriptionId -PolicyType [PolicyType]::Encryption
$cmkPolicies | Select-Object -Property ResourceId, Location, Name
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
# Load the environment script
. "$PSScriptRoot\..\Common\EnterprisePolicyOperations.ps1"
<#
SAMPLE CODE NOTICE

function GetCMKEnterprisePolicyByResourceId
{
param(
[Parameter(
Mandatory=$true,
HelpMessage="The Policy Id"
)]
[string]$enterprisePolicyArmId
)
THIS SAMPLE CODE IS MADE AVAILABLE AS IS. MICROSOFT MAKES NO WARRANTIES, WHETHER EXPRESS OR IMPLIED,
OF FITNESS FOR A PARTICULAR PURPOSE, OF ACCURACY OR COMPLETENESS OF RESPONSES, OF RESULTS, OR CONDITIONS OF MERCHANTABILITY.
THE ENTIRE RISK OF THE USE OR THE RESULTS FROM THE USE OF THIS SAMPLE CODE REMAINS WITH THE USER.
NO TECHNICAL SUPPORT IS PROVIDED. YOU MAY NOT DISTRIBUTE THIS CODE UNLESS YOU HAVE A LICENSE AGREEMENT WITH MICROSOFT THAT ALLOWS YOU TO DO SO.
#>

Write-Host "Logging In..." -ForegroundColor Green
$connect = AzureLogin
if ($false -eq $connect)
{
return
}
param(
[Parameter(Mandatory, HelpMessage="The Policy Id")]
[string]$EnterprisePolicyArmId
)

Write-Host "Logged In..." -ForegroundColor Green
$ErrorActionPreference = "Stop"

$policy = GetEnterprisePolicy $enterprisePolicyArmId
$policyString = $policy | ConvertTo-Json -Depth 7
Write-Host $policyString
Import-Module "$PSScriptRoot\..\Common\EnterprisePolicies" -Force

if (-not(Connect-Azure))
{
return
}
GetCMKEnterprisePolicyByResourceId

$policy = Get-EnterprisePolicy -PolicyArmId $EnterprisePolicyArmId
$policyString = $policy | ConvertTo-Json -Depth 7
Write-Host $policyString
Loading