在上层使用swift提供的云存储服务的过程中,提出了无需验证的使用需求。

在参考了:http://my.oschina.net/alanlqc/blog/160196(curl命令操作)

官方文档:

http://docs.openstack.org/api/openstack-object-storage/1.0/content/special-metadata-acls.html(ACL基本介绍)

以及:

http://blog.fsquat.net/?p=40(ACL修改)

三篇文章之后,我总结出了以下步骤:

找到两个方法来修改ACL,一个是通过swift命令,另一个是使用curl工具。下面先讲一下使用swift命令:

因为container是属于account的,从curl使用的方法http://my.oschina.net/u/138210/blog/164619来看,account就是由tenant决定。因此,只有对要操作的tenant拥有role的user,才能被修改ACL。

目前的帐户情况是:

一个tenant: test-newcomer

二个user: test-swift, test-swift2
user对tenant拥有的role分别为:admin, _Member_

1. 首先查看下当前的ACL情况:

user:test-swift
# swift --os-tenant-name=test-newcomer --os-username=test-swift --os-password=testswift --os-auth-url=http://localhost:5000/v2.0 stat y1
Account: ff5bd8fb39a5429cbd2495576ebff5f7
Container: y1
Objects: 0
Bytes: 0
Read ACL:
Write ACL:
Sync To:
Sync Key:
Accept-Ranges: bytes
X-Timestamp: 1386227063.30466
Content-Type: text/plain; charset=utf-8

user:test-swift2
# swift --os-tenant-name=test-newcomer --os-username=test-swift2 --os-password=testswift2 --os-auth-url=http://localhost:5000/v2.0 stat y1
Container HEAD failed: http://localhost:8888/v1/ff5bd8fb39a5429cbd2495576ebff5f7/y1 403 Forbidden

2. 使用命令修改y1的ACL,读权限:

# swift --os-tenant-name=test-newcomer --os-username=test-swift --os-password=testswift --os-auth-url=http://localhost:5000/v2.0 post y1 -r 'test-newcomer:test-swift2'

3. 再次查看:
user:test-swift
# swift --os-tenant-name=test-newcomer --os-username=test-swift --os-password=testswift --os-auth-url=http://localhost:5000/v2.0 stat y1
Account: ff5bd8fb39a5429cbd2495576ebff5f7
Container: y1
Objects: 1
Bytes: 916
Read ACL: test-newcomer:test-swift2
Write ACL:
Sync To:
Sync Key:
Accept-Ranges: bytes
X-Timestamp: 1386227063.30466
Content-Type: text/plain; charset=utf-8

user:test-swift2
L# swift --os-tenant-name=test-newcomer --os-username=test-swift2 --os-password=testswift2 --os-auth-url=http://localhost:5000/v2.0 stat y1
Account: ff5bd8fb39a5429cbd2495576ebff5f7
Container: y1
Objects: 1
Bytes: 916
Read ACL:
Write ACL:
Sync To:
Sync Key:
Accept-Ranges: bytes
X-Timestamp: 1386227063.30466
Content-Type: text/plain; charset=utf-8

4. 此时使用swift其他操作命令,可以发现,test-swift2已经可以对y1进行stat/download/list操作,但是对post/upload/delete依然没有权限。

5. 继续修改读权限:
# swift --os-tenant-name=test-newcomer --os-username=test-swift --os-password=testswift --os-auth-url=http://localhost:5000/v2.0 post y1 -r '.r:*,.rlistings'
此时即可实现匿名读取container。在浏览器中输入http://localhost:8888/v1/ff5bd8fb39a5429cbd2495576ebff5f7/y1,可以直接看到container的内容。

6. 接下来是写权限:
L# swift --os-tenant-name=test-newcomer --os-username=test-swift --os-password=testswift --os-auth-url=http://localhost:5000/v2.0 post y1 -w 'test-newcomer:test-swift2'

7. 此时查看信息:
# swift --os-tenant-name=test-newcomer --os-username=test-swift --os-password=testswift --os-auth-url=http://localhost:5000/v2.0 stat y1
Account: ff5bd8fb39a5429cbd2495576ebff5f7
Container: y1
Objects: 1
Bytes: 916
Read ACL: test-newcomer:test-swift2
Write ACL: test-newcomer:test-swift2
Sync To:
Sync Key:
Accept-Ranges: bytes
X-Timestamp: 1386227063.30466

这样就可以进行upload/delete操作。
需要注意两点:
1).  经验证,可以仅赋予写权限。但是只能在拥有读权限的情况下,写权限才可以发挥作用。
2).  不支持匿名写操作。

curl命令的使用可参考上述参考文档。curl在设置读权限时,使用了 -H "X-Container-Read"参数。
对应于上述操作,分别使用如下的操作格式,即可实现同样的效果:
-H "X-Container-Read: test-newcomer:test-swift2"
-H "X-Container-Read: .r:*,.rlistings"
要注意的是:理论上来讲,使用-H "X-Container-Write"可以设置写权限。但是在实验时,使用下述方法
-H "X-Container-Write: test-newcomer:test-swift2"出现了Unauthorized错误。

通过设置swift中container的ACL提供匿名访问及用户授权读取服务的更多相关文章

  1. SQL Server 2005中设置Reporting Services发布web报表的匿名访问

    原文:SQL Server 2005中设置Reporting Services发布web报表的匿名访问 一位朋友提出个问题:集成到SQL Server 2005中的Reporting Services ...

  2. 设置电脑中的某个程序不弹出UAC用户控制提示的方法

    有用户发现在电脑开机后总是会弹出UAC用户账户控制窗口,这是因为电脑中的某个程序设置了开机启动,这样就会在开机后启动该程序时出现UAC提示.如果想要省略该提示,可以在电脑中设置该程序不弹出UAC用户控 ...

  3. mySQL中如何给某一IP段的用户授权?

    给一个用用户use ip: 192.168.0.1 语句是: grant all on *.* to root@192.168.0.1 identified by 'pass' 来授权 其中:root ...

  4. 一览Swift中的常用关键字

    要学习Swift这门语言,就必须先了解Swift的关键字及对应的解释.这里就列一下在Swift中常用到的关键字. 关键字是类似于标识符的保留字符序列,除非用重音符号(`)将其括起来,否则不能用作标识符 ...

  5. [翻译]理解Swift中的Optional

    原文出处:Understanding Optionals in Swift 苹果新的Swift编程语言带来了一些新的技巧,能使软件开发比以往更方便.更安全.然而,一个很有力的特性Optional,在你 ...

  6. 如何为基于windows验证的站点的某个页面、文件或文件夹单独设置匿名访问

    在MOSS的项目中,我们经常碰到要单独为基于windows验证的站点的某个页面.文件或文件夹单独设置匿名访问即不登录就可以直接访问.比如说站点的A的某些图片或文件URL存在B站点下的文件夹下.此时访问 ...

  7. swift 设置string 中汉字中变色等处理代码

    我们在做弹窗 或者显示label string的时候经常会用到字体变色 变大 等特殊处理, swift中提供一个函数 NSMutableAttributedString 使用方法简介 var main ...

  8. swift中第三方网络请求库Alamofire的安装与使用

    swift中第三方网络请求库Alamofire的安装与使用 Alamofire是swift中一个比较流行的网络请求库:https://github.com/Alamofire/Alamofire.下面 ...

  9. Swift基础--Swift中的分类以及在分类中扩展init方法的注意事项

    Swift中的分类 1.创建一个空的swift文件 2.关键字extension,格式: extension 要扩展的类名 {} extension UIButton { } Swift中扩展init ...

随机推荐

  1. STL中vector怎么实现邻接表

    最近,同期的一位大佬给我出了一道题目,改编自 洛谷 P2783 有机化学之神偶尔会做作弊 这道题好坑啊,普通链表过不了,只能用vector来存边.可能更快一些吧? 所以,我想记录并分享一下vector ...

  2. Redis通过PUBLISH / SUBSCRIBE 等命令实现了订阅与发布模式

    # 切换目录 [root@localhost /]# cd /opt/redis-4.0.10 # 启动客户端 -p 指定端口 [root@localhost ~]# redis-cli -p 638 ...

  3. Symfony 如何使用ckeditor

    首先: 1)加载以下两个bundle "egeloen/ckeditor-bundle": "^4.0","helios-ag/fm-elfinder ...

  4. LATEX ——WinEdt 破解

    WinEdt 是目前我发现最好的LaTeX编辑器,但是在国内支付不便,且学生许可需$40,只能出此下策,望有余力者尽量购买正版. WinEdt 的旧版本的破解方法众所周知,只需定时删除HKCU\Sof ...

  5. Java多线程系列 面试题

    1. https://blog.csdn.net/jjj19891128/article/details/24393661  多线程经典面试题 2. https://blog.csdn.net/ll6 ...

  6. python 3 面向过程编程

    python 3 面向过程编程 核心是过程(流水线式思维),过程即解决问题的步骤,面向过程的设计就像设计好一条工业流水线,是一种机械式的思维方式. 1.优点:程序结构清晰,可以把复杂的问题简单化,流程 ...

  7. python有哪些关键字?让他自己“吐”出来!

    通过调用库来输出!for循环控制! 源代码: import keyword c = 0 for i in keyword.kwlist: print(i) c += 1 代码截图: 哈哈,关键字: F ...

  8. CSS3响应式侧边菜单

    在线演示 本地下载

  9. 20145229吴姗珊两天小总结 《Java程序设计》第4周学习总结

    20145229吴姗珊两天小总结 <Java程序设计>第4周学习总结 教材学习内容总结 由于自己的基础不好对知识的理解不透彻,所以这两天的学习还是集中在第六章和第七章,对知识点多了一点理解 ...

  10. python的字符串操作函数之一览

    s.strip(chars) s.find(x,start,end) s.index(x.start,end)#见上: s.format()#见上: s.partition(x)#见上: s.repl ...