0Pricing
Elasticsearch & Full Text Search Systems · Lección

Seguridad a nivel de campo y documento

Implemente seguridad granular restringiendo el acceso a campos específicos o incluso a documentos individuales según los roles de usuario.

Seguridad a nivel de campo y documento es una lección gratuita de Elasticsearch & Full Text Search Systems en CoddyKit. Esta es la lección 2 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Elasticsearch & Full Text Search Systems, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Elasticsearch & Full Text Search Systems incluye 4 lecciones en total.

Partes de esta lección aún no han sido traducidas y se muestran en inglés.

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_name and price.
  • An inventory manager might need quantity and supplier_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.

Preguntas frecuentes

¿La lección «Seguridad a nivel de campo y documento» es gratis?

Sí — el texto completo de «Seguridad a nivel de campo y documento» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Elasticsearch & Full Text Search Systems, actualiza a CoddyKit PRO. El curso de Elasticsearch & Full Text Search Systems incluye 4 lecciones en total.

¿Qué aprenderé en «Seguridad a nivel de campo y documento»?

Implemente seguridad granular restringiendo el acceso a campos específicos o incluso a documentos individuales según los roles de usuario. Practicas Elasticsearch & Full Text Search Systems con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.

¿Necesito experiencia previa para empezar Elasticsearch & Full Text Search Systems?

No se requiere experiencia previa. Elasticsearch & Full Text Search Systems en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 2 de 4.

¿Cuánto tiempo toma la lección «Seguridad a nivel de campo y documento»?

La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.

¿Puedo escribir y ejecutar código en esta lección de Elasticsearch & Full Text Search Systems?

Sí. Cada lección de Elasticsearch & Full Text Search Systems incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.

Todas las lecciones de este curso

  1. Autenticación y roles de usuarios
  2. Seguridad a nivel de campo y documento
  3. TLS/SSL y seguridad de red
  4. Claves de API y registro de auditoría
← Volver a Elasticsearch & Full Text Search Systems