refactor!(keycloak): use podman quadlet setup
This commit is contained in:
parent
476660fd65
commit
d2e0f53ca0
13 changed files with 319 additions and 289 deletions
|
@ -1,25 +1,17 @@
|
||||||
---
|
- name: Install Keycloak.
|
||||||
# Infrastructure
|
|
||||||
# Ansible instructions to deploy the infrastructure
|
|
||||||
# Copyright (C) 2019-2020 Christoph (Sheogorath) Kern
|
|
||||||
# Copyright (C) 2020 Saibotk
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, version 3 of the License.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
- name: Install & configure Keycloak
|
|
||||||
hosts: keycloak
|
hosts: keycloak
|
||||||
|
|
||||||
roles:
|
roles:
|
||||||
- docker
|
- role: podman
|
||||||
- docker_cleanup
|
become: true
|
||||||
- traefik
|
tags:
|
||||||
- keycloak
|
- always
|
||||||
|
- podman
|
||||||
|
- role: caddy
|
||||||
|
become: true
|
||||||
|
tags:
|
||||||
|
- always
|
||||||
|
- caddy
|
||||||
|
- role: keycloak
|
||||||
|
become: true
|
||||||
|
|
|
@ -1,35 +0,0 @@
|
||||||
Keycloak
|
|
||||||
=========
|
|
||||||
|
|
||||||
This will setup a [Keycloak](https://www.keycloak.org) instance using their official docker container and traefik as a reverse proxy.
|
|
||||||
|
|
||||||
Requirements
|
|
||||||
------------
|
|
||||||
|
|
||||||
You will need to have docker, docker-compose and traefik installed or declared as dependencies with their respective roles.
|
|
||||||
|
|
||||||
**This role assumes that you have setup traefik with an endpoint called `websecure`.**
|
|
||||||
|
|
||||||
Role Variables
|
|
||||||
--------------
|
|
||||||
|
|
||||||
**Please look at the [defaults/main.yml](defaults/main.yml) for all available variables and their description.**
|
|
||||||
|
|
||||||
**Note: Lines that are commented out via `#` are usually still valid/used variables, but they are not defined by default, so they might enable a feature, when uncommenting/defining them!**
|
|
||||||
|
|
||||||
### Global variables, that are used:
|
|
||||||
|
|
||||||
- `proxy_network`: Defined by the local traefik installation, this is the shared proxy network used by traefik to reach the containers. (optional)
|
|
||||||
- `proxy_hiddenservice`: Defined by the local traefik installation, this is used to generate the alt-svc header for the alternative Tor domain. (optional)
|
|
||||||
|
|
||||||
Dependencies
|
|
||||||
------------
|
|
||||||
|
|
||||||
- docker
|
|
||||||
- docker-compose
|
|
||||||
- traefik
|
|
||||||
|
|
||||||
License
|
|
||||||
-------
|
|
||||||
|
|
||||||
GPL-3.0-only
|
|
|
@ -1,58 +1,41 @@
|
||||||
---
|
keycloak_install_dir: "/opt/keycloak"
|
||||||
# Default variables for the keycloak role
|
|
||||||
|
|
||||||
# Infrastructure
|
keycloak_domains:
|
||||||
# Ansible instructions to deploy the infrastructure
|
- keycloak.example.com
|
||||||
# Copyright (C) 2019-2020 Christoph (Sheogorath) Kern
|
- keycloak2.example.com
|
||||||
# Copyright (C) 2020 Alexander Wellbrock
|
|
||||||
# Copyright (C) 2020 Saibotk
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, version 3 of the License.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
# Install locations
|
keycloak_containerimage: quay.io/keycloak/keycloak
|
||||||
keycloak_install_location: /srv/keycloak
|
|
||||||
keycloak_database_location: "{{ keycloak_install_location }}/database"
|
|
||||||
|
|
||||||
# The keycloak image to use
|
|
||||||
keycloak_baseimage: quay.io/keycloak/keycloak
|
|
||||||
|
|
||||||
# The keycloak & postgres version
|
|
||||||
# !!! Don't just update the postgres version, instead backup first and check if you need to migrate !!!
|
|
||||||
# renovate: depName=quay.io/keycloak/keycloak
|
# renovate: depName=quay.io/keycloak/keycloak
|
||||||
keycloak_version: 26.0.5
|
keycloak_image_tag: "26.1.0"
|
||||||
|
|
||||||
|
keycloak_postgres_containerimage: docker.io/library/postgres
|
||||||
# renovate: depName=docker.io/library/postgres
|
# renovate: depName=docker.io/library/postgres
|
||||||
keycloak_postgres_version: 17.0
|
keycloak_postgres_image_tag: "17.2-alpine"
|
||||||
|
|
||||||
# The image tags
|
keycloak_selinux_level: "{{ omit }}"
|
||||||
keycloak_image_version: "{{ keycloak_version }}"
|
|
||||||
keycloak_postgres_image_version: "{{ keycloak_postgres_version }}-alpine"
|
|
||||||
|
|
||||||
# The log level settings for keycloak
|
# Default JVM params of Keycloak need at least 512mb of ram
|
||||||
keycloak_log_level: "ERROR"
|
keycloak_memory_low: 512m
|
||||||
keycloak_root_log_level: "ERROR"
|
keycloak_memory_high: 0
|
||||||
|
keycloak_swap_max: -1
|
||||||
|
|
||||||
# The certresolver traefik should use for this domain
|
keycloak_postgres_memory_low: 256m
|
||||||
keycloak_traefik_certresolver: letsencrypt_http
|
keycloak_postgres_memory_high: 0
|
||||||
|
keycloak_postgres_swap_max: -1
|
||||||
|
|
||||||
# The domain which traefik will serve keycloak under
|
keycloak_database_password: "{{ lookup('passwordstore', 'keycloak.example.com/database create=true') }}"
|
||||||
keycloak_domain: keycloak.example.com
|
|
||||||
|
|
||||||
# The database credentials.
|
keycloak_environment_vars:
|
||||||
keycloak_database_user: "keycloak"
|
KC_HOSTNAME_STRICT: "true"
|
||||||
keycloak_database_password: "{{ lookup('passwordstore', keycloak_domain + '/database' + ' create=true') }}"
|
# Unless you include 'https://' HTTPS won't be enforced
|
||||||
|
KC_HOSTNAME: "https://{{ keycloak_domains | first }}"
|
||||||
|
KC_LOG_LEVEL: ERROR
|
||||||
|
KC_DB_URL_HOST: keycloak-postgres
|
||||||
|
KC_DB_URL_DATABASE: keycloak
|
||||||
|
KC_DB_USERNAME: "keycloak"
|
||||||
|
KC_DB_PASSWORD: "{{ keycloak_database_password }}"
|
||||||
|
|
||||||
# The default welcome theme keycloak will use
|
keycloak_postgres_environment_vars:
|
||||||
keycloak_theme_welcome: "{{ omit }}"
|
POSTGRES_DB: "keycloak"
|
||||||
|
POSTGRES_USER: "keycloak"
|
||||||
# The SELinux level that should be used for the postgres data folder/container
|
POSTGRES_PASSWORD: "{{ keycloak_database_password }}"
|
||||||
keycloak_postgres_selinux_level: "{{ omit }}"
|
|
||||||
|
|
25
roles/keycloak/handlers/main.yml
Normal file
25
roles/keycloak/handlers/main.yml
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
- name: Apply new SELinux file context to filesystem.
|
||||||
|
ansible.builtin.command: "restorecon -irF {{ keycloak_install_dir }}"
|
||||||
|
become: true
|
||||||
|
listen: "keycloak selinux context changed"
|
||||||
|
|
||||||
|
- name: Restart keycloak service.
|
||||||
|
ansible.builtin.systemd:
|
||||||
|
state: restarted
|
||||||
|
name: keycloak.service
|
||||||
|
daemon_reload: true
|
||||||
|
become: true
|
||||||
|
listen:
|
||||||
|
- "keycloak service changed"
|
||||||
|
- "keycloak network changed"
|
||||||
|
|
||||||
|
- name: Restart keycloak postgres service.
|
||||||
|
ansible.builtin.systemd:
|
||||||
|
state: restarted
|
||||||
|
name: keycloak-postgres.service
|
||||||
|
daemon_reload: true
|
||||||
|
become: true
|
||||||
|
listen:
|
||||||
|
- "keycloak postgres service changed"
|
||||||
|
- "keycloak selinux context changed"
|
||||||
|
- "keycloak network changed"
|
|
@ -1,44 +1,21 @@
|
||||||
galaxy_info:
|
galaxy_info:
|
||||||
author: saibotk
|
author: histalek
|
||||||
description: "Installs Keycloak via the official container and traefik."
|
description: Deploy keycloak with podman and systemd.
|
||||||
|
|
||||||
|
issue_tracker_url: https://git.histalek.de/histalek-de/infrastructure/-/issues
|
||||||
|
|
||||||
license: GPL-3.0-only
|
license: GPL-3.0-only
|
||||||
min_ansible_version: "2.9"
|
|
||||||
standalone: true
|
min_ansible_version: "2.10"
|
||||||
|
|
||||||
platforms:
|
platforms:
|
||||||
- name: EL
|
|
||||||
versions:
|
|
||||||
- all
|
|
||||||
- name: GenericUNIX
|
|
||||||
versions:
|
|
||||||
- all
|
|
||||||
- name: Fedora
|
- name: Fedora
|
||||||
versions:
|
versions:
|
||||||
- all
|
- "39"
|
||||||
- name: opensuse
|
- "40"
|
||||||
versions:
|
|
||||||
- all
|
standalone: true
|
||||||
- name: GenericBSD
|
|
||||||
versions:
|
|
||||||
- all
|
|
||||||
- name: FreeBSD
|
|
||||||
versions:
|
|
||||||
- all
|
|
||||||
- name: Ubuntu
|
|
||||||
versions:
|
|
||||||
- all
|
|
||||||
- name: SLES
|
|
||||||
versions:
|
|
||||||
- all
|
|
||||||
- name: GenericLinux
|
|
||||||
versions:
|
|
||||||
- all
|
|
||||||
- name: Debian
|
|
||||||
versions:
|
|
||||||
- all
|
|
||||||
|
|
||||||
galaxy_tags: []
|
galaxy_tags: []
|
||||||
|
|
||||||
dependencies:
|
dependencies: []
|
||||||
- role: docker
|
|
||||||
- role: traefik
|
|
||||||
|
|
|
@ -1,78 +1,132 @@
|
||||||
---
|
|
||||||
# Tasks file for the keycloak role
|
|
||||||
|
|
||||||
# Infrastructure
|
|
||||||
# Ansible instructions to deploy the infrastructure
|
|
||||||
# Copyright (C) 2019-2020 Christoph (Sheogorath) Kern
|
|
||||||
# Copyright (C) 2020 Alexander Wellbrock
|
|
||||||
# Copyright (C) 2020 Saibotk
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, version 3 of the License.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
- name: Update default SELinux contexts
|
- name: Update default SELinux contexts
|
||||||
community.general.sefcontext:
|
community.general.sefcontext:
|
||||||
target: "{{ item }}(/.*)?"
|
target: "{{ keycloak_install_dir }}/postgres(/.*)?"
|
||||||
setype: "container_file_t"
|
setype: "container_file_t"
|
||||||
selevel: "{{ keycloak_postgres_selinux_level }}"
|
selevel: "{{ keycloak_selinux_level }}"
|
||||||
state: present
|
state: present
|
||||||
with_items:
|
|
||||||
- "{{ keycloak_database_location }}"
|
|
||||||
become: true
|
become: true
|
||||||
|
notify: "keycloak selinux context changed"
|
||||||
|
|
||||||
- name: Create install directory
|
- name: Create keycloak directories.
|
||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
path: "{{ item }}"
|
path: "{{ keycloak_install_dir }}"
|
||||||
state: directory
|
|
||||||
mode: "0700"
|
|
||||||
owner: "root"
|
owner: "root"
|
||||||
group: "root"
|
group: "root"
|
||||||
with_items:
|
|
||||||
- "{{ keycloak_install_location }}"
|
|
||||||
tags:
|
|
||||||
- keycloak
|
|
||||||
become: true
|
|
||||||
|
|
||||||
- name: Create data directory
|
|
||||||
ansible.builtin.file: # noqa risky-file-permissions # Container manages permissions on its own
|
|
||||||
path: "{{ item }}"
|
|
||||||
state: directory
|
state: directory
|
||||||
setype: "container_file_t"
|
mode: "0700"
|
||||||
selevel: "{{ keycloak_postgres_selinux_level }}"
|
|
||||||
with_items:
|
|
||||||
- "{{ keycloak_database_location }}"
|
|
||||||
tags:
|
|
||||||
- keycloak
|
|
||||||
become: true
|
become: true
|
||||||
|
|
||||||
- name: Deploy docker-compose.yml
|
- name: Ensure keycloak postgres directory exists.
|
||||||
|
block:
|
||||||
|
- name: Stat keycloak postgres dir.
|
||||||
|
ansible.builtin.stat:
|
||||||
|
path: "{{ keycloak_install_dir }}/postgres"
|
||||||
|
become: true
|
||||||
|
register: keycloak_stat_postgres_dir
|
||||||
|
|
||||||
|
- name: Create keycloak postgres directory.
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ keycloak_install_dir }}/postgres"
|
||||||
|
owner: "{{ keycloak_stat_postgres_dir.stat.uid | default('root') }}"
|
||||||
|
group: "{{ keycloak_stat_postgres_dir.stat.gid | default('root') }}"
|
||||||
|
state: directory
|
||||||
|
mode: "0700"
|
||||||
|
setype: "container_file_t"
|
||||||
|
selevel: "{{ keycloak_selinux_level }}"
|
||||||
|
become: true
|
||||||
|
|
||||||
|
- name: Deploy keycloak environment file.
|
||||||
ansible.builtin.template:
|
ansible.builtin.template:
|
||||||
src: docker-compose.yml
|
src: keycloak.env.j2
|
||||||
dest: "{{ keycloak_install_location }}/docker-compose.yml"
|
dest: "{{ keycloak_install_dir }}/keycloak.env"
|
||||||
mode: "0600"
|
mode: "0600"
|
||||||
owner: "root"
|
owner: "root"
|
||||||
group: "root"
|
group: "root"
|
||||||
validate: docker compose -f %s config -q
|
become: true
|
||||||
tags:
|
notify: "keycloak service changed"
|
||||||
- docker
|
|
||||||
- keycloak
|
- name: Deploy keycloak postgres environment file.
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: keycloak-postgres.env.j2
|
||||||
|
dest: "{{ keycloak_install_dir }}/keycloak-postgres.env"
|
||||||
|
mode: "0600"
|
||||||
|
owner: "root"
|
||||||
|
group: "root"
|
||||||
|
become: true
|
||||||
|
notify: "keycloak postgres service changed"
|
||||||
|
|
||||||
|
- name: Ensure container image is present on the host.
|
||||||
|
containers.podman.podman_image:
|
||||||
|
name: "{{ item.name }}"
|
||||||
|
state: present
|
||||||
|
tag: "{{ item.tag }}"
|
||||||
|
loop:
|
||||||
|
- name: "{{ keycloak_containerimage }}"
|
||||||
|
tag: "{{ keycloak_image_tag }}"
|
||||||
|
- name: "{{ keycloak_postgres_containerimage }}"
|
||||||
|
tag: "{{ keycloak_postgres_image_tag }}"
|
||||||
become: true
|
become: true
|
||||||
|
|
||||||
- name: Compose keycloak
|
- name: Add caddy config file.
|
||||||
community.docker.docker_compose_v2:
|
block:
|
||||||
state: present
|
- name: Check caddy config dir.
|
||||||
project_src: "{{ keycloak_install_location }}"
|
ansible.builtin.stat:
|
||||||
pull: always
|
path: "{{ caddy_install_dir }}/config"
|
||||||
remove_orphans: true
|
become: true
|
||||||
tags:
|
register: caddy_stat_config_dir
|
||||||
- keycloak
|
|
||||||
|
- name: Template caddy config for keycloak.
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: keycloak.caddy.j2
|
||||||
|
dest: "{{ caddy_install_dir }}/config/keycloak.caddy"
|
||||||
|
mode: "0600"
|
||||||
|
setype: "container_file_t"
|
||||||
|
selevel: "{{ caddy_selinux_level }}"
|
||||||
|
owner: "{{ caddy_stat_config_dir.stat.uid }}"
|
||||||
|
group: "{{ caddy_stat_config_dir.stat.gid }}"
|
||||||
|
notify: "caddy config changed"
|
||||||
|
become: true
|
||||||
|
|
||||||
|
- name: Create keycloak container file.
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: keycloak.container.j2
|
||||||
|
dest: "/etc/containers/systemd/keycloak.container"
|
||||||
|
owner: "root"
|
||||||
|
group: "root"
|
||||||
|
mode: "0644"
|
||||||
|
become: true
|
||||||
|
notify: "keycloak service changed"
|
||||||
|
|
||||||
|
- name: Create keycloak postgres container file.
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: keycloak-postgres.container.j2
|
||||||
|
dest: "/etc/containers/systemd/keycloak-postgres.container"
|
||||||
|
owner: "root"
|
||||||
|
group: "root"
|
||||||
|
mode: "0644"
|
||||||
|
become: true
|
||||||
|
notify: "keycloak postgres service changed"
|
||||||
|
|
||||||
|
- name: Create keycloak network file.
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: keycloak.network.j2
|
||||||
|
dest: /etc/containers/systemd/keycloak.network
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: "0644"
|
||||||
|
become: true
|
||||||
|
notify: "keycloak network changed"
|
||||||
|
|
||||||
|
- name: Flush handlers
|
||||||
|
ansible.builtin.meta: flush_handlers
|
||||||
|
|
||||||
|
- name: Ensure keycloak services are started.
|
||||||
|
ansible.builtin.systemd:
|
||||||
|
state: started
|
||||||
|
enabled: true
|
||||||
|
name: "{{ item }}"
|
||||||
|
daemon_reload: true
|
||||||
|
loop:
|
||||||
|
- keycloak.service
|
||||||
|
- keycloak-postgres.service
|
||||||
become: true
|
become: true
|
||||||
|
|
|
@ -1,90 +0,0 @@
|
||||||
{{ ansible_managed | comment }}
|
|
||||||
|
|
||||||
# Infrastructure
|
|
||||||
# Ansible instructions to deploy the infrastructure
|
|
||||||
# Copyright (C) 2019-2020 Christoph (Sheogorath) Kern
|
|
||||||
# Copyright (C) 2020 Saibotk
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, version 3 of the License.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
version: '2'
|
|
||||||
services:
|
|
||||||
keycloak:
|
|
||||||
image: {{ keycloak_baseimage }}:{{ keycloak_image_version }}
|
|
||||||
mem_limit: 1gb
|
|
||||||
memswap_limit: 1280mb
|
|
||||||
security_opt:
|
|
||||||
- no-new-privileges
|
|
||||||
labels:
|
|
||||||
- "traefik.http.routers.keycloak.rule=Host(`{{ keycloak_domain }}`) && PathPrefix(`/`)"
|
|
||||||
- "traefik.http.routers.keycloak.entrypoints=websecure"
|
|
||||||
- "traefik.http.routers.keycloak.tls=true"
|
|
||||||
- "traefik.http.routers.keycloak.tls.certresolver={{ keycloak_traefik_certresolver }}"
|
|
||||||
- "traefik.http.routers.keycloak.middlewares=keycloak,compress"
|
|
||||||
- "traefik.http.middlewares.keycloak.headers.sslredirect=true"
|
|
||||||
- "traefik.http.middlewares.keycloak.headers.stsSeconds=63072000"
|
|
||||||
|
|
||||||
- "traefik.enable=true"
|
|
||||||
{% if proxy_network is defined %}
|
|
||||||
- "traefik.docker.network={{ proxy_network }}"
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
environment:
|
|
||||||
- "KC_PROXY_HEADERs=xforwarded"
|
|
||||||
- "KC_HTTP_ENABLED=true"
|
|
||||||
- "KC_FEATURES=scripts,persistent-user-sessions"
|
|
||||||
- "KC_HOSTNAME_STRICT=true"
|
|
||||||
- "KC_HOSTNAME=https://{{ keycloak_domain }}"
|
|
||||||
- "KC_LOGLEVEL={{ keycloak_log_level }}"
|
|
||||||
- "KC_DB_URL_HOST=database"
|
|
||||||
- "KC_DB_USERNAME={{ keycloak_database_user }}"
|
|
||||||
- "KC_DB_PASSWORD={{ keycloak_database_password }}"
|
|
||||||
networks:
|
|
||||||
backend:
|
|
||||||
{% if proxy_network is defined %}
|
|
||||||
{{ proxy_network }}:
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
command: ["start", "--db=postgres"{% if keycloak_theme_welcome != omit %}, "--spi-theme-welcome-theme={{ keycloak_theme_welcome }}"{% endif %}]
|
|
||||||
restart: always
|
|
||||||
|
|
||||||
database:
|
|
||||||
image: docker.io/library/postgres:{{ keycloak_postgres_image_version }}
|
|
||||||
mem_limit: 256mb
|
|
||||||
memswap_limit: 512mb
|
|
||||||
read_only: true
|
|
||||||
{% if keycloak_postgres_selinux_level != omit %}
|
|
||||||
security_opt:
|
|
||||||
- label=level:{{ keycloak_postgres_selinux_level }}
|
|
||||||
{% endif %}
|
|
||||||
tmpfs:
|
|
||||||
- /run/postgresql:size=512K
|
|
||||||
- /tmp:size=128K
|
|
||||||
stop_grace_period: 2m
|
|
||||||
stop_signal: SIGINT
|
|
||||||
environment:
|
|
||||||
- POSTGRES_USER={{ keycloak_database_user }}
|
|
||||||
- POSTGRES_PASSWORD={{ keycloak_database_password }}
|
|
||||||
volumes:
|
|
||||||
- ./database:/var/lib/postgresql/data
|
|
||||||
networks:
|
|
||||||
backend:
|
|
||||||
restart: always
|
|
||||||
|
|
||||||
networks:
|
|
||||||
backend:
|
|
||||||
internal: true
|
|
||||||
{% if proxy_network is defined %}
|
|
||||||
{{ proxy_network }}:
|
|
||||||
external: true
|
|
||||||
{% endif %}
|
|
42
roles/keycloak/templates/keycloak-postgres.container.j2
Normal file
42
roles/keycloak/templates/keycloak-postgres.container.j2
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
{{ ansible_managed | comment }}
|
||||||
|
|
||||||
|
[Unit]
|
||||||
|
Description = Postgres for keycloak
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Restart = always
|
||||||
|
RestartSec = 5s
|
||||||
|
|
||||||
|
[Container]
|
||||||
|
Image = {{ keycloak_postgres_containerimage }}:{{ keycloak_postgres_image_tag }}
|
||||||
|
ContainerName = keycloak-postgres
|
||||||
|
|
||||||
|
AutoUpdate = registry
|
||||||
|
LogDriver = journald
|
||||||
|
|
||||||
|
NoNewPrivileges = true
|
||||||
|
ReadOnly = true
|
||||||
|
DropCapability = all
|
||||||
|
AddCapability = CHOWN DAC_OVERRIDE SETUID SETGID
|
||||||
|
UserNS = auto:size=65535
|
||||||
|
{% if keycloak_selinux_level != omit %}
|
||||||
|
SecurityLabelLevel = {{ keycloak_selinux_level }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
Network = keycloak.network
|
||||||
|
ExposeHostPort = 5432
|
||||||
|
|
||||||
|
EnvironmentFile = {{ keycloak_install_dir }}/keycloak-postgres.env
|
||||||
|
|
||||||
|
Volume = {{ keycloak_install_dir }}/postgres:/var/lib/postgresql/data:U
|
||||||
|
Tmpfs = /run/postgresql:rw,noexec,nosuid,nodev,size=1m
|
||||||
|
Tmpfs = /tmp:rw,noexec,nosuid,nodev,size=50m
|
||||||
|
|
||||||
|
PodmanArgs = --memory={{ keycloak_postgres_memory_high }}
|
||||||
|
PodmanArgs = --memory-swap={{ keycloak_postgres_swap_max }}
|
||||||
|
PodmanArgs = --memory-reservation={{ keycloak_postgres_memory_low }}
|
||||||
|
|
||||||
|
PodmanArgs = --stop-signal=SIGINT
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy = default.target
|
7
roles/keycloak/templates/keycloak-postgres.env.j2
Normal file
7
roles/keycloak/templates/keycloak-postgres.env.j2
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{{ ansible_managed | comment}}
|
||||||
|
|
||||||
|
{% if keycloak_postgres_environment_vars is mapping %}
|
||||||
|
{% for key, value in keycloak_postgres_environment_vars.items() %}
|
||||||
|
{{ key }}={{ value }}
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
21
roles/keycloak/templates/keycloak.caddy.j2
Normal file
21
roles/keycloak/templates/keycloak.caddy.j2
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
{{ ansible_managed | comment }}
|
||||||
|
|
||||||
|
{{ keycloak_domains | join(', ') }} {
|
||||||
|
encode gzip
|
||||||
|
|
||||||
|
header {
|
||||||
|
# enable HSTS
|
||||||
|
Strict-Transport-Security "max-age=31536000; preload;"
|
||||||
|
|
||||||
|
# disable clients from sniffing the media type
|
||||||
|
X-Content-Type-Options nosniff
|
||||||
|
|
||||||
|
# keep referrer data off of HTTP connections
|
||||||
|
Referrer-Policy no-referrer-when-downgrade
|
||||||
|
|
||||||
|
# Server name removing
|
||||||
|
-Server
|
||||||
|
}
|
||||||
|
|
||||||
|
reverse_proxy keycloak:8080
|
||||||
|
}
|
40
roles/keycloak/templates/keycloak.container.j2
Normal file
40
roles/keycloak/templates/keycloak.container.j2
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
{{ ansible_managed | comment }}
|
||||||
|
|
||||||
|
[Unit]
|
||||||
|
Description = Keycloak Server
|
||||||
|
Requires = keycloak-postgres.service
|
||||||
|
After = keycloak-postgres.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Restart = always
|
||||||
|
RestartSec = 5s
|
||||||
|
|
||||||
|
[Container]
|
||||||
|
Image = {{ keycloak_containerimage }}:{{ keycloak_image_tag }}
|
||||||
|
ContainerName = keycloak
|
||||||
|
|
||||||
|
Exec = start \
|
||||||
|
--db=postgres \
|
||||||
|
--proxy-headers=xforwarded \
|
||||||
|
--http-enabled=true \
|
||||||
|
--features=persistent-user-sessions
|
||||||
|
|
||||||
|
AutoUpdate = registry
|
||||||
|
LogDriver = journald
|
||||||
|
|
||||||
|
NoNewPrivileges = true
|
||||||
|
DropCapability = all
|
||||||
|
UserNS = auto:size=65535
|
||||||
|
|
||||||
|
Network = keycloak.network
|
||||||
|
Network = caddy.network
|
||||||
|
ExposeHostPort = 8080
|
||||||
|
|
||||||
|
EnvironmentFile = {{ keycloak_install_dir }}/keycloak.env
|
||||||
|
|
||||||
|
PodmanArgs = --memory={{ keycloak_memory_high }}
|
||||||
|
PodmanArgs = --memory-swap={{ keycloak_swap_max }}
|
||||||
|
PodmanArgs = --memory-reservation={{ keycloak_memory_low }}
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy = default.target
|
7
roles/keycloak/templates/keycloak.env.j2
Normal file
7
roles/keycloak/templates/keycloak.env.j2
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{{ ansible_managed | comment}}
|
||||||
|
|
||||||
|
{% if keycloak_environment_vars is mapping %}
|
||||||
|
{% for key, value in keycloak_environment_vars.items() %}
|
||||||
|
{{ key }}={{ value }}
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
7
roles/keycloak/templates/keycloak.network.j2
Normal file
7
roles/keycloak/templates/keycloak.network.j2
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{{ ansible_managed | comment }}
|
||||||
|
|
||||||
|
[Network]
|
||||||
|
NetworkName = keycloak_internal
|
||||||
|
Driver = bridge
|
||||||
|
Internal = true
|
||||||
|
IPv6 = true
|
Loading…
Add table
Reference in a new issue