Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Role-based access control
📖 Scenario: You are managing access to an Elasticsearch cluster. Different users have different roles, and each role has specific permissions to access certain indices.We want to create a simple role-based access control setup using Elasticsearch role definitions.
🎯 Goal: Build a role definition in Elasticsearch that assigns specific index permissions to roles, then check the permissions assigned.
📋 What You'll Learn
Create a role called read_only with read access to the products index
Create a role called write_access with write access to the orders index
Create a variable roles that holds these role definitions as a dictionary
Print the permissions of the read_only role
💡 Why This Matters
🌍 Real World
Role-based access control is essential in Elasticsearch to secure data by limiting what users can see or change.
💼 Career
Many jobs require managing Elasticsearch security roles to protect sensitive data and ensure proper access.
Progress0 / 4 steps
1
Create role definitions
Create a dictionary called roles with two keys: read_only and write_access. The read_only role should have indices permission with names as ["products"] and privileges as ["read"]. The write_access role should have indices permission with names as ["orders"] and privileges as ["write"].
Elasticsearch
Hint
Use a dictionary with keys read_only and write_access. Each key maps to another dictionary with key indices which is a list of dictionaries specifying names and privileges.
2
Add a helper variable for role to check
Create a variable called role_to_check and set it to the string "read_only".
Elasticsearch
Hint
Just assign the string "read_only" to a variable named role_to_check.
3
Extract permissions for the selected role
Create a variable called permissions and set it to the indices value inside the roles dictionary for the key stored in role_to_check.
Elasticsearch
Hint
Use the variable role_to_check as a key to get the role from roles, then get the indices key from that role.
4
Print the permissions
Write a print statement to display the value of the permissions variable.
Elasticsearch
Hint
Use print(permissions) to show the permissions.
Practice
(1/5)
1. What is the main purpose of Role-based Access Control (RBAC) in Elasticsearch?
easy
A. To control who can perform specific actions by assigning roles
B. To speed up search queries
C. To store data in different formats
D. To backup Elasticsearch clusters automatically
Solution
Step 1: Understand RBAC concept
RBAC is about managing permissions by assigning roles to users.
Step 2: Identify RBAC purpose in Elasticsearch
It controls who can do what actions on the cluster or indexes.
Final Answer:
To control who can perform specific actions by assigning roles -> Option A
Quick Check:
RBAC = Control access by roles [OK]
Hint: RBAC means controlling access by roles, not data or speed [OK]
Common Mistakes:
Confusing RBAC with data storage or backup
Thinking RBAC speeds up queries
Assuming RBAC changes data formats
2. Which of the following is the correct JSON structure to define a role with read access to the index logs-2024?
easy
A. {"cluster": ["all"], "indices": [{"names": ["logs-2024"], "privileges": ["monitor"]}]}
B. {"cluster": ["all"], "indices": [{"names": ["logs-2024"], "privileges": ["write"]}]}
C. {"cluster": ["read"], "indices": [{"names": ["logs-2024"], "privileges": ["write"]}]}
D. {"cluster": ["monitor"], "indices": [{"names": ["logs-2024"], "privileges": ["read"]}]}
Solution
Step 1: Check cluster privileges for read access
Read access to an index usually requires cluster privileges like 'monitor', not 'all' or 'read'.
Step 2: Verify index privileges
The index privileges must include 'read' for the specified index.
Final Answer:
{"cluster": ["monitor"], "indices": [{"names": ["logs-2024"], "privileges": ["read"]}]} -> Option D
Quick Check:
Cluster 'monitor' + index 'read' = correct role [OK]
Hint: Cluster 'monitor' + index 'read' grants read access [OK]
Common Mistakes:
Using 'all' cluster privilege unnecessarily
Confusing 'write' with 'read' privileges
Assigning 'read' cluster privilege which is invalid
3. Given this role definition, what permissions does a user have on the sales-data index?
Thinking 'run_as' is required for write permission
5. You want to create a role that allows a user to read from all indexes starting with prod- but only write to prod-logs. Which role definition is correct?