Bezpieczeństwo na poziomie pól i dokumentów
Wdrażaj szczegółową kontrolę dostępu, ograniczając dostęp do określonych pól, a nawet pojedynczych dokumentów na podstawie ról użytkowników.
Bezpieczeństwo na poziomie pól i dokumentów to bezpłatna lekcja Elasticsearch & Full Text Search Systems na CoddyKit. To lekcja 2 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej Elasticsearch & Full Text Search Systems, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs Elasticsearch & Full Text Search Systems zawiera 4 lekcji w sumie.
Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.
Why Fine-Grained Security?
In Elasticsearch, you might not want every user to see all data. Sometimes, certain users should only access specific parts of documents or only a subset of documents.
This is where fine-grained security comes in. It allows you to control access at a much more detailed level than just index permissions.
What is Field Level Security (FLS)?
Field Level Security (FLS) lets you restrict which fields within a document a user can see. Imagine a product document with many fields.
- A sales agent might only need to see
product_nameandprice. - An inventory manager might need
quantityandsupplier_id.
FLS ensures users only retrieve the fields relevant to their role, hiding sensitive or irrelevant data.
Configuring FLS in Roles
FLS is configured within a user's role definition. You specify which fields are granted (allowed) or excepted (disallowed) for specific indices.
Using grant is generally safer as it follows a whitelist approach, only allowing explicitly listed fields.
{
"applications": [],
"cluster": [],
"indices": [
{
"names": ["products"],
"privileges": ["read"],
"field_security": {
"grant": ["product_name", "price"]
}
}
],
"run_as": [],
"metadata": {},
"transient_metadata": {}
}FLS Example: Product Viewer Role
Let's create a role named product_viewer. Users with this role can read documents from the products index, but only see the product_name and price fields.
Other fields like internal_cost or supplier_secret would be hidden.
PUT /_security/role/product_viewer
{
"indices": [
{
"names": ["products"],
"privileges": ["read"],
"field_security": {
"grant": ["product_name", "price"]
}
}
]
}What is Document Level Security (DLS)?
Document Level Security (DLS) allows you to restrict which documents a user can see. Instead of hiding fields, DLS filters entire documents based on a query.
For example, a regional sales manager should only see sales orders from their specific region, not from other regions.
Configuring DLS in Roles
DLS is configured in a role using a query object. This query acts as a filter that is automatically applied to all search requests made by users assigned to that role.
Only documents matching this query will be returned to the user, regardless of their original search request.
{
"applications": [],
"cluster": [],
"indices": [
{
"names": ["sales_data"],
"privileges": ["read"],
"query": {
"term": { "region.keyword": "east" }
}
}
],
"run_as": [],
"metadata": {},
"transient_metadata": {}
}DLS Example: East Region Sales
Let's create a role named east_sales_manager. Users with this role can read documents from the sales_data index, but only those documents where the region field is east.
This effectively isolates sales data by region.
PUT /_security/role/east_sales_manager
{
"indices": [
{
"names": ["sales_data"],
"privileges": ["read"],
"query": {
"term": { "region.keyword": "east" }
}
}
]
}Combining FLS and DLS
You can apply both Field Level Security and Document Level Security within a single role definition.
This means a user could be restricted to seeing only specific fields, AND only specific documents that match a filter query. This offers a very powerful way to create fine-grained access control.
Best Practices for FLS/DLS
When implementing FLS and DLS:
- Design roles carefully: Plan out exactly what each user group needs to see.
- Test thoroughly: Always verify that your roles provide the intended level of access, and nothing more.
- Use `grant` for FLS: Whitelisting fields is generally more secure than blacklisting.
- Keep DLS queries simple: Complex queries can impact performance.
- Least privilege: Always grant the minimum necessary permissions.
Quick Check: Security Features
Which of the following statements about Elasticsearch Field and Document Level Security are true?
Recap: Fine-Grained Security
You've learned about Field Level Security (FLS) for restricting visible fields and Document Level Security (DLS) for filtering documents based on queries.
These powerful features, configured within user roles, enable you to create highly granular access control, ensuring users only see the data they are authorized for. This is crucial for maintaining data privacy and security in your Elasticsearch cluster.
Często zadawane pytania
Czy lekcja „Bezpieczeństwo na poziomie pól i dokumentów” jest bezpłatna?
Tak — pełny tekst „Bezpieczeństwo na poziomie pól i dokumentów” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu Elasticsearch & Full Text Search Systems, przejdź na CoddyKit PRO. Kurs Elasticsearch & Full Text Search Systems zawiera 4 lekcji w sumie.
Co nauczysz się w „Bezpieczeństwo na poziomie pól i dokumentów”?
Wdrażaj szczegółową kontrolę dostępu, ograniczając dostęp do określonych pól, a nawet pojedynczych dokumentów na podstawie ról użytkowników. Ćwiczysz Elasticsearch & Full Text Search Systems z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.
Czy potrzebuję doświadczenia, aby zacząć Elasticsearch & Full Text Search Systems?
Nie wymagamy żadnego doświadczenia. Elasticsearch & Full Text Search Systems w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 2 z 4.
Ile czasu zajmuje lekcja „Bezpieczeństwo na poziomie pól i dokumentów”?
Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.
Czy mogę pisać i uruchamiać kod w tej lekcji Elasticsearch & Full Text Search Systems?
Tak. Każda lekcja Elasticsearch & Full Text Search Systems zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.
Wszystkie lekcje w tym kursie
- Uwierzytelnianie użytkowników i role
- Bezpieczeństwo na poziomie pól i dokumentów
- TLS/SSL i bezpieczeństwo sieci
- Klucze API i rejestrowanie audytowe