This document describes how to create secure tags, attach them to a
Managed Service for Apache Spark cluster, and then use the tags to secure cluster networking.

> [!NOTE]
> **Note:** In this document, [Resource Manager tags](https://docs.cloud.google.com/resource-manager/docs/tags/tags-overview.md.txt) attached to Managed Service for Apache Spark clusters are called `secure tags`.

## Benefits of using secure tags

Secure tags have key differences from
[network tags](https://docs.cloud.google.com/vpc/docs/add-remove-network-tags.md.txt),
including Identity and Access Management access control, tag inheritance,
and single VPC network binding, which produce the following key benefits:

<br />

Enhanced access control and security Secure tags resolve the security issues inherent with network tags by providing IAM controlled access. Unlike network tags, which can be modified by a user with cluster access, secure tags prevent unauthorized modification of tags and the resulting unwanted changes to firewall rules.<br />

Using secure tags in IAM policies enable
[conditional access control](https://docs.cloud.google.com/iam/docs/conditions-overview.md.txt), strengthening
security by granting or denying roles based on the presence of tags.

<br />

<br />

Simplified firewall management The [global](https://docs.cloud.google.com/firewall/docs/network-firewall-policies.md.txt) and [regional](https://docs.cloud.google.com/firewall/docs/regional-firewall-policies.md.txt) network firewall policies support secure tags. This support simplifies firewall management in Managed Service for Apache Spark across shared networks.

<br />

Unlike VPC firewall rules, network firewall policies that are enhanced by secure
tags enable efficient grouping and simultaneous updating of multiple rules, all
governed by IAM access controls. Compared to VPC firewall rules
that utilize network tags, secure tags provide enhanced security and management
capabilities within network firewall policies.

<br />

<br />

Hierarchical resource inheritance for efficient management Secure tags inherit from parent resources within the Google Cloud hierarchy. This inheritance simplifies management by letting you define tags at a higher level---for example, at the organization level---so that they automatically propagate to child resources, such as folders and projects. This enables consistent tagging across your organization. For more information, see [Tag inheritance](https://docs.cloud.google.com/resource-manager/docs/tags/tags-overview.md.txt#inheritance).

<br />

<br />

Improved network management across shared and peered VPCs Network tags identify sources or targets in firewall rules within a specified VPC network. Secure tags, when used to specify a source for an ingress rule in a network firewall policy, identify traffic sources in both the Managed Service for Apache Spark cluster VPC network and peered VPC networks. When secure tags are used to specify targets for ingress or egress rules, they identify targets only within their own VPC network.

<br />

To learn more about the differences between Resource Manager tags and network tags,
see
[Comparison of Tags and network tags](https://docs.cloud.google.com/firewall/docs/tags-firewalls-overview.md.txt#differences).

To learn more about the differences between Resource Manager tags and labels,
see
[Tags and labels](https://docs.cloud.google.com/resource-manager/docs/tags/tags-overview.md.txt#tags_and_labels).

## Before you begin

Certain IAM roles are required to
run the examples on this page. Depending on organization policies, these
roles may have already been granted. To check role grants, see
[Do you need to grant roles?](https://docs.cloud.google.com/managed-spark/docs/concepts/iam/iam.md.txt#do_you_need_to_grant_roles).

For more information about granting roles, see
[Manage access to projects,folders, and organizations](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access.md.txt).

### User role


To get the permissions that
you need to create tags,

ask your administrator to grant you the
[](https://docs.cloud.google.com/iam/docs/roles-permissions/resourcemanager.md.txt#resourcemanager.tagAdmin)[Tag Administrator](https://docs.cloud.google.com/iam/docs/roles-permissions/resourcemanager.md.txt#resourcemanager.tagAdmin) (`roles/resourcemanager.tagAdmin`) IAM role on Resource Manager tags.


For more information about granting roles, see [Manage access to projects, folders, and organizations](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access.md.txt).


You might also be able to get
the required permissions through [custom
roles](https://docs.cloud.google.com/iam/docs/creating-custom-roles) or other [predefined
roles](https://docs.cloud.google.com/iam/docs/roles-overview#predefined).

### Service account role


To ensure that [Managed Service for Apache Spark Service Agent service account](https://docs.cloud.google.com/managed-spark/docs/concepts/configuring-clusters/service-accounts.md.txt#service_agent_account) has the necessary
permissions to attach secure tags to a Managed Service for Apache Spark cluster,

ask your administrator to grant the
[](https://docs.cloud.google.com/iam/docs/roles-permissions/dataproc.md.txt#dataproc.serviceAgent)[Managed Service for Apache Spark Service Agent role](https://docs.cloud.google.com/managed-spark/docs/concepts/iam/iam.md.txt#dataproc.serviceAgent) (`roles/dataproc.serviceAgent`) IAM role to [Managed Service for Apache Spark Service Agent service account](https://docs.cloud.google.com/managed-spark/docs/concepts/configuring-clusters/service-accounts.md.txt#service_agent_account) on the project.


**Important:** You must grant this role to [Managed Service for Apache Spark Service Agent service account](https://docs.cloud.google.com/managed-spark/docs/concepts/configuring-clusters/service-accounts.md.txt#service_agent_account), *not* to your user account. Failure to grant the role to the correct principal might result in permission errors.

<br />

## Limitations

- You can attach secure tags to a cluster only at the time of cluster creation.
- Updation and deletion of secure tags aren't supported.

## Create a secure tag

To attach a secure tag to a Managed Service for Apache Spark cluster, you must first
[create a Resource Manager tag](https://docs.cloud.google.com/resource-manager/docs/tags/tags-creating-and-managing.md.txt#creating)
with a specified key and one or more values.

## Attach secure tags to the Managed Service for Apache Spark cluster

Create a Managed Service for Apache Spark cluster, specifying the secure tag
`TAG_KEY:TAG_VALUE` pair.

### Google Cloud CLI

To create a Managed Service for Apache Spark cluster and add a secure tag to the
cluster, run the
[gcloud Managed Service for Apache Spark clusters create](https://docs.cloud.google.com/sdk/gcloud/reference/dataproc/clusters/create.md.txt)
command with the `--resource-manager-tags` flag.

    gcloud dataproc clusters create CLUSTER_NAME \
      --region REGION \
      --resource-manager-tags=TAG_KEY=TAG_VALUE

Replace the following:

- <var translate="no">CLUSTER_NAME</var>: the name of the new cluster.
- <var translate="no">REGION</var>: the [Compute Engine region](https://docs.cloud.google.com/compute/docs/regions-zones.md.txt#available) in which to locate the cluster.
- <var translate="no">TAG_KEY</var> and <var translate="no">TAG_VALUE</var>: the key and a value of the [Resource Manager tag that you created](https://docs.cloud.google.com/managed-spark/docs/guides/use-secure-tags.md.txt#create-a-secure-tag). Tag keys can be specified in namespaced or non-namespaced format, as follows:
  - Namespace format: `PROJECT-ID/KEY_NAME`=`PROJECT-ID/KEY_NAME/KEY_VALUE`.

    Example:

    ```
    --resource-manager-tags="test-project/testkey"=test-project/testkey/testvalue
    ```
  - Non-namespaced format: `tagKeys/TAG_KEY_ID`=`tagValues/TAG_VALUE_ID`

    Example:

    ```
    --resource-manager-tags=tagKeys/123456789012=tagValues/987654321098
    ```
    - You can specify a comma-separated list to attach multiple secure tags comprised of the same key with different values, or different keys and values.
    - You must provide all tag key-value pairs in either namespaced or non-namespaced format; if both formats are used, an error is generated.

### REST

To create a Managed Service for Apache Spark cluster and add a secure tag to the
cluster, include the
[`resourceManagerTags`](https://docs.cloud.google.com/managed-spark/docs/reference/rest/v1/ClusterConfig.md.txt#GceClusterConfig.FIELDS.resource_manager_tags)
field as part of a
[clusters.create](https://docs.cloud.google.com/managed-spark/docs/reference/rest/v1/projects.regions.clusters/create.md.txt)
request that includes attaching a `"TAG_KEY":"TAG_VALUE"`
secure tag to the cluster.

```json
{
  "clusterName": "CLUSTER_NAME",
  "config": {
    "gceClusterConfig": {
      "resourceManagerTags": {
        "TAG_KEY":"TAG_VALUE"
      }
    }
  }
}
```

Replace the following:

- <var translate="no">CLUSTER_NAME</var>: the name of the new cluster.
- <var translate="no">TAG_KEY</var> and <var translate="no">TAG_VALUE</var>: the key and a value of the [Resource Manager tag that you created](https://docs.cloud.google.com/managed-spark/docs/guides/use-secure-tags.md.txt#create-a-secure-tag). Tag keys can be specified in namespaced or non-namespaced format, as follows:
  - Namespace format: `PROJECT-ID/KEY_NAME`:`PROJECT-ID/KEY_NAME/KEY_VALUE`.

    Example:

    ```
    "test-project/testkey":"test-project/testkey/testvalue"
    ```
  - Non-namespaced format: `tagKeys/TAG_KEY_ID`:`tagValues/TAG_VALUE_ID`

    Example:

    ```
    "tagKeys/123456789012":"tagValues/987654321098"
    ```
    - You can specify a comma-separated list to attach multiple secure tags comprised of the same key with different values, or different keys and values.
    - You must provide all tag key:value pairs in either namespaced or non-namespaced format; if both formats are used, an error is generated.

## Use secure tags for cluster networking

After attaching secure tags to a cluster, use secure tags to configure
cluster networking:

- Use secure tags to [define firewall rules](https://docs.cloud.google.com/managed-spark/docs/concepts/configuring-clusters/network.md.txt#firewall_requirements).

## What's next

- Learn more about [tags](https://docs.cloud.google.com/resource-manager/docs/tags/tags-overview.md.txt).
- Learn more about [network tags](https://docs.cloud.google.com/vpc/docs/add-remove-network-tags.md.txt).