|
| 1 | +# Keycloak Integration |
| 2 | + |
| 3 | +The Compose file includes a Keycloak instance that you can use for authentication instead of spinning up a separate one or using one of the deployed instances. (It's enabled by default but running it won't prevent you from using a separate instance.) |
| 4 | + |
| 5 | +## Default Settings |
| 6 | + |
| 7 | +There are some defaults that are part of this. |
| 8 | + |
| 9 | +_SSL Certificate_: There's a self-signed cert that's in `config/keycloak/tls` - if you'd rather set up your own (or you have a real cert or something to use), you can drop the PEM files in there. See the README there for info. |
| 10 | + |
| 11 | +_Realm_: There's a `default-realm.json` in `config/keycloak` that will get loaded by Keycloak when it starts up, and will set up a realm for you with some users and a client so you don't have to set it up yourself. The realm it creates is called `ol-local`. |
| 12 | + |
| 13 | +The users it sets up are: |
| 14 | + |
| 15 | +| User | Password | |
| 16 | +| ------------------- | --------- | |
| 17 | +| `[email protected]` | `student` | |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | +The client it sets up is called `apisix`. You can change the passwords and get the secret in the admin. |
| 22 | + |
| 23 | +## Making it Work |
| 24 | + |
| 25 | +If you don't have a Keycloak instance running locally already, you can use the pack-in one. It starts with the rest of the services and is configured to be at `http://kc.ol.local:8006` and `https://kc.ol.local:8007` by default (but you can change this in the `env` files). |
| 26 | + |
| 27 | +Some setup is required to use the pack-in instance: |
| 28 | + |
| 29 | +1. Set required keycloak environment values in your `.env` file: |
| 30 | + - Set a keystore password via `KEYCLOAK_SVC_KEYSTORE_PASSWORD`. This is required, but the password need not be anything special. |
| 31 | + - Set `KEYCLOAK_CLIENT_SECRET`; ask another developer for the relevant value. |
| 32 | +2. Optionally add `KEYCLOAK_SVC_HOSTNAME`, `KEYCLOAK_SVC_ADMIN`, and `KEYCLOAK_SVC_ADMIN_PASSWORD` to your `.env` file. |
| 33 | + 1. `KEYCLOAK_SVC_HOSTNAME` is the hostname you want to use for the instance - the default is `kc.ol.local`. |
| 34 | + 2. `KEYCLOAK_SVC_ADMIN` is the admin username. The default is `admin`. |
| 35 | + 3. `KEYCLOAK_SVC_ADMIN_PASSWORD` is the admin password. The default is `admin`. |
| 36 | +3. Re-start the stack. |
| 37 | + |
| 38 | +The Keycloak container should start and stay running. Once it does, you should be able to log in at `https://kc.ol.local:8007` with username and password `admin` (or the values you supplied). |
| 39 | + |
| 40 | +If you'd rather use a separate Keycloak instance, ensure these settings are present in the appropriate `env` file (best is probably `backend.local.env`): |
| 41 | + |
| 42 | +- `KEYCLOAK_REALM` |
| 43 | + |
| 44 | + Sets the realm used by APISIX for Keycloak authentication. Defaults to `ol-local`. |
| 45 | + |
| 46 | +- `KEYCLOAK_DISCOVERY_URL` |
| 47 | + |
| 48 | + Sets the discovery URL for the Keycloak OIDC service. (In Keycloak admin, navigate to the realm you're using, then go to Realm Settings under Configure, and the link is under OpenID Endpoint Configuration.) This defaults to a valid value for the pack-in Keycloak instance. |
| 49 | + |
| 50 | +- `KEYCLOAK_CLIENT_ID` |
| 51 | + |
| 52 | + The client ID for the OIDC client for APISIX. Defaults to `apisix`. |
| 53 | + |
| 54 | +- `KEYCLOAK_CLIENT_SECRET` |
| 55 | + |
| 56 | + The client secret for the OIDC client. No default - you will need to get this from the Keycloak admin, even if you're using the pack-in Keycloak instance. |
| 57 | + |
| 58 | +> If you're using a Keycloak instance also hosted within a Docker container on the same machine you're running the AI chatbots, you'll need to make sure it can be seen from within the `apigateway` container. This will _require_ some work on your part - generally, stuff within Composer environments can't see things outside of their own environment. There's an example of this in the `docker-compose.services.yml` file if your Keycloak instance uses a Compose environment, as we use it so that the Keycloak OIDC URLs all match externally and internally. |
0 commit comments