Skip to content

Commit 09530df

Browse files
authored
[AKS] Support Azure Hybrid User Benefits (#21764)
* [AKS] support parameter OutboundType * [AKS] Fixed the issue of Enable-AzAksAddon when there are no addons * [AKS] Support EnableAHUB * update changelog and help md
1 parent 96f7769 commit 09530df

File tree

9 files changed

+4376
-22
lines changed

9 files changed

+4376
-22
lines changed

src/Aks/Aks.Test/ScenarioTests/KubernetesTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,5 +219,12 @@ public void TestOutboundType()
219219
{
220220
TestRunner.RunTestScript("Test-OutboundType");
221221
}
222+
223+
[Fact]
224+
[Trait(Category.AcceptanceType, Category.CheckIn)]
225+
public void TestEnableAHUB()
226+
{
227+
TestRunner.RunTestScript("Test-EnableAHUB");
228+
}
222229
}
223230
}

src/Aks/Aks.Test/ScenarioTests/KubernetesTests.ps1

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,4 +1248,33 @@ function Test-OutboundType {
12481248
finally {
12491249
Remove-AzResourceGroup -Name $resourceGroupName -Force
12501250
}
1251+
}
1252+
1253+
function Test-EnableAHUB {
1254+
# Setup
1255+
$resourceGroupName = Get-RandomResourceGroupName
1256+
$kubeClusterName = Get-RandomClusterName
1257+
$location = 'eastus'
1258+
1259+
try {
1260+
New-AzResourceGroup -Name $resourceGroupName -Location $location
1261+
1262+
$SecurePassword = ConvertTo-SecureString 'Abcdefg@123456' -AsPlainText -Force
1263+
New-AzAksCluster -ResourceGroupName $resourceGroupName -Name $kubeClusterName -NodeCount 1 -WindowsProfileAdminUserName azure -WindowsProfileAdminUserPassword $SecurePassword -EnableAHUB
1264+
$cluster = Get-AzAksCluster -ResourceGroupName $resourceGroupName -Name $kubeClusterName
1265+
Assert-AreEqual 'Windows_Server' $cluster.WindowsProfile.LicenseType
1266+
$cluster = Set-AzAksCluster -ResourceGroupName $resourceGroupName -Name $kubeClusterName -EnableAHUB:$false
1267+
Assert-AreEqual 'None' $cluster.WindowsProfile.LicenseType
1268+
1269+
1270+
$kubeClusterName = Get-RandomClusterName
1271+
New-AzAksCluster -ResourceGroupName $resourceGroupName -Name $kubeClusterName -NodeCount 1
1272+
$cluster = Get-AzAksCluster -ResourceGroupName $resourceGroupName -Name $kubeClusterName
1273+
Assert-Null $cluster.WindowsProfile.LicenseType
1274+
$cluster = $cluster | Set-AzAksCluster -EnableAHUB
1275+
Assert-AreEqual 'Windows_Server' $cluster.WindowsProfile.LicenseType
1276+
}
1277+
finally {
1278+
Remove-AzResourceGroup -Name $resourceGroupName -Force
1279+
}
12511280
}

src/Aks/Aks.Test/SessionRecords/Commands.Aks.Test.ScenarioTests.KubernetesTests/TestEnableAHUB.json

Lines changed: 4247 additions & 0 deletions
Large diffs are not rendered by default.

src/Aks/Aks/ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
-->
2020
## Upcoming Release
2121
* Fixed the issue of `Enable-AzAksAddon` when there are no addons. [#21665]
22+
* Added parameter `-EnableAHUB` for `New-AzAksCluster` and `Set-AzAksCluster`
23+
* Added parameter `-WindowsProfileAdminUserPassword` for `Set-AzAksCluster`
2224

2325
## Version 5.4.0
2426
* Added cmdlet `New-AzAksMaintenanceConfiguration`, `Get-AzAksMaintenanceConfiguration`, `Remove-AzAksMaintenanceConfiguration`, `New-AzAksSnapshot`, `Get-AzAksSnapshot`, `Remove-AzAksSnapshot`, `Get-AzAksManagedClusterCommandResult`, `Get-AzAksManagedClusterOSOption`, `Get-AzAksManagedClusterOutboundNetworkDependencyEndpoint`, `Invoke-AzAksAbortAgentPoolLatestOperation`, `Invoke-AzAksAbortManagedClusterLatestOperation`, `Invoke-AzAksRotateManagedClusterServiceAccountSigningKey`, `Start-AzAksManagedClusterCommand`, `New-AzAksTimeInWeekObject`, `New-AzAksTimeSpanObject`.

src/Aks/Aks/Commands/CreateOrUpdateKubeBase.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
using Microsoft.Azure.Commands.Common.MSGraph.Version1_0;
4141
using ResourceIdentityType = Microsoft.Azure.Management.ContainerService.Models.ResourceIdentityType;
4242
using Microsoft.Azure.Commands.Aks.Commands;
43+
using Microsoft.Azure.Commands.Aks.Utils;
44+
using System.Security;
4345

4446
namespace Microsoft.Azure.Commands.Aks
4547
{
@@ -197,6 +199,14 @@ public abstract class CreateOrUpdateKubeBase : KubeCmdletBase
197199
[Parameter(Mandatory = false, HelpMessage = "The Azure Active Directory configuration.")]
198200
public ManagedClusterAADProfile AadProfile { get; set; }
199201

202+
[Parameter(Mandatory = false, HelpMessage = "The administrator password to use for Windows VMs. Password requirement:"
203+
+ "At least one lower case, one upper case, one special character !@#$%^&*(), the minimum lenth is 12.")]
204+
[ValidateSecureString(RegularExpression = "^(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%\\^&\\*\\(\\)])[a-zA-Z\\d!@#$%\\^&\\*\\(\\)]{12,123}$", ParameterName = nameof(WindowsProfileAdminUserPassword))]
205+
public SecureString WindowsProfileAdminUserPassword { get; set; }
206+
207+
[Parameter(Mandatory = false, HelpMessage = "Whether to enable Azure Hybrid User Benefits (AHUB) for Windows VMs.")]
208+
public SwitchParameter EnableAHUB { get; set; }
209+
200210
protected void BeforeBuildNewCluster()
201211
{
202212
if (!string.IsNullOrEmpty(ResourceGroupName) && string.IsNullOrEmpty(Location))

src/Aks/Aks/Commands/NewAzureRmAks.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
using System.IO;
2020
using System.Linq;
2121
using System.Management.Automation;
22-
using System.Security;
2322
using Microsoft.Azure.Commands.Aks.Models;
2423
using Microsoft.Azure.Commands.Aks.Properties;
2524
using Microsoft.Azure.Commands.Aks.Utils;
@@ -31,7 +30,6 @@
3130
using Microsoft.Rest;
3231
using Microsoft.WindowsAzure.Commands.Common;
3332
using Microsoft.WindowsAzure.Commands.Utilities.Common;
34-
using Newtonsoft.Json;
3533

3634
namespace Microsoft.Azure.Commands.Aks
3735
{
@@ -88,11 +86,6 @@ public class NewAzureRmAks : CreateOrUpdateKubeBase
8886
[Parameter(Mandatory = false, HelpMessage = "The administrator username to use for Windows VMs.")]
8987
public string WindowsProfileAdminUserName { get; set; }
9088

91-
[Parameter(Mandatory = false, HelpMessage = "The administrator password to use for Windows VMs. Password requirement:"
92-
+ "At least one lower case, one upper case, one special character !@#$%^&*(), the minimum lenth is 12.")]
93-
[ValidateSecureString(RegularExpression = "^(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%\\^&\\*\\(\\)])[a-zA-Z\\d!@#$%\\^&\\*\\(\\)]{12,123}$", ParameterName = nameof(WindowsProfileAdminUserPassword))]
94-
public SecureString WindowsProfileAdminUserPassword { get; set; }
95-
9689
[Parameter(Mandatory = false, HelpMessage = "Network plugin used for building Kubernetes network.")]
9790
[PSArgumentCompleter("azure", "kubenet")]
9891
public string NetworkPlugin { get; set; } = "azure";
@@ -490,6 +483,10 @@ private ManagedClusterWindowsProfile GetWindowsProfile()
490483
{
491484
windowsProfile = new ManagedClusterWindowsProfile(WindowsProfileAdminUserName,
492485
WindowsProfileAdminUserPassword?.ConvertToString());
486+
if (this.IsParameterBound(c => c.EnableAHUB) && EnableAHUB.ToBool())
487+
{
488+
windowsProfile.LicenseType = "Windows_Server";
489+
}
493490
}
494491
return windowsProfile;
495492
}

src/Aks/Aks/Commands/SetAzureRmAks.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,24 @@ public override void ExecuteCmdlet()
427427
{
428428
cluster.OidcIssuerProfile = new ManagedClusterOIDCIssuerProfile(enabled: true);
429429
}
430+
if (cluster.WindowsProfile != null)
431+
{
432+
if (this.IsParameterBound(c => c.WindowsProfileAdminUserPassword) && WindowsProfileAdminUserPassword != null)
433+
{
434+
cluster.WindowsProfile.AdminPassword = WindowsProfileAdminUserPassword.ConvertToString();
435+
}
436+
if (this.IsParameterBound(c => c.EnableAHUB))
437+
{
438+
if (EnableAHUB.ToBool())
439+
{
440+
cluster.WindowsProfile.LicenseType = "Windows_Server";
441+
}
442+
else
443+
{
444+
cluster.WindowsProfile.LicenseType = "None";
445+
}
446+
}
447+
}
430448
SetIdentity(cluster);
431449

432450
var kubeCluster = this.CreateOrUpdate(ResourceGroupName, Name, cluster);
@@ -439,7 +457,7 @@ public override void ExecuteCmdlet()
439457
{
440458
cluster.DisableLocalAccounts = DisableLocalAccount;
441459
}
442-
460+
443461
WriteObject(AdapterHelper<ManagedCluster, PSKubernetesCluster>.Adapt(kubeCluster));
444462
});
445463
}

src/Aks/Aks/help/New-AzAksCluster.md

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@ The cmdlet may call below Microsoft Graph API according to input parameters:
2020
New-AzAksCluster [-NodeVmSetType <String>] [-NodeVnetSubnetID <String>] [-NodeMaxPodCount <Int32>]
2121
[-NodeSetPriority <String>] [-NodePoolMode <String>] [-NodeOsSKU <String>]
2222
[-NodeScaleSetEvictionPolicy <String>] [-AddOnNameToBeEnabled <String[]>] [-WorkspaceResourceId <String>]
23-
[-SubnetName <String>] [-EnableRbac] [-WindowsProfileAdminUserName <String>]
24-
[-WindowsProfileAdminUserPassword <SecureString>] [-NetworkPlugin <String>] [-NetworkPolicy <String>]
25-
[-PodCidr <String>] [-ServiceCidr <String>] [-DnsServiceIP <String>] [-DockerBridgeCidr <String>]
26-
[-OutboundType <String>] [-LoadBalancerSku <String>] [-Force] [-GenerateSshKey] [-EnableNodePublicIp]
27-
[-NodePublicIPPrefixID <String>] [-AvailabilityZone <String[]>] [-NodeResourceGroup <String>]
28-
[-EnableEncryptionAtHost] [-EnableUltraSSD] [-NodeLinuxOSConfig <LinuxOSConfig>]
23+
[-SubnetName <String>] [-EnableRbac] [-WindowsProfileAdminUserName <String>] [-NetworkPlugin <String>]
24+
[-NetworkPolicy <String>] [-PodCidr <String>] [-ServiceCidr <String>] [-DnsServiceIP <String>]
25+
[-DockerBridgeCidr <String>] [-OutboundType <String>] [-LoadBalancerSku <String>] [-Force] [-GenerateSshKey]
26+
[-EnableNodePublicIp] [-NodePublicIPPrefixID <String>] [-AvailabilityZone <String[]>]
27+
[-NodeResourceGroup <String>] [-EnableEncryptionAtHost] [-EnableUltraSSD] [-NodeLinuxOSConfig <LinuxOSConfig>]
2928
[-NodeKubeletConfig <KubeletConfig>] [-NodeMaxSurge <String>] [-PPG <String>] [-EnableFIPS]
3029
[-AutoScalerProfile <ManagedClusterPropertiesAutoScalerProfile>] [-GpuInstanceProfile <String>]
3130
[-EnableUptimeSLA] [-EdgeZone <String>] [-NodeHostGroupID <String>] [-NodePodSubnetID <String>]
@@ -43,8 +42,8 @@ New-AzAksCluster [-NodeVmSetType <String>] [-NodeVnetSubnetID <String>] [-NodeMa
4342
[-DiskEncryptionSetID <String>] [-DisableLocalAccount] [-HttpProxy <String>] [-HttpsProxy <String>]
4443
[-HttpProxyConfigNoProxyEndpoint <String[]>] [-HttpProxyConfigTrustedCa <String>]
4544
[-AksCustomHeader <Hashtable>] [-AadProfile <ManagedClusterAADProfile>]
46-
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [-SubscriptionId <String>]
47-
[<CommonParameters>]
45+
[-WindowsProfileAdminUserPassword <SecureString>] [-EnableAHUB] [-DefaultProfile <IAzureContextContainer>]
46+
[-WhatIf] [-Confirm] [-SubscriptionId <String>] [<CommonParameters>]
4847
```
4948

5049
## DESCRIPTION
@@ -397,6 +396,21 @@ Accept pipeline input: False
397396
Accept wildcard characters: False
398397
```
399398
399+
### -EnableAHUB
400+
Whether to enable Azure Hybrid User Benefits (AHUB) for Windows VMs.
401+
402+
```yaml
403+
Type: System.Management.Automation.SwitchParameter
404+
Parameter Sets: (All)
405+
Aliases:
406+
407+
Required: False
408+
Position: Named
409+
Default value: None
410+
Accept pipeline input: False
411+
Accept wildcard characters: False
412+
```
413+
400414
### -EnableApiServerAccessPrivateCluster
401415
Whether to create the cluster as a private cluster or not.
402416

src/Aks/Aks/help/Set-AzAksCluster.md

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ Set-AzAksCluster [-NodePoolMode <String>] [-AcrNameToDetach <String>] [-NodeImag
3030
[-DiskEncryptionSetID <String>] [-DisableLocalAccount] [-HttpProxy <String>] [-HttpsProxy <String>]
3131
[-HttpProxyConfigNoProxyEndpoint <String[]>] [-HttpProxyConfigTrustedCa <String>]
3232
[-AksCustomHeader <Hashtable>] [-AadProfile <ManagedClusterAADProfile>]
33-
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [-SubscriptionId <String>]
34-
[<CommonParameters>]
33+
[-WindowsProfileAdminUserPassword <SecureString>] [-EnableAHUB] [-DefaultProfile <IAzureContextContainer>]
34+
[-WhatIf] [-Confirm] [-SubscriptionId <String>] [<CommonParameters>]
3535
```
3636

3737
### InputObjectParameterSet
@@ -51,8 +51,8 @@ Set-AzAksCluster -InputObject <PSKubernetesCluster> [-NodePoolMode <String>] [-A
5151
[-DiskEncryptionSetID <String>] [-DisableLocalAccount] [-HttpProxy <String>] [-HttpsProxy <String>]
5252
[-HttpProxyConfigNoProxyEndpoint <String[]>] [-HttpProxyConfigTrustedCa <String>]
5353
[-AksCustomHeader <Hashtable>] [-AadProfile <ManagedClusterAADProfile>]
54-
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [-SubscriptionId <String>]
55-
[<CommonParameters>]
54+
[-WindowsProfileAdminUserPassword <SecureString>] [-EnableAHUB] [-DefaultProfile <IAzureContextContainer>]
55+
[-WhatIf] [-Confirm] [-SubscriptionId <String>] [<CommonParameters>]
5656
```
5757

5858
### IdParameterSet
@@ -72,8 +72,8 @@ Set-AzAksCluster [-NodePoolMode <String>] [-AcrNameToDetach <String>] [-NodeImag
7272
[-DiskEncryptionSetID <String>] [-DisableLocalAccount] [-HttpProxy <String>] [-HttpsProxy <String>]
7373
[-HttpProxyConfigNoProxyEndpoint <String[]>] [-HttpProxyConfigTrustedCa <String>]
7474
[-AksCustomHeader <Hashtable>] [-AadProfile <ManagedClusterAADProfile>]
75-
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [-SubscriptionId <String>]
76-
[<CommonParameters>]
75+
[-WindowsProfileAdminUserPassword <SecureString>] [-EnableAHUB] [-DefaultProfile <IAzureContextContainer>]
76+
[-WhatIf] [-Confirm] [-SubscriptionId <String>] [<CommonParameters>]
7777
```
7878

7979
## DESCRIPTION
@@ -343,6 +343,21 @@ Accept pipeline input: False
343343
Accept wildcard characters: False
344344
```
345345
346+
### -EnableAHUB
347+
Whether to enable Azure Hybrid User Benefits (AHUB) for Windows VMs.
348+
349+
```yaml
350+
Type: System.Management.Automation.SwitchParameter
351+
Parameter Sets: (All)
352+
Aliases:
353+
354+
Required: False
355+
Position: Named
356+
Default value: None
357+
Accept pipeline input: False
358+
Accept wildcard characters: False
359+
```
360+
346361
### -EnableApiServerAccessPrivateCluster
347362
Whether to create the cluster as a private cluster or not.
348363
@@ -902,6 +917,21 @@ Accept pipeline input: False
902917
Accept wildcard characters: False
903918
```
904919
920+
### -WindowsProfileAdminUserPassword
921+
The administrator password to use for Windows VMs. Password requirement:At least one lower case, one upper case, one special character !@#$%^&*(), the minimum lenth is 12.
922+
923+
```yaml
924+
Type: System.Security.SecureString
925+
Parameter Sets: (All)
926+
Aliases:
927+
928+
Required: False
929+
Position: Named
930+
Default value: None
931+
Accept pipeline input: False
932+
Accept wildcard characters: False
933+
```
934+
905935
### -Confirm
906936
Prompts you for confirmation before running the cmdlet.
907937

0 commit comments

Comments
 (0)