|
| 1 | +[note] |
| 2 | +**Note**: All commands are written for `juju >= v.3.0` |
| 3 | + |
| 4 | +If you are using an earlier version, check the [Juju 3.0 Release Notes](https://juju.is/docs/juju/roadmap#heading--juju-3-0-0---22-oct-2022). |
| 5 | +[/note] |
| 6 | + |
| 7 | +[note] |
| 8 | +LDAP is available on channels: `14/edge` and `16/edge`, from revision `600`. |
| 9 | +[/note] |
| 10 | + |
| 11 | + |
| 12 | +# How to enable LDAP authentication |
| 13 | + |
| 14 | +LDAP (*Lightweight Directory Access Protocol*) enables centralized authentication for PostgreSQL clusters, reducing the overhead of managing local credentials and access policies. |
| 15 | + |
| 16 | +This guide goes over the steps to integrate LDAP as an authentication method with the PostgreSQL charm, all within the Juju ecosystem. |
| 17 | + |
| 18 | +## Deploy an LDAP server in a K8s environment |
| 19 | + |
| 20 | +[note type="caution"] |
| 21 | +**Disclaimer:** In this guide, we use [self-signed certificates](https://en.wikipedia.org/wiki/Self-signed_certificate) provided by the [`self-signed-certificates` operator](https://github.com/canonical/self-signed-certificates-operator). |
| 22 | + |
| 23 | +**This is not recommended for a production environment.** |
| 24 | + |
| 25 | +For production environments, check the collection of [Charmhub operators](https://charmhub.io/?q=tls-certificates) that implement the `tls-certificate` interface, and choose the most suitable for your use-case. |
| 26 | +[/note] |
| 27 | + |
| 28 | +Switch to the Kubernetes controller: |
| 29 | + |
| 30 | +```shell |
| 31 | +juju switch <k8s_controller> |
| 32 | +``` |
| 33 | + |
| 34 | +Deploy the [GLAuth charm](https://charmhub.io/glauth-k8s): |
| 35 | +```shell |
| 36 | +juju add-model glauth |
| 37 | +juju deploy self-signed-certificates |
| 38 | +juju deploy postgresql-k8s --channel 14/stable --trust |
| 39 | +juju deploy glauth-k8s --channel edge --trust |
| 40 | +``` |
| 41 | + |
| 42 | +Integrate (formerly known as "relate") the three applications: |
| 43 | +```shell |
| 44 | +juju integrate glauth-k8s self-signed-certificates |
| 45 | +juju integrate glauth-k8s postgresql-k8s |
| 46 | +``` |
| 47 | + |
| 48 | +Deploy the [GLAuth-utils charm](https://charmhub.io/glauth-utils), in order to manage LDAP users: |
| 49 | + |
| 50 | +```shell |
| 51 | +juju deploy glauth-utils --channel edge --trust |
| 52 | +``` |
| 53 | + |
| 54 | +Integrate (formerly known as "relate") the two applications: |
| 55 | + |
| 56 | +```shell |
| 57 | +juju integrate glauth-k8s glauth-utils |
| 58 | +``` |
| 59 | + |
| 60 | +## Expose cross-controller URLs |
| 61 | + |
| 62 | +Enable the required micro-k8s plugin: |
| 63 | + |
| 64 | +```shell |
| 65 | +IPADDR=$(ip -4 -j route get 2.2.2.2 | jq -r '.[] | .prefsrc') |
| 66 | +sudo microk8s enable metallb $IPADDR-$IPADDR |
| 67 | +``` |
| 68 | + |
| 69 | +Deploy the [Traefik charm](https://charmhub.io/traefik-k8s), in order to expose endpoints from the K8s cluster: |
| 70 | + |
| 71 | +```shell |
| 72 | +juju deploy traefik-k8s --trust |
| 73 | +``` |
| 74 | + |
| 75 | +Integrate (formerly known as "relate") the two applications: |
| 76 | + |
| 77 | +```shell |
| 78 | +juju integrate traefik-k8s glauth-k8s:ingress |
| 79 | +``` |
| 80 | + |
| 81 | +## Expose cross-model relations |
| 82 | + |
| 83 | +To offer the GLAuth interfaces, run: |
| 84 | + |
| 85 | +```shell |
| 86 | +juju offer glauth-k8s:ldap ldap |
| 87 | +juju offer glauth-k8s:send-ca-cert send-ca-cert |
| 88 | +``` |
| 89 | + |
| 90 | +## Enable LDAP |
| 91 | + |
| 92 | +Switch to the VM controller: |
| 93 | + |
| 94 | +```shell |
| 95 | +juju switch <lxd_controller>:postgresql |
| 96 | +``` |
| 97 | + |
| 98 | +To have LDAP offers consumed: |
| 99 | + |
| 100 | +```shell |
| 101 | +juju consume <k8s_controller>:admin/glauth.ldap |
| 102 | +juju consume <k8s_controller>:admin/glauth.send-ca-cert |
| 103 | +``` |
| 104 | + |
| 105 | +To have LDAP authentication enabled, integrate the PostgreSQL charm with the GLAuth charm: |
| 106 | + |
| 107 | +```shell |
| 108 | +juju integrate postgresql:ldap ldap |
| 109 | +juju integrate postgresql:receive-ca-cert send-ca-cert |
| 110 | +``` |
| 111 | + |
| 112 | +## Map LDAP users to PostgreSQL |
| 113 | + |
| 114 | +To have LDAP users available in PostgreSQL, provide a comma separated list of LDAP groups to already created PostgreSQL authorization groups. To create those groups before hand, refer to the Data Integrator charm [page](https://charmhub.io/data-integrator). |
| 115 | + |
| 116 | +```shell |
| 117 | +juju config postgresql ldap_map="<ldap_group>=<psql_group>" |
| 118 | +``` |
| 119 | + |
| 120 | +## Disable LDAP |
| 121 | + |
| 122 | +You can disable LDAP removing the following relations: |
| 123 | + |
| 124 | +```shell |
| 125 | +juju remove-relation postgresql.receive-ca-cert send-ca-cert |
| 126 | +juju remove-relation postgresql.ldap ldap |
| 127 | +``` |
0 commit comments