Аутентификация пользователей и роли
Настраивайте аутентификацию пользователей, создавайте роли и назначайте разрешения, чтобы контролировать доступ к кластеру и доступные пользователям действия.
«Аутентификация пользователей и роли» — бесплатный урок Elasticsearch & Full Text Search Systems на CoddyKit. Это урок 1 из 4. Ты можешь прочитать весь урок бесплатно ниже — а потом практиковать его прямо в браузере с встроенным редактором кода и ИИ-репетитором 24/7. Это часть пути обучения Elasticsearch & Full Text Search Systems, и твой прогресс синхронизируется между веб-версией и приложением CoddyKit. Курс Elasticsearch & Full Text Search Systems содержит 4 уроков всего.
Части этого урока еще не переведены и отображаются на английском.
Securing Your Search Data
Imagine your search engine holds sensitive customer data or internal documents. Without proper security, anyone could potentially access, modify, or delete it.
This lesson will show you how to protect your Elasticsearch cluster by controlling who can do what.
Elasticsearch Security Features
Elasticsearch's security features, part of what was formerly X-Pack, provide robust controls for your cluster. They include:
- Authentication: Verifying user identities.
- Authorization: Defining what authenticated users can do.
- Encryption: Securing communication.
We'll focus on authentication and authorization in this lesson.
Activating Security Settings
To enable security, you need to configure your elasticsearch.yml file. This is typically done during the initial setup of your cluster.
Add the following line to enable security features in your configuration:
xpack.security.enabled: trueBuilt-in Administrator Users
When security is enabled, Elasticsearch creates several built-in users with predefined roles. The most important is the elastic user.
elastic: The superuser, with full administrative privileges. Use this for initial setup and critical operations.kibana_system: Used by Kibana to connect to Elasticsearch.logstash_system: Used by Logstash for monitoring.
You'll set passwords for these during the initial setup process.
Creating Your First User
Let's create a new user named dev_user. We'll use the Elasticsearch Users API, which allows you to manage users via REST calls.
This API call creates a user and sets their password. Remember to use strong, unique passwords!
PUT /_security/user/dev_user
{
"password": "myStrongPassword123",
"full_name": "Developer User",
"email": "dev@example.com"
}Defining User Permissions with Roles
In Elasticsearch, roles are central to authorization. A role is a collection of privileges that define what actions a user can perform.
- Simplifies Management: Assign a role, not individual permissions, to users.
- Granular Control: Roles can grant cluster-level and index-level privileges.
- Cumulative: Users can have multiple roles, and their privileges are combined.
Common Predefined Roles
Elasticsearch comes with several useful built-in roles, providing common sets of permissions:
superuser: Grants all privileges across the cluster.viewer: Can read data from all indices.editor: Can read and write data to all indices.kibana_user: Allows access to Kibana features.
These roles are great starting points, but often you'll need more specific control.
Crafting Custom Roles
Let's create a custom role called my_app_reader that can only read data from an index named my_application_data.
This role grants read and view_index_metadata privileges on a specific index. It also includes basic cluster monitoring privileges.
PUT /_security/role/my_app_reader
{
"cluster": [
"monitor",
"read_ilm"
],
"indices": [
{
"names": [ "my_application_data" ],
"privileges": [ "read", "view_index_metadata" ]
}
]
}Assigning Roles to Users
Now that we have our dev_user and my_app_reader role, let's assign the role to the user. We'll update the dev_user to have this role.
Remember, users can be assigned multiple roles, inheriting all privileges from each one they possess.
PUT /_security/user/dev_user
{
"password": "myStrongPassword123",
"full_name": "Developer User",
"email": "dev@example.com",
"roles": [ "my_app_reader" ]
}Understanding Roles & Privileges
Consider a user named analyst. This user has two roles assigned:
sales_reader: Grantsreadprivilege on thesales_dataindex.finance_writer: Grantsreadandwriteprivileges on thefinance_reportsindex.
Which of the following actions are permitted for the analyst user?
Recap: Secure Your Cluster
You've learned the fundamentals of Elasticsearch security!
- We discussed why security is crucial for your data.
- Explored how to enable security and identify built-in users.
- Understood roles as collections of privileges.
- Created custom users and roles using the Security API.
- Assigned roles to users to control access.
Proper authentication and authorization are key to a secure and robust Elasticsearch deployment.
Часто задаваемые вопросы
Урок «Аутентификация пользователей и роли» бесплатный?
Да — полный текст урока «Аутентификация пользователей и роли» бесплатно доступен здесь в веб-версии. Чтобы практиковать его интерактивно (встроенный редактор кода и ИИ-репетитор 24/7) и разблокировать остальной курс Elasticsearch & Full Text Search Systems, подпишись на CoddyKit PRO. Курс Elasticsearch & Full Text Search Systems содержит 4 уроков всего.
Чему я научусь в уроке «Аутентификация пользователей и роли»?
Настраивайте аутентификацию пользователей, создавайте роли и назначайте разрешения, чтобы контролировать доступ к кластеру и доступные пользователям действия. Ты практикуешь Elasticsearch & Full Text Search Systems с помощью реального кода, который запускаешь прямо в браузере, и ИИ-репетитор 24/7 отвечает на твои вопросы во время урока.
Нужен ли мне опыт, чтобы начать Elasticsearch & Full Text Search Systems?
Предыдущий опыт не требуется. Elasticsearch & Full Text Search Systems на CoddyKit структурирован для всех уровней — от новичков до продвинутых, поэтому ты можешь начать отсюда или с самого начала и учиться в своем темпе. Это урок 1 из 4.
Сколько времени занимает урок «Аутентификация пользователей и роли»?
Большинство уроков CoddyKit занимают около 5–10 минут. Каждый из них компактный и интерактивный, поэтому ты постоянно делаешь прогресс и продолжаешь с того же места в веб-версии и приложении.
Можно ли писать и запускать код в этом уроке Elasticsearch & Full Text Search Systems?
Да. Каждый урок Elasticsearch & Full Text Search Systems включает встроенный редактор кода, поэтому ты пишешь и запускаешь реальный код прямо в браузере и получаешь моментальную обратную связь от AI — локальная установка не требуется.
Все уроки этого курса
- Аутентификация пользователей и роли
- Безопасность на уровне полей и документов
- TLS/SSL и безопасность сети
- Ключи API и журнал аудита