Skip to content

Added daemon and databag secret-key options in ChefExtension for ASM and ARM commands. #3387

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

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
4 changes: 4 additions & 0 deletions src/ResourceManager/Compute/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
- Additional information about change #1
-->
## Current Release
* Updated Set-AzureRmVMChefExtension cmdlet to add following new options :
- Daemon: Configures the chef-client service for unattended execution. e.g. -Daemon 'none' or e.g. -Daemon 'service'."
- Secret: The encryption key used to encrypt and decrypt the data bag item values.
- SecretFile: The path to the file that contains the encryption key used to encrypt and decrypt the data bag item values.

## Version 2.5.0
* Fix Get-AzureRmVM with -Status issue: Get-AzureRmVM throws an exception when Get-AzureRmVM lists multiple VMs and some of the VMs are deleted during Get-AzureRmVM is performed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public class SetAzureVMChefExtensionCommand : VirtualMachineExtensionBaseCmdlet
private string JsonAttributeTemplate = "custom_json_attr";
private string ChefServiceIntervalTemplate = "chef_service_interval";
private string RunListTemplate = "runlist";
private string DaemonTemplate = "daemon";
private string SecretTemplate = "encrypted_data_bag_secret";

[Parameter(
Mandatory = true,
Expand Down Expand Up @@ -114,6 +116,27 @@ public string TypeHandlerVersion
[ValidateNotNullOrEmpty]
public string ChefServiceInterval { get; set; }

[Parameter(
ValueFromPipelineByPropertyName = true,
HelpMessage = "Configures the chef-client service for unattended execution. The node platform should be Windows." +
"Options: 'none' or 'service'." +
"none - Currently prevents the chef-client service from being configured as a service." +
"service - Configures the chef-client to run automatically in the background as a service.")]
[ValidateNotNullOrEmpty]
public string Daemon { get; set; }

[Parameter(
ValueFromPipelineByPropertyName = true,
HelpMessage = "The encryption key used to encrypt and decrypt the data bag item values.")]
[ValidateNotNullOrEmpty]
public string Secret { get; set; }

[Parameter(
ValueFromPipelineByPropertyName = true,
HelpMessage = "The path to the file that contains the encryption key used to encrypt and decrypt the data bag item values.")]
[ValidateNotNullOrEmpty]
public string SecretFile { get; set; }

[Parameter(
ValueFromPipelineByPropertyName = true,
HelpMessage = "The Chef Server Node Runlist.")]
Expand Down Expand Up @@ -228,6 +251,7 @@ private Hashtable PublicConfiguration
bool IsJsonAttributeEmpty = string.IsNullOrEmpty(this.JsonAttribute);
bool IsChefServiceIntervalEmpty = string.IsNullOrEmpty(this.ChefServiceInterval);
string BootstrapVersion = string.IsNullOrEmpty(this.BootstrapVersion) ? "" : this.BootstrapVersion;
bool IsDaemonEmpty = string.IsNullOrEmpty(this.Daemon);

//Cases handled:
// 1. When clientRb given by user and:
Expand Down Expand Up @@ -300,6 +324,11 @@ private Hashtable PublicConfiguration
hashTable.Add(ChefServiceIntervalTemplate, ChefServiceInterval);
}

if (this.Windows.IsPresent && !IsDaemonEmpty)
{
hashTable.Add(DaemonTemplate, this.Daemon);
}

this.publicConfiguration = hashTable;
}

Expand All @@ -314,6 +343,12 @@ private Hashtable PrivateConfiguration
if (this.privateConfiguration == null)
{
var hashTable = new Hashtable();

if (!string.IsNullOrEmpty(this.SecretFile))
hashTable.Add(SecretTemplate, File.ReadAllText(this.SecretFile).TrimEnd('\r', '\n'));
else if (!string.IsNullOrEmpty(this.Secret))
hashTable.Add(SecretTemplate, this.Secret);

hashTable.Add(PrivateConfigurationTemplate, File.ReadAllText(this.ValidationPem).TrimEnd('\r', '\n'));
this.privateConfiguration = hashTable;
}
Expand Down Expand Up @@ -398,12 +433,30 @@ private void ValidateParameters()
bool IsClientRbEmpty = string.IsNullOrEmpty(this.ClientRb);
bool IsChefServerUrlEmpty = string.IsNullOrEmpty(this.ChefServerUrl);
bool IsValidationClientNameEmpty = string.IsNullOrEmpty(this.ValidationClientName);
bool IsDaemonEmpty = string.IsNullOrEmpty(this.Daemon);
// Validate ClientRb or ChefServerUrl and ValidationClientName should exist.
if (IsClientRbEmpty && (IsChefServerUrlEmpty || IsValidationClientNameEmpty))
{
throw new ArgumentException(
"Required -ClientRb or -ChefServerUrl and -ValidationClientName options.");
}

if (!IsDaemonEmpty)
{
bool IsDaemonValueInvalid = Array.IndexOf(new String[2] {"none", "service"}, this.Daemon) == -1;
// Validation against the invalid use of Daemon option.
if (IsDaemonValueInvalid || this.Linux.IsPresent)
{
throw new ArgumentException(
"Invalid use of -Daemon option.");
}
}

if (!string.IsNullOrEmpty(this.SecretFile) && !File.Exists(this.SecretFile))
{
throw new FileNotFoundException(
"File specified in -SecretFile option does not exist.");
}
}

public override void ExecuteCmdlet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13015,6 +13015,24 @@ PS C:\> Set-AzureRmVMBootDiagnostics -VM $VM -Enable -ResourceGroupName "Reso
<maml:uri /></dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="True (ByPropertyName)" position="named" aliases="none"><maml:name>Secret</maml:name>
<maml:Description><maml:para>The encryption key used to encrypt and decrypt the data bag item values.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@markcowl I have fixed all the review comments. Just I did not understand this part add regenerate the help xml. from the above comment, can you elaborate this part as I am not aware of this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our help now resides in Markdown files. See: https://github.com/Azure/azure-powershell/blob/dev/documentation/platyPSHelp-documentation.md for details. This is designed to make it easire for you to update the help for cmdlets, in this case, because you used a different mechanism, it's an extra step, but next time, this should make it easier.

</maml:para>
</maml:Description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
<dev:type><maml:name>String</maml:name>
<maml:uri /></dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="True (ByPropertyName)" position="named" aliases="none"><maml:name>SecretFile</maml:name>
<maml:Description><maml:para>The path to the file that contains the encryption key used to encrypt and decrypt the data bag item values.
</maml:para>
</maml:Description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
<dev:type><maml:name>String</maml:name>
<maml:uri /></dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="True (ByPropertyName)" position="named" aliases="none"><maml:name>ClientRb</maml:name>
<maml:Description><maml:para>Specifies the full path of the Chef client.rb.
</maml:para>
Expand Down Expand Up @@ -13185,6 +13203,36 @@ PS C:\&gt; Set-AzureRmVMBootDiagnostics -VM $VM -Enable -ResourceGroupName "Reso
<maml:uri /></dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="True (ByPropertyName)" position="named" aliases="none"><maml:name>Daemon</maml:name>
<maml:Description><maml:para>Configures the chef-client service for unattended execution. The node platform should be Windows.
Options: 'none' or 'service'
none - Currently prevents the chef-client service from being configured as a service.
service - Configures the chef-client to run automatically in the background as a service.
</maml:para>
</maml:Description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
<dev:type><maml:name>String</maml:name>
<maml:uri /></dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="True (ByPropertyName)" position="named" aliases="none"><maml:name>Secret</maml:name>
<maml:Description><maml:para>The encryption key used to encrypt and decrypt the data bag item values.
</maml:para>
</maml:Description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
<dev:type><maml:name>String</maml:name>
<maml:uri /></dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="True (ByPropertyName)" position="named" aliases="none"><maml:name>SecretFile</maml:name>
<maml:Description><maml:para>The path to the file that contains the encryption key used to encrypt and decrypt the data bag item values.
</maml:para>
</maml:Description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
<dev:type><maml:name>String</maml:name>
<maml:uri /></dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="True (ByPropertyName)" position="named" aliases="none"><maml:name>ClientRb</maml:name>
<maml:Description><maml:para>Specifies the full path of the Chef client.rb.
</maml:para>
Expand Down Expand Up @@ -13310,6 +13358,36 @@ PS C:\&gt; Set-AzureRmVMBootDiagnostics -VM $VM -Enable -ResourceGroupName "Reso
<maml:uri /></dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="True (ByPropertyName)" position="named" aliases="none"><maml:name>Daemon</maml:name>
<maml:Description><maml:para>Configures the chef-client service for unattended execution. The node platform should be Windows.
Options: 'none' or 'service'
none - Currently prevents the chef-client service from being configured as a service.
service - Configures the chef-client to run automatically in the background as a service.
</maml:para>
</maml:Description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
<dev:type><maml:name>String</maml:name>
<maml:uri /></dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="True (ByPropertyName)" position="named" aliases="none"><maml:name>Secret</maml:name>
<maml:Description><maml:para>The encryption key used to encrypt and decrypt the data bag item values.
</maml:para>
</maml:Description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
<dev:type><maml:name>String</maml:name>
<maml:uri /></dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="True (ByPropertyName)" position="named" aliases="none"><maml:name>SecretFile</maml:name>
<maml:Description><maml:para>The path to the file that contains the encryption key used to encrypt and decrypt the data bag item values.
</maml:para>
</maml:Description>
<command:parameterValue required="true" variableLength="false">String</command:parameterValue>
<dev:type><maml:name>String</maml:name>
<maml:uri /></dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="True (ByPropertyName)" position="named" aliases="none"><maml:name>ClientRb</maml:name>
<maml:Description><maml:para>Specifies the full path of the Chef client.rb.
</maml:para>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Set-AzureRmVMChefExtension [-ResourceGroupName] <String> [-VMName] <String> [[-T
[-ChefServerUrl <String>] [-ValidationClientName <String>] [-OrganizationName <String>]
[-BootstrapVersion <String>] [-Linux] [[-Location] <String>] [[-Name] <String>]
[[-AutoUpgradeMinorVersion] <Boolean>] [-WhatIf] [-Confirm] [<CommonParameters>]
[-Secret <String>]
```

### Windows
Expand All @@ -28,6 +29,7 @@ Set-AzureRmVMChefExtension [-ResourceGroupName] <String> [-VMName] <String> [[-T
[-ChefServerUrl <String>] [-ValidationClientName <String>] [-OrganizationName <String>]
[-BootstrapVersion <String>] [-Windows] [[-Location] <String>] [[-Name] <String>]
[[-AutoUpgradeMinorVersion] <Boolean>] [-WhatIf] [-Confirm] [<CommonParameters>]
[-Daemon <String>] [-SecretFile <String>]
```

## DESCRIPTION
Expand All @@ -37,15 +39,15 @@ The **Set-AzureVMChefExtension** cmdlet adds the Chef extension to the virtual m

### Example 1: Add a Chef extension to a Windows virtual machine
```
PS C:\>Set-AzureRmVMChefExtension -ResourceGroupName "ResourceGroup001" -VMName "WindowsVM001" -ValidationPem "C:\my-org-validator.pem" -ClientRb "C:\client.rb" -RunList "Apache" -Windows
PS C:\>Set-AzureRmVMChefExtension -ResourceGroupName "ResourceGroup001" -VMName "WindowsVM001" -ValidationPem "C:\my-org-validator.pem" -ClientRb "C:\client.rb" -RunList "Apache" -Daemon "service" -SecretFile "C:\my_encrypted_data_bag_secret" -Windows
```

This command adds a Chef extension to a Windows virtual machine named WindowsVM001.
When the virtual machine starts, Chef bootstraps the virtual machine to run Apache.

### Example 2: Add a Chef extension to a Linux virtual machine
```
PS C:\>Set-AzureRmVMChefExtension -ResourceGroupName "ResourceGroup002" -VMName "LinuxVM001" -ValidationPem "C:\my-org-validator.pem" -ClientRb "C:\client.rb" -RunList "Apache" -Linux
PS C:\>Set-AzureRmVMChefExtension -ResourceGroupName "ResourceGroup002" -VMName "LinuxVM001" -ValidationPem "C:\my-org-validator.pem" -ClientRb "C:\client.rb" -RunList "Apache" -Secret "my_secret" -Linux
```

This command adds a Chef extension to a Linux virtual machine named LinuxVM001.
Expand Down Expand Up @@ -284,6 +286,54 @@ Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```

### -Daemon
Configures the chef-client service for unattended execution. The node platform should be Windows.
Options: 'none' or 'service'
none - Currently prevents the chef-client service from being configured as a service.
service - Configures the chef-client to run automatically in the background as a service.

```yaml
Type: String
Parameter Sets: Windows
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```

### -Secret
The encryption key used to encrypt and decrypt the data bag item values.

```yaml
Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```

### -SecretFile
The path to the file that contains the encryption key used to encrypt and decrypt the data bag item values.

```yaml
Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```

### -Windows
Indicates that this cmdlet creates a Windows virtual machine.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


namespace Microsoft.WindowsAzure.Commands.ScenarioTest
{
{
public class ChefExtensionTests
{
private EnvironmentSetupHelper helper = new EnvironmentSetupHelper();
Expand All @@ -33,6 +33,13 @@ public void TestSetAzureVMChefExtension()
this.RunPowerShellTest("Test-SetAzureVMChefExtension");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestSetAzureVMChefExtensionAdvancedOptions()
{
this.RunPowerShellTest("Test-SetAzureVMChefExtensionAdvancedOptions");
}

protected void SetupManagementClients()
{
var rdfeTestFactory = new RDFETestEnvironmentFactory();
Expand All @@ -53,7 +60,7 @@ protected void RunPowerShellTest(params string[] scripts)
using (UndoContext context = UndoContext.Current)
{
context.Start(TestUtilities.GetCallingClass(1), TestUtilities.GetCurrentMethodName(2));

SetupManagementClients();

var modules = new List<string>
Expand All @@ -76,6 +83,6 @@ protected void RunPowerShellTest(params string[] scripts)

helper.RunPowerShellTest(scriptEnvPath, scripts);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@
<None Include="Resources\ChefExtension\tstorgnztn-validator.pem">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Resources\ChefExtension\encrypted_data_bag_secret">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Resources\DiagnosticsExtension\DiagnosticsExtensionTests.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -283,6 +286,9 @@
<None Include="SessionRecords\Microsoft.WindowsAzure.Commands.ScenarioTest.ChefExtensionTests\TestSetAzureVMChefExtension.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.WindowsAzure.Commands.ScenarioTest.ChefExtensionTests\TestSetAzureVMChefExtensionAdvancedOptions.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.WindowsAzure.Commands.ScenarioTest.DscExtensionTests\TestGetAzureVMDscExtension.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
Loading