zoukankan      html  css  js  c++  java
  • 通过设置swift中container的ACL提供匿名访问及用户授权读取服务

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

  • 相关阅读:
    利用JavaScript+DIV+CSS实现下拉菜单。当鼠标移动到菜单选项的时候显示对应的DIV:function show(menu)。当鼠标移出的时候隐藏所有的DIV:function hide()。
    java编程——图片旋转
    名言
    利用CSS对注册页面实现修饰
    软件过程
    Warning: Failed to halt at after bootloader, forced stop at
    cc2650 7x7封装更换为 5X5 4x4
    IAR 路径导致的错误
    cc2650-cc2640蓝牙开发准备手记
    window10装机 nvem简介,针对于 联想R720系列
  • 原文地址:https://www.cnblogs.com/Clisa/p/3461668.html
Copyright © 2011-2022 走看看