You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/azure-arc/servers/run-command.md
+176-1Lines changed: 176 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: How to remotely and securely configure servers using Run command (Preview)
3
3
description: Learn how to remotely and securely configure servers using Run Command.
4
-
ms.date: 12/22/2023
4
+
ms.date: 02/07/2024
5
5
ms.topic: conceptual
6
6
---
7
7
@@ -22,6 +22,181 @@ Run Command on Azure Arc-enabled servers (Public Preview) uses the Connected Mac
22
22
-**Configuration:** Run Command doesn't require more configuration or the deployment of any extensions. The
23
23
Connected Machine agent version must be 1.33 or higher.
24
24
25
+
26
+
## Limiting access to Run Command using RBAC
27
+
28
+
Listing the run commands or showing details of a command requires the `Microsoft.HybridCompute/machines/runCommands/read` permission. The built-in [Reader](/azure/role-based-access-control/built-in-roles) role and higher levels have this permission.
29
+
30
+
Running a command requires the `Microsoft.HybridCompute/machines/runCommands/write` permission. The [Azure Connected Machine Resource Administrator](/azure/role-based-access-control/built-in-roles) role and higher levels have this permission.
31
+
32
+
You can use one of the [built-in roles](/azure/role-based-access-control/built-in-roles) or create a [custom role](/azure/role-based-access-control/custom-roles) to use Run Command.
33
+
34
+
## Blocking run commands locally
35
+
36
+
The Connected Machine agent supports local configurations that allow you to set an allowlist or a blocklist. See [Extension allowlists and blocklists](security-overview.md#extension-allowlists-and-blocklists) to learn more.
37
+
38
+
For Windows:
39
+
40
+
`azcmagent config set extensions.blocklist " microsoft.cplat.core/runcommandhandlerwindows"`
41
+
42
+
For Linux:
43
+
44
+
`azcmagent config set extensions.blocklist " microsoft.cplat.core/runcommandhandlerlinux"`
45
+
46
+
47
+
## Azure CLI
48
+
49
+
The following examples use [az connectedmachine run-command](/cli/azure/connectedmachine/run-command) to run a shell script on an Azure Windows machine.
50
+
51
+
### Execute a script with the machine
52
+
53
+
This command delivers the script to the machine, executes it, and returns the captured output.
### List all deployed RunCommand resources on a machine
60
+
61
+
This command returns a full list of previously deployed run commands along with their properties.
62
+
63
+
```azurecli
64
+
az connectedmachine run-command list --machine-name "myMachine" --resource-group "myRG"
65
+
```
66
+
67
+
### Get execution status and results
68
+
69
+
This command retrieves current execution progress, including latest output, start/end time, exit code, and terminal state of the execution.
70
+
71
+
```azurecli
72
+
az connectedmachine run-command show --name "myRunCommand" --machine-name "myMachine" --resource-group "myRG"
73
+
```
74
+
75
+
> [!NOTE]
76
+
> Output and error fields in `instanceView` is limited to the last 4KB. To access the full output and error, you can forward the output and error data to storage append blobs using `-outputBlobUri` and `-errorBlobUri` parameters while executing Run Command.
77
+
>
78
+
79
+
### Delete RunCommand resource from the machine
80
+
81
+
Remove the RunCommand resource previously deployed on the machine. If the script execution is still in progress, execution will be terminated.
82
+
83
+
```azurecli
84
+
az connectedmachine run-command delete --name "myRunCommand" --machine-name "myMachine" --resource-group "myRG"
### Execute a script on the machine using SourceScriptUri parameter
96
+
97
+
`OutputBlobUri` and `ErrorBlobUri` are optional parameters.
98
+
99
+
```powershell
100
+
New-AzConnectedMachineRunCommand -ResourceGroupName -MachineName -RunCommandName -SourceScriptUri “< SAS URI of a storage blob with read access or public URI>” -OutputBlobUri “< SAS URI of a storage append blob with read, add, create, write access>” -ErrorBlobUri “< SAS URI of a storage append blob with read, add, create, write access>”
101
+
```
102
+
103
+
### List all deployed RunCommand resources on a machine
104
+
105
+
This command returns a full list of previously deployed Run Commands along with their properties.
### Create or update Run Command on a machine using SourceScriptUri (storage blob SAS URL)
120
+
121
+
Create or update Run Command on a Windows machine using a SAS URL of a storage blob that contains a PowerShell script. `SourceScriptUri` can be a storage blob’s full SAS URL or public URL.
> SAS URL must provide read access to the blob. An expiration time of 24 hours is suggested for SAS URL. SAS URLs can be generated on the Azure portal using blob options, or SAS token using `New-AzStorageBlobSASToken`. If generating SAS token using `New-AzStorageBlobSASToken`, your SAS URL = "base blob URL" + "?" + "SAS token from `New-AzStorageBlobSASToken`"
129
+
>
130
+
131
+
### Get a Run Command Instance View for a machine after creating or updating Run Command
132
+
133
+
Get a Run Command for machine with Instance View. Instance View contains the execution state of run command (Succeeded, Failed, etc.), exit code, standard output, and standard error generated by executing the script using Run Command. A non-zero ExitCode indicates an unsuccessful execution.
### Create or update Run Command on a machine using OutputBlobUri, ErrorBlobUri to stream standard output and standard error messages to output and error Append blobs
152
+
153
+
Create or update Run Command on a machine and stream standard output and standard error messages to output and error Append blobs.
> Output and error blobs must be the AppendBlob type and their SAS URLs must provide read, append, create, write access to the blob. An expiration time of 24 hours is suggested for SAS URL. If output or error blob does not exist, a blob of type AppendBlob will be created. SAS URLs can be generated on Azure portal using blob's options, or SAS token from using `New-AzStorageBlobSASToken`.
161
+
>
162
+
163
+
### Create or update Run Command on a machine as a different user using RunAsUser and RunAsPassword parameters
164
+
165
+
Create or update Run Command on a machine as a different user using `RunAsUser` and `RunAsPassword` parameters. For RunAs to work properly, contact the administrator the of machine and make sure user is added on the machine, user has access to resources accessed by the Run Command (directories, files, network etc.), and in case of Windows machine, 'Secondary Logon' service is running on the machine.
> SAS URL must provide read access to the blob. An expiry time of 24 hours is suggested for SAS URL. SAS URLs can be generated on Azure portal using blob options or SAS token using `New-AzStorageBlobSASToken`. If generating SAS token using `New-AzStorageBlobSASToken`, the SAS URL format is: base blob URL + "?" + the SAS token from `New-AzStorageBlobSASToken`.
182
+
>
183
+
184
+
### Create or update Run Command on a machine instance using Parameter and ProtectedParameter parameters (Public and Protected Parameters to script)
185
+
186
+
Use ProtectedParameter to pass any sensitive inputs to script such as passwords, keys etc.
187
+
188
+
- Windows: Parameters and ProtectedParameters are passed to script as arguments are passed to script and run like this: `myscript.ps1 -publicParam1 publicParam1value -publicParam2 publicParam2value -secret1 secret1value -secret2 secret2value`
189
+
190
+
- Linux: Named Parameters and its values are set to environment config, which should be accessible within the .sh script. For Nameless arguments, pass an empty string to name input. Nameless arguments are passed to script and run like this: `myscript.sh publicParam1value publicParam2value secret1value secret2value`
191
+
192
+
### Delete RunCommand resource from the machine
193
+
194
+
Remove the RunCommand resource previously deployed on the machine. If the script execution is still in progress, execution will be terminated.
0 commit comments