Saltar al contenido

Grafana y LDAP: Aumenta la seguridad en menos de 5 minutos

Este artículo cubrirá cómo integrar rápidamente Grafana y el servidor LDAP para aumentar la seguridad de su aplicación

¿Cómo integrar Grafana y LDAP?
¿Cómo integrar Grafana y LDAP?

Grafana es una de las herramientas de panel más utilizadas, principalmente para las plataformas de observabilidad en entornos de carga de trabajo en la nube. Pero ninguna de estas herramientas está completa hasta que pueda configurarlas para cumplir con sus estándares de seguridad. La seguridad se está volviendo cada vez más importante y esto es especialmente cierto cuando hablamos de cualquier componente relacionado con la nube. Por lo tanto, este tema siempre debe ser algo que cualquier arquitecto de la nube tenga en mente cuando esté definiendo o implementando cualquier pieza de software hoy en día.

Y en ese punto, la integración LDAP es una de las principales cosas que siempre necesitarás hacer. No conozco ninguna empresa, grande o pequeña, que permita el uso de cualquier herramienta con una interfaz gráfica de usuario si no está conectada al directorio corporativo.

Así que, veamos cómo podemos implementar esto con una herramienta popular como Grafana. En mi caso, voy a usar una versión en contenedor de Grafana, pero los pasos y cosas a hacer siguen siendo los mismos sin importar el modelo de implementación.

La tarea que vamos a realizar se basa en tres pasos:

  • Habilitar la configuración de LDAP
  • Configuración básica de LDAP
  • Configuración de mapeo de grupos

Lo primero que necesitamos modificar es el grafana.ini añadiendo el siguiente fragmento:

    [auth.ldap]
    enabled = true
    config_file = /etc/grafana/ldap.toml

Eso significa que estamos habilitando la autenticación basada en LDAP y estableciendo la ubicación del archivo de configuración de LDAP. Este ldap.toml tiene toda la configuración necesaria para el LDAP:

    [[servers]]
    host = "localhost"
    port = 389
    use_ssl = false
    start_tls = false
    ssl_skip_verify = false
  
    bind_dn = "XXXXXX-XXXXXXXXX"
    bind_password = "XXXXXX"
    
	search_filter = "(&(sAMAccountName=%s)(memberOf=ADMIN_GROUP))"
    search_base_dns = [DC=example,DC=org"]

  
    [servers.attributes]
    member_of = "member"
    email =  "mail"
    name = "givenName"
    surname = "sn"
    username = "sAMAccountName"

    [[servers.group_mappings]]
    group_dn = "*"
    org_role = "Admin"

La primera parte se refiere a la conexión principal. Estableceremos la ubicación del host y el puerto, el usuario administrador y la contraseña. Después de eso, necesitaremos una segunda sección que defina search_filter y search_base_dns para definir los usuarios que pueden acceder al sistema.

Finalmente, tenemos otra sección para definir el mapeo entre los atributos de LDAP y los atributos de Grafana para poder recopilar los datos del LDAP.

    [servers.attributes]
    member_of = "member"
    email =  "mail"
    name = "givenName"
    surname = "sn"
    username = "sAMAccountName"

Además, podemos definir los privilegios que los diferentes grupos permiten tener a los varios org_roles en Grafana, como puedes ver en el fragmento a continuación:

    [[servers.group_mappings]]
    group_dn = "*"
    org_role = "Admin"

Con todos esos cambios en su lugar, necesitas reiniciar el servidor de Grafana para ver toda esta configuración aplicada. Después de ese punto, puedes iniciar sesión usando las credenciales de LDAP como puedes ver en la imagen a continuación y ver todos los datos recuperados del servidor LDAP:

Usando el servidor admin por defecto, también puedes usar una nueva función para probar la configuración de LDAP usando la opción LDAP que puedes ver en la imagen a continuación:

Y luego puedes buscar un Usuario y verás cómo este usuario se desempeñará en el servidor de Grafana:

  • Verificar los atributos que se mapearán del servidor LDAP al servidor Grafana
  • También verificar el estado de actividad y el rol permitido a este usuario

Puedes ver un ejemplo en la imagen a continuación:

Espero que este artículo te ayude a mejorar la configuración de seguridad en tus instalaciones de Grafana para integrarse con el servidor LDAP. Si deseas ver más información sobre este y temas similares, te animo a que eches un vistazo a los enlaces que encontrarás debajo de estas oraciones.

Etiquetas:

Grafana and LDAP: Increase Security in Less Than 5 minutes

This article will cover how to quickly integrate Grafana and LDAP server to increase the security of your application

How To Integrate Grafana and LDAP?
How To Integrate Grafana and LDAP?

Grafana is one of the most used dashboard tools, mainly for the observability platforms on cloud-workload environments. But none of these tools is complete until you can configure them to meet your security standards. Security is becoming each time more and more important and this is especially true when we are talking about any cloud-related component. So this topic should always something that any cloud architect has in mind when they are defining or implementing any piece of software today.

And at that point, the LDAP integration is one of the main things you will always need to do. I don’t know any enterprise, big or small, that allows the usage of any tool with a Graphical User Interface if it is not connected to the corporate directory.

So, let’s see how we can implement this with a popular tool such as Grafana. In my case, I’m going to use a containerized version of grafana, but the steps and things to do remains the same no matter the deployment model.

The task that we are going to perform is based on three steps:

  • Enable the LDAP settings
  • Basic LDAP settings configuration
  • Group mapping configuration

The first thing we need to modify is the grafana.ini adding the following snippet:

    [auth.ldap]
    enabled = true
    config_file = /etc/grafana/ldap.toml

That means that we are enabling the authentication based on LDAP and setting the location of the LDAP configuration file. This ldap.toml has all the configuration needed for the LDAP:

    [[servers]]
    host = "localhost"
    port = 389
    use_ssl = false
    start_tls = false
    ssl_skip_verify = false
  
    bind_dn = "XXXXXX-XXXXXXXXX"
    bind_password = "XXXXXX"
    
	search_filter = "(&(sAMAccountName=%s)(memberOf=ADMIN_GROUP))"
    search_base_dns = [DC=example,DC=org"]

  
    [servers.attributes]
    member_of = "member"
    email =  "mail"
    name = "givenName"
    surname = "sn"
    username = "sAMAccountName"

    [[servers.group_mappings]]
    group_dn = "*"
    org_role = "Admin"

The first part is regarding the primary connection. We will establish the host location and port, the admin user, and the password. After that, we will need a second section that definesearch_filter and search_base_dns to define the users that can access the system.

Finally, we have another section to define the mapping between the LDAP attributes and the grafana attributes to be able to gather the data from the LDAP.

    [servers.attributes]
    member_of = "member"
    email =  "mail"
    name = "givenName"
    surname = "sn"
    username = "sAMAccountName"

Also, we can define the privileges that the different groups allow to have to the various org_rolesin Grafana, as you can see in the snippet below:

    [[servers.group_mappings]]
    group_dn = "*"
    org_role = "Admin"

With all those changes in place, you need to restart the Grafana server to see all this configuration applied. After that point, you can log in using the LDAP credentials as you can see in the picture below and see all the data retrieved from the LDAP Server:

Using the default admin server, you can also use a new feature to test the LDAP configuration using the LDAP option that you can see in the picture below:

And then you can search for a User and you will see how this user will play on the Grafana Server:

  • Check the attributes will map from the LDAP server to the Grafana server
  • Also check the status of activity and the role allowed to this user

You can see one sample in the picture below:

I hope that this article helps you in a way to level up the security settings on your Grafana installations to integrate with the LDAP server. If you want to see more information about this and similar topics I encourage you to take a look at the links that you would find below these sentences.

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *