start keycloak docs
This commit is contained in:
3
active/podman_keycloak/compose/README.md
Normal file
3
active/podman_keycloak/compose/README.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Compose
|
||||||
|
|
||||||
|
Put your compose.yaml here.
|
||||||
19
active/podman_keycloak/compose/compose.yaml
Normal file
19
active/podman_keycloak/compose/compose.yaml
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
services:
|
||||||
|
keycloak:
|
||||||
|
container_name: keycloak
|
||||||
|
restart: always
|
||||||
|
image: quay.io/keycloak/keycloak:26.4.5
|
||||||
|
ports:
|
||||||
|
- "9443:443"
|
||||||
|
- "8443:8443"
|
||||||
|
volumes:
|
||||||
|
- /home/foobar/data:/var/app/data
|
||||||
|
security_opt:
|
||||||
|
- label=disable
|
||||||
|
userns_mode: keep-id
|
||||||
|
command:
|
||||||
|
- "start"
|
||||||
|
- "--hostname"
|
||||||
|
- "https://keycloak.reeseapps.com"
|
||||||
|
- "--hostname-admin"
|
||||||
|
- "https://keycloak.reeselink.com:8443"
|
||||||
186
active/podman_keycloak/keycloak.md
Normal file
186
active/podman_keycloak/keycloak.md
Normal file
@@ -0,0 +1,186 @@
|
|||||||
|
# Podman keycloak
|
||||||
|
|
||||||
|
- [Podman keycloak](#podman-keycloak)
|
||||||
|
- [Setup keycloak Project](#setup-keycloak-project)
|
||||||
|
- [Install Keycloak with Docker](#install-keycloak-with-docker)
|
||||||
|
- [Install Keycloak with Podman](#install-keycloak-with-podman)
|
||||||
|
- [Create the keycloak user](#create-the-keycloak-user)
|
||||||
|
- [Write the keycloak compose spec](#write-the-keycloak-compose-spec)
|
||||||
|
- [A Note on Volumes](#a-note-on-volumes)
|
||||||
|
- [Convert keycloak compose spec to quadlets](#convert-keycloak-compose-spec-to-quadlets)
|
||||||
|
- [Create any container-mounted directories](#create-any-container-mounted-directories)
|
||||||
|
- [Start and enable your systemd quadlet](#start-and-enable-your-systemd-quadlet)
|
||||||
|
- [Expose keycloak](#expose-keycloak)
|
||||||
|
- [firewalld](#firewalld)
|
||||||
|
- [Backup keycloak](#backup-keycloak)
|
||||||
|
- [Upgrade keycloak](#upgrade-keycloak)
|
||||||
|
- [Upgrade Quadlets](#upgrade-quadlets)
|
||||||
|
- [Uninstall](#uninstall)
|
||||||
|
- [Notes](#notes)
|
||||||
|
- [SELinux](#selinux)
|
||||||
|
|
||||||
|
## Setup keycloak Project
|
||||||
|
|
||||||
|
- [ ] Copy and rename this folder to active/podman_keycloak
|
||||||
|
- [ ] Find and replace keycloak with the name of the service.
|
||||||
|
- [ ] Create the rootless user to run the podman containers
|
||||||
|
- [ ] Write the compose.yaml spec for your service
|
||||||
|
- [ ] Convert the compose.yaml spec to a quadlet
|
||||||
|
- [ ] Install the quadlet on the podman server
|
||||||
|
- [ ] Expose the quadlet service
|
||||||
|
- [ ] Install a backup service and timer
|
||||||
|
|
||||||
|
## Install Keycloak with Docker
|
||||||
|
|
||||||
|
<https://www.keycloak.org/getting-started/getting-started-docker>
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Test in dev mode
|
||||||
|
docker run -p 8080:8080 -e KC_BOOTSTRAP_ADMIN_USERNAME=admin -e KC_BOOTSTRAP_ADMIN_PASSWORD=admin quay.io/keycloak/keycloak:26.4.7 start-dev
|
||||||
|
```
|
||||||
|
|
||||||
|
## Install Keycloak with Podman
|
||||||
|
|
||||||
|
### Create the keycloak user
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# SSH into your podman server as root
|
||||||
|
useradd keycloak
|
||||||
|
loginctl enable-linger $(id -u keycloak)
|
||||||
|
systemctl --user --machine=keycloak@.host enable podman-restart
|
||||||
|
systemctl --user --machine=keycloak@.host enable --now podman.socket
|
||||||
|
mkdir -p /home/keycloak/.config/containers/systemd
|
||||||
|
```
|
||||||
|
|
||||||
|
### Write the keycloak compose spec
|
||||||
|
|
||||||
|
<https://www.keycloak.org/getting-started/getting-started-podman>
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Based on the example
|
||||||
|
podman run \
|
||||||
|
-p 127.0.0.1:8080:8080 \
|
||||||
|
-e KC_BOOTSTRAP_ADMIN_USERNAME=admin \
|
||||||
|
-e KC_BOOTSTRAP_ADMIN_PASSWORD=admin \
|
||||||
|
quay.io/keycloak/keycloak:26.4.5 start-dev
|
||||||
|
```
|
||||||
|
|
||||||
|
#### A Note on Volumes
|
||||||
|
|
||||||
|
Named volumes are stored at `/home/keycloak/.local/share/containers/storage/volumes/`.
|
||||||
|
|
||||||
|
### Convert keycloak compose spec to quadlets
|
||||||
|
|
||||||
|
Run the following to convert a compose.yaml into the various `.container` files for systemd:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Generate the systemd service
|
||||||
|
podman run \
|
||||||
|
--security-opt label=disable \
|
||||||
|
--rm \
|
||||||
|
-v $(pwd)/active/podman_keycloak/:/compose \
|
||||||
|
-v $(pwd)/active/podman_keycloak/quadlets:/quadlets \
|
||||||
|
quay.io/k9withabone/podlet \
|
||||||
|
-f /quadlets \
|
||||||
|
-i \
|
||||||
|
--overwrite \
|
||||||
|
compose /compose/compose.yaml
|
||||||
|
|
||||||
|
# Copy the files to the server
|
||||||
|
export PODMAN_SERVER=
|
||||||
|
scp -r active/podman_keycloak/quadlets/. $PODMAN_SERVER:/home/keycloak/.config/containers/systemd/
|
||||||
|
ssh $PODMAN_SERVER chown -R keycloak:keycloak /home/keycloak/.config/containers/systemd/
|
||||||
|
```
|
||||||
|
|
||||||
|
### Create any container-mounted directories
|
||||||
|
|
||||||
|
SSH into your podman server as root:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
machinectl shell keycloak@
|
||||||
|
podman unshare
|
||||||
|
mkdir some_volume
|
||||||
|
# Chown to the namespaced user with UID 1000
|
||||||
|
# This will be some really obscure UID outside the namespace
|
||||||
|
# This will also solve most permission denied errors
|
||||||
|
chown -R 1000:1000 some_volume
|
||||||
|
```
|
||||||
|
|
||||||
|
### Start and enable your systemd quadlet
|
||||||
|
|
||||||
|
SSH into your podman server as root:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
machinectl shell keycloak@
|
||||||
|
systemctl --user daemon-reload
|
||||||
|
systemctl --user restart keycloak
|
||||||
|
# Enable auto-update service which will pull new container images automatically every day
|
||||||
|
systemctl --user enable --now podman-auto-update.timer
|
||||||
|
```
|
||||||
|
|
||||||
|
### Expose keycloak
|
||||||
|
|
||||||
|
1. If you need a domain, follow the [DDNS instructions](/active/podman_ddns/ddns.md#install-a-new-ddns-service)
|
||||||
|
2. For a web service, follow the [Caddy instructions](/active/podman_caddy/caddy.md#adding-a-new-caddy-record)
|
||||||
|
3. Finally, follow your OS's guide for opening ports via its firewall service.
|
||||||
|
|
||||||
|
#### firewalld
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# command to get current active zone and default zone
|
||||||
|
firewall-cmd --get-active-zones
|
||||||
|
firewall-cmd --get-default-zone
|
||||||
|
|
||||||
|
# command to open 443 on tcp
|
||||||
|
firewall-cmd --permanent --zone=<zone> --add-port=443/tcp
|
||||||
|
|
||||||
|
# command to open 80 and 443 on tcp and udp
|
||||||
|
firewall-cmd --permanent --zone=<zone> --add-port={80,443}/{tcp,udp}
|
||||||
|
|
||||||
|
# command to list available services and then open http and https
|
||||||
|
firewall-cmd --get-services
|
||||||
|
firewall-cmd --permanent --zone=<zone> --add-service={http,https}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Backup keycloak
|
||||||
|
|
||||||
|
Follow the [Borg Backup instructions](/active/systemd_borg/borg.md#set-up-a-client-for-backup)
|
||||||
|
|
||||||
|
## Upgrade keycloak
|
||||||
|
|
||||||
|
### Upgrade Quadlets
|
||||||
|
|
||||||
|
Upgrades should be a repeat of [writing the compose spec](#convert-keycloak-compose-spec-to-quadlets) and [installing the quadlets](#start-and-enable-your-systemd-quadlet)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
export PODMAN_SERVER=
|
||||||
|
scp -r quadlets/. $PODMAN_SERVER$:/home/keycloak/.config/containers/systemd/
|
||||||
|
ssh keycloak systemctl --user daemon-reload
|
||||||
|
ssh keycloak systemctl --user restart keycloak
|
||||||
|
```
|
||||||
|
|
||||||
|
## Uninstall
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Stop the user's services
|
||||||
|
systemctl --user disable podman-restart
|
||||||
|
podman container stop --all
|
||||||
|
systemctl --user disable --now podman.socket
|
||||||
|
systemctl --user disable --now podman-auto-update.timer
|
||||||
|
|
||||||
|
# Delete the user (this won't delete their home directory)
|
||||||
|
# userdel might spit out an error like:
|
||||||
|
# userdel: user keycloak is currently used by process 591255
|
||||||
|
# kill those processes and try again
|
||||||
|
userdel keycloak
|
||||||
|
```
|
||||||
|
|
||||||
|
## Notes
|
||||||
|
|
||||||
|
### SELinux
|
||||||
|
|
||||||
|
<https://blog.christophersmart.com/2021/01/31/podman-volumes-and-selinux/>
|
||||||
|
|
||||||
|
:z allows a container to share a mounted volume with all other containers.
|
||||||
|
|
||||||
|
:Z allows a container to reserve a mounted volume and prevents any other container from accessing.
|
||||||
3
active/podman_keycloak/quadlets/README.md
Normal file
3
active/podman_keycloak/quadlets/README.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Quadlets
|
||||||
|
|
||||||
|
Put your quadlets here.
|
||||||
Reference in New Issue
Block a user