[Yandex Cloud documentation](../../../index.md) > [Yandex Compute Cloud](../../index.md) > [Step-by-step guides](../index.md) > Managing an instance group > Configuring instance group access permissions

# Configuring instance group access permissions

To grant a user, group, or [service account](../../../iam/concepts/users/service-accounts.md) access to an [instance group](../../concepts/instance-groups/index.md), assign a [role](../../../iam/concepts/access-control/roles.md) for it.

## Assigning a role {#access-to-user}

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select the folder containing the instance group.
  1. Navigate to **Compute Cloud**.
  1. In the left-hand panel, select ![image](../../../_assets/console-icons/layers-3-diagonal.svg) **Instance groups**.
  1. Select the group.
  1. Navigate to the ![image](../../../_assets/console-icons/persons.svg) **Access bindings** tab.
  1. Click **Assign roles**.
  1. In the window that opens, select the group, user, or service account you want to grant access to the instance group.
  1. Click ![image](../../../_assets/console-icons/plus.svg) **Add role** and select the required [roles](../../security/index.md#roles-list).
  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.

  1. See the description of the CLI command for assigning a role for an instance group:

     ```bash
     yc compute instance-group add-access-binding --help
     ```

  1. Get a list of instance groups in the default folder:

     ```bash
     yc compute instance-group list
     ```
     
     Result:
     
     ```text
     +----------------------+----------------------+--------+------+
     |          ID          |          NAME        | STATUS | SIZE |
     +----------------------+----------------------+--------+------+
     | cl15b3mrkk88******** | first-instance-group | ACTIVE |    3 |
     +----------------------+----------------------+--------+------+
     ```

  1. Check what roles are currently assigned for the resource in question:

     ```bash
     yc compute instance-group list-access-bindings <instance_group_name_or_ID>
     ```

  1. Assign the role using this command:

     * To a user:

       ```bash
       yc compute instance-group add-access-binding <instance_group_name_or_ID> \
         --user-account-id <user_ID> \
         --role <role>
       ```

       Where:

       * `--user-account-id`: [User ID](../../../organization/operations/users-get.md).
       * `--role`: [Role](../../security/index.md#roles-list).

     * To a service account:

       ```bash
       yc compute instance-group add-access-binding <instance_group_name_or_ID> \
         --service-account-id <service_account_ID> \
         --role <role>
       ```

       Where:

       * `--service-account-id`: [Service account ID](../../../iam/operations/sa/get-id.md).
       * `--role`: Role.

- API {#api}

  Use the [updateAccessBindings](../../instancegroup/api-ref/InstanceGroup/updateAccessBindings.md) REST API method for the [InstanceGroup](../../instancegroup/api-ref/InstanceGroup/index.md) resource or the [InstanceGroupService/UpdateAccessBindings](../../instancegroup/api-ref/grpc/InstanceGroup/updateAccessBindings.md) gRPC API call. In the request body, set the `action` property to `ADD` and specify the user type and ID under `subject`.

{% endlist %}

## Assigning multiple roles {#multiple-roles}

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select the folder containing the instance group.
  1. Navigate to **Compute Cloud**.
  1. In the left-hand panel, select ![image](../../../_assets/console-icons/layers-3-diagonal.svg) **Instance groups**.
  1. Select the group.
  1. Navigate to the ![image](../../../_assets/console-icons/persons.svg) **Access bindings** tab.
  1. Click **Assign roles**.
  1. In the window that opens, select the group, user, or service account you want to grant access to the instance group.
  1. Click ![image](../../../_assets/console-icons/plus.svg) **Add role** and select the required [roles](../../security/index.md#roles-list).
  1. To add another role, click **Add role**.
  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.

  You can assign multiple roles using the `set-access-bindings` command.

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

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

     ```bash
     yc compute instance-group list-access-bindings <instance_group_name_or_ID>
     ```

  1. See the description of the CLI command for assigning roles for an instance group:

     ```bash
     yc compute instance-group set-access-bindings --help
     ```

  1. Assign roles:

     ```bash
     yc compute instance-group set-access-bindings <instance_group_name_or_ID> \
       --access-binding role=<role>,subject=<subject_type>:<subject_ID>
     ```

     Where:

     * `--access-binding`: Role:

       * `role`: Role ID.
       * `subject`: Type and ID of the [subject](../../../iam/concepts/access-control/index.md#subject) the role is assigned to.

     For example, assign roles to several users and one service account:

     ```bash
     yc compute instance-group set-access-bindings test-group \
       --access-binding role=editor,subject=userAccount:gfei8n54hmfh******** \
       --access-binding role=viewer,subject=userAccount:helj89sfj80a******** \
       --access-binding role=editor,subject=serviceAccount:ajel6l0jcb9s********
     ```

- API {#api}

  Use the [setAccessBindings](../../instancegroup/api-ref/InstanceGroup/setAccessBindings.md) REST API method for the [InstanceGroup](../../instancegroup/api-ref/InstanceGroup/index.md) resource or the [InstanceGroupService/SetAccessBindings](../../instancegroup/api-ref/grpc/InstanceGroup/setAccessBindings.md) gRPC API call.

{% endlist %}

## Revoking a role {#revoke-role}

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select the folder containing the instance group.
  1. Navigate to **Compute Cloud**.
  1. In the left-hand panel, select ![image](../../../_assets/console-icons/layers-3-diagonal.svg) **Instance groups**.
  1. Select the group.
  1. Navigate to the ![image](../../../_assets/console-icons/persons.svg) **Access bindings** tab.
  1. In the line with the user in question, click ![icon-context-menu](../../../_assets/console-icons/ellipsis.svg) and select **Edit roles**.
  1. Click ![cross](../../../_assets/console-icons/xmark.svg) next to a role to delete it.
  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.

  1. See the description of the CLI command for revoking a role for an instance group:

     ```bash
     yc compute instance-group remove-access-binding --help
     ```

  1. View the list of users and their roles for the resource:

     ```bash
     yc compute instance-group list-access-bindings <instance_group_name_or_ID>
     ```

  1. To revoke access permissions, run this command:

     ```bash
     yc compute instance-group remove-access-binding <instance_group_name_or_ID> \
       --role <role_ID> \
       --subject <subject_type>:<subject_ID>
     ```

     Where:

     * `--role`: ID of the role you need to revoke.
     * `--subject`: [Subject](../../../iam/concepts/access-control/index.md#subject) to revoke the role from.

     For example, this command revokes the `viewer` role for the instance group from a user with the `ajel6l0jcb9s********` ID:

     ```bash
     yc compute instance-group remove-access-binding test-group \
       --role viewer \
       --subject userAccount:ajel6l0jcb9s********
     ```

- API {#api}

  Use the [updateAccessBindings](../../instancegroup/api-ref/InstanceGroup/updateAccessBindings.md) REST API method for the [InstanceGroup](../../instancegroup/api-ref/InstanceGroup/index.md) resource or the [InstanceGroupService/UpdateAccessBindings](../../instancegroup/api-ref/grpc/InstanceGroup/updateAccessBindings.md) gRPC API call. In the request body, set the `action` property to `REMOVE` and specify the user type and ID under `subject`.

{% endlist %}