首页 技术 正文
技术 2022年11月12日
0 收藏 447 点赞 3,635 浏览 3234 个字

在上层使用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错误。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,490
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,905
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,739
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,491
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,130
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,292