我是一名.NET开发人员,负责一个包含多个WCF服务的项目。 一些自动化testing尝试托pipe这些服务,但根据我是否不使用pipe理权限运行testing,这些testing会失败,并显示以下错误:
System.ServiceModel.AddressAccessDeniedException : HTTP could not register URL http://+:45566/SomeService/. Your process does not have access rights to this namespace (see http://go.microsoft.com/fwlink/?LinkId=70353 for details). ----> System.Net.HttpListenerException : Access is denied
在提供的链接之后,看起来我必须使用netsh命令为自己(普通域用户)提供某种访问权限,如下所示:
netsh http add urlacl url=http://+:45566/SomeService user=DOMAIN\me
不幸的是,似乎没有办法(我可以find)为端口或相对URL部分使用通配符,例如为了授予我本地访问本地主机上的所有内容的权限。
因此,我的问题是:这个ACL是什么,我可以在文件或其他东西中find它,以便更容易地操纵它?
更妙的是:由于本地pipe理员帐户似乎默认有访问权限,我可以不知何故地告诉系统在这个后面闭嘴,让我做我的工作?
每个URL访问控制列表(ACL)为特定用户组保留一部分HTTP URL名称空间。 这个保留让这些用户有权创build在这个名字空间部分上侦听的服务。 有关命名空间预留的更多信息,请参阅https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/configuring-http-and-https 。
您可以在registry中find并操作所有已定义的URL ACL。
如果您使用以下命令添加了URL ACL:
netsh http add urlacl url=http://+:45566/SomeService user=DOMAIN\me
您可以使用以下命令查询此URL ACL的registry项:
reg query HKLM\SYSTEM\ControlSet001\Services\HTTP\Parameters\UrlAclInfo /v 'http://+:45566/SomeService/' HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\HTTP\Parameters\UrlAclInfo http://+:45566/SomeService/ REG_BINARY 010004800000000000000000000000001400000002002C000100000000002400000000200105 00000000000515000000B262BFF6EAC6403B59D621B1360C0000
registry项的值是一个二进制安全描述符。 您可以使用WMI类的帮助程序方法将二进制SD转换为SDDLstringWin32_SecurityDescriptorHelper
([wmiclass]"Win32_SecurityDescriptorHelper").BinarySDToSDDL( [System.Runtime.Remoting.Metadata.W3cXsd2001.SoapHexBinary]::Parse( "010004800000000000000000000000001400000002002C00010000000000240000 000020010500000000000515000000B262BFF6EAC6403B59D621B1360C0000") .Value).SDDL D:(A;;GX;;;S-1-5-21-4139737778-994100970-2971784793-3126)
并将SDDLstring转换回二进制SD:
(New-Object System.Runtime.Remoting.Metadata.W3cXsd2001.SoapHexBinary (,([wmiclass]"Win32_SecurityDescriptorHelper").SDDLToBinarySD( "D:(A;;GX;;;S-1-5-21-4139737778-994100970-2971784793-3126)").BinarySD)).ToString() 010004800000000000000000000000001400000002002C000100000000002400000000200105000000 00000515000000B262BFF6EAC6403B59D621B1360C0000
您可以添加另一个URL ACL到registry中:
reg add HKLM\SYSTEM\ControlSet001\Services\HTTP\Parameters\UrlAclInfo \ /v 'http://+:45567/AnotherService/' /t REG_BINARY \ /d 010004800000000000000000000000001400000002002C00010000000000 \ 240000000020010500000000000515000000B262BFF6EAC6403B59D621B1360C0000
在netsh命令中可以看到:
netsh http show urlacl 'http://+:45567/AnotherService/' URL Reservations: ----------------- Reserved URL : http://+:45567/AnotherService/ User: DOMAIN\me Listen: Yes Delegate: No SDDL: D:(A;;GX;;;S-1-5-21-4139737778-994100970-2971784793-3126)