怎样提高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 ...
随机推荐
- Ubuntu安装Eclips for C/C++及相关配置
1,安装JDK: sudo apt-get install aptitude sudo aptitude search openjava sudo aptitude install openjdk-7 ...
- POJ 1515 Street Directions --一道连通题的双连通和强连通两种解法
题意:将一个无向图中的双向边改成单向边使图强连通,问最多能改多少条边,输出改造后的图. 分析: 1.双连通做法: 双连通图转强连通图的算法:对双连通图进行dfs,在搜索的过程中就能按照搜索的方向给所有 ...
- POJ 1984 Navigation Nightmare
并查集,给n个点和m条边,每条边有方向和长度,再给q个询问,第i个询问查询两个点之间在Ti时刻时的曼哈顿距离(能连通则输出曼哈顿距离,否则输出-1) 这题跟Corporative Network 有点 ...
- BIO、NIO与NIO.2的区别与联系
BIO.NIO.NIO.2之间的区别主要是通过同步/异步.阻塞/非阻塞来进行区分的 同步: 程序与操作系统进行交互的时候采取的是问答的形式 异步: 程序与操作系统取得连接后,操作系统会主动通知程序消息 ...
- scanf和cin的差异
scanf和cin的差异 引例:http://www.cnblogs.com/shenben/p/5516996.html 大家都知道,在C++中有两种输入.输出方式—scanf和cin,但是,它们之 ...
- 如何免费访问Google?
访问Google方法(以Mac为例) 1.替换hosts文件中的内容,文件链接如下: https://github.com/racaljk/hosts 2.下载Google浏览器,链接如下: http ...
- delphi数组作为参数传值
在函数中如果数组的个数不定,可以使用开放数组参数 实参可以接受静态数组和动态数组 procedure p1(a:array of Byte); begin ShowMessage( IntToHex( ...
- 客户端缓存(Client Cache)
通常在服务器端大家都已经做了很多缓存的工作,ASP.NET CACHE也好MemeryCache也好却总是忽略了客户端缓存. 因为大家都知道不管哪个client都会缓存已经访问过的站点,但是浏览器缓存 ...
- C语言 读取文件中特定数据
//读取文件数据 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> struct jia ...
- php基础02:变量
1.创建变量 <?php $num1 = 15; $num2 = 15.5; echo $num1+$num2; echo "<br>"; ?> 2.Loc ...