简体   繁体   English

ASP.NET PowerShell模拟

[英]ASP.NET PowerShell Impersonation

I have developed an ASP.NET MVC Web Application to execute PowerShell scripts. 我开发了一个ASP.NET MVC Web应用程序来执行PowerShell脚本。

I am using the VS web server and can execute scripts fine. 我正在使用VS Web服务器,可以很好地执行脚本。

However, a requirement is that users are able to execute scripts against AD to perform actions that their own user accounts are not allowed to do. 但是,要求是用户能够针对AD执行脚本以执行不允许其自己的用户帐户执行的操作。

Therefore I am using impersonation to switch the identity before creating the PowerShell runspace: 因此,我在创建PowerShell运行空间之前使用模拟来切换标识:

            Runspace runspace = RunspaceFactory.CreateRunspace(config);

        var currentuser = WindowsIdentity.GetCurrent().Name;

        if (runspace.RunspaceStateInfo.State == RunspaceState.BeforeOpen) {
            runspace.Open();
        }

I have tested using a domain admin account and I get the following exception when calling runspace.Open(): 我已经使用域管理员帐户进行了测试,并且在调用runspace.Open()时出现以下异常:

Security Exception Description: The application attempted to perform an operation not allowed by the security policy. 安全异常说明:应用程序尝试执行安全策略不允许的操作。 To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file. 要授予此应用程序所需的权限,请与您的系统管理员联系或在配置文件中更改应用程序的信任级别。 Exception Details: System.Security.SecurityException: Requested registry access is not allowed. 异常详细信息:System.Security.SecurityException:不允许请求的注册表访问。

The web application is running in full trust and I have explicitly added the account I am using for impersonation to the local administrators group of the machine (even though the domain admins group was already there). Web应用程序完全信任,我已明确将我用于模拟的帐户添加到计算机的本地管理员组(即使域管理员组已经存在)。

I'm using advapi32.dll LogonUser call to perform the impersonation in a similar way to this post ( http://blogs.msdn.com/webdav_101/archive/2008/09/25/howto-calling-exchange-powershell-from-an-impersonated-thead.aspx ) 我正在使用advapi32.dll LogonUser调用以与此帖相似的方式执行模拟( http://blogs.msdn.com/webdav_101/archive/2008/09/25/howto-calling-exchange-powershell-from -an-impersonated-thead.aspx

Any help appreciated as this is a bit of a show stopper at the moment. 任何帮助表示欣赏,因为这是目前的一个显示阻止。

Thanks Ben 谢谢Ben

Does this blog post help? 这篇博文是否有帮助? Comes straight from the PowerShell devs. 直接来自PowerShell开发人员。 Essentially, PowerShell starts a new thread to run the pipeline, and since .NET2.0 doesn't allow the thread to use the impersonation from the calling thread, it fails. 本质上,PowerShell启动一个新线程来运行管道,并且由于.NET2.0不允许线程使用来自调用线程的模拟,因此它失败了。

http://blogs.msdn.com/powershell/archive/2007/09/10/impersonation-and-hosting-powershell.aspx http://blogs.msdn.com/powershell/archive/2007/09/10/impersonation-and-hosting-powershell.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM