Провижининг RBAC с помощью Grafana
Note
Доступно в Grafana Enterprise для самостоятельно развёрнутых экземпляров. Эта функция недоступна в Grafana Cloud.
Вы можете создавать, изменять и удалять
пользовательские роли, а также создавать и удалять
назначения базовых ролей, добавив один или несколько YAML-файлов конфигурации в каталог provisioning/access-control/.
Поскольку этот метод требует доступа к файловой системе, в которой работает Grafana, он доступен только для самостоятельно развёрнутых экземпляров Grafana. Чтобы настроить провижининг RBAC в Grafana Cloud, используйте Terraform или HTTP API.
Grafana выполняет провижининг при запуске. После изменения файла конфигурации вы можете перезагрузить его во время работы. Перезапускать сервер Grafana для применения изменений не требуется.
Прежде чем начать:
- Убедитесь, что у вас есть доступ к файлам на сервере, где работает Grafana.
Чтобы управлять ролями RBAC и назначать их с помощью провижининга:
-
Войдите на сервер Grafana.
-
Найдите каталог провижининга Grafana.
-
Создайте новый YAML в следующем каталоге: provisioning/access-control. Например,
provisioning/access-control/custom-roles.yml -
Добавьте в файл конфигурации сведения о провижининге RBAC.
Инструкции см. в разделах Управление ролями RBAC и Назначение ролей RBAC.
Полный пример файла провижининга см. в разделе пример файла провижининга ролей.
-
Перезагрузите файл конфигурации провижининга.
Дополнительные сведения о перезагрузке конфигурации провижининга во время работы см. в разделе Перезагрузка конфигураций провижининга.
Пример файла конфигурации ролей с использованием провижининга Grafana
В следующем примере показан полный файл конфигурации YAML, который:
- Создаёт пользовательские роли
- Удаляет пользовательские роли
- Обновляет разрешения базовых ролей
- Назначает роли командам
- Отзывает назначения ролей командам
Пример
---
# config file version
apiVersion: 2
# <list> list of roles to insert/update/delete
roles:
# <string, required> name of the role you want to create or update. Required.
- name: 'custom:users:writer'
# <string> uid of the role. Has to be unique for all orgs.
uid: customuserswriter1
# <string> description of the role, informative purpose only.
description: 'Create, read, write users'
# <int> version of the role. Has to be greater than the stored role version to apply updates. Increase by 1 when you change the role.
version: 2
# <int> org id. Defaults to Grafana's default if not specified.
orgId: 1
# <list> list of the permissions granted by this role.
permissions:
# <string, required> action allowed.
- action: 'users:read'
#<string> scope it applies to.
scope: 'users:*'
- action: 'users:write'
scope: 'users:*'
- action: 'users:create'
# NOTE: the `datasources:query` action implies `datasources:read`
# Optional `datasourceType` for scopes `datasources:uid:<DATASOURCE_UID>`.
# If you omit it, Grafana resolves the plugin type from the data source when this file is provisioned.
# It is required if there are two datasources with the same uid.
- action: 'datasources:query'
scope: 'datasources:uid:loki-uid-here'
datasourceType: loki
- name: 'custom:global:users:reader'
# <bool> overwrite org id and creates a global role.
global: true
# <string> state of the role. Defaults to 'present'. If 'absent', role will be deleted.
state: 'absent'
# <bool> force deletion revoking all grants of the role.
force: true
- uid: 'basic_editor'
# <bool> always apply the specified changes to the role, regardless of the role version in the database
overrideRole: true
global: true
# <list> list of roles to copy permissions from.
from:
- uid: 'basic_editor'
global: true
- name: 'fixed:users:writer'
global: true
# <list> list of the permissions to add/remove on top of the copied ones.
permissions:
- action: 'users:read'
scope: 'users:*'
- action: 'users:write'
scope: 'users:*'
# <string> state of the permission. Defaults to 'present'. If 'absent', the permission will be removed.
state: absent
# <list> list role assignments to teams to create or remove.
teams:
# <string, required> name of the team you want to assign roles to. Required.
- name: 'Users writers'
# <int> org id. Will default to Grafana's default if not specified.
orgId: 1
# <list> list of roles to assign to the team
roles:
# <string> uid of the role you want to assign to the team.
- uid: 'customuserswriter1'
# <int> org id. Will default to Grafana's default if not specified.
orgId: 1
# <string> name of the role you want to assign to the team.
- name: 'fixed:users:writer'
# <bool> overwrite org id to specify the role is global.
global: true
# <string> state of the assignment. Defaults to 'present'. If 'absent', the assignment will be revoked.
state: absent