【问题标题】:Updating Google Storage object metadata without full access在没有完全访问权限的情况下更新 Google Storage 对象元数据
【发布时间】:2014-09-03 07:43:42
【问题描述】:

在使用具有对存储桶的读/写(但不是完全)访问权限的 OAuth2 身份验证令牌时,是否可以更新 Google 存储中对象的元数据?

我的幼稚尝试(将x-goog-copy-source 设置为同一对象的 HTTP PUT,以及 x-goog-metadata-directive: REPLACE) 失败并出现 AccessDenied 错误。 gsutil 似乎也有同样的问题:

$ gsutil config -r -w 
[...]
$ echo hello > foo.txt
$ gsutil -h "x-goog-meta-foo: bar" cp foo.txt gs://nikratio-test/
Copying file://foo.txt [Content-Type=text/plain]...
Uploading   gs://nikratio-test/foo.txt:                          0 B/6 B    
$ gsutil stat gs://nikratio-test/foo.txt
gs://nikratio-test/foo.txt:
    Creation time:      Sun, 09 Nov 2014 22:34:22 GMT
    Content-Language:   en
    Content-Length:     6
    Content-Type:       text/plain
    Metadata:
        foo:         bar
    Hash (crc32c):      NT3Yvg==
    Hash (md5):     sZRqySSS0jR8YjW00mERhA==
    ETag:           CID8ka7K7sECEAE=
    Generation:     1415572462272000
    Metageneration:     1
$ gsutil setmeta -h "x-goog-meta-foo: com" gs://nikratio-test/foo.txt
Setting metadata on gs://nikratio-test/foo.txt...
AccessDeniedException: 403 Forbidden

我认为这是因为 setmeta 操作还允许我更改对象的 ACL。 但是,在我看来,如果我能够删除对象并使用相同的授权使用不同的元数据重新上传它,那么确实应该有一种方法来更改元数据。

【问题讨论】:

    标签: google-cloud-storage


    【解决方案1】:

    设置元数据适用于 OAuth2。我建议运行此 gsutil 命令并将它生成的协议输出与您正在执行的操作进行比较:

    gsutil -o GSUtil:prefer_api=xml -d setmeta -h x-goog-meta-data-00:gAJ9cQBYBQAAAGFwcGxlcQFYCAAAAHBvdGF0b2VzcQJzLg gs://your-bucket/your-object

    【讨论】:

    • 问题不在于使用 OAuth2,而在于 OAuth2 和对存储桶的读/写(但不是完全)访问。 gsutil 遇到了同样的问题,它只有在 auth 令牌具有完全访问权限时才有效。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-24
    相关资源
    最近更新 更多