【问题标题】:Google cloud storage permission only on some object谷歌云存储权限仅对某些对象
【发布时间】:2020-12-11 02:02:08
【问题描述】:

我有一个包含多个文件夹的存储桶,每个文件夹包含多个对象 (pdf)。是否可以只允许某些用户只看到特定的对象(如果他可以看到其他文件夹就可以了)?

在创建对象后,我尝试仅对某些对象应用 reader acl 权限:

myFile.acl.add({ entity: 'group-' + email, role: 'READER' })

但是用户看不到存储桶,所以我给了他“存储对象查看器”权限,但现在他可以看到所有对象。

组是正确的(我希望),我创建了一个包含特定用户的组。

感谢您的帮助!

【问题讨论】:

  • 我编辑了我的答案以提供更多信息

标签: node.js google-cloud-storage acl bucket


【解决方案1】:

通过添加READER 的角色,您允许用户按照here 的说明列出存储桶内容

允许用户列出存储桶的内容。还允许用户读取存储桶元数据,不包括 ACL。

为了允许特定用户,您可以使用 addUser 函数:

  const {Storage} = require('@google-cloud/storage');

  const storage = new Storage();

  async function addFileReader() {
    await storage
      .bucket(bucketName)
      .file(filename)
      .acl.readers.addUser(userEmail);
  }

或者如果你想添加一个组:

  const {Storage} = require('@google-cloud/storage');

  const storage = new Storage();
  async function addFileReader() {
    await storage
      .bucket(bucketName)
      .file(filename)
      .acl.readers.addGroup(groupEmail);
  }

您也可以通过 UI 进行操作:

  1. 进入Storage 部分
  2. 点击您要授予访问权限的特定存储桶
  3. 单击您要授予访问权限的特定文件
  4. 转到EDIT PERMISSIONS,在Entity 列中的弹出窗口中选择UserGroupName 列中输入电子邮件并在Access 列中选择Reader

【讨论】:

    猜你喜欢
    • 2016-08-18
    • 2023-03-08
    • 1970-01-01
    • 1970-01-01
    • 2018-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多