0Pricing
Elasticsearch & Full Text Search Systems · 课时

用户身份验证与角色

配置用户身份验证、创建角色并分配权限,以控制哪些用户可以访问集群以及可以执行哪些操作。

用户身份验证与角色 是 CoddyKit 上的免费 Elasticsearch & Full Text Search Systems 课时。 这是第 1 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 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: true

Built-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: Grants read privilege on the sales_data index.
  • finance_writer: Grants read and write privileges on the finance_reports index.

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.

常见问题解答

「用户身份验证与角色」课时是免费的吗?

是的 — 「用户身份验证与角色」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Elasticsearch & Full Text Search Systems 课程的其余内容,请升级到 CoddyKit PRO。 Elasticsearch & Full Text Search Systems 课程共包含 4 节课。

「用户身份验证与角色」这节课中我会学到什么?

配置用户身份验证、创建角色并分配权限,以控制哪些用户可以访问集群以及可以执行哪些操作。 你通过在浏览器中直接运行的动手代码来练习 Elasticsearch & Full Text Search Systems,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 Elasticsearch & Full Text Search Systems 需要有经验吗?

无需任何先前经验。CoddyKit 上的 Elasticsearch & Full Text Search Systems 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 1 节课,共 4 节。

「用户身份验证与角色」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 Elasticsearch & Full Text Search Systems 课中编写并运行代码吗?

能。每节 Elasticsearch & Full Text Search Systems 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. 用户身份验证与角色
  2. 字段级与文档级安全
  3. TLS/SSL 与网络安全
  4. 接口密钥与审计日志记录
← 返回 Elasticsearch & Full Text Search Systems