在上层使用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. ACM-最小生成树之继续畅通project——hdu1879

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/lx417147512/article/details/27092583 ************** ...

  2. xpath中如何使用变量

    xpath (python)xpath中如何使用变量描述: 在xpath中该如何使用变量,想选择id是某个值的元素,这个值是个变量. response.xpath('//div[@id=val]'). ...

  3. Iptalbes练习题(一)

    实验环境: KVM 虚拟机 centos6.7 test1:192.168.124.87  test2:192.168.124.94 场景一: 要求:1.对所有地址开放本机的tcp(80.22.10- ...

  4. pymysql插入datetime类型

    第一种 create_time=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") 第二种 update_time=time ...

  5. python微信库 --- itchat

    python实现微信接口——itchat模块 安装 pip install itchat 登录 itchat.auto_login() # 这种方法将会通过微信扫描二维码登录,但是这种登录的方式确实短 ...

  6. 剑指offer——不能被继承的类

    方法一:通过将类的构造函数和析构函数声明成private来防止子类继承.声明静态的方法来构造和析构类的对象. 但是用起来不是很方便.只能得到在堆上的实例,而不能得到在栈上的实例. 方法二:构造辅助类C ...

  7. 剑指offer之 奇数偶数数组位置调整且保存顺序不变

    public class Solution { public void reOrderArray(int [] array) { reOrderCore(array,array.length); } ...

  8. EntityFramework 学习 一 Eager Loading

    贪婪加载是指查询一个类型实体的时候同时查询与实体关联的类型 通过Include()方法实现 using (var context = new SchoolDBEntities()) { var stu ...

  9. 算法(Algorithms)第4版 练习 1.5.6

    对于weighted quick-union,对每个输入数据对,其最大的循环次数为lgN(sites) 故对于109 sites和106 input pairs,其总的指令次数为:sum = lg10 ...

  10. 算法(Algorithms)第4版 练习 1.3.7

    package com.qiusongde; import java.util.Iterator; import java.util.NoSuchElementException; import ed ...