在上层使用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. centos下安装pip时失败:

    [root@wfm ~]# yum -y install pipLoaded plugins: fastestmirror, refresh-packagekit, securityLoading m ...

  2. setTimeout解决循环值的几种方法

    for(var i=0;i<5;i++){ setTimeout(function(){ console.log(`错误 ${i}`); },0) } for(var i=0;i<5;i+ ...

  3. Android中子线程真的不能更新UI吗?

    Android的UI访问是没有加锁的,这样在多个线程访问UI是不安全的.所以Android中规定只能在UI线程中访问UI. 但是有没有极端的情况?使得我们在子线程中访问UI也可以使程序跑起来呢?接下来 ...

  4. maven导入项目时,缺少部分source folder

    今天导入公司的maven项目时,少了一些source folder,运行启动正常,但是页面打不开,找不到对应的目录文件,使用maven更新项目,重启编辑器也无效. 问题描述如图所示,缺少了图中的2个目 ...

  5. 10款CSS3进度条Loading动画

    在线演示 本地下载

  6. day3--集合、文件操作、字符编码与转换、函数(递归,lambda,filter,map)、字典排序

    list1 = set([1, 2, 3, 4, 5, 6, 5, 5, 5])list2 = set([11, 2, 36, 'a', 5, 6, 5, 5, 5])list3 = set([1, ...

  7. android 真心话大冒险 摇色子

    android 真心话大冒险  摇色子 软件

  8. LUA学习之一 初次接触

    对于一个开源工程,开始学习它的第一步自然是编译工程. 使用vc编译lua,在网上已有许多介绍,但“纸上得来终觉浅”,自己走一遍还是有必要的. 步骤如下: 1.下载源代码,从lua.org下载最新源代码 ...

  9. python-字典和json

    Python的字典和JSON在表现形式上非常相似 #这是Python中的一个字典 dic = { 'str': 'this is a string', 'list': [1, 2, 'a', 'b'] ...

  10. Java微信开发_Exception_02_"errcode":40164,"errmsg":"invalid ip 61.172.68.219, not in whitelist hint

    ip查询网址: http://www.ip.cn/ 一.异常现象 今天开始做微信开发,在办公室时能正常获取access_token,晚上回家之后获取access_token时却报出下列错误信息: {& ...