Skip to content

Commit acdbb36

Browse files
unknownunknown
authored andcommitted
WinRM, CustomData, Secrets, SshKey, AddtionalUnattendContent
Set-AzureVMOperatiingSystem New-AzureAdditionalUnattendContent New-AzureSshPublicKey New-AzureVaultCertificate New-AzureVaultSecretGroup
1 parent 2cbed85 commit acdbb36

File tree

8 files changed

+456
-10
lines changed

8 files changed

+456
-10
lines changed

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/VirtualMachineProfileTests.ps1

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,87 @@ function Test-VirtualMachineProfile
6666
Assert-AreEqual $p.StorageProfile.DataDisks[1].Lun 1;
6767
Assert-AreEqual $p.StorageProfile.DataDisks[1].VirtualHardDisk.Uri $dataDiskVhdUri2;
6868

69-
# OS
69+
# Windows OS
7070
$user = "Foo12";
7171
$password = 'BaR@000' + ((Get-Random) % 10000);
7272
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force;
7373
$cred = New-Object System.Management.Automation.PSCredential ($user, $securePassword);
7474
$computerName = 'test';
7575
$vhdContainer = "https://$stoname.blob.core.windows.net/test";
7676
$img = 'a699494373c04fc0bc8f2bb1389d6106__Windows-Server-2012-Datacenter-201503.01-en.us-127GB.vhd';
77-
78-
$p = Set-AzureVMOperatingSystem -VM $p -Windows -ComputerName $computerName -Credential $cred;
77+
78+
$referenceUri = "/subscriptions/05cacd0c-6f9b-492e-b673-d8be41a7644f/resourceGroups/RgTest1/providers/Microsoft.KeyVault/vaults/TestVault123";
79+
$certStore = "My";
80+
$certUrl = "https://testvault123.vault.azure.net/secrets/Test1/514ceb769c984379a7e0230bdd703272";
81+
$vaultCert = New-AzureVaultCertificate -CertificateStore $certStore -CertificateUrl $certUrl;
82+
$vaultSG = New-AzureVaultSecretGroup -ReferenceUri $referenceUri -VaultCertificates $vaultCert;
83+
84+
$aucSetting = "AutoLogon";
85+
$aucContent = "<UserAccounts><AdministratorPassword><Value>p@ssw0rd</Value><PlainText>true</PlainText></AdministratorPassword></UserAccounts>";
86+
$auc1 = New-AzureAdditionalUnattendContent -Content $aucContent -SettingName $aucSetting;
87+
$auc2 = New-AzureAdditionalUnattendContent -Content $aucContent -SettingName $aucSetting;
88+
89+
$winRMCertUrl = "http://keyVaultName.vault.azure.net/secrets/secretName/secretVersion";
90+
$timeZone = "Pacific Standard Time";
91+
$custom = "echo 'Hello World'";
92+
$encodedCustom = "ZWNobyAnSGVsbG8gV29ybGQn";
93+
94+
$p = Set-AzureVMOperatingSystem -VM $p -Windows -ComputerName $computerName -Credential $cred -CustomData $custom -Secrets $vaultSG -WinRMHttp -WinRMHttps -WinRMCertUrl $winRMCertUrl -ProvisionVMAgent -EnableAutoUpdate -TimeZone $timeZone -AdditionalUnattendContents $auc1,$auc2;
7995
$p = Set-AzureVMSourceImage -VM $p -Name $img -DestinationVhdsContainer $vhdContainer;
8096

8197
Assert-AreEqual $p.OSProfile.AdminUsername $user;
8298
Assert-AreEqual $p.OSProfile.ComputerName $computerName;
8399
Assert-AreEqual $p.OSProfile.AdminPassword $password;
84100
Assert-AreEqual $p.StorageProfile.DestinationVhdsContainer.ToString() $vhdContainer;
85101
Assert-AreEqual $p.StorageProfile.SourceImage.ReferenceUri ('/' + (Get-AzureSubscription -Current).SubscriptionId + '/services/images/' + $img);
102+
Assert-AreEqual $p.OSProfile.Secrets[0].SourceVault.ReferenceUri $referenceUri;
103+
Assert-AreEqual $p.OSProfile.Secrets[0].VaultCertificates[0].CertificateStore $certStore;
104+
Assert-AreEqual $p.OSProfile.Secrets[0].VaultCertificates[0].CertificateUrl $certUrl;
105+
Assert-AreEqual $encodedCustom $p.OSProfile.CustomData;
106+
107+
# Verify WinRM
108+
Assert-AreEqual $null $p.OSProfile.WindowsConfiguration.WinRMConfiguration.Listeners[0].CertificateUrl;
109+
Assert-AreEqual "http" $p.OSProfile.WindowsConfiguration.WinRMConfiguration.Listeners[0].Protocol ;
110+
Assert-AreEqual $winRMCertUrl $p.OSProfile.WindowsConfiguration.WinRMConfiguration.Listeners[1].CertificateUrl ;
111+
Assert-AreEqual "https" $p.OSProfile.WindowsConfiguration.WinRMConfiguration.Listeners[1].Protocol ;
112+
113+
# Verify Windows Provisioning Setup
114+
Assert-AreEqual $true $p.OSProfile.WindowsConfiguration.ProvisionVMAgent;
115+
Assert-AreEqual $true $p.OSProfile.WindowsConfiguration.EnableAutomaticUpdates;
116+
Assert-AreEqual $timeZone $p.OSProfile.WindowsConfiguration.TimeZone;
117+
118+
# Verify Additional Unattend Content
119+
Assert-AreEqual "Microsoft-Windows-Shell-Setup" $p.OSProfile.WindowsConfiguration.AdditionalUnattendContents[0].ComponentName;
120+
Assert-AreEqual $aucContent $p.OSProfile.WindowsConfiguration.AdditionalUnattendContents[0].Content;
121+
Assert-AreEqual "oobeSystem" $p.OSProfile.WindowsConfiguration.AdditionalUnattendContents[0].PassName;
122+
Assert-AreEqual $aucSetting $p.OSProfile.WindowsConfiguration.AdditionalUnattendContents[0].SettingName;
123+
Assert-AreEqual "Microsoft-Windows-Shell-Setup" $p.OSProfile.WindowsConfiguration.AdditionalUnattendContents[1].ComponentName;
124+
Assert-AreEqual $aucContent $p.OSProfile.WindowsConfiguration.AdditionalUnattendContents[1].Content;
125+
Assert-AreEqual "oobeSystem" $p.OSProfile.WindowsConfiguration.AdditionalUnattendContents[1].PassName;
126+
Assert-AreEqual $aucSetting $p.OSProfile.WindowsConfiguration.AdditionalUnattendContents[1].SettingName;
127+
128+
# Linux OS
129+
$img = "b4590d9e3ed742e4a1d46e5424aa335e__SUSE-Linux-Enterprise-Server-11-SP3-v206";
130+
$sshPath = "/home/pstestuser/.ssh/authorized_keys";
131+
$sshPublicKey = "MIIDszCCApugAwIBAgIJALBV9YJCF/tAMA0GCSqGSIb3DQEBBQUAMEUxCzAJBgNV";
132+
133+
$sshKey = New-AzureSshPublicKey -KeyData $sshPublicKey -Path $sshPath;
134+
135+
$p = Set-AzureVMOperatingSystem -VM $p -Linux -ComputerName $computerName -Credential $cred -CustomData $custom -Secrets $vaultSG -SSHPublicKeys $sshKey -DisablePasswordAuthentication;
136+
$p = Set-AzureVMSourceImage -VM $p -Name $img -DestinationVhdsContainer $vhdContainer;
137+
138+
Assert-AreEqual $p.OSProfile.AdminUsername $user;
139+
Assert-AreEqual $p.OSProfile.ComputerName $computerName;
140+
Assert-AreEqual $p.OSProfile.AdminPassword $password;
141+
Assert-AreEqual $p.StorageProfile.DestinationVhdsContainer.ToString() $vhdContainer;
142+
Assert-AreEqual $p.StorageProfile.SourceImage.ReferenceUri ('/' + (Get-AzureSubscription -Current).SubscriptionId + '/services/images/' + $img);
143+
Assert-AreEqual $p.OSProfile.Secrets[0].SourceVault.ReferenceUri $referenceUri;
144+
Assert-AreEqual $p.OSProfile.Secrets[0].VaultCertificates[0].CertificateStore $certStore;
145+
Assert-AreEqual $p.OSProfile.Secrets[0].VaultCertificates[0].CertificateUrl $certUrl;
146+
Assert-AreEqual $encodedCustom $p.OSProfile.CustomData;
147+
148+
# Verify SSH configuration
149+
Assert-AreEqual $sshPublicKey $p.OSProfile.LinuxConfiguration.SshConfiguration.PublicKeys[0].KeyData;
150+
Assert-AreEqual $sshPath $p.OSProfile.LinuxConfiguration.SshConfiguration.PublicKeys[0].Path;
151+
Assert-AreEqual $true $p.OSProfile.LinuxConfiguration.DisablePasswordAuthentication
86152
}

src/ResourceManager/Compute/Commands.Compute/Commands.Compute.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@
151151
<Compile Include="VirtualMachineSizes\VirtualMachineSizeBaseCmdlet.cs" />
152152
<Compile Include="VirtualMachine\Action\SaveAzureVMImageCommand.cs" />
153153
<Compile Include="VirtualMachine\Action\SetAzureVMCommand.cs" />
154+
<Compile Include="VirtualMachine\Config\NewAzureAdditionalUnattendContentCommand.cs" />
155+
<Compile Include="VirtualMachine\Config\NewAzureSshPublicKeyCommand.cs" />
156+
<Compile Include="VirtualMachine\Config\NewAzureVaultCertificateCommand.cs" />
157+
<Compile Include="VirtualMachine\Config\NewAzureVaultSecretGroupCommand.cs" />
154158
<Compile Include="VirtualMachine\Config\RemoveAzureVMDataDiskCommand.cs" />
155159
<Compile Include="VirtualMachine\Config\SetAzureVMSourceImage.cs" />
156160
<Compile Include="VirtualMachine\Config\SetAzureVMOSDiskCommand.cs" />

src/ResourceManager/Compute/Commands.Compute/Common/ConstantStringTypes.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,10 @@ public static class ProfileNouns
7272
public const string VirtualMachineSize = "AzureVMSize";
7373

7474
public const string VirtualMachineImage = "AzureVMImage";
75+
76+
public const string SshPublicKey = "AzureSshPublicKey";
77+
public const string AdditionalUnattendContent = "AzureAdditionalUnattendContent";
78+
public const string VaultCertificate = "AzureVaultCertificate";
79+
public const string VaultSecretGroup = "AzureVaultSecretGroup";
7580
}
7681
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Commands.Compute.Common;
16+
using Microsoft.Azure.Management.Compute.Models;
17+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
18+
using System.Management.Automation;
19+
20+
namespace Microsoft.Azure.Commands.Compute
21+
{
22+
/// <summary>
23+
/// Create Additional Unattend Content Object
24+
/// </summary>
25+
[Cmdlet(
26+
VerbsCommon.New,
27+
ProfileNouns.AdditionalUnattendContent),
28+
OutputType(
29+
typeof(AdditionalUnattendContent))]
30+
public class NewAzureAdditionalUnattendContentCommand : AzurePSCmdlet
31+
{
32+
private const string defaultComponentName = "Microsoft-Windows-Shell-Setup";
33+
private const string defaultPassName = "oobeSystem";
34+
35+
[Parameter(
36+
DontShow = true, // Currently, the only allowable value is 'Microsoft-Windows-Shell-Setup'.
37+
Position = 0,
38+
ValueFromPipelineByPropertyName = true,
39+
HelpMessage = "Component Name.")]
40+
[ValidateNotNullOrEmpty]
41+
public string ComponentName { get; set; }
42+
43+
[Parameter(
44+
Position = 1,
45+
ValueFromPipelineByPropertyName = true,
46+
HelpMessage = "XML Formatted Content.")]
47+
[ValidateNotNullOrEmpty]
48+
public string Content { get; set; }
49+
50+
[Parameter(
51+
DontShow = true, // Currently, the only allowable value is 'oobeSystem'.
52+
Position = 2,
53+
ValueFromPipelineByPropertyName = true,
54+
HelpMessage = "Pass name")]
55+
[ValidateNotNullOrEmpty]
56+
public string PassName { get; set; }
57+
58+
[Parameter(
59+
Position = 3,
60+
ValueFromPipelineByPropertyName = true,
61+
HelpMessage = "Setting Name.")]
62+
[ValidateNotNullOrEmpty]
63+
public string SettingName { get; set; }
64+
65+
public override void ExecuteCmdlet()
66+
{
67+
WriteObject(new AdditionalUnattendContent
68+
{
69+
ComponentName = defaultComponentName,
70+
Content = this.Content,
71+
PassName = defaultPassName,
72+
SettingName = this.SettingName,
73+
});
74+
}
75+
}
76+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Commands.Compute.Common;
16+
using Microsoft.Azure.Management.Compute.Models;
17+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
18+
using System.Management.Automation;
19+
20+
namespace Microsoft.Azure.Commands.Compute
21+
{
22+
/// <summary>
23+
/// Create Ssh Public Key object
24+
/// </summary>
25+
[Cmdlet(
26+
VerbsCommon.New,
27+
ProfileNouns.SshPublicKey),
28+
OutputType(
29+
typeof(SshPublicKey))]
30+
public class NewAzureSshPublicKeyCommand : AzurePSCmdlet
31+
{
32+
[Parameter(
33+
Position = 0,
34+
ValueFromPipelineByPropertyName = true,
35+
HelpMessage = "Certificate Public Key")]
36+
[ValidateNotNullOrEmpty]
37+
public string KeyData { get; set; }
38+
39+
[Parameter(
40+
Position = 1,
41+
ValueFromPipelineByPropertyName = true,
42+
HelpMessage = "Full Path on VM where SSH Public Key is Stored.")]
43+
[ValidateNotNullOrEmpty]
44+
public string Path { get; set; }
45+
46+
public override void ExecuteCmdlet()
47+
{
48+
WriteObject(new SshPublicKey
49+
{
50+
KeyData = this.KeyData,
51+
Path = this.Path,
52+
});
53+
}
54+
}
55+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Commands.Compute.Common;
16+
using Microsoft.Azure.Management.Compute.Models;
17+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
18+
using System.Management.Automation;
19+
20+
namespace Microsoft.Azure.Commands.Compute
21+
{
22+
/// <summary>
23+
/// Create Vault Certificate object
24+
/// </summary>
25+
[Cmdlet(
26+
VerbsCommon.New,
27+
ProfileNouns.VaultCertificate),
28+
OutputType(
29+
typeof(VaultCertificate))]
30+
public class NewAzureVaultCertificateCommand : AzurePSCmdlet
31+
{
32+
[Parameter(
33+
Position = 0,
34+
ValueFromPipelineByPropertyName = true,
35+
HelpMessage = "Certificate store in LocalMachine")]
36+
[ValidateNotNullOrEmpty]
37+
public string CertificateStore { get; set; }
38+
39+
[Parameter(
40+
Position = 1,
41+
ValueFromPipelineByPropertyName = true,
42+
HelpMessage = "URL referencing a secret in a Key Vault.")]
43+
[ValidateNotNullOrEmpty]
44+
public string CertificateUrl { get; set; }
45+
46+
public override void ExecuteCmdlet()
47+
{
48+
WriteObject(new VaultCertificate
49+
{
50+
CertificateStore = this.CertificateStore,
51+
CertificateUrl = this.CertificateUrl,
52+
});
53+
}
54+
}
55+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Commands.Compute.Common;
16+
using Microsoft.Azure.Management.Compute.Models;
17+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
18+
using System.Management.Automation;
19+
using System.Collections.Generic;
20+
21+
namespace Microsoft.Azure.Commands.Compute
22+
{
23+
/// <summary>
24+
/// Create Vault Secret Group object
25+
/// </summary>
26+
[Cmdlet(
27+
VerbsCommon.New,
28+
ProfileNouns.VaultSecretGroup),
29+
OutputType(
30+
typeof(VaultSecretGroup))]
31+
public class NewAzureVaultSecretGroupCommand : AzurePSCmdlet
32+
{
33+
[Parameter(
34+
Position = 0,
35+
ValueFromPipelineByPropertyName = true,
36+
HelpMessage = "Certificate store in LocalMachine")]
37+
[ValidateNotNullOrEmpty]
38+
public string ReferenceUri { get; set; }
39+
40+
[Parameter(
41+
Position = 1,
42+
ValueFromPipelineByPropertyName = true,
43+
HelpMessage = "URL referencing a secret in a Key Vault.")]
44+
[ValidateNotNullOrEmpty]
45+
public List<VaultCertificate> VaultCertificates { get; set; }
46+
47+
public override void ExecuteCmdlet()
48+
{
49+
WriteObject(new VaultSecretGroup
50+
{
51+
SourceVault = new SourceVaultReference { ReferenceUri = this.ReferenceUri },
52+
VaultCertificates = this.VaultCertificates,
53+
});
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)