You can use Google Cloud *tags* and Cloud Storage *bucket labels* to
organize your Cloud Storage buckets, manage access, and analyze costs.

Tags let you manage access control and analyze cost data at the bucket level,
and at higher levels of the [resource hierarchy](https://docs.cloud.google.com/resource-manager/docs/cloud-platform-resource-hierarchy.md.txt) across Google Cloud.
You can use tags to grant conditional access to resources by referencing tags in
[IAM policy bindings](https://docs.cloud.google.com/iam/docs/tags-access-control.md.txt). You manage tags using Resource Manager.

Labels let you [apply custom metadata](https://docs.cloud.google.com/storage/docs/using-bucket-labels.md.txt) to your buckets using
Cloud Storage tools.

Tags and labels work independently, and you can apply both to the same bucket.

## Tags

Tags are key-value pairs you can apply to your resources for fine-grained access
control and granular cost data at the bucket level.

Tags are created at the organization or project level and managed through
[Resource Manager](https://docs.cloud.google.com/resource-manager/docs/tags/tags-overview.md.txt), which is used across Google Cloud. Once you attach
a tag to a Cloud Storage bucket, you can [use the tag](https://docs.cloud.google.com/iam/docs/conditions-attribute-reference.md.txt#resource-tags) with
[IAM Conditions](https://docs.cloud.google.com/storage/docs/access-control/using-iam-permissions.md.txt#conditions-iam) to grant access to resources or
with [organization policies](https://docs.cloud.google.com/resource-manager/docs/organization-policy/tags-organization-policy) to enforce constraints on resources. You can
also use the tag to analyze
[detailed usage cost data exported to Cloud Billing](https://docs.cloud.google.com/billing/docs/how-to/export-data-bigquery-tables/detailed-usage.md.txt#tags).

When using tags, note the following restrictions:

- Tags can be attached to a bucket only after the bucket has been created.

- Tags cannot be applied to objects.

- You can have a maximum of 50 tag bindings per bucket.

### Required permissions

Although tags are managed through Resource Manager, you need the following
IAM permissions to set and manage tags on buckets:

- `storage.buckets.listTagBindings`
- `storage.buckets.listEffectiveTags`
- `storage.buckets.createTagBinding`
- `storage.buckets.deleteTagBinding`

These permissions can be inherited through [custom roles](https://docs.cloud.google.com/iam/docs/creating-custom-roles.md.txt) or
[predefined roles](https://docs.cloud.google.com/iam/docs/roles-permissions.md.txt), such as the Tag User (`roles/resourcemanager.tagUser`)
role or the Storage Admin (`roles/storage.admin`) role.

### Examples for attaching tags to Cloud Storage buckets

Once you've [created and defined](https://docs.cloud.google.com/resource-manager/docs/tags/tags-creating-and-managing.md.txt#creating) a tag, you can attach the tag to your
bucket.

Consider the following scenario:

- The tag value has a namespaced name of `815471563813/color/blue`.
- Your bucket is named `my-bucket`.
- Your bucket is located in `us-central1`.

The following gcloud command attaches the tag to `my-bucket`:

```
gcloud resource-manager tags bindings create \
--tag-value=815471563813/color/blue \
--parent=//storage.googleapis.com/projects/_/buckets/my-bucket \
--location=us-central1
```

The following gcloud command detaches the tag from `my-bucket`:

```
gcloud resource-manager tags bindings delete \
--tag-value=815471563813/color/blue \
--parent=//storage.googleapis.com/projects/_/buckets/my-bucket \
--location=us-central1
```

The following gcloud command lists all tags directly attached to `my-bucket`, except
tags that `my-bucket` has inherited:

```
gcloud resource-manager tags bindings list \
    --parent=//storage.googleapis.com/projects/_/buckets/my-bucket \
    --location=us-central1
```

For more detailed instructions, see [Attaching tags to resources](https://docs.cloud.google.com/resource-manager/docs/tags/tags-creating-and-managing.md.txt#attaching).

### Pricing details for tags

Tags attached to buckets are [subject to monthly charges](https://docs.cloud.google.com/storage/pricing#tags).

## Bucket labels

Bucket *labels* allow you to create arbitrary key:value pairs that are stored
as part of the bucket's metadata. You can use labels to organize your buckets
along with other Google Cloud resources such as [virtual machine instances](https://docs.cloud.google.com/compute/docs/instances.md.txt).
For example, say you want a key named `team` that has the values `alpha`,
`beta`, and `delta`, which you will use to indicate which team is associated
with certain Google Cloud resources. You can [apply the labels](https://docs.cloud.google.com/storage/docs/using-bucket-labels.md.txt)
`team:alpha`, `team:beta`, and `team:delta` to the resources to achieve this.

Keep in mind the following when working with bucket labels:

- Keys and values cannot be longer than 63 characters each.
- Keys and values can only contain lowercase letters, numeric characters, underscores, and dashes. International characters are allowed.
- Label keys must start with a lowercase letter and international characters are allowed.
- Label keys cannot be empty.
- Each bucket can have a maximum of 64 labels actively applied to it.
- As is generally the case for bucket metadata, bucket labels are not associated with individual objects or object metadata.

For a general example of how to use labels to organize your resources for
billing, see [Example queries for Cloud Billing data export](https://docs.cloud.google.com/billing/docs/how-to/bq-examples.md.txt).

### Pricing details for labels

Labels set on buckets are not subject to monthly charges.

## What's next

- Learn how to [use bucket tags](https://docs.cloud.google.com/resource-manager/docs/tags/tags-creating-and-managing.md.txt).
- Learn how to [use bucket labels](https://docs.cloud.google.com/storage/docs/using-bucket-labels.md.txt).