windows - 如何提升在 Azure VM 上运行的远程命令的权限

标签 windows azure powershell virtual-machine

在 Azure VM 上运行远程命令时,权限提升或运行方式的最佳实践方式是什么?

我的命令是通过使用“runCommands”的 BICEP/ARM 模板通过 Azure DevOps 任务调用的

引用:https://learn.microsoft.com/en-us/azure/templates/microsoft.compute/virtualmachines/runcommands?tabs=bicep

我还尝试过 powershell:Invoke-AzVMRunCommand

引用:https://learn.microsoft.com/en-us/powershell/module/az.compute/invoke-azvmruncommand?view=azps-8.0.0

两者都会导致远程命令在远程虚拟机上作为计算机帐户运行。

我需要以特定 AD 组成员的用户身份运行命令。

将其提升为以特定用户身份运行的最佳实践方法是什么?

理想情况下,我希望避免将凭据传递到虚拟机。

我目前正在尝试使用 Windows 任务计划程序 - 有一个作为目标用户运行 PowerShell 脚本的预配置任务 - 并远程触发此任务运行,但感觉不太对劲。

最佳答案

• 在远程 Azure VM 上执行 powershell 脚本而不暴露凭据的最佳实践是为该 VM 创建托管标识并为其分配仅访问其他 Azure 资源或执行特定任务所需的权限。另请注意,如果将托管标识授予 Azure 虚拟机,则本地管理员可能能够继承授予此标识的权限,并获得对 Azure 资源的访问权限,或通过获取该标识来使用该标识执行 powershell 脚本通过该托管身份的 token

创建用户分配的托管身份并使用它获取 token ,请为此目的点击下面给出的文档链接:-

<强> https://learn.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/tutorial-windows-vm-ua-arm

• <强> Once the token is achieved using the ‘Invoke-webrequest’ command as stated above, then you can use that to login to the Azure VM and execute the script through powershell 。要在 Azure VM 上使用托管标识进行登录,请参阅以下文档链接了解详细信息:-

https://github.com/MicrosoftDocs/azure-docs/blob/main/articles/active-directory/managed-identities-azure-resources/how-to-use-vm-sign-in.md

为托管身份配置 RBAC 访问和相关权限时,请记住以下几点:-

a) Remote access to Azure VM for local admin should be limited as much as possible .

b) Permissions granted to managed identities for VM should be as restrictive as possible (for example, avoid “Storage Account Contributor” and use “Storage Blob Data Contributor” to avoid accessing storage account keys) .

c) Ensure logging is enabled in this scenario to detect as early as possible any suspicious activities related to misuse of these credentials .

关于windows - 如何提升在 Azure VM 上运行的远程命令的权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72855375/

相关文章:

windows - 如何使用 Adob​​e Flash CS4 解决从 Mac 到 Windows 的字体兼容性问题?

powershell - 尝试从 Get-ADUser 中找出经理名称

powershell - 如何在用户 session 中运行Powershell ScheduledJob(-AtLogOn)?

Powershell IF 和 not 条件无法正常工作

C#,将数据库值转换为字符串?

windows - 为什么 Windows 环境变量名称使用特殊的转义字符?

windows - 通过 tf.exe 确定 TFS 工作区的本地路径

azure - 是否可以将 System.File.IO 与 Azure 文件共享一起使用?

c# - Azure Function c# - 检索订阅的 WebApp 列表

azure - 为什么 Azure ASP(应用服务计划)手动扩展太慢?