怎样提高Windows Azure Cloud Service中的WebRole的文件访问权限
关键字:WebRole
1. 背景
Web应用程序需要读取和写入该项目下的文件的权限。
在默认情况下,W3wp.exe 和WaIISHost.exe的运行账号是Network Service,而Network Service 的对文件的访问权只有读取权限。


所以要读取和更改web站点下的文件,需要提升IIS对该文件的访问权限,也就是提高Network Service账号的访问该文件的权限。
2. 解决办法
首先我们会想到在ServiceDefinition.cscfg配置文件加上提升权限的配置。如:
<WebRole name="WebRole1" vmsize="Small">
<Runtime executionContext="elevated"/>
这里提升的是部署WebRole的权限。
但是要知道,不管怎么提升,w3wp这个进程在webrole里面始终以Network Service 来运行,所以这种配置是无效的。
http://technet.microsoft.com/en-us/library/cc771170(v=ws.10).aspx
从上述文档中知道,
如果运行在一个具有很高权限的账号下Application pool会有安全风险的
文章Startup Lifecycle of a Windows Azure Role告诉我们不能在部署Startup task中来更改Network Service的权限,因为这个时候IIS Application Pool 还没有生成。
我们可以更改文件的访问权限,这个是跟IIS配置无关的。也就是上面贴图中network service的权限列表。
1)编写Startup.cmd
set filePath=%RoleRoot%\sitesroot\0\App_Data\mycompactdb.sdf
ModifyFileSecurity.exe "%filePath%" "NETWORK SERVICE"
EXIT /B 0
2)编写ModifyFileSecurity
ModifyFileSecurity.exe
class Program
{
static void Main(string[] args)
{
if (args.Length == 2)
{
string fileName = args[0];
string account = args[1];
AddFileSecurity(fileName, account, FileSystemRights.Modify, AccessControlType.Allow);
}
}
public static void AddFileSecurity(string fileName, string account,
FileSystemRights rights, AccessControlType controlType)
{
// Get a FileSecurity object that represents the
// current security settings.
FileSecurity fSecurity = File.GetAccessControl(fileName);
// Add the FileSystemAccessRule to the security settings.
fSecurity.AddAccessRule(new FileSystemAccessRule(account,
rights, controlType));
// Set the new access settings.
File.SetAccessControl(fileName, fSecurity);
}
}
当然我们也可以编写Powershell 命令SET-ACL来辩解访问文件的访问权限
http://technet.microsoft.com/en-us/library/hh849810.aspx
http://technet.microsoft.com/en-us/library/ff730951.aspx
http://blogs.msdn.com/b/johan/archive/2008/10/01/powershell-editing-permissions-on-a-file-or-folder.aspx
How to update role code in startup task.
怎样提高Windows Azure Cloud Service中的WebRole的文件访问权限的更多相关文章
- Windows Azure Cloud Service (42) 使用Azure In-Role Cache缓存(1)Co-located Role
<Windows Azure Platform 系列文章目录> Update 2016-01-12 https://azure.microsoft.com/zh-cn/documentat ...
- Windows Azure Cloud Service (43) 使用Azure In-Role Cache缓存(2)Dedicated Role
<Windows Azure Platform 系列文章目录> Update 2016-01-12 https://azure.microsoft.com/zh-cn/documentat ...
- Windows Azure Cloud Service (11) PaaS之Web Role, Worker Role(上)
<Windows Azure Platform 系列文章目录> 本文是对Windows Azure Platform (六) Windows Azure应用程序运行环境内容的补充. 我们知 ...
- Windows Azure Cloud Service (36) 在Azure Cloud Service配置SSL证书
<Windows Azure Platform 系列文章目录> 在某些时候,我们需要在Azure PaaS Cloud Service配置HTTPS连接.本章将介绍如何在本地创建证书,然后 ...
- Windows Azure Cloud Service (38) 微软IaaS与PaaS比较
<Windows Azure Platform 系列文章目录> 最近一直想总结Azure IaaS和PaaS的区别与比较,写个博文详细说明一下.建议读者在阅读之前,先熟悉微软PaaS和Ia ...
- Windows Azure Cloud Service (39) 如何将现有Web应用迁移到Azure PaaS平台
<Windows Azure Platform 系列文章目录> 本文将简单介绍,如何将企业内现有的ASP.NET应用程序迁移到Azure PaaS平台. 因为在迁移过程中,可能需要对现有的 ...
- Windows Azure Cloud Service (47) 修改Cloud Service时区
<Windows Azure Platform 系列文章目录> 本文介绍内容适合于Azure Global和Azure China 我们在使用Cloud Service的时候,会发现默认的 ...
- 【Azure 云服务】如何从Azure Cloud Service中获取项目的部署文件
问题描述 在历史已经部署的云服务(Azure Cloud Service)中,如何获取到项目在很久以前的部署包文件呢? 解决办法 1)如果部署云服务是通过门户上传部署包到存储账号中,则可以直接从存储账 ...
- 跟我学Windows Azure 四 Cloud Service中的WebRole与WorkRole,及他们之间的通信
Cloud Service 中WebRole就相当与我们的WebSite,而WorkRole相当与我们在服务器上写了个Windows Service,站在高可用的角度上来讲,Cloud Service ...
随机推荐
- 一个自定义 HBase Filter -“通过RowKeys来高性能获取数据”
摘要: 大家在使用HBase和Solr搭建系统中经常遇到的一个问题就是:“我通过SOLR得到了RowKeys后,该怎样去HBase上取数据”.使用现有的Filter性能差劲,网上也没有现成的自定义Fi ...
- Climbing Stairs
Climbing Stairs https://leetcode.com/problems/climbing-stairs/ You are climbing a stair case. It tak ...
- DW Basic Knowledge1
以下内容,常读常新,每次都有新的感悟和认识. 数据仓库必须使组织机构的信息变得容易存取. 数据仓库的内容需要是容易理解的,数据对业务人员也必定是直观的,明显的. 数据仓库重新组织了原来OLTP数据库的 ...
- 【温故而知新-Javascript】为DOM元素设置样式
1. 使用样式表 可以通过document.styleSheets属性访问文档中可用的CSS样式表,它会返回一组对象集合,这些对象代表了与文档管理的各个样式表. 每个样式表 都由一个CSSStyleS ...
- UVA 12730 Skyrk's Bar --期望问题
题意:有n个地方,现在要站人进去,而每两个人之间至少要隔k个空地,问这n个地方能站的人数的期望是多少. 分析:考虑dp[i]表示 i 个地方能站的期望数,从左往右推, 如果i-k-1<1,那么最 ...
- Mango Weekly Training Round #3 解题报告
A. Codeforces 92A Chips 签到题.. #include <iostream> #include <cstdio> #include <cstring ...
- POJ 2001 Shortest Prefix
字典树基本题. 代码: #include <iostream> #include <cstdio> #include <cstring> #include < ...
- JavaWeb学习----JSTL标签库
一.JSTL简介: JSTL全名为JavaServer Pages Standard Tag Library,中文名称为JSP标准标签函数库,目前最新的版本为1.2.JSTL是由JCP(Java Co ...
- A*寻路初探 GameDev.net
A*寻路初探 GameDev.net MulinB按:经典的智能寻路算法,一个老外写的很透彻很清晰,很容易让人理解神秘的A*算法.以下是一个中文翻译版. A*寻路初探 GameDev.net 作者: ...
- [转]在Eclipse中使用JUnit4进行单元测试(高级篇)
通过前2篇文章,您一定对JUnit有了一个基本的了解,下面我们来探讨一下JUnit4中一些高级特性. 一.高级Fixture 上一篇文章中我们介绍了两个Fixture标注,分别是@Before和@Af ...