יצירת רשימות של בקרת גישה (ACL) וניהול שלהן

סקירה כללית

הדף הזה מסביר איך לשלוט בגישה לקטגוריות ולאובייקטים באמצעות רשימות של בקרת גישה (ACL). רשימות ACL הן מנגנון שאפשר להשתמש בו כדי להגדיר למי יש גישה לקטגוריות ולאובייקטים שלכם, ואיזו רמת גישה יש להם.

כדי לדעת האם כדאי להשתמש ברשימות ACL לשליטה בגישה למשאבים שלכם, קראו את הסקירה הכללית על ACL.

התפקידים הנדרשים

כדי לקבל את ההרשאות שדרושות ליצירה ולניהול של ACLs, צריך לבקש מהאדמין להקצות לכם את תפקיד ה-IAM 'אדמין לניהול אחסון' (roles/storage.admin) בקטגוריה שמכילה את האובייקטים שאתם רוצים ליצור ולנהל עבורם ACLs.

התפקיד המוגדר מראש הזה מכיל את ההרשאות שנדרשות ליצירה ולניהול של רשימות ACL. כדי לראות בדיוק אילו הרשאות נדרשות, אפשר להרחיב את הקטע ההרשאות הנדרשות:

ההרשאות הנדרשות

  • storage.buckets.get
  • storage.buckets.list
    • ההרשאה הזו נדרשת רק כדי להשתמש ב Google Cloud מסוף לביצוע המשימות שבדף הזה.
  • storage.buckets.setIamPolicy
  • storage.buckets.update
  • storage.objects.get
  • storage.objects.getIamPolicy
  • storage.objects.setIamPolicy
  • storage.objects.update

אפשר לקבל את ההרשאות האלה גם באמצעות תפקידים בהתאמה אישית.

במאמר הגדרה וניהול של מדיניות IAM בקטגוריות מוסבר איך מקצים תפקידים בקטגוריות.

הגדרת רשימות ACL או שינוי שלהן

המסוף

  1. נכנסים לדף Cloud Storage browser במסוף Google Cloud .
    כניסה לדף Cloud Storage browser

  2. ברשימת הקטגוריות, לוחצים על שם הקטגוריה שמכילה את האובייקט שרוצים לשנות את רשימת ה-ACL שלו.

  3. לוחצים על שם האובייקט שרוצים להגדיר או לשנות את רשימות ה-ACL שלו.

  4. לוחצים על עריכת הגישה.

    תיפתח תיבת דו-שיח של הרשאות עם רשימת ה-ACL הנוכחית של האובייקט.

  5. לוחצים על + הוספת רשומה.

  6. בוחרים את הסוג של Entity שיקבל את ההרשאה.

    השדה Entity מציין את סוג הדבר שמקבל את ההרשאה (לדוגמה, משתמש או קבוצה). לרשימת הערכים שנתמכים בשדה Entity, עיינו בהיקפי בקרת גישה.

  7. מזינים ערך בשדה Name.

    השדה Name משמש לזיהוי של משתמש, קבוצה או ישות אחרת ספציפיים. לרשימת הערכים שנתמכים בשדה Name, עיינו בהיקפי בקרת גישה.

    השדות Entity ו-Name מגדירים ביחד על מי חלה ההרשאה.

  8. בוחרים ערך בשדה Access.

    השדה Access מגדיר את ההרשאה שרוצים להגדיר באובייקט. לרשימת הערכים שנתמכים בשדה Access, עיינו בהרשאות של בקרת גישה.

  9. לוחצים על Save.

במאמר פתרון בעיות מוסבר איך מקבלים מידע מפורט על שגיאות בנושא פעולות ב-Cloud Storage שנכשלו במסוף Google Cloud .

שורת הפקודה

כדי להוסיף, לשנות או להסיר הרשאת גישה ספציפית באובייקט, משתמשים בפקודה objects update עם הדגל הרלוונטי:

gcloud storage objects update gs://BUCKET_NAME/OBJECT_NAME FLAG

כאשר:

  • BUCKET_NAME הוא שם הקטגוריה שמכילה את האובייקט שעליו חל השינוי. לדוגמה, example-travel-maps.

  • OBJECT_NAME הוא שם האובייקט שעליו חל השינוי. לדוגמה, paris.jpg.

  • FLAG הוא אחד מהבאים:

    • --add-acl-grant, יחד עם ההרשאה שרוצים להוסיף או לשנות. לדוגמה, --add-acl-grant=entity=user-jeffersonloveshiking@gmail.com,role=READER.

    • --remove-acl-grant, יחד עם הישות שרוצים לבטל את הרשאת הגישה שלה. לדוגמה, --remove-acl-grant=user-jeffersonloveshiking@gmail.com.

כדי להחליף את כל רשימות ה-ACL של אובייקט:

  1. מגדירים את רשימות ה-ACL בקובץ בפורמט JSON או YAML.

    לדוגמה, רשימות ה-ACL הבאות מעניקות את ההרשאה OWNER לאובייקט paris.jpg לבעלי הפרויקט 867489160491 ולמשתמש jeffersonloveshiking@gmail.com, וגם את ההרשאה READER לאובייקט paris.jpg לחברים בקבוצה gs-announce:

    [
    {
      "entity": "project-owners-867489160491",
      "role": "OWNER",
      "projectTeam": {
        "projectNumber": "867489160491",
        "team": "owners"
      },
    },
    {
      "entity": "user-jeffersonloveshiking@gmail.com",
      "email": "jeffersonloveshiking@gmail.com",
      "role": "OWNER"
    },
    {
      "entity": "group-gs-announce@googlegroups.com",
      "email": "gs-announce@googlegroups.com",
      "role": "READER"
    }
    ]
    
  2. משתמשים בפקודה objects update עם הדגל --acl-file:

    gcloud storage objects update gs://BUCKET_NAME/OBJECT_NAME --acl-file=FILE_LOCATION

    כאשר:

    • BUCKET_NAME הוא שם הקטגוריה שמכילה את האובייקט שעליו חלות רשימות ה-ACL. לדוגמה, example-travel-maps.

    • OBJECT_NAME הוא שם האובייקט שעליו חלות רשימות ה-ACL. לדוגמה, paris.jpg.

    • FILE_LOCATION הוא הנתיב המקומי לקובץ שמכיל את רשימות ה-ACL שהגדרתם. לדוגמה, Desktop/acls.json.

ספריות לקוח

C++

למידע נוסף, קראו את מאמרי העזרה של Cloud Storage C++ API.

כדי לבצע אימות ב-Cloud Storage, אתם צריכים להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לספריות לקוח.

הדוגמה הבאה מוסיפה ACL לאובייקט:

namespace gcs = ::google::cloud::storage;
using ::google::cloud::StatusOr;
[](gcs::Client client, std::string const& bucket_name,
   std::string const& object_name, std::string const& entity) {
  StatusOr<gcs::ObjectAccessControl> patched_acl =
      client.CreateObjectAcl(bucket_name, object_name, entity,
                             gcs::ObjectAccessControl::ROLE_OWNER());

  if (!patched_acl) throw std::move(patched_acl).status();
  std::cout << "ACL entry for " << patched_acl->entity() << " in object "
            << patched_acl->object() << " in bucket " << patched_acl->bucket()
            << " is now " << *patched_acl << "\n";
}

הדוגמה הבאה מסירה ACL מאובייקט:

namespace gcs = ::google::cloud::storage;
using ::google::cloud::StatusOr;
[](gcs::Client client, std::string const& bucket_name,
   std::string const& object_name, std::string const& entity) {
  StatusOr<gcs::ObjectMetadata> original_metadata = client.GetObjectMetadata(
      bucket_name, object_name, gcs::Projection::Full());
  if (!original_metadata) throw std::move(original_metadata).status();

  std::vector<gcs::ObjectAccessControl> original_acl =
      original_metadata->acl();
  auto it = std::find_if(original_acl.begin(), original_acl.end(),
                         [entity](gcs::ObjectAccessControl const& entry) {
                           return entry.entity() == entity &&
                                  entry.role() ==
                                      gcs::ObjectAccessControl::ROLE_OWNER();
                         });

  if (it == original_acl.end()) {
    std::cout << "Could not find entity " << entity << " for file "
              << object_name << " with role OWNER in bucket " << bucket_name
              << "\n";
    return;
  }

  gcs::ObjectAccessControl owner = *it;
  google::cloud::Status status =
      client.DeleteObjectAcl(bucket_name, object_name, owner.entity());

  if (!status.ok()) throw std::runtime_error(status.message());
  std::cout << "Deleted ACL entry for " << owner.entity() << " for file "
            << object_name << " in bucket " << bucket_name << "\n";
}

C#

למידע נוסף, קראו את מאמרי העזרה של Cloud Storage C# API.

כדי לבצע אימות ב-Cloud Storage, אתם צריכים להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לספריות לקוח.

הדוגמה הבאה מוסיפה ACL לאובייקט:


using Google.Apis.Storage.v1.Data;
using Google.Cloud.Storage.V1;
using System;

public class AddFileOwnerSample
{
    public Google.Apis.Storage.v1.Data.Object AddFileOwner(
        string bucketName = "your-unique-bucket-name",
        string objectName = "my-file-name",
        string userEmail = "dev@iam.gserviceaccount.com")
    {
        var storage = StorageClient.Create();
        var storageObject = storage.GetObject(bucketName, objectName, new GetObjectOptions
        {
            Projection = Projection.Full
        });

        storageObject.Acl.Add(new ObjectAccessControl
        {
            Bucket = bucketName,
            Entity = $"user-{userEmail}",
            Role = "OWNER",
        });
        var updatedObject = storage.UpdateObject(storageObject);
        Console.WriteLine($"Added user { userEmail} as an owner on file { objectName}.");
        return updatedObject;
    }
}

הדוגמה הבאה מסירה ACL מאובייקט:


using Google.Cloud.Storage.V1;
using System;
using System.Linq;

public class RemoveFileOwnerSample
{
    public void RemoveFileOwner(
        string bucketName = "your-unique-bucket-name",
        string objectName = "your-object-name",
        string userEmail = "dev@iam.gserviceaccount.com")
    {
        var storage = StorageClient.Create();
        var storageObject = storage.GetObject(bucketName, objectName, new GetObjectOptions { Projection = Projection.Full });
        if (storageObject.Acl == null)
        {
            Console.WriteLine("No owner to remove");
        }
        else
        {
            storageObject.Acl = storageObject.Acl.Where((acl) => !(acl.Entity == $"user-{userEmail}" && acl.Role == "OWNER")).ToList();
            var updatedObject = storage.UpdateObject(storageObject);
            Console.WriteLine($"Removed user {userEmail} from file {objectName}.");
        }
    }
}

Go

למידע נוסף, קראו את מאמרי העזרה של Cloud Storage Go API.

כדי לבצע אימות ב-Cloud Storage, אתם צריכים להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לספריות לקוח.

הדוגמה הבאה מוסיפה ACL לאובייקט:

import (
	"context"
	"fmt"

	"cloud.google.com/go/storage"
)

// addFileOwner adds ACL to the specified object.
func addFileOwner(bucket, object string, entity storage.ACLEntity) error {
	// bucket := "bucket-name"
	// object := "object-name"
	// entity := storage.AllUsers
	role := storage.RoleOwner

	ctx := context.Background()
	client, err := storage.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("storage.NewClient: %w", err)
	}
	defer client.Close()

	acl := client.Bucket(bucket).Object(object).ACL()
	if err := acl.Set(ctx, entity, role); err != nil {
		return fmt.Errorf("ACLHandle.Set: %w", err)
	}
	return nil
}

הדוגמה הבאה מסירה ACL מאובייקט:

import (
	"context"
	"fmt"

	"cloud.google.com/go/storage"
)

// removeFileOwner removes default ACL from the given object.
func removeFileOwner(bucket, object string, entity storage.ACLEntity) error {
	// bucket := "bucket-name"
	// object := "object-name"
	// entity := storage.AllUsers
	ctx := context.Background()
	client, err := storage.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("storage.NewClient: %w", err)
	}
	defer client.Close()

	acl := client.Bucket(bucket).Object(object).ACL()
	if err := acl.Delete(ctx, entity); err != nil {
		return fmt.Errorf("ACLHandle.Delete: %w", err)
	}
	return nil
}

Java

למידע נוסף, קראו את מאמרי העזרה של Cloud Storage Java API.

כדי לבצע אימות ב-Cloud Storage, אתם צריכים להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לספריות לקוח.

הדוגמה הבאה מוסיפה ACL לאובייקט:


import com.google.cloud.storage.Acl;
import com.google.cloud.storage.Acl.Role;
import com.google.cloud.storage.Acl.User;
import com.google.cloud.storage.Blob;
import com.google.cloud.storage.BlobId;
import com.google.cloud.storage.Storage;
import com.google.cloud.storage.StorageOptions;

public class AddBlobOwner {

  public static void addBlobOwner(
      String projectId, String bucketName, String userEmail, String blobName) {
    // The ID of your GCP project
    // String projectId = "your-project-id";

    // The ID of your GCS bucket
    // String bucketName = "your-unique-bucket-name";

    // Email of the user you wish to add as a file owner
    // String userEmail = "someuser@domain.com"

    // The name of the blob/file that you wish to modify permissions on
    // String blobName = "your-blob-name";

    Storage storage = StorageOptions.newBuilder().setProjectId(projectId).build().getService();
    Blob blob = storage.get(BlobId.of(bucketName, blobName));
    Acl newOwner = Acl.of(new User(userEmail), Role.OWNER);

    blob.createAcl(newOwner);
    System.out.println(
        "Added user "
            + userEmail
            + " as an owner on blob "
            + blobName
            + " in bucket "
            + bucketName);
  }
}

הדוגמה הבאה מסירה ACL מאובייקט:


import com.google.cloud.storage.Acl.User;
import com.google.cloud.storage.Blob;
import com.google.cloud.storage.BlobId;
import com.google.cloud.storage.Storage;
import com.google.cloud.storage.StorageOptions;

public class RemoveBlobOwner {

  public static void removeBlobOwner(
      String projectId, String bucketName, String userEmail, String blobName) {
    // The ID of your GCP project
    // String projectId = "your-project-id";

    // The ID of your GCS bucket
    // String bucketName = "your-unique-bucket-name";

    // Email of the user you wish to remove as a file owner
    // String userEmail = "someuser@domain.com"

    // The name of the blob/file that you wish to modify permissions on
    // String blobName = "your-blob-name";

    Storage storage = StorageOptions.newBuilder().setProjectId(projectId).build().getService();
    Blob blob = storage.get(BlobId.of(bucketName, blobName));
    User ownerToRemove = new User(userEmail);

    boolean success = blob.deleteAcl(ownerToRemove);
    if (success) {
      System.out.println(
          "Removed user "
              + userEmail
              + " as an owner on file "
              + blobName
              + " in bucket "
              + bucketName);
    } else {
      System.out.println("User " + userEmail + " was not found");
    }
  }
}

Node.js

למידע נוסף, קראו את מאמרי העזרה של Cloud Storage Node.js API.

כדי לבצע אימות ב-Cloud Storage, אתם צריכים להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לספריות לקוח.

הדוגמה הבאה מוסיפה ACL לאובייקט:

/**
 * TODO(developer): Uncomment the following lines before running the sample.
 */
// The ID of your GCS bucket
// const bucketName = 'your-unique-bucket-name';

// The name of the file to access
// const fileName = 'file.txt';

// The email address of the user to add
// const userEmail = 'user-email-to-add';

// Imports the Google Cloud client library
const {Storage} = require('@google-cloud/storage');

// Creates a client
const storage = new Storage();

async function addFileOwner() {
  await storage
    .bucket(bucketName)
    .file(fileName)
    .acl.owners.addUser(userEmail);

  console.log(`Added user ${userEmail} as an owner on file ${fileName}.`);
}

addFileOwner().catch(console.error);

הדוגמה הבאה מסירה ACL מאובייקט:

/**
 * TODO(developer): Uncomment the following lines before running the sample.
 */
// The ID of your GCS bucket
// const bucketName = 'your-unique-bucket-name';

// The ID of your GCS file
// const fileName = 'your-file-name';

// The email address of the user to remove
// const userEmail = 'user-email-to-remove';

// Imports the Google Cloud client library
const {Storage} = require('@google-cloud/storage');

// Creates a client
const storage = new Storage();

async function removeFileOwner() {
  // Removes the user from the access control list of the file. You can use
  // deleteAllUsers(), deleteDomain(), deleteProject(), deleteGroup(), and
  // deleteAllAuthenticatedUsers() to remove access for different types of entities.
  await storage
    .bucket(bucketName)
    .file(fileName)
    .acl.owners.deleteUser(userEmail);

  console.log(`Removed user ${userEmail} from file ${fileName}.`);
}

removeFileOwner().catch(console.error);

PHP

למידע נוסף, קראו את מאמרי העזרה של Cloud Storage PHP API.

כדי לבצע אימות ב-Cloud Storage, אתם צריכים להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לספריות לקוח.

הדוגמה הבאה מוסיפה ACL לאובייקט:

use Google\Cloud\Storage\StorageClient;

/**
 * Add an entity and role to an object's ACL.
 *
 * @param string $bucketName The name of your Cloud Storage bucket.
 *        (e.g. 'my-bucket')
 * @param string $objectName The name of your Cloud Storage object.
 *        (e.g. 'my-object')
 * @param string $entity The entity for which to update access controls.
 *        (e.g. 'user-example@domain.com')
 * @param string $role The permissions to add for the specified entity.
 *        (e.g. 'OWNER')
 */
function add_object_acl(string $bucketName, string $objectName, string $entity, string $role): void
{
    $storage = new StorageClient();
    $bucket = $storage->bucket($bucketName);
    $object = $bucket->object($objectName);
    $acl = $object->acl();
    $acl->add($entity, $role);
    printf('Added %s (%s) to gs://%s/%s ACL' . PHP_EOL, $entity, $role, $bucketName, $objectName);
}

הדוגמה הבאה מסירה ACL מאובייקט:

use Google\Cloud\Storage\StorageClient;

/**
 * Delete an entity from an object's ACL.
 *
 * @param string $bucketName The name of your Cloud Storage bucket.
 *        (e.g. 'my-bucket')
 * @param string $objectName The name of your Cloud Storage object.
 *        (e.g. 'my-object')
 * @param string $entity The entity for which to update access controls.
 *        (e.g. 'user-example@domain.com')
 */
function delete_object_acl(string $bucketName, string $objectName, string $entity): void
{
    $storage = new StorageClient();
    $bucket = $storage->bucket($bucketName);
    $object = $bucket->object($objectName);
    $acl = $object->acl();
    $acl->delete($entity);
    printf('Deleted %s from gs://%s/%s ACL' . PHP_EOL, $entity, $bucketName, $objectName);
}

Python

למידע נוסף, קראו את מאמרי העזרה של Cloud Storage Python API.

כדי לבצע אימות ב-Cloud Storage, אתם צריכים להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לספריות לקוח.

הדוגמה הבאה מוסיפה ACL לאובייקט:

from google.cloud import storage


def add_blob_owner(bucket_name, blob_name, user_email):
    """Adds a user as an owner on the given blob."""
    # bucket_name = "your-bucket-name"
    # blob_name = "your-object-name"
    # user_email = "name@example.com"

    storage_client = storage.Client()
    bucket = storage_client.bucket(bucket_name)
    blob = bucket.blob(blob_name)

    # Reload fetches the current ACL from Cloud Storage.
    blob.acl.reload()

    # You can also use `group`, `domain`, `all_authenticated` and `all` to
    # grant access to different types of entities. You can also use
    # `grant_read` or `grant_write` to grant different roles.
    blob.acl.user(user_email).grant_owner()
    blob.acl.save()

    print(
        "Added user {} as an owner on blob {} in bucket {}.".format(
            user_email, blob_name, bucket_name
        )
    )

הדוגמה הבאה מסירה ACL מאובייקט:

from google.cloud import storage


def remove_blob_owner(bucket_name, blob_name, user_email):
    """Removes a user from the access control list of the given blob in the
    given bucket."""
    # bucket_name = "your-bucket-name"
    # blob_name = "your-object-name"
    # user_email = "name@example.com"

    storage_client = storage.Client()
    bucket = storage_client.bucket(bucket_name)
    blob = bucket.blob(blob_name)

    # You can also use `group`, `domain`, `all_authenticated` and `all` to
    # remove access for different types of entities.
    blob.acl.user(user_email).revoke_read()
    blob.acl.user(user_email).revoke_write()
    blob.acl.user(user_email).revoke_owner()
    blob.acl.save()

    print(
        f"Removed user {user_email} from blob {blob_name} in bucket {bucket_name}."
    )

Ruby

למידע נוסף, קראו את מאמרי העזרה של Cloud Storage Ruby API.

כדי לבצע אימות ב-Cloud Storage, אתם צריכים להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לספריות לקוח.

הדוגמה הבאה מוסיפה ACL לאובייקט:

# The ID of your GCS bucket
# bucket_name = "your-unique-bucket-name"
# file_name   = "Name of a file in the Storage bucket"
# email       = "Google Cloud Storage ACL Entity email"

require "google/cloud/storage"

storage = Google::Cloud::Storage.new
bucket  = storage.bucket bucket_name
file    = bucket.file file_name

file.acl.add_owner email

puts "Added OWNER permission for #{email} to #{file_name}"

הדוגמה הבאה מסירה ACL מאובייקט:

# The ID of your GCS bucket
# bucket_name = "your-unique-bucket-name"
# file_name   = "Name of a file in the Storage bucket"
# email       = "Google Cloud Storage ACL Entity email"

require "google/cloud/storage"

storage = Google::Cloud::Storage.new
bucket  = storage.bucket bucket_name
file    = bucket.file file_name

file.acl.delete email

puts "Removed ACL permissions for #{email} from #{file_name}"

ממשקי API ל-REST

‫API בפורמט JSON

כשיוצרים אובייקט, אפשר לציין את המאפיין (property) acl[] בגוף הבקשה, או את פרמטר השאילתה predefinedAcl בבקשת insert. באובייקט קיים, אתם צריכים לציין את המאפיין acl[] או את פרמטר השאילתה predefinedAcl בבקשת patch או בבקשת update.

להגדרת מאפיין ACL של האובייקט, עיינו במידע על המשאב ObjectAccessControls.

  1. מגדירים את רשימות ה-ACL בקובץ JSON.

    לדוגמה, אם רשימת ה-ACL מעניקה לבעלי הפרויקט 867489160491 ולמשתמש jeffersonloveshiking@gmail.com הרשאת OWNER, יחד עם הענקת הרשאת READER לחברים בקבוצת gs-announce, יכול להיות שיהיה לכם קובץ בשם acls.json עם התוכן הבא:

    {
    "acl": [
      {
        "entity": "project-owners-867489160491",
        "role": "OWNER",
        "projectTeam": {
          "projectNumber": "867489160491",
          "team": "owners"
        }
      },
      {
        "entity": "user-jeffersonloveshiking@gmail.com",
        "role": "OWNER",
        "email": "jeffersonloveshiking@gmail.com"
      },
      {
        "entity": "group-gs-announce@googlegroups.com",
        "role": "READER",
        "email": "gs-announce@googlegroups.com"
      }
    ]
    }
    
  2. שולחים בקשת patch באמצעות קובץ ה-JSON ומציינים את האובייקט שבו צריך להגדיר את רשימות ה-ACL.

לדוגמה, פקודת curl הבאה מחילה מטען ייעודי (payload) של JSON מהמסמך acls.json על אובייקט בשם paris.jpg בקטגוריה example-travel-maps:

curl -X PATCH --data @acls.json -H "Content-Type: application/json" \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    https://storage.googleapis.com/storage/v1/b/example-travel-maps/o/paris.jpg

‫API בפורמט XML

ב-API בפורמט XML עובדים עם רשימות ACL בפורמט XML. כדי לשנות רשימות ACL של קטגוריות ואובייקטים, אתם צריכים לצרף מסמך XML לגוף הבקשות. כאשר מקבלים רשימות ACL של קטגוריות ואובייקטים, מוחזר מסמך XML. מסמך ה-XML מכיל את רשומות ה-ACL של הקטגוריה הבודדת או של האובייקט הבודד.

  • אחרי שיוצרים קטגוריה באמצעות בקשה של קטגוריית PUT, משתמשים בבקשה שנייה של קטגוריית PUT עם הפרמטר ?acl כדי לשנות את ה-ACL של הקטגוריה.

  • אחרי שמעלים אובייקט באמצעות בקשה של אובייקט PUT, משנים את ה-ACL על ידי בקשת PUT נוספת באמצעות הפרמטר ?acl או כותרת הבקשה x-googl-acl.

לדוגמה, פקודת curl הבאה מחילה מטען ייעודי (payload) של XML מהמסמך acls.xml על אובייקט בשם paris.jpg בקטגוריה example-travel-maps:

curl -X PUT --data-binary @acls.xml \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    https://storage.googleapis.com/example-travel-maps/paris.jpg?acl

במסמך ה-XML, אתם צריכים להשתמש בתחביר ACL הבא:

רכיב תיאור
AccessControlList קונטיינר של הרכיבים Entries ו-Owner.
Owner קונטיינר של הרכיבים DisplayName ו-ID. הרכיב הזה לא נדרש לאובייקטים כי אובייקט תמיד נמצא בבעלות המשתמש שהעלה אותו. הרכיב הזה נמצא בשימוש כשמשתמשים בתחביר ACL של Amazon S3 בתרחיש העברה.

Amazon Simple Storage Service™‎ ו-Amazon S3™‎ הם סימנים מסחריים של Amazon.com, Inc.‎ או של השותפים העצמאיים שלה בארצות הברית או במדינות אחרות.
ID מזהה Cloud Storage של בעלי הקטגוריה.
DisplayName לא מיושמת. הערך הוא תמיד מחרוזת ריקה.
Entries קונטיינר של אפס רכיבי Entry או יותר.
Entry קונטיינר של הרכיבים Scope ו-Permission. ‫Entry יכול להכיל רק רכיב Scope אחד ורכיב Permission אחד.
Scope קונטיינר של אחד מהרכיבים ID, EmailAddress או Domain שמגדיר את ההיקף של רשימת ה-ACL. לרכיב הזה חייב להיות מאפיין type שמכיל אחד מהערכים הבאים: UserByID, UserByEmail, GroupByID, GroupByEmail, GroupByDomain, AllUsers או AllAuthenticatedUsers.
ID מזהה של מקבל ההרשאה כשרשומת ההרשאה מצוינת לפי המזהה.
EmailAddress מזהה האימייל של מקבל ההרשאה כשרשומת ההרשאה מצוינת לפי האימייל.
Domain מזהה הדומיין של מקבל ההרשאה כשרשומת ההרשאה מצוינת לפי הדומיין.
Name רכיב אופציונלי שאפשר לציין או שאפשר להוסיף באופן אוטומטי אם ההיקף הוא UserByEmail או GroupByEmail.
Permission ההרשאה שהוענקה: READ, WRITE או FULL_CONTROL.

בעבודה עם רשימות ACL באמצעות ממשק ה-API בפורמט XML:

  • אפשר להשתמש רק בפורמט ה-XML שמתואר למעלה.
  • אי אפשר להגדיר היקפים כפולים.

    ב-XML של רשימת ה-ACL יכולות להיות רשומות רבות, אבל לא יכולות להיות רשומות עם היקפים כפולים. לדוגמה, אי אפשר לכלול שתי רשומות עם אותו רכיב היקף של jane@example.com.

הדוגמה הבאה מציגה רשומות ACL שונות של קטגוריה:

<?xml version="1.0" encoding="UTF-8"?>
<AccessControlList>
  <Owner>
    <ID>00b4903a9721...</ID>
  </Owner>
  <Entries>
    <Entry>
      <Scope type="GroupById">
        <ID>00b4903a9722...</ID>
      </Scope>
      <Permission>FULL_CONTROL</Permission>
    </Entry>
    <Entry>
      <Scope type="GroupByDomain">
        <Domain>example.com</Domain>
      </Scope>
      <Permission>READ</Permission>
    </Entry>
    <Entry>
      <Scope type="GroupByEmail">
        <EmailAddress>gs-announce@googlegroups.com</EmailAddress>
      </Scope>
      <Permission>READ</Permission>
    </Entry>
    <Entry>
      <Scope type="UserByEmail">
        <EmailAddress>jeffersonloveshiking@gmail.com</EmailAddress>
        <Name>Jefferson</Name>
      </Scope>
      <Permission>FULL_CONTROL</Permission>
    </Entry>
    <Entry>
      <Scope type="AllUsers"/>
      <Permission>READ</Permission>
    </Entry>
    <Entry>
      <Scope type="AllAuthenticatedUsers"/>
      <Permission>READ</Permission>
    </Entry>
  </Entries>
</AccessControlList>

הגדרת רכיב השם ב-XML של ACL

כשמאחזרים ACL מקטגוריה או מאובייקט, יכול להיות שיצורף רכיב <Name> נוסף לחלק מהרשומות. לדוגמה, יכול להיות שתראו רשומה שנראית כך:

<Entry>
  <Scope type="UserByEmail">
    <EmailAddress>jeffersonloveshiking@gmail.com</EmailAddress>
    <Name>Jefferson</Name>
  </Scope>
  <Permission>FULL_CONTROL</Permission>
</Entry>

רכיבי <Name> האופציונליים האלה מאוכלסים בשתי נסיבות:

  1. כאשר רשימות ה-ACL של הקטגוריה או האובייקט כוללות את <Name> כרכיב.

    כשמגדירים רשימות ACL, אפשר לכלול את הרכיב <Name> עם רשומות ה-ACL. ברכיב <Name> אפשר לציין כל ערך. הערכים האלה יישמרו ב-Cloud Storage עד שתסירו או תחליפו את ה-ACL. כדאי להשתמש בשיטה הזו אם אתם משתמשים במזהים שלא פשוטים לזיהוי.

  2. כשההיקף של UserByEmail או GroupByEmail מכיל פרופיל Google ציבורי.

    אם אתם משתמשים באחד מההיקפים האלה בלי לספק רכיב <Name>, Cloud Storage בודק אם למשתמש או לקבוצה ב-Google שמשויכים לכתובת האימייל יש פרופיל Google ציבורי עם שם ציבורי. במקרה כזה, מערכת Cloud Storage מאכלסת את הרכיב <Name> באופן אוטומטי עם השם הציבורי.

החלת רשימת ACL מוגדרת מראש

במקום לציין את כל רשימת ה-ACL באמצעות כל רשומה בנפרד כפי שמוצג למעלה, תוכלו להשתמש ברשימת ACL מוגדרת מראש, שתחיל באופן אוטומטי מספר רשומות שהותאמו לתרחיש ספציפי. תוכלו להשתמש ב-Google Cloud CLI, ב-API בפורמט JSON או ב-API בפורמט XML כדי להחיל רשימת ACL מוגדרת מראש על קטגוריה או על אובייקט.

על אובייקטים חדשים

כדי להחיל רשימת ACL מוגדרת מראש על אובייקט במהלך העלאת האובייקט:

המסוף

אי אפשר להחיל רשימת ACL מוגדרת מראש באמצעות מסוף Google Cloud . במקום זאת, אתם צריכים להשתמש ב-gcloud storage.

שורת הפקודה

משתמשים בפקודה gcloud storage cp עם הדגל --predefined-acl:

gcloud storage cp OBJECT gs://BUCKET_NAME --predefined-acl=PREDEFINED_ACL

לדוגמה, כדי להחיל את רשימת ה-ACL bucketOwnerRead שהוגדרה מראש כשמעלים אובייקט paris.jpg לקטגוריה example-travel-maps:

gcloud storage cp paris.jpg gs://example-travel-maps --predefined-acl=bucketOwnerRead

ממשקי API בארכיטקטורת REST

‫API בפורמט JSON

משתמשים בפרמטר predefinedAcl של מחרוזת השאילתה בבקשת insert כדי להחיל את רשימת ה-ACL שהוגדרה מראש.

לדוגמה, כדי להחיל את רשימת ה-ACL bucketOwnerRead שהוגדרה מראש כשמעלים אובייקט paris.jpg לקטגוריה example-travel-maps:

curl -X POST --data-binary @paris.jpg -H "Content-Type: image/jpeg" \
    -H "Authorization: Bearer $(gcloud auth print-access-token)"  \
    "https://storage.googleapis.com/upload/storage/v1/b/example-travel-maps/o?name=paris.jpg&predefinedAcl=bucketOwnerRead"

‫API בפורמט XML

כדי להחיל את רשימת ה-ACL שהוגדרה מראש, משתמשים בכותרת x-goog-acl בבקשת האובייקט Put.

לדוגמה, כדי להחיל את רשימת ה-ACL bucket-owner-read שהוגדרה מראש כשמעלים אובייקט paris.jpg לקטגוריה example-travel-maps:

curl -X PUT --upload-file paris.jpg -H "x-goog-acl: bucket-owner-read" \
    -H "Authorization: Bearer $(gcloud auth print-access-token)"  \
    https://storage.googleapis.com/example-travel-maps/paris.jpg

על קטגוריות קיימות או אובייקטים קיימים

אפשר להחיל רשימת ACL מוגדרת מראש גם על קטגוריה או אובייקט קיימים. זה שימושי אם רוצים לעבור מרשימת ACL מוגדרת מראש אחת לאחרת, או לעדכן רשימות ACL מותאמות אישית לרשימת ACL מוגדרת מראש.

המסוף

אי אפשר להחיל רשימת ACL מוגדרת מראש באמצעות מסוף Google Cloud . במקום זאת, אתם צריכים להשתמש ב-gcloud storage.

שורת הפקודה

משתמשים בפקודה objects update עם הדגל --predefined-acl:

gcloud storage objects update gs://BUCKET_NAME/OBJECT_NAME --predefined-acl=PREDEFINED_ACL_NAME

לדוגמה, כדי להחיל את רשימת ה-ACL private שהוגדרה מראש על האובייקט paris.jpg בקטגוריה example-travel-maps:

gcloud storage objects update gs://example-travel-maps/paris.jpg --predefined-acl=private

ממשקי API בארכיטקטורת REST

‫API בפורמט JSON

כדי להחיל את רשימת ה-ACL המוגדרת מראש משתמשים בפרמטר predefinedAcl של מחרוזת השאילתה ומציינים נכס acl ריק בבקשת patch.

לדוגמה, כדי להחיל את רשימת ה-ACL private שהוגדרה מראש על האובייקט paris.jpg בקטגוריה example-travel-maps:

curl -X PATCH --data '{"acl": []}'  -H "Content-Type: application/json" \
    -H "Authorization: Bearer $(gcloud auth print-access-token)"  \
    https://storage.googleapis.com/storage/v1/b/example-travel-maps/o/paris.jpg?predefinedAcl=private

‫API בפורמט XML

משתמשים בכותרת x-goog-acl עם הפרמטר של מחרוזת השאילתה acl בבקשת Put Object, אבל לא כוללים מסמך XML בבקשה.

לדוגמה, כדי להחיל את רשימת ה-ACL private שהוגדרה מראש על האובייקט paris.jpg בקטגוריה example-travel-maps:

curl -X PUT -H "Content-Length: 0" \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "x-goog-acl: private" \
    https://storage.googleapis.com/example-travel-maps/paris.jpg?acl

הגדרת רשימות ACL שמשמשות כברירת מחדל של אובייקטים

כדי להימנע מלהגדיר רשימות ACL בכל פעם שיוצרים אובייקט חדש, אפשר להגדיר רשימת ACL שמשמשת כברירת מחדל של אובייקטים בקטגוריה מסוימת. לאחר מכן, בכל פעם שיתווסף לקטגוריה אובייקט חדש ללא רשימת ACL מפורשת, תחול עליו ברירת המחדל. לדוגמה, יכול להיות שתרצו לציין שרק לקבוצת משתמשים מסוימת תהיה גישה לרוב האובייקטים בקטגוריה מסוימת. אפשר לשנות את רשימת ה-ACL שמשמשת כברירת המחדל של אובייקטים, ואז להוסיף אובייקטים לקטגוריה. רשימת ה-ACL שמשמשת כברירת המחדל של אובייקטים מוחלת באופן אוטומטי על האובייקטים שהוספתם. עם זאת, אפשר לתת לאובייקטים מסוימים רשימות ACL שונות, ובמקרה כזה לא תחול עליהם ברירת המחדל.

כדי לצפות ברשימת ה-ACL שמשמשת כברירת המחדל של אובייקטים בקטגוריה מסוימת ולשנות אותה:

המסוף

אי אפשר להגדיר רשימות ACL שמשמשות כברירת מחדל של אובייקטים באמצעות מסוף Google Cloud . במקום זאת, אתם צריכים להשתמש ב-gcloud storage.

שורת הפקודה

  1. כדי לאחזר את רשימת ה-ACL שמשמשת כברירת המחדל של האובייקטים בקטגוריה, משתמשים בפקודה buckets describe עם הדגל --format:

    gcloud storage buckets describe gs://BUCKET_NAME --format="default(default_acl)"

    כאשר BUCKET_NAME הוא שם הקטגוריה שרוצים לצפות ברשימת ה-ACL שמשמשת כברירת המחדל של האובייקטים שלה. לדוגמה, my-bucket.

  2. כדי לשנות את רשימת ה-ACL שמשמשת כברירת המחדל של האובייקטים בקטגוריה, משתמשים בפקודה buckets update עם הדגל הרצוי:

    gcloud storage buckets update gs://BUCKET_NAME FLAG

    כאשר:

    • BUCKET_NAME הוא שם הקטגוריה שרוצים לשנות את רשימת ה-ACL שמשמשת כברירת המחדל של האובייקטים שלה. לדוגמה, my-bucket.

    • FLAG הוא אחד מהבאים:

      • --add-default-object-acl-grant וההרשאה שרוצים להוסיף לכל רשימת ה-ACL שמשמשת כברירת המחדל של האובייקטים בקטגוריה.

      • --default-object-acl-file והנתיב לקובץ מקומי שמגדיר רשימת ACL שמשמשת כברירת מחדל של אובייקטים בקטגוריה.

      • --predefined-default-object-acl והשם של רשימת ACL מוגדרת מראש של אובייקטים, שתחליף את רשימת ה-ACL שמשמשת כברירת המחדל של האובייקטים בקטגוריה.

      • --remove-default-object-acl-grant והישות שרוצים להסיר מכל רשימת ה-ACL שמשמשת כברירת המחדל של האובייקטים בקטגוריה.

ספריות לקוח

C++

למידע נוסף, קראו את מאמרי העזרה של Cloud Storage C++ API.

כדי לבצע אימות ב-Cloud Storage, אתם צריכים להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לספריות לקוח.

הדוגמה הבאה מוסיפה לקטגוריה רשימת ACL שמשמשת כברירת מחדל של אובייקטים:

namespace gcs = ::google::cloud::storage;
using ::google::cloud::StatusOr;
[](gcs::Client client, std::string const& bucket_name,
   std::string const& entity, std::string const& role) {
  StatusOr<gcs::ObjectAccessControl> default_object_acl =
      client.CreateDefaultObjectAcl(bucket_name, entity, role);
  if (!default_object_acl) throw std::move(default_object_acl).status();

  std::cout << "Role " << default_object_acl->role()
            << " will be granted default to " << default_object_acl->entity()
            << " on any new object created on bucket "
            << default_object_acl->bucket() << "\n"
            << "Full attributes: " << *default_object_acl << "\n";
}

הדוגמה הבאה מוחקת מקטגוריה רשימת ACL שמשמשת כברירת מחדל של אובייקטים:

namespace gcs = ::google::cloud::storage;
[](gcs::Client client, std::string const& bucket_name,
   std::string const& entity) {
  google::cloud::Status status =
      client.DeleteDefaultObjectAcl(bucket_name, entity);

  if (!status.ok()) throw std::runtime_error(status.message());
  std::cout << "Deleted ACL entry for " << entity << " in bucket "
            << bucket_name << "\n";
}

C#

למידע נוסף, קראו את מאמרי העזרה של Cloud Storage C# API.

כדי לבצע אימות ב-Cloud Storage, אתם צריכים להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לספריות לקוח.

הדוגמה הבאה מדפיסה את רשימת ה-ACL שמשמשת כברירת המחדל של האובייקטים בקטגוריה:


using Google.Apis.Storage.v1.Data;
using Google.Cloud.Storage.V1;
using System;
using System.Collections.Generic;

public class PrintBucketDefaultAclSample
{
    public IEnumerable<ObjectAccessControl> PrintBucketDefaultAcl(string bucketName = "your-unique-bucket-name")
    {
        var storage = StorageClient.Create();
        var bucket = storage.GetBucket(bucketName, new GetBucketOptions { Projection = Projection.Full });

        foreach (var acl in bucket.DefaultObjectAcl)
        {
            Console.WriteLine($"{acl.Role}:{acl.Entity}");
        }

        return bucket.DefaultObjectAcl;
    }
}

הדוגמה הבאה מוסיפה לקטגוריה רשימת ACL שמשמשת כברירת מחדל של אובייקטים:


using Google.Apis.Storage.v1.Data;
using Google.Cloud.Storage.V1;
using System;

public class AddBucketDefaultOwnerSample
{
    public Bucket AddBucketDefaultOwner(
        string bucketName = "your-unique-bucket-name",
        string userEmail = "dev@iam.gserviceaccount.com")
    {
        var storage = StorageClient.Create();
        var bucket = storage.GetBucket(bucketName, new GetBucketOptions { Projection = Projection.Full });

        bucket.DefaultObjectAcl.Add(new ObjectAccessControl
        {
            Bucket = bucketName,
            Entity = $"user-{userEmail}",
            Role = "OWNER",
        });
        var updatedBucket = storage.UpdateBucket(bucket);
        Console.WriteLine($"Added user {userEmail} as a default owner on bucket {bucketName}.");
        return updatedBucket;
    }
}

הדוגמה הבאה מוחקת מקטגוריה רשימת ACL שמשמשת כברירת מחדל של אובייקטים:


using Google.Cloud.Storage.V1;
using System;
using System.Linq;

public class RemoveBucketDefaultOwnerSample
{
    public void RemoveBucketDefaultOwner(
        string bucketName = "your-unique-bucket-name",
        string userEmail = "user@iam.gserviceaccount.com")
    {
        var storage = StorageClient.Create();
        var bucket = storage.GetBucket(bucketName, new GetBucketOptions { Projection = Projection.Full });
        if (bucket.DefaultObjectAcl == null)
        {
            Console.WriteLine("No default owner to remove");
        }
        else
        {
            bucket.DefaultObjectAcl = bucket.DefaultObjectAcl.Where(acl => !(acl.Entity == $"user-{userEmail}" && acl.Role == "OWNER")).ToList();
            var updatedBucket = storage.UpdateBucket(bucket);
            Console.WriteLine($"Removed user {userEmail} from bucket {bucketName}.");
        }
    }
}

Go

למידע נוסף, קראו את מאמרי העזרה של Cloud Storage Go API.

כדי לבצע אימות ב-Cloud Storage, אתם צריכים להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לספריות לקוח.

הדוגמה הבאה מוסיפה לקטגוריה רשימת ACL שמשמשת כברירת מחדל של אובייקטים:

import (
	"context"
	"fmt"

	"cloud.google.com/go/storage"
)

// addBucketDefaultOwner adds default ACL to the specified bucket.
func addBucketDefaultOwner(bucket string, entity storage.ACLEntity) error {
	// bucket := "bucket-name"
	// entity := storage.AllUsers
	role := storage.RoleOwner

	ctx := context.Background()
	client, err := storage.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("storage.NewClient: %w", err)
	}
	defer client.Close()

	acl := client.Bucket(bucket).DefaultObjectACL()
	if err := acl.Set(ctx, entity, role); err != nil {
		return fmt.Errorf("ACLHandle.Set: %w", err)
	}
	return nil
}

הדוגמה הבאה מוחקת מקטגוריה רשימת ACL שמשמשת כברירת מחדל של אובייקטים:

import (
	"context"
	"fmt"

	"cloud.google.com/go/storage"
)

// deleteDefaultBucketACL removes default ACL from a bucket.
func removeBucketDefaultOwner(bucket string, entity storage.ACLEntity) error {
	// bucket := "bucket-name"
	// entity := storage.AllUsers
	ctx := context.Background()
	client, err := storage.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("storage.NewClient: %w", err)
	}
	defer client.Close()

	acl := client.Bucket(bucket).DefaultObjectACL()
	if err := acl.Delete(ctx, entity); err != nil {
		return fmt.Errorf("ACLHandle.Delete: %w", err)
	}
	return nil
}

Java

למידע נוסף, קראו את מאמרי העזרה של Cloud Storage Java API.

כדי לבצע אימות ב-Cloud Storage, אתם צריכים להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לספריות לקוח.

הדוגמה הבאה מוסיפה לקטגוריה רשימת ACL שמשמשת כברירת מחדל של אובייקטים:


import com.google.cloud.storage.Acl;
import com.google.cloud.storage.Acl.Role;
import com.google.cloud.storage.Acl.User;
import com.google.cloud.storage.Bucket;
import com.google.cloud.storage.Storage;
import com.google.cloud.storage.StorageOptions;

public class AddBucketDefaultOwner {

  public static void addBucketDefaultOwner(String bucketName, String userEmail) {

    // The ID of your GCS bucket
    // String bucketName = "your-unique-bucket-name";

    // The email of the user you wish to add as a default owner
    // String userEmail = "someuser@domain.com"

    Storage storage = StorageOptions.newBuilder().build().getService();
    Bucket bucket = storage.get(bucketName);
    Acl newDefaultOwner = Acl.of(new User(userEmail), Role.OWNER);

    bucket.createDefaultAcl(newDefaultOwner);
    System.out.println("Added user " + userEmail + " as an owner on " + bucketName);
  }
}

הדוגמה הבאה מוחקת מקטגוריה רשימת ACL שמשמשת כברירת מחדל של אובייקטים:


import com.google.cloud.storage.Acl.User;
import com.google.cloud.storage.Bucket;
import com.google.cloud.storage.Storage;
import com.google.cloud.storage.StorageOptions;

public class RemoveBucketDefaultOwner {

  public static void removeBucketDefaultOwner(String bucketName, String userEmail) {

    // The ID of your GCS bucket
    // String bucketName = "your-unique-bucket-name";

    // The email of the user you wish to remove as a default owner
    // String userEmail = "someuser@domain.com"

    Storage storage = StorageOptions.newBuilder().build().getService();
    Bucket bucket = storage.get(bucketName);
    User userToRemove = new User(userEmail);

    boolean success = bucket.deleteDefaultAcl(userToRemove);
    if (success) {
      System.out.println("Removed user " + userEmail + " as an owner on " + bucketName);
    } else {
      System.out.println("User " + userEmail + " was not found");
    }
  }
}

Node.js

למידע נוסף, קראו את מאמרי העזרה של Cloud Storage Node.js API.

כדי לבצע אימות ב-Cloud Storage, אתם צריכים להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לספריות לקוח.

הדוגמה הבאה מוסיפה לקטגוריה רשימת ACL שמשמשת כברירת מחדל של אובייקטים:

/**
 * TODO(developer): Uncomment the following lines before running the sample.
 */
// The ID of your GCS bucket
// const bucketName = 'your-unique-bucket-name';

// The email address of the user to add
// const userEmail = 'user-email-to-add';

// Imports the Google Cloud client library
const {Storage} = require('@google-cloud/storage');

// Creates a client
const storage = new Storage();

async function addBucketDefaultOwner() {
  // Makes the user an owner in the default ACL of the bucket. You can use
  // addAllUsers(), addDomain(), addProject(), addGroup(), and
  // addAllAuthenticatedUsers() to grant access to different types of entities.
  // You can also use "readers" and "writers" to grant different roles.
  await storage.bucket(bucketName).acl.default.owners.addUser(userEmail);

  console.log(`Added user ${userEmail} as an owner on bucket ${bucketName}.`);
}

addBucketDefaultOwner().catch(console.error);

הדוגמה הבאה מוחקת מקטגוריה רשימת ACL שמשמשת כברירת מחדל של אובייקטים:

/**
 * TODO(developer): Uncomment the following lines before running the sample.
 */
// The ID of your GCS bucket
// const bucketName = 'your-unique-bucket-name';

// The email address of the user to remove
// const userEmail = 'user-email-to-remove';

// Imports the Google Cloud client library
const {Storage} = require('@google-cloud/storage');

// Creates a client
const storage = new Storage();

async function removeBucketDefaultOwner() {
  // Removes the user from the access control list of the bucket. You can use
  // deleteAllUsers(), deleteDomain(), deleteProject(), deleteGroup(), and
  // deleteAllAuthenticatedUsers() to remove access for different types of entities.
  await storage.bucket(bucketName).acl.default.owners.deleteUser(userEmail);

  console.log(`Removed user ${userEmail} from bucket ${bucketName}.`);
}

removeBucketDefaultOwner().catch(console.error);

PHP

למידע נוסף, קראו את מאמרי העזרה של Cloud Storage PHP API.

כדי לבצע אימות ב-Cloud Storage, אתם צריכים להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לספריות לקוח.

הדוגמה הבאה מוסיפה לקטגוריה רשימת ACL שמשמשת כברירת מחדל של אובייקטים:

use Google\Cloud\Storage\StorageClient;

/**
 * Add an entity and role to a bucket's default ACL.
 *
 * @param string $bucketName The name of your Cloud Storage bucket.
 *        (e.g. 'my-bucket')
 * @param string $entity The entity for which to update access controls.
 *        (e.g. 'user-example@domain.com')
 * @param string $role The permissions to add for the specified entity.
 *        (e.g. 'OWNER')
 */
function add_bucket_default_acl(string $bucketName, string $entity, string $role): void
{
    $storage = new StorageClient();
    $bucket = $storage->bucket($bucketName);
    $acl = $bucket->defaultAcl();
    $acl->add($entity, $role);
    printf('Added %s (%s) to gs://%s default ACL' . PHP_EOL, $entity, $role, $bucketName);
}

הדוגמה הבאה מוחקת מקטגוריה רשימת ACL שמשמשת כברירת מחדל של אובייקטים:

use Google\Cloud\Storage\StorageClient;

/**
 * Delete an entity from a bucket's default ACL.
 *
 * @param string $bucketName The name of your Cloud Storage bucket.
 *        (e.g. 'my-bucket')
 * @param string $entity The entity for which to update access controls.
 *        (e.g. 'user-example@domain.com')
 */
function delete_bucket_default_acl(string $bucketName, string $entity): void
{
    $storage = new StorageClient();
    $bucket = $storage->bucket($bucketName);
    $acl = $bucket->defaultAcl();
    $acl->delete($entity);
    printf('Deleted %s from gs://%s default ACL' . PHP_EOL, $entity, $bucketName);
}

Python

למידע נוסף, קראו את מאמרי העזרה של Cloud Storage Python API.

כדי לבצע אימות ב-Cloud Storage, אתם צריכים להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לספריות לקוח.

הדוגמה הבאה מוסיפה לקטגוריה רשימת ACL שמשמשת כברירת מחדל של אובייקטים:

from google.cloud import storage


def add_bucket_default_owner(bucket_name, user_email):
    """Adds a user as an owner in the given bucket's default object access
    control list."""
    # bucket_name = "your-bucket-name"
    # user_email = "name@example.com"

    storage_client = storage.Client()
    bucket = storage_client.bucket(bucket_name)

    # Reload fetches the current ACL from Cloud Storage.
    bucket.acl.reload()

    # You can also use `group`, `domain`, `all_authenticated` and `all` to
    # grant access to different types of entities. You can also use
    # `grant_read` or `grant_write` to grant different roles.
    bucket.default_object_acl.user(user_email).grant_owner()
    bucket.default_object_acl.save()

    print(
        "Added user {} as an owner in the default acl on bucket {}.".format(
            user_email, bucket_name
        )
    )

הדוגמה הבאה מוחקת מקטגוריה רשימת ACL שמשמשת כברירת מחדל של אובייקטים:

from google.cloud import storage


def remove_bucket_default_owner(bucket_name, user_email):
    """Removes a user from the access control list of the given bucket's
    default object access control list."""
    # bucket_name = "your-bucket-name"
    # user_email = "name@example.com"

    storage_client = storage.Client()
    bucket = storage_client.bucket(bucket_name)

    # Reload fetches the current ACL from Cloud Storage.
    bucket.acl.reload()

    # You can also use `group`, `domain`, `all_authenticated` and `all` to
    # remove access for different types of entities.
    bucket.default_object_acl.user(user_email).revoke_read()
    bucket.default_object_acl.user(user_email).revoke_write()
    bucket.default_object_acl.user(user_email).revoke_owner()
    bucket.default_object_acl.save()

    print(
        f"Removed user {user_email} from the default acl of bucket {bucket_name}."
    )

Ruby

למידע נוסף, קראו את מאמרי העזרה של Cloud Storage Ruby API.

כדי לבצע אימות ב-Cloud Storage, אתם צריכים להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לספריות לקוח.

הדוגמה הבאה מוסיפה לקטגוריה רשימת ACL שמשמשת כברירת מחדל של אובייקטים:

# The ID of your GCS bucket
# bucket_name = "your-unique-bucket-name"
# email       = "Google Cloud Storage ACL Entity email"

require "google/cloud/storage"

storage = Google::Cloud::Storage.new
bucket  = storage.bucket bucket_name

bucket.default_acl.add_owner email

puts "Added default OWNER permission for #{email} to #{bucket_name}"

הדוגמה הבאה מוחקת מקטגוריה רשימת ACL שמשמשת כברירת מחדל של אובייקטים:

# The ID of your GCS bucket
# bucket_name = "your-unique-bucket-name"
# email       = "Google Cloud Storage ACL Entity email"

require "google/cloud/storage"

storage = Google::Cloud::Storage.new
bucket  = storage.bucket bucket_name

bucket.default_acl.delete email

puts "Removed default ACL permissions for #{email} from #{bucket_name}"

ממשקי API ל-REST

‫API בפורמט JSON

  1. מאחזרים את רשימת ה-ACL שמשמשת כברירת המחדל של האובייקטים באמצעות בקשת GET. לדוגמה:

    curl -X GET -H "Authorization: Bearer $(gcloud auth print-access-token)" \
        https://storage.googleapis.com/storage/v1/b/BUCKET_NAME?projection=full
    
  2. משתמשים בבקשת patch כדי להחליף את רשימת ה-ACL שמשמשת כברירת המחדל של האובייקטים. לדוגמה, הבקשה הבאה מחליפה את רשימת ה-ACL שמשמשת כברירת המחדל של האובייקטים ברשימת ה-ACL שצוינה ב-defacls.json בקטגוריה example-travel-maps:

    curl -X PATCH --data @defacls.json -H "Content-Type: application/json" -H "Authorization: Bearer $(gcloud auth print-access-token)" \
        https://storage.googleapis.com/storage/v1/b/example-travel-maps
    

    דוגמה של defacls.json:

    {
    "defaultObjectAcl": [
      {
        "email": "jeffersonloveshiking@gmail.com",
        "entity": "user-jeffersonloveshiking@gmail.com",
        "role": "READER"
      }
    ]
    }
    

‫API בפורמט XML

  1. מאחזרים את רשימת ה-ACL שמשמשת כברירת המחדל של האובייקטים באמצעות בקשת GET בהיקף של הקטגוריה, והפרמטר ?defaultObjectAcl. לדוגמה:

    curl -X GET -H "Authorization: Bearer $(gcloud auth print-access-token)" \
        https://storage.googleapis.com/BUCKET_NAME?defaultObjectAcl
    
  2. משתמשים בבקשת PUT בהיקף של הקטגוריה באמצעות הפרמטר ?defaultObjectAcl, כדי להחליף את רשימת ה-ACL שמשמשת כברירת המחדל של האובייקטים ב-ACL שצוין ב-acls.xml. לדוגמה:

    curl -X PUT --data-binary @acls.xml -H "Authorization: Bearer $(gcloud auth print-access-token)" \
        http://storage.googleapis.com/BUCKET_NAME?defaultObjectAcl
    

    דוגמה של acls.xml:

    <AccessControlList>
      <Entries>
        <Entry>
          <Permission>FULL_CONTROL</Permission>
          <Scope type="UserByEmail">
            <EmailAddress>jeffersonloveshiking@gmail.com</EmailAddress>
          </Scope>
        </Entry>
      </Entries>
    </AccessControlList>
    

התחביר של רשימות ACL מתואר בהגדרה של רשימות ACL. אפשר גם לציין רשימת ACL מוגדרת מראש בתור רשימת ה-ACL שמשמשת כברירת המחדל של האובייקטים.

כדי להגדיר שרשימת ה-ACL שמשמשת כברירת המחדל של האובייקטים בקטגוריה תהיה רשימת ACL מוגדרת מראש:

המסוף

אי אפשר להגדיר רשימות ACL שמשמשות כברירת מחדל של אובייקטים באמצעות מסוף Google Cloud . במקום זאת, אתם צריכים להשתמש ב-gcloud storage.

שורת הפקודה

משתמשים בפקודה buckets update עם הדגל --predefined-default-object-acl:

gcloud storage buckets update gs://BUCKET_NAME --predefined-default-object-acl=PREDEFINED_ACL

כאשר:

  • BUCKET_NAME הוא שם הקטגוריה שרוצים לשנות את רשימת ה-ACL שמשמשת כברירת המחדל של האובייקטים שלה. לדוגמה, my-bucket.

  • PREDEFINED_ACL הוא השם של רשימת ACL מוגדרת מראש ותקינה. לדוגמה, projectPrivate.

ממשקי API ל-REST

‫API בפורמט JSON

משתמשים בבקשת PUT ובפרמטר predefinedAcl.

לדוגמה:

curl -X PUT -H "Content-Length: 0" -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    https://storage.googleapis.com/storage/v1/b/BUCKET_NAME?predefinedAcl=private

‫API בפורמט XML

משתמשים בבקשה PUT בהיקף של הקטגוריה באמצעות הפרמטר ?defaultObjectAcl והכותרת x-goog-acl.

לדוגמה:

curl -X PUT -H "x-goog-acl: project-private" -H "Content-Length: 0" -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    http://storage.googleapis.com/BUCKET_NAME?defaultObjectAcl

רשימות ACL שמשמשות כברירת מחדל של אובייקטים בקטגוריות חדשות שנוצרו:

בדוגמאות הבאות מוצגות רשימות ה-ACL שמשמשות כברירת המחדל של אובייקטים, שמוחלות באופן אוטומטי על קטגוריות חדשות שנוצרות כשלא מציינים רשימות ACL משלכם שמשמשות כברירת המחדל של אובייקטים כחלק מהבקשה. כדי לראות אם רשימות ה-ACL שמשמשות כברירת המחדל של האובייקטים בקטגוריה שלכם השתנו, אתם צריכים להשוות את רשימות ה-ACL הנוכחיות שמשמשות כברירת המחדל של האובייקטים בקטגוריה שלכם לדוגמאות שבהמשך.

המסוף

אי אפשר לעבוד עם רשימות ה-ACL שמשמשות כברירת המחדל של האובייקטים באמצעות מסוף Google Cloud . במקום זאת, אתם צריכים להשתמש ב-gcloud storage.

שורת הפקודה

בדוגמה הבאה מזהה הפרויקט הוא '123412341234'. מזהה הפרויקט שלכם יהיה שונה.

defaultObjectAcl:
– entity: project-owners-123412341234
  etag: CAE=
  kind: storage#objectAccessControl
  projectTeam:
    projectNumber: '123412341234'
    team: owners
  role: OWNER
– entity: project-editors-123412341234
  etag: CAE=
  kind: storage#objectAccessControl
  projectTeam:
    projectNumber: '123412341234'
    team: editors
  role: OWNER
– entity: project-viewers-123412341234
  etag: CAE=
  kind: storage#objectAccessControl
  projectTeam:
    projectNumber: '123412341234'
    team: viewers
  role: READER

ממשקי API בארכיטקטורת REST

‫API בפורמט JSON

בדוגמה הבאה מזהה הפרויקט הוא '123412341234'. מזהה הפרויקט שלכם יהיה שונה.

"defaultObjectAcl": [
  {
    "kind": "storage#objectAccessControl",
    "entity": "project-owners-123412341234",
    "role": "OWNER",
    "projectTeam": {
      "projectNumber": "123412341234",
      "team": "owners"
    }
  },
  {
    "kind": "storage#objectAccessControl",
    "entity": "project-editors-123412341234",
    "role": "OWNER",
    "projectTeam": {
      "projectNumber": "123412341234",
      "team": "editors"
    }
  },
  {
    "kind": "storage#objectAccessControl",
    "entity": "project-viewers-123412341234",
    "role": "READER",
    "projectTeam": {
      "projectNumber": "123412341234",
      "team": "viewers"
    }
  }
]

‫API בפורמט XML

בדוגמה הבאה, המזהים של תפקידי הפרויקטים מתחילים ב-'00b4903a97...'. מזהי הפרויקטים שלכם יהיו שונים.

<?xml version='1.0' encoding='UTF-8'?>
<AccessControlList>
  <Entries>
    <Entry>
      <Scope type='GroupById'>
        <ID>00b4903a9721...</ID>
      </Scope>
      <Permission>FULL_CONTROL</Permission>
    </Entry>
    <Entry>
      <Scope type='GroupById'>
        <ID>00b4903a9722...</ID>
      </Scope>
      <Permission>FULL_CONTROL</Permission>
    </Entry>
    <Entry>
      <Scope type='GroupById'>
        <ID>00b4903a9723...</ID>
      </Scope>
      <Permission>READ</Permission>
    </Entry>
  </Entries>
</AccessControlList>

שימו לב שרשימת ה-ACL שמשמשת כברירת המחדל של האובייקטים בקטגוריה חדשה שנוצרה זהה לרשימת ה-ACL projectPrivate שהוגדרה מראש.

אחזור רשימות ACL

כדי לאחזר את רשימת ה-ACL של משאב קיים:

המסוף

  1. נכנסים לדף Cloud Storage browser במסוף Google Cloud .
    כניסה לדף Cloud Storage browser

  2. עוברים אל האובייקט שרוצים לצפות ברשימת ה-ACL שלו.

  3. בתפריט הנפתח של האובייקט, בוחרים באפשרות גישת עריכה.

    תופיע תיבת דו-שיח עם ההרשאות של האובייקט.

במאמר פתרון בעיות מוסבר איך מקבלים מידע מפורט על שגיאות בנושא פעולות ב-Cloud Storage שנכשלו במסוף Google Cloud .

שורת הפקודה

  1. כדי לאחזר ACL של אובייקט, משתמשים בפקודה objects describe עם הדגל --format:

    gcloud storage objects describe gs://BUCKET_NAME/OBJECT_NAME --format="default(acl)"

    כאשר:

    • BUCKET_NAME הוא שם הקטגוריה שמכילה את האובייקט שרוצים לצפות ברשימת ה-ACL שלו. לדוגמה, my-bucket.

    • OBJECT_NAME הוא שם האובייקט שרוצים לצפות ברשימת ה-ACL שלו. לדוגמה, paris.jpg.

ספריות לקוח

C++

למידע נוסף, קראו את מאמרי העזרה של Cloud Storage C++ API.

כדי לבצע אימות ב-Cloud Storage, אתם צריכים להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לספריות לקוח.

הדוגמה הבאה מאחזרת ACL של אובייקט:

namespace gcs = ::google::cloud::storage;
using ::google::cloud::StatusOr;
[](gcs::Client client, std::string const& bucket_name,
   std::string const& object_name) {
  StatusOr<std::vector<gcs::ObjectAccessControl>> items =
      client.ListObjectAcl(bucket_name, object_name);

  if (!items) throw std::move(items).status();
  std::cout << "ACLs for object=" << object_name << " in bucket "
            << bucket_name << "\n";
  for (gcs::ObjectAccessControl const& acl : *items) {
    std::cout << acl.role() << ":" << acl.entity() << "\n";
  }
}

C#

למידע נוסף, קראו את מאמרי העזרה של Cloud Storage C# API.

כדי לבצע אימות ב-Cloud Storage, אתם צריכים להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לספריות לקוח.

הדוגמה הבאה מאחזרת ACL של אובייקט:


using Google.Apis.Storage.v1.Data;
using Google.Cloud.Storage.V1;
using System;
using System.Collections.Generic;

public class PrintFileAclSample
{
    public IEnumerable<ObjectAccessControl> PrintObjectAcl(
        string bucketName = "your-unique-bucket-name",
        string objectName = "your-object-name")
    {
        var storage = StorageClient.Create();
        var storageObject = storage.GetObject(bucketName, objectName, new GetObjectOptions
        {
            Projection = Projection.Full
        });

        foreach (var acl in storageObject.Acl)
        {
            Console.WriteLine($"{acl.Role}:{acl.Entity}");
        }

        return storageObject.Acl;
    }
}

Go

למידע נוסף, קראו את מאמרי העזרה של Cloud Storage Go API.

כדי לבצע אימות ב-Cloud Storage, אתם צריכים להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לספריות לקוח.

הדוגמה הבאה מאחזרת ACL של אובייקט:

import (
	"context"
	"fmt"
	"io"

	"cloud.google.com/go/storage"
)

// printFileACL lists ACL of the specified object.
func printFileACL(w io.Writer, bucket, object string) error {
	// bucket := "bucket-name"
	// object := "object-name"
	ctx := context.Background()
	client, err := storage.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("storage.NewClient: %w", err)
	}
	defer client.Close()

	rules, err := client.Bucket(bucket).Object(object).ACL().List(ctx)
	if err != nil {
		return fmt.Errorf("ACLHandle.List: %w", err)
	}
	for _, rule := range rules {
		fmt.Fprintf(w, "ACL rule: %v\n", rule)
	}
	return nil
}

Java

למידע נוסף, קראו את מאמרי העזרה של Cloud Storage Java API.

כדי לבצע אימות ב-Cloud Storage, אתם צריכים להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לספריות לקוח.

הדוגמה הבאה מאחזרת ACL של אובייקט:


import com.google.cloud.storage.Acl;
import com.google.cloud.storage.Blob;
import com.google.cloud.storage.BlobId;
import com.google.cloud.storage.Storage;
import com.google.cloud.storage.StorageOptions;
import java.util.List;

public class PrintBlobAcl {

  public static void printBlobAcl(String bucketName, String blobName) {

    // The ID to give your GCS bucket
    // String bucketName = "your-unique-bucket-name";

    // The name of the blob/file that you wish to view Acls of
    // String blobName = "your-blob-name";

    Storage storage = StorageOptions.newBuilder().build().getService();
    Blob blob = storage.get(BlobId.of(bucketName, blobName));
    List<Acl> blobAcls = blob.getAcl();

    for (Acl acl : blobAcls) {

      // This will give you the role.
      // See https://cloud.google.com/storage/docs/access-control/lists#permissions
      String role = acl.getRole().name();

      // This will give you the Entity type (i.e. User, Group, Project etc.)
      // See https://cloud.google.com/storage/docs/access-control/lists#scopes
      String entityType = acl.getEntity().getType().name();

      System.out.printf("%s: %s %n", role, entityType);
    }
  }
}

Node.js

למידע נוסף, קראו את מאמרי העזרה של Cloud Storage Node.js API.

כדי לבצע אימות ב-Cloud Storage, אתם צריכים להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לספריות לקוח.

הדוגמה הבאה מאחזרת ACL של אובייקט:

/**
 * TODO(developer): Uncomment the following lines before running the sample.
 */
// The ID of your GCS bucket
// const bucketName = 'your-unique-bucket-name';

// The ID of your GCS file
// const fileName = 'your-file-name';

// Imports the Google Cloud client library
const {Storage} = require('@google-cloud/storage');

// Creates a client
const storage = new Storage();

async function printFileAcl() {
  // Gets the ACL for the file
  const [acls] = await storage.bucket(bucketName).file(fileName).acl.get();

  acls.forEach(acl => {
    console.log(`${acl.role}: ${acl.entity}`);
  });
}

printFileAcl().catch(console.error);

PHP

למידע נוסף, קראו את מאמרי העזרה של Cloud Storage PHP API.

כדי לבצע אימות ב-Cloud Storage, אתם צריכים להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לספריות לקוח.

הדוגמה הבאה מאחזרת ACL של אובייקט:

use Google\Cloud\Storage\StorageClient;

/**
 * Print all entities and roles for an object's ACL.
 *
 * @param string $bucketName The name of your Cloud Storage bucket.
 *        (e.g. 'my-bucket')
 * @param string $objectName The name of your Cloud Storage object.
 *        (e.g. 'my-object')
 */
function get_object_acl(string $bucketName, string $objectName): void
{
    $storage = new StorageClient();
    $bucket = $storage->bucket($bucketName);
    $object = $bucket->object($objectName);
    $acl = $object->acl();
    foreach ($acl->get() as $item) {
        printf('%s: %s' . PHP_EOL, $item['entity'], $item['role']);
    }
}

Python

למידע נוסף, קראו את מאמרי העזרה של Cloud Storage Python API.

כדי לבצע אימות ב-Cloud Storage, אתם צריכים להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לספריות לקוח.

הדוגמה הבאה מאחזרת ACL של אובייקט:

from google.cloud import storage


def print_blob_acl(bucket_name, blob_name):
    """Prints out a blob's access control list."""

    storage_client = storage.Client()
    bucket = storage_client.bucket(bucket_name)
    blob = bucket.blob(blob_name)

    for entry in blob.acl:
        print(f"{entry['role']}: {entry['entity']}")

Ruby

למידע נוסף, קראו את מאמרי העזרה של Cloud Storage Ruby API.

כדי לבצע אימות ב-Cloud Storage, אתם צריכים להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לספריות לקוח.

הדוגמה הבאה מאחזרת ACL של אובייקט:

# The ID of your GCS bucket
# bucket_name = "your-unique-bucket-name"
# file_name   = "Name of a file in the Storage bucket"
# email       = "Google Cloud Storage ACL Entity email"

require "google/cloud/storage"

storage = Google::Cloud::Storage.new
bucket  = storage.bucket bucket_name
file    = bucket.file file_name

puts "ACL for #{file_name} in #{bucket_name}:"

file.acl.owners.each do |owner|
  puts "OWNER #{owner}"
end

file.acl.readers.each do |reader|
  puts "READER #{reader}"
end

ממשקי API ל-REST

‫API בפורמט JSON

  1. חשוב לוודא שיש לכם הרשאה מסוג OWNER על האובייקט.

  2. מאחזרים את ה-ACL של האובייקט באמצעות בקשת GET.

    ה-ACL של האובייקט מוחזר בפורמט JSON ומצורף לגוף התגובה.

לדוגמה, כדי להחזיר את ה-ACL של האובייקט paris.jpg בקטגוריה example-travel-maps:

curl -X GET -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    https://storage.googleapis.com/storage/v1/b/example-travel-maps/o/paris.jpg?projection=full

אתם אמורים לראות תגובה שנראית כך:

{
  "kind": "storage#object",
  "id": "example-travel-maps/paris.jpg/1412805837131000",
  "selfLink": "https://www.googleapis.com/storage/v1/b/example-travel-maps/o/paris.jpg",
  "name": "paris.jpg",
    "bucket": "example-travel-maps",
  ...
  "acl": [
    {
      ...
      "entity": "project-owners-867489160491",
      "role": "OWNER",
      "projectTeam": {
        "projectNumber": "867489160491",
        "team": "owners"
      },
      ...
    },
    {
      ...
      "entity": "user-jeffersonloveshiking@gmail.com",
      "role": "OWNER",
      "email": "jeffersonloveshiking@gmail.com",
      ...
    },
    {
      ...
      "entity": "group-gs-announce@googlegroups.com",
      "role": "READER",
      "email": "gs-announce@googlegroups.com",
      ...
    }
    ],
  "owner": {
    "entity": "user-jeffersonloveshiking@gmail.com"
  },
  ...
}

אפשר גם להשתמש ב-method GET של המשאב objectAccessControls כדי להחזיר רשומות בודדות ב-ACL של אובייקט.

‫API בפורמט XML

  1. חשוב לוודא שיש לכם הרשאת FULL_CONTROL בקטגוריה או באובייקט.

  2. מאחזרים את ה-ACL של הקטגוריה או האובייקט באמצעות הפרמטר acl של מחרוזת השאילתה בבקשת אובייקט GET.

רשימות ה-ACL מתוארות ב-XML ומצורפות לגוף התגובה.

לדוגמה, כדי להחזיר את ה-ACL של האובייקט paris.jpg בקטגוריה example-travel-maps:

curl -X GET -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    https://storage.googleapis.com/example-travel-maps/paris.jpg?acl

אתם אמורים לראות תגובה שנראית כך:

<?xml version="1.0" encoding="UTF-8"?>
<AccessControlList>
  <Owner>
    <ID>84fac329bceSAMPLE777d5d22b8SAMPLE77d85ac2SAMPLE2dfcf7c4adf34da46</ID>
    <Name>Owner Name</Name>
  </Owner>
  <Entries>
    <Entry>
      <Scope type="UserById">
        <ID>84fac329bceSAMPLE777d5d22b8SAMPLE77d85ac2SAMPLE2dfcf7c4adf34da46</ID>
        <Name>Name</Name>
      </Scope>
      <Permission>FULL_CONTROL</Permission>
    </Entry>
    <Entry>
      <Scope type="UserByEmail">
        <EmailAddress>jeffersonloveshiking@gmail.com</EmailAddress>
        <Name>Jefferson</Name>
      </Scope>
      <Permission>FULL_CONTROL</Permission>
    </Entry>
    <Entry>
      <Scope type="GroupByEmail">
        <EmailAddress>gs-announce@googlegroups.com</EmailAddress>
      </Scope>
      <Permission>READ</Permission>
    </Entry>
  </Entries>
</AccessControlList>

אפשר גם להשתמש ב-method GET בפורמט JSON של המשאב ObjectAccessControls כדי להחזיר רשומת ACL ספציפית.

המאמרים הבאים