Compare commits

..

1 Commits

Author SHA1 Message Date
bceab9d9f6 feat(hydra-cleaner): clean authentication_session table 2025-09-18 14:07:15 +02:00
4 changed files with 201 additions and 1 deletions

View File

@@ -16,10 +16,13 @@ set -o nounset
# -> delete "cascade" on table "flow" cleans access, code, oidc, pkce and refresh tables.
# For table authentication_session, a simple delete on this table is enough.
# Delete all rows without reference from table flow (foreign key)
DSN="${DSN:-postgresql://${HYDRA_DATABASE_USER}:${HYDRA_DATABASE_PASSWORD}@${HYDRA_DATABASE_SERVICE_NAME}:${HYDRA_DATABASE_SERVICE_PORT:-5432}/hydra?sslmode=disable}"
RETENTION_HOURS="${RETENTION_HOURS:-48}"
BATCH_SIZE="${BATCH_SIZE:-50}"
BATCH_SIZE_ORIG="${BATCH_SIZE}"
LIMIT="${LIMIT:-1000}"
BEFORE_DATE="$(date +'%Y-%m-%d %H:%M:%S' --date=@$(($(date +%s) - RETENTION_HOURS * 3600)))"
@@ -66,6 +69,9 @@ where table_schema = 'public'
order by 4 desc;
EOF
### Flow table
log "Cleaning flow table..."
REMAINING_ELMTS="${LIMIT}"
while [ "${REMAINING_ELMTS}" -gt 0 ]; do
@@ -86,7 +92,7 @@ EOF
log "${OUTPUT}"
if ! [[ "${OUTPUT}" =~ '^DELETE ' ]] ; then
log "Output doesn't seems OK..."
log "Output doesn't seem OK..."
break
fi
OUTPUT_NB=$(echo "${OUTPUT}" | cut -d' ' -f 2)
@@ -101,6 +107,75 @@ EOF
fi
done
### Authentication session table
log "Cleaning authentication_session table..."
BATCH_SIZE="${BATCH_SIZE_ORIG}"
REMAINING_ELMTS="${LIMIT}"
OUTPUT=$(psql "${DSN}" <<EOF
DO \$\$
BEGIN
DROP TABLE IF EXISTS hydra_cleaner.hydra_childless_auth_session;
DROP SCHEMA IF EXISTS hydra_cleaner;
CREATE SCHEMA hydra_cleaner;
CREATE TABLE hydra_cleaner.hydra_childless_auth_session AS
SELECT id
FROM hydra_oauth2_authentication_session
WHERE NOT EXISTS (
SELECT 1
FROM hydra_oauth2_flow
WHERE hydra_oauth2_authentication_session.id = hydra_oauth2_flow.login_session_id
)
LIMIT ${REMAINING_ELMTS};
END \$\$;
EOF
)
log "${OUTPUT}"
while [ "${REMAINING_ELMTS}" -gt 0 ]; do
OUTPUT=$(psql "${DSN}" <<EOF
WITH childless_auth_session_batch AS (
SELECT id
FROM hydra_cleaner.hydra_childless_auth_session
LIMIT ${BATCH_SIZE}
),
auth_session_deleted AS (
DELETE
FROM hydra_oauth2_authentication_session
WHERE hydra_oauth2_authentication_session.id IN (SELECT * FROM childless_auth_session_batch)
AND NOT EXISTS (
SELECT 1
FROM hydra_oauth2_flow
WHERE hydra_oauth2_authentication_session.id = hydra_oauth2_flow.login_session_id
)
)
DELETE
FROM hydra_cleaner.hydra_childless_auth_session
WHERE hydra_cleaner.hydra_childless_auth_session.id IN (SELECT * FROM childless_auth_session_batch);
EOF
)
log "${OUTPUT}"
if ! [[ "${OUTPUT}" =~ '^DELETE ' ]] ; then
log "Output doesn't seem OK..."
break
fi
OUTPUT_NB=$(echo "${OUTPUT}" | cut -d' ' -f 2)
if [ "${OUTPUT_NB}" -lt "${BATCH_SIZE}" ]; then
break
fi
REMAINING_ELMTS=$((REMAINING_ELMTS - BATCH_SIZE))
if [ "${REMAINING_ELMTS}" -lt "${BATCH_SIZE}" ]; then
BATCH_SIZE="${REMAINING_ELMTS}"
fi
done
log "Final estimated size:"
psql "${DSN}" <<EOF

View File

@@ -17,6 +17,43 @@ spec:
app.kubernetes.io/name: hydra-oidc
spec:
containers:
- name: hydra-oidc-php-fpm
image: reg.cadoles.com/cadoles/hydra-oidc-base:2025.6.13-develop.1333.aa5c382
imagePullPolicy: IfNotPresent
args: ["/usr/sbin/php-fpm81", "-F", "-e"]
readinessProbe:
exec:
command:
- sh
- -c
- test -f /etc/php81/php-fpm.d/www.conf
livenessProbe:
exec:
command:
- php
- bin/console
- -V
initialDelaySeconds: 10
periodSeconds: 30
env:
- name: PHP_FPM_LISTEN
value: 127.0.0.1:9000
- name: PHP_MEMORY_LIMIT
value: 128m
- name: PHP_FPM_MEMORY_LIMIT
value: 128m
envFrom:
- configMapRef:
name: hydra-oidc-env
volumeMounts:
- name: oidc-tmp
mountPath: /tmp
resources: {}
securityContext:
runAsNonRoot: true
runAsGroup: 1000
runAsUser: 1000
- name: hydra-oidc-caddy
image: reg.cadoles.com/cadoles/hydra-oidc-base:2025.6.13-develop.1333.aa5c382
imagePullPolicy: IfNotPresent

View File

@@ -20,6 +20,52 @@ spec:
app.kubernetes.io/name: hydra-sql
spec:
containers:
- name: hydra-sql-fpm
image: reg.cadoles.com/cadoles/hydra-sql-base:2025.7.30-develop.1146.5f2654c
imagePullPolicy: IfNotPresent
args: ["/usr/sbin/php-fpm84", "-F", "-e"]
readinessProbe:
exec:
command:
- sh
- -c
- test -f /etc/php84/php-fpm.d/www.conf
livenessProbe:
exec:
command:
- php
- bin/console
- -V
initialDelaySeconds: 10
periodSeconds: 30
resources: {}
securityContext:
runAsNonRoot: true
runAsGroup: 1000
runAsUser: 1000
envFrom:
- configMapRef:
name: hydra-sql-env
env:
- name: PHP_FPM_LISTEN
value: 127.0.0.1:9000
- name: PHP_MEMORY_LIMIT
value: 128m
- name: PHP_FPM_MEMORY_LIMIT
value: 128m
- name: PHP_FPM_LOG_LEVEL
value: warning
- name: OPCACHE_VALIDATE_TIMESTAMP
value: "0"
- name: OPCACHE_REVALIDATE_FREQ
value: "0"
volumeMounts:
- name: hydra-sql-php-ini
mountPath: /etc/php84/conf.d/03_base.ini
subPath: 03_base.ini
- name: sql-tmp
mountPath: /tmp
- name: hydra-sql-caddy
image: reg.cadoles.com/cadoles/hydra-sql-base:2025.7.30-develop.1146.5f2654c
imagePullPolicy: IfNotPresent

View File

@@ -18,6 +18,48 @@ spec:
app.kubernetes.io/name: hydra-dispatcher
spec:
containers:
- name: hydra-dispatcher-php-fpm
image: reg.cadoles.com/cadoles/hydra-dispatcher-base:2025.8.28-develop.1505.75881cb
args: ["/usr/sbin/php-fpm84", "-F", "-e"]
readinessProbe:
exec:
command:
- sh
- -c
- test -f /etc/php84/php-fpm.d/www.conf
livenessProbe:
exec:
command:
- php
- bin/console
- -V
initialDelaySeconds: 10
periodSeconds: 30
env:
- name: PHP_FPM_LISTEN
value: 127.0.0.1:9000
- name: PHP_MEMORY_LIMIT
value: 128m
- name: PHP_FPM_MEMORY_LIMIT
value: 128m
- name: OPCACHE_VALIDATE_TIMESTAMP
value: "0"
- name: OPCACHE_REVALIDATE_FREQ
value: "0"
envFrom:
- configMapRef:
name: hydra-dispatcher-env
volumeMounts:
- name: hydra-dispatcher-php-ini
mountPath: /etc/php84/conf.d/03_base.ini
subPath: 03_base.ini
- name: dispatcher-tmp
mountPath: /tmp
resources: {}
securityContext:
runAsNonRoot: true
runAsGroup: 1000
runAsUser: 1000
- name: hydra-dispatcher-caddy
image: reg.cadoles.com/cadoles/hydra-dispatcher-base:2025.8.28-develop.1505.75881cb
imagePullPolicy: IfNotPresent