[Yandex Cloud documentation](../../index.md) > [Yandex Key Management Service](../index.md) > [Step-by-step guides](index.md) > Digital signature > Access permissions for a digital signature key pair

# Configuring access permissions for a digital signature key pair

You can grant access to an asymmetric [digital signature key pair](../concepts/asymmetric-signature-key.md) to a user, service account, or user group. To do this, assign [roles](../../iam/concepts/access-control/roles.md)for the digital signature key pair. To choose the ones you need, [learn](../security/index.md#roles-list) about the service's roles.

## Assigning a role {#add-access-binding}

{% list tabs group=instructions %}

- Management console {#console}

   1. In the [management console](https://console.yandex.cloud), select a folder containing an asymmetric encryption key pair.
   1. Navigate to **Key Management Service**.
   1. In the left-hand panel, select ![image](../../_assets/kms/asymmetric-key.svg) **Asymmetric keys**.
   1. On the **Signature** tab, click the name of the key pair.
   1. Navigate to ![image](../../_assets/console-icons/persons.svg) **Access bindings** and click **Assign roles**.
   1. Select the group, user, or service account you want to grant access to the key pair.
   1. Click ![image](../../_assets/console-icons/plus.svg) **Add role** and select the required roles.
   1. Click **Save**.

- CLI {#cli}

   If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../cli/quickstart.md#install).

   The folder used by default is the one specified when [creating](../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

   To assign a role for an asymmetric digital signature key pair:

   1. View the description of the CLI command for assigning roles:

      ```bash
      yc kms asymmetric-signature-key add-access-binding --help
      ```

   1. Get a list of digital signature key pairs with their IDs:

      ```bash
      yc kms asymmetric-signature-key list
      ```

   1. Get the [ID of the user](../../organization/operations/users-get.md), [service account](../../iam/operations/sa/get-id.md), or user group you are assigning a role to.
   1. Use one of these commands to assign a role:

      * To a user:

         ```bash
         yc kms asymmetric-signature-key add-access-binding \
           --id <key_pair_ID> \
           --role <role> \
           --user-account-id <user_ID>
         ```

      * To a federated user:

         ```bash
         yc kms asymmetric-signature-key add-access-binding \
           --id <key_pair_ID> \
           --role <role> \
           --subject federatedUser:<user_ID>
         ```

      * To a service account:

         ```bash
         yc kms asymmetric-signature-key add-access-binding \
           --id <key_pair_ID> \
           --role <role> \
           --service-account-id <service_account_ID>
         ```

      * To a user group:

         ```bash
         yc kms asymmetric-signature-key add-access-binding \
           --id <key_pair_ID> \
           --role <role> \
           --subject group:<group_ID>
         ```

- Terraform {#tf}

   With [Terraform](https://www.terraform.io/), you can quickly create a cloud infrastructure in Yandex Cloud and manage it using configuration files. These files store the infrastructure description written in HashiCorp Configuration Language (HCL). If you change the configuration files, Terraform automatically detects which part of your configuration is already deployed, and what should be added or removed.
   
   Terraform is distributed under the [Business Source License](https://github.com/hashicorp/terraform/blob/main/LICENSE). The [Yandex Cloud provider for Terraform](https://github.com/yandex-cloud/terraform-provider-yandex) is distributed under the [MPL-2.0](https://www.mozilla.org/en-US/MPL/2.0/) license.
   
   For more information about the provider resources, see the guides on the [Terraform](https://www.terraform.io/docs/providers/yandex/index.html) website or [its mirror](../../terraform/index.md).

   If you do not have Terraform yet, [install it and configure the Yandex Cloud provider](../../tutorials/infrastructure-management/terraform-quickstart.md#install-terraform).
   
   
   To manage infrastructure using Terraform under a service account or user accounts (a Yandex account, a federated account, or a local user), [authenticate](../../terraform/authentication.md) using the appropriate method.

   To assign a role for an asymmetric digital signature key pair through Terraform:

   1. In the Terraform configuration file, describe the resources you want to create:

       ```hcl
       resource "yandex_kms_asymmetric_signature_key_iam_member" "key-viewers" {
         asymmetric_signature_key_id  = "<key_pair_ID>"

         role   = "<role_1>"
         member = "<subject_type>:<subject_ID>"
       }
       ```

       Where:

       * `asymmetric_signaturen_key_id `: ID of the digital signature key pair.
       * `role`: [Role](../security/index.md#roles-list) to assign.
       * `member`: Type and ID of the [subject](../../iam/concepts/access-control/index.md#subject) the role is assigned to. Specify it as `userAccount:<user_ID>` or `serviceAccount:<service_account_ID>`.

       For more information about the `yandex_kms_asymmetric_signature_key` resource properties, see [this provider guide](../../terraform/resources/kms_asymmetric_signature_key.md).

   1. Create the resources:

       1. In the terminal, navigate to the configuration file directory.
       1. Make sure the configuration is correct using this command:
       
          ```bash
          terraform validate
          ```
       
          If the configuration is valid, you will get this message:
       
          ```bash
          Success! The configuration is valid.
          ```
       
       1. Run this command:
       
          ```bash
          terraform plan
          ```
       
          You will see a list of resources and their properties. No changes will be made at this step. Terraform will show any errors in the configuration.
       1. Apply the configuration changes:
       
          ```bash
          terraform apply
          ```
       
       1. Type `yes` and press **Enter** to confirm the changes.

       Terraform will create all the required resources. You can check the new resources using this [CLI](../../cli/index.md) command:

       ```bash
       yc kms asymmetric-signature-key list-access-bindings <key_pair_ID>
       ```

- API {#api}

   Use the [updateAccessBindings](../asymmetricsignature/api-ref/AsymmetricSignatureKey/updateAccessBindings.md) method for the [AsymmetricSignatureKey](../asymmetricsignature/api-ref/AsymmetricSignatureKey/index.md) resource or the [AsymmetricSignatureKeyService/UpdateAccessBindings](../asymmetricsignature/api-ref/grpc/AsymmetricSignatureKey/updateAccessBindings.md) gRPC API call and provide the following in the request:

   * `ADD` value in the `access_binding_deltas[].action` parameter to add a role.
   * Role in the `access_binding_deltas[].access_binding.role_id` parameter.
   * ID of the subject you are assigning the role to in the `access_binding_deltas[].access_binding.subject.id` parameter.
   * Type of the subject you are assigning the role to in the `access_binding_deltas[].access_binding.subject.type` parameter.

{% endlist %}

## Assigning multiple roles {#set-access-bindings}

{% list tabs group=instructions %}

- Management console {#console}

   1. In the [management console](https://console.yandex.cloud), select a folder containing an asymmetric encryption key pair.
   1. Navigate to **Key Management Service**.
   1. In the left-hand panel, select ![image](../../_assets/kms/asymmetric-key.svg) **Asymmetric keys**.
   1. On the **Signature** tab, click the name of the key pair.
   1. Navigate to ![image](../../_assets/console-icons/persons.svg) **Access bindings** and click **Assign roles**.
   1. Select the group, user, or service account you want to grant access to the key pair.
   1. Click ![image](../../_assets/console-icons/plus.svg) **Add role** and select the required roles.
   1. Click **Save**.

- CLI {#cli}

   {% note alert %}
   
   The `set-access-bindings` command for assigning multiple roles completely rewrites access permissions for the resource. All current resource roles will be deleted.
   
   {% endnote %}

   If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../cli/quickstart.md#install).

   The folder used by default is the one specified when [creating](../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

   To assign multiple roles for a digital signature key pair:

   1. Make sure the key pair has no roles assigned that you would not want to lose:

      ```bash
      yc kms asymmetric-signature-key list-access-bindings \
        --id <key_pair_ID>
      ```

   1. View the description of the CLI command for assigning roles:

      ```bash
      yc kms asymmetric-signature-key set-access-bindings --help
      ```

   1. Get a list of digital signature key pairs with their IDs:

      ```bash
      yc kms asymmetric-signature-key list
      ```

   1. Get the [ID of the user](../../organization/operations/users-get.md), [service account](../../iam/operations/sa/get-id.md), or user group you are assigning roles to.
   1. Use one of the commands below to assign roles:

      * To a Yandex account user or local user:

         ```bash
         yc kms asymmetric-signature-key set-access-bindings \
           --id <key_pair_ID> \
           --access-binding role=<role>,user-account-id=<user_ID>
         ```

      * To a federated user:

         ```bash
         yc kms asymmetric-signature-key set-access-bindings \
           --id <key_pair_ID> \
           --access-binding role=<role>,subject=federatedUser:<user_ID>
         ```

      * To a service account:

         ```bash
         yc kms asymmetric-signature-key set-access-bindings \
           --id <key_pair_ID> \
           --access-binding role=<role>,service-account-id=<service_account_ID>
         ```

      * To a user group:

         ```bash
         yc kms asymmetric-signature-key set-access-bindings \
           --id <key_pair_ID> \
           --access-binding role=<role>,subject=group:<group_ID>
         ```

      Provide a separate `--access-binding` parameter for each role. Here is an example:

      ```bash
      yc kms asymmetric-signature-key set-access-bindings \
        --id <key_pair_ID> \
        --access-binding role=<role_1>,service-account-id=<service_account_ID> \
        --access-binding role=<role_2>,service-account-id=<service_account_ID> \
        --access-binding role=<role_3>,service-account-id=<service_account_ID>
      ```

- Terraform {#tf}

   With [Terraform](https://www.terraform.io/), you can quickly create a cloud infrastructure in Yandex Cloud and manage it using configuration files. These files store the infrastructure description written in HashiCorp Configuration Language (HCL). If you change the configuration files, Terraform automatically detects which part of your configuration is already deployed, and what should be added or removed.
   
   Terraform is distributed under the [Business Source License](https://github.com/hashicorp/terraform/blob/main/LICENSE). The [Yandex Cloud provider for Terraform](https://github.com/yandex-cloud/terraform-provider-yandex) is distributed under the [MPL-2.0](https://www.mozilla.org/en-US/MPL/2.0/) license.
   
   For more information about the provider resources, see the guides on the [Terraform](https://www.terraform.io/docs/providers/yandex/index.html) website or [its mirror](../../terraform/index.md).

   If you do not have Terraform yet, [install it and configure the Yandex Cloud provider](../../tutorials/infrastructure-management/terraform-quickstart.md#install-terraform).
   
   
   To manage infrastructure using Terraform under a service account or user accounts (a Yandex account, a federated account, or a local user), [authenticate](../../terraform/authentication.md) using the appropriate method.

   To assign multiple roles for an asymmetric digital signature key pair through Terraform:

   1. In the Terraform configuration file, describe the resources you want to create:

       ```hcl
       # Role 1
       resource "yandex_kms_asymmetric_signature_key_iam_member" "key-viewers" {
         asymmetric_signature_key_id = "<key_pair_ID>"

         role   = "<role_1>"
         member = "<subject_type>:<subject_ID>"
       }

       # Role 2
       resource "yandex_kms_asymmetric_signature_key_iam_member" "key-editors" {
         asymmetric_signature_key_id = "<key_pair_ID>"
         
         role   = "<role_2>"
         member = "<subject_type>:<subject_ID>"
       }
       ```

       Where:

       * `asymmetric_signature_key_id`: ID of the digital signature key pair.
       * `role`: [Role](../security/index.md#roles-list) to assign.
       * `member`: Type and ID of the [subject](../../iam/concepts/access-control/index.md#subject) the role is assigned to. Specify it as `userAccount:<user_ID>` or `serviceAccount:<service_account_ID>`.

       For more information about the `yandex_kms_asymmetric_signature_key` resource properties, see [this provider guide](../../terraform/resources/kms_asymmetric_signature_key.md).

   1. Create the resources:

       1. In the terminal, navigate to the configuration file directory.
       1. Make sure the configuration is correct using this command:
       
          ```bash
          terraform validate
          ```
       
          If the configuration is valid, you will get this message:
       
          ```bash
          Success! The configuration is valid.
          ```
       
       1. Run this command:
       
          ```bash
          terraform plan
          ```
       
          You will see a list of resources and their properties. No changes will be made at this step. Terraform will show any errors in the configuration.
       1. Apply the configuration changes:
       
          ```bash
          terraform apply
          ```
       
       1. Type `yes` and press **Enter** to confirm the changes.

       Terraform will create all the required resources. You can check the new resources using this [CLI](../../cli/index.md) command:

       ```bash
       yc kms asymmetric-signature-key list-access-bindings <key_pair_ID>
       ```

- API {#api}

   {% note alert %}
   
   The `setAccessBindings` method for assigning multiple roles completely rewrites access permissions for the resource. All current resource roles will be deleted.
   
   {% endnote %}

   Use the [SetAccessBindings](../asymmetricsignature/api-ref/AsymmetricSignatureKey/setAccessBindings.md) method for the [AsymmetricSignatureKey](../asymmetricsignature/api-ref/AsymmetricSignatureKey/index.md) resource or the [AsymmetricSignatureKeyService/SetAccessBindings](../asymmetricsignature/api-ref/grpc/AsymmetricSignatureKey/setAccessBindings.md) gRPC API call. In your request, provide an array of objects, each one matching a particular role and containing the following data:

   * Role in the `access_bindings[].role_id` parameter.
   * ID of the subject getting the roles in the `access_bindings[].subject.id` parameter.
   * Type of the subject getting the roles in the `access_bindings[].subject.type` parameter.

{% endlist %}