mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-12-06 01:40:19 +00:00
fix(web-app-phpmyadmin): share sessions and the cookie secret across replicas
Every replica kept its sessions in local files and generated its own blowfish_secret, so a login on one replica was unknown to the next one behind the load balancer. The role now builds its image with phpredis (pinned, tracked by git tags) and a zz-infinito-session.ini that stores sessions in redis with locking, its save path taken from PHPMYADMIN_SESSION_SAVE_PATH at runtime. A redis service joins the role (shared when svc-db-redis runs, dedicated in variant 1), and a per-deployment blowfish_secret (random_hex_32) is loaded with sodium_hex2bin in config.user.inc.php, which now ships whether or not the design is enabled. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a67dd9b372
commit
040c019ad6
8 files changed
+61
-2
No files matched your search
@@ -0,0 +1,21 @@
|
||||
ARG PHPMYADMIN_IMAGE
|
||||
ARG PHPMYADMIN_VERSION
|
||||
FROM ${PHPMYADMIN_IMAGE}:${PHPMYADMIN_VERSION}
|
||||
|
||||
ARG PHPMYADMIN_PHPREDIS_VERSION
|
||||
|
||||
RUN set -eu; \
|
||||
: "${PHPMYADMIN_PHPREDIS_VERSION:?}"; \
|
||||
pecl install "redis-${PHPMYADMIN_PHPREDIS_VERSION}"; \
|
||||
docker-php-ext-enable redis; \
|
||||
rm -rf /tmp/pear; \
|
||||
php -m | grep -qx redis
|
||||
|
||||
RUN set -eu; \
|
||||
printf '%s\n' \
|
||||
'session.save_handler = redis' \
|
||||
'session.save_path = "${PHPMYADMIN_SESSION_SAVE_PATH}"' \
|
||||
'redis.session.locking_enabled = 1' \
|
||||
'redis.session.lock_retries = -1' \
|
||||
> "${PHP_INI_DIR}/conf.d/zz-infinito-session.ini"; \
|
||||
test "$(PHPMYADMIN_SESSION_SAVE_PATH=tcp://probe:6379 php -r 'echo ini_get("session.save_handler"), " ", ini_get("session.save_path");')" = "redis tcp://probe:6379"
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
credentials:
|
||||
blowfish_secret:
|
||||
description: phpMyAdmin $cfg['blowfish_secret'] (hex-encoded 32 random bytes, decoded with sodium_hex2bin), one per deployment so a login cookie issued by
|
||||
one replica decrypts on every other
|
||||
algorithm: random_hex_32
|
||||
validation: ^[a-f0-9]{64}$
|
||||
@@ -16,6 +16,15 @@ mariadb:
|
||||
bond: 1
|
||||
enabled: true # nocheck: dynamic-flag
|
||||
shared: "{{ 'svc-db-mariadb' in group_names }}"
|
||||
# nocheck: playwright-service-flag — session store behind every request, no Playwright surface of its own
|
||||
redis:
|
||||
bond: 1
|
||||
backup:
|
||||
disabled: true
|
||||
enabled: true # nocheck: dynamic-flag
|
||||
shared: "{{ 'svc-db-redis' in group_names }}"
|
||||
cpus: "0.25"
|
||||
mem_reservation: 128m
|
||||
phpmyadmin:
|
||||
healthcheck:
|
||||
flavor: tcp
|
||||
@@ -27,6 +36,12 @@ phpmyadmin:
|
||||
version: 5.2.3
|
||||
name: phpmyadmin
|
||||
image: phpmyadmin
|
||||
custom: true
|
||||
phpredis_version: 6.3.0
|
||||
update:
|
||||
- key: phpredis_version
|
||||
type: git_tags
|
||||
repository: https://github.com/phpredis/phpredis.git
|
||||
min_storage: 422MB
|
||||
autologin: false
|
||||
ports:
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
shared: true
|
||||
mariadb:
|
||||
shared: true
|
||||
redis:
|
||||
shared: true
|
||||
matomo:
|
||||
enabled: true
|
||||
shared: true
|
||||
@@ -48,6 +50,8 @@
|
||||
shared: false
|
||||
mariadb:
|
||||
shared: false
|
||||
redis:
|
||||
shared: false
|
||||
matomo:
|
||||
enabled: false
|
||||
shared: false
|
||||
|
||||
@@ -2,6 +2,11 @@
|
||||
|
||||
{% set service_name = 'phpmyadmin' %}
|
||||
{{ service_name }}:
|
||||
{{ lookup('template', 'roles/sys-svc-container/templates/build.yml.j2') | indent(4) }}
|
||||
args:
|
||||
PHPMYADMIN_IMAGE: "{{ PHPMYADMIN_IMAGE }}"
|
||||
PHPMYADMIN_VERSION: "{{ PHPMYADMIN_VERSION }}"
|
||||
PHPMYADMIN_PHPREDIS_VERSION: "{{ PHPMYADMIN_PHPREDIS_VERSION }}"
|
||||
{{ lookup('container_image', application_id, 'phpmyadmin') }}
|
||||
{{ lookup('compose_only', 'container_name', PHPMYADMIN_CONTAINER) }}
|
||||
{% include 'roles/sys-svc-container/templates/base.yml.j2' %}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
$cfg['blowfish_secret'] = sodium_hex2bin('{{ PHPMYADMIN_BLOWFISH_SECRET }}');
|
||||
{% if PHPMYADMIN_DESIGN_ENABLED | bool %}
|
||||
{% set design = lookup('design', application_id) %}
|
||||
$cfg['ThemeDefault'] = '{{ PHPMYADMIN_THEME_NAME }}';
|
||||
{% if design.title is string %}
|
||||
@@ -8,3 +10,4 @@ $cfg['TitleServer'] = '@HTTP_HOST@ / @VSERVER@ | {{ title }}';
|
||||
$cfg['TitleDatabase'] = '@HTTP_HOST@ / @VSERVER@ / @DATABASE@ | {{ title }}';
|
||||
$cfg['TitleTable'] = '@HTTP_HOST@ / @VSERVER@ / @DATABASE@ / @TABLE@ | {{ title }}';
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
@@ -5,6 +5,5 @@ PMA_HOST={{ PHPMAYADMIN_DB_HOST }}
|
||||
PMA_USER={{ PHPMAYADMIN_ROOT_USER }}
|
||||
PMA_PASSWORD={{ PHPMAYADMIN_ROOT_PASSWORD | dotenv_quote }}
|
||||
{% endif %}
|
||||
{% if PHPMYADMIN_DESIGN_ENABLED | bool %}
|
||||
PMA_USER_CONFIG_BASE64={{ lookup('template', 'config.user.inc.php.j2') | b64encode }}
|
||||
{% endif %}
|
||||
PHPMYADMIN_SESSION_SAVE_PATH={{ PHPMYADMIN_SESSION_SAVE_PATH }}
|
||||
@@ -4,6 +4,11 @@ application_id: "web-app-phpmyadmin"
|
||||
database_host: "{{ lookup('config','svc-db-mariadb', 'services.mariadb.name') if lookup('database', application_id, 'shared') }}"
|
||||
|
||||
PHPMYADMIN_CONTAINER: "{{ lookup('config', application_id, 'services.phpmyadmin.name') }}"
|
||||
PHPMYADMIN_IMAGE: "{{ lookup('config', application_id, 'services.phpmyadmin.image') }}"
|
||||
PHPMYADMIN_VERSION: "{{ lookup('config', application_id, 'services.phpmyadmin.version') }}"
|
||||
PHPMYADMIN_PHPREDIS_VERSION: "{{ lookup('config', application_id, 'services.phpmyadmin.phpredis_version') }}"
|
||||
PHPMYADMIN_SESSION_SAVE_PATH: "{{ lookup('engine', 'redis', application_id, 'session_path') }}"
|
||||
PHPMYADMIN_BLOWFISH_SECRET: "{{ lookup('config', application_id, 'secrets.credentials.blowfish_secret') }}"
|
||||
PHPMAYADMIN_AUTOLOGIN_ENABLED: "{{ lookup('config', application_id, 'services.phpmyadmin.autologin') | bool }}"
|
||||
|
||||
PHPMAYADMIN_ROOT_PASSWORD: "{{ lookup('config','svc-db-mariadb', 'secrets.credentials.root_password') }}"
|
||||
|
||||
Reference in new issue
Block a user