這篇文章主要講解了“怎么禁止S3用戶刪除Object”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“怎么禁止S3用戶刪除Object”吧!
成都創(chuàng)新互聯(lián)公司專業(yè)為企業(yè)提供大化網(wǎng)站建設(shè)、大化做網(wǎng)站、大化網(wǎng)站設(shè)計、大化網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計與制作、大化企業(yè)網(wǎng)站模板建站服務(wù),10年大化做網(wǎng)站經(jīng)驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡(luò)服務(wù)。
需求描述:需要關(guān)閉某些S3賬號的刪除權(quán)限,但是默認DELETE操作是由bucket WIRTE權(quán)限進行控制的,無法單獨拆分DELETE操作。
解決思路:
1. 過濾前端HTTP請求的DELETE操作(需要寫點代碼)
2. 修改S3內(nèi)置用戶的metadata信息,本文用的就是這個方法。
root@demo# radosgw-admin metadata get user:s3user { "key": "user:s3user", "ver": { "tag": "_HUtHU_6yBqHTSzDLb9y8tjX", "ver": 2 }, "mtime": 1493110079, "data": { "user_id": "s3user", "display_name": "s3user", "email": "", "suspended": 0, "max_buckets": 1000, "auid": 0, "subusers": [], "keys": [ { "user": "s3user", "access_key": "xxx", "secret_key": "xxx" } ], "swift_keys": [], "caps": [], "op_mask": "read, write,delete", #這里有delete權(quán)限 "default_placement": "", "placement_tags": [], "bucket_quota": { "enabled": false, "max_size_kb": -1, "max_objects": -1 }, "user_quota": { "enabled": false, "max_size_kb": -1, "max_objects": -1 }, "temp_url_keys": [] } }
root@demo# radosgw-admin metadata get user:s3user > s3user.json
修改生成的s3user.json文件,修改"op_mask",刪除“delete”字段
"op_mask": "read, write",
root@demo6# radosgw-admin metadata put user:s3user < s3user.json
root@demo# radosgw-admin metadata get user:s3user { "key": "user:s3user", "ver": { "tag": "_HUtHU_6yBqHTSzDLb9y8tjX", "ver": 2 }, "mtime": 1493110079, "data": { "user_id": "s3user", "display_name": "s3user", "email": "", "suspended": 0, "max_buckets": 1000, "auid": 0, "subusers": [], "keys": [ { "user": "s3user", "access_key": "xxx", "secret_key": "xxx" } ], "swift_keys": [], "caps": [], "op_mask": "read, write", #delete權(quán)限沒了 "default_placement": "", "placement_tags": [], "bucket_quota": { "enabled": false, "max_size_kb": -1, "max_objects": -1 }, "user_quota": { "enabled": false, "max_size_kb": -1, "max_objects": -1 }, "temp_url_keys": [] } }
from boto.s3.connection import S3Connectionimport boto endpoint = 's3.ceph.work'bucket_name = 'test1'access_key = 'xx'secret_key = 'xx'local_file = '/tmp/ct.shutdown'key_name = 'new_file'conn = boto.connect_s3( aws_access_key_id=access_key, aws_secret_access_key=secret_key, host=endpoint, is_secure=False, calling_format=boto.s3.connection.SubdomainCallingFormat(), validate_certs=True, ) bucket = conn.create_bucket(bucket_name) key_ = bucket.new_key(key_name) key_.set_contents_from_filename(local_file)#方法1bucket.delete_keys([key_name])#方法2# key_.delete()#方法3# bucket.delete_key(key_name)
上面3種方式都會提示403錯誤
Traceback (most recent call last): ..... boto.exception.S3ResponseError: S3ResponseError: 403 ForbiddenAccessDenied
感謝各位的閱讀,以上就是“怎么禁止S3用戶刪除Object”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對怎么禁止S3用戶刪除Object這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識點的文章,歡迎關(guān)注!