关键字: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的文件访问权限的更多相关文章

  1. 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 ...

  2. 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 ...

  3. Windows Azure Cloud Service (11) PaaS之Web Role, Worker Role(上)

    <Windows Azure Platform 系列文章目录> 本文是对Windows Azure Platform (六) Windows Azure应用程序运行环境内容的补充. 我们知 ...

  4. Windows Azure Cloud Service (36) 在Azure Cloud Service配置SSL证书

    <Windows Azure Platform 系列文章目录> 在某些时候,我们需要在Azure PaaS Cloud Service配置HTTPS连接.本章将介绍如何在本地创建证书,然后 ...

  5. Windows Azure Cloud Service (38) 微软IaaS与PaaS比较

    <Windows Azure Platform 系列文章目录> 最近一直想总结Azure IaaS和PaaS的区别与比较,写个博文详细说明一下.建议读者在阅读之前,先熟悉微软PaaS和Ia ...

  6. Windows Azure Cloud Service (39) 如何将现有Web应用迁移到Azure PaaS平台

    <Windows Azure Platform 系列文章目录> 本文将简单介绍,如何将企业内现有的ASP.NET应用程序迁移到Azure PaaS平台. 因为在迁移过程中,可能需要对现有的 ...

  7. Windows Azure Cloud Service (47) 修改Cloud Service时区

    <Windows Azure Platform 系列文章目录> 本文介绍内容适合于Azure Global和Azure China 我们在使用Cloud Service的时候,会发现默认的 ...

  8. 【Azure 云服务】如何从Azure Cloud Service中获取项目的部署文件

    问题描述 在历史已经部署的云服务(Azure Cloud Service)中,如何获取到项目在很久以前的部署包文件呢? 解决办法 1)如果部署云服务是通过门户上传部署包到存储账号中,则可以直接从存储账 ...

  9. 跟我学Windows Azure 四 Cloud Service中的WebRole与WorkRole,及他们之间的通信

    Cloud Service 中WebRole就相当与我们的WebSite,而WorkRole相当与我们在服务器上写了个Windows Service,站在高可用的角度上来讲,Cloud Service ...

随机推荐

  1. Linux date命令的用法

    在linux shell编程中,经常用到日期的加减运算以前都是自己通过expr函数计算,很麻烦.其实date命令本身提供了日期的加减运算非常方便. 例如:得到昨天的时间date  --date=&qu ...

  2. Storm 基础知识

    分布式的实时计算框架,storm对于实时计算的意义类似于hadoop对于批处理的意义. Storm的适用场景: 1.流数据处理:storm可以用来处理流式数据,处理之后将结果写到某个存入中去. 2.持 ...

  3. TFS 与活动目录AD(Active Directory)的同步机制

    TFS用户管理机制 TFS系统与企业域服务器用户系统(或本地计算机用户系统)高度集成在一起,使用域服务器验证系统用户的账户和密码,从而在企业中实现单一用户,单点登录.也就是说,TFS系统自身并没有用户 ...

  4. Openstack-Ceilometer-SNMP的使用

    1. 物理服务器配置 1.1安装 #yum install -y net-snmp net-snmp-utils 1.2      配置 复制[附件]中snmpd.conf文件到/etc/snmp/目 ...

  5. Jenkins插件hyper slaves源码分析

    1.public class HyperSlaves extends Plugin implements Describable<HyperSlaves> (1).init():初始化co ...

  6. python中thread模块中join函数

    http://www.cnblogs.com/vingi/articles/2657790.html for i in range(10): t = ThreadTest(i) thread_arr. ...

  7. Codeforces Round #258 E Devu and Flowers --容斥原理

    这题又是容斥原理,最近各种做容斥原理啊.当然,好像题解给的不是容斥原理的方法,而是用到Lucas定理好像.这里只讲容斥的做法. 题意:从n个容器中总共取s朵花出来,问有多少种情况.其中告诉你每个盒子中 ...

  8. QTP 10 安装及破解

    QTP(QuickTest Professional),是一款比较优秀的商业自动化测试工具,主要用于web项目和C/S结构程序的测试. QTP具有的一大特性:关键字驱动测试(keyword-drive ...

  9. java 21 - 3 字符输入流

    所谓的输入流,就是读取文件中的数据 同样的,字符输入流InputStreamReader 4个构造方法,不过2个比较常用: 构造方法: A:InputStreamReader(InputStream ...

  10. angular常见坑洞

    由于版本不同,可能有些问题在某些版本下出现,某些版本下不出现. 指令不可平行(v1.3.2): 多个指令不能这样一个接着一个排下去: <div> <directive-one/> ...