Compare commits

...

14 Commits

Author SHA1 Message Date
a26b8aafe1 Merge pull request 'fix(hydra): use same liveness URL as ory's helm' (#63) from fix/hydra_liveness_probe_url into unstable
Reviewed-on: #63
Reviewed-by: wpetit <wpetit@cadoles.com>
Reviewed-by: pcaseiro <pcaseiro@cadoles.com>
2025-03-07 13:52:29 +01:00
06235bccad feat(hydra): disable logs about health requests by default 2025-03-07 12:29:46 +01:00
19039c5e1c feat(hydra): adding readiness and startup probes 2025-03-07 11:50:26 +01:00
9e02d7badb fix(hydra): use same liveness URL as ory's helm 2025-03-07 11:15:43 +01:00
87a056be2c Merge pull request 'feat(hydra-cleaner): add component' (#61) from f/hydra_cleaner into unstable
Reviewed-on: #61
Reviewed-by: wpetit <wpetit@cadoles.com>
2025-03-06 11:55:17 +01:00
fedf44a062 feat(hydra-cleaner): configurable dsn and hydra port 2025-03-06 10:12:18 +01:00
b0506995e5 feat: integrate hydra-cleaner in example app 2025-03-06 10:12:18 +01:00
7a09045e82 feat(hydra-cleaner): add component 2025-02-27 16:20:34 +01:00
f300b91316 Merge pull request 'feat(redis): manage limits' (#60) from feat/redis_limits into unstable
Reviewed-on: #60
2025-02-21 14:43:22 +01:00
30ba1f4d5a feat(redis): manage limits 2025-02-21 14:34:06 +01:00
d9bdbccfe4 Merge pull request 'fix(redis): fsGroup in security context is not applied' (#59) from fix/redis_fsgroup into unstable
Reviewed-on: #59
2025-02-19 14:55:24 +01:00
2d329501c0 fix(redis): fsGroup in security context is not applied
The fsGroup is not applied to configuration of the pod and it's disturbing
flux.
2025-02-19 14:43:25 +01:00
dc2c97c7f6 Merge pull request 'fix(hydra-ldap): adding behavior to secret and CM generators' (#57) from fix/hydra_ldap_flux into unstable
Reviewed-on: #57
2025-02-19 11:27:49 +01:00
c9d8917e6c fix(hydra-ldap): adding behavior to secret and CM generators 2025-02-19 11:22:36 +01:00
13 changed files with 260 additions and 2 deletions

View File

@ -0,0 +1,116 @@
#!/bin/sh
set -e
set -o nounset
# 4 tables to empty, at least
# oidc, code, flow, authentication_session
# \d hydra_oauth2_flow
#Referenced by:
# TABLE "hydra_oauth2_access" CONSTRAINT "hydra_oauth2_access_challenge_id_fk" FOREIGN KEY (challenge_id) REFERENCES hydra_oauth2_flow(consent_challenge_id) ON DELETE CASCADE
# TABLE "hydra_oauth2_code" CONSTRAINT "hydra_oauth2_code_challenge_id_fk" FOREIGN KEY (challenge_id) REFERENCES hydra_oauth2_flow(consent_challenge_id) ON DELETE CASCADE
# TABLE "hydra_oauth2_oidc" CONSTRAINT "hydra_oauth2_oidc_challenge_id_fk" FOREIGN KEY (challenge_id) REFERENCES hydra_oauth2_flow(consent_challenge_id) ON DELETE CASCADE
# TABLE "hydra_oauth2_pkce" CONSTRAINT "hydra_oauth2_pkce_challenge_id_fk" FOREIGN KEY (challenge_id) REFERENCES hydra_oauth2_flow(consent_challenge_id) ON DELETE CASCADE
# TABLE "hydra_oauth2_refresh" CONSTRAINT "hydra_oauth2_refresh_challenge_id_fk" FOREIGN KEY (challenge_id) REFERENCES hydra_oauth2_flow(consent_challenge_id) ON DELETE CASCADE
# -> delete "cascade" on table "flow" cleans access, code, oidc, pkce and refresh tables.
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}"
LIMIT="${LIMIT:-1000}"
BEFORE_DATE="$(date +'%Y-%m-%d %H:%M:%S' --date=@$(($(date +%s) - RETENTION_HOURS * 3600)))"
log() {
echo "$(date +'%d-%m-%y %H:%M:%S%z')| $1"
}
perror() {
log "Something went wrong, exiting."
trap - EXIT
exit 1
}
trap perror EXIT
if ! [[ ${RETENTION_HOURS} =~ '^[0-9]+$' ]]; then
log "Error: variable RETENTION_HOURS is not a positive integer."
perror
fi
if ! [[ ${LIMIT} =~ '^[0-9]+$' ]]; then
log "Error: variable LIMIT is not a positive integer."
perror
fi
if ! [[ ${BATCH_SIZE} =~ '^[0-9]+$' ]]; then
log "Error: variable BATCH_SIZE is not a positive integer."
perror
fi
log "Starting hydra cleaner"
log "Removing up to ${LIMIT} elements before ${BEFORE_DATE} by batch of ${BATCH_SIZE}"
log "Beginning estimated size:"
psql "${DSN}" <<EOF
select
table_name, reltuples as estimate,
pg_size_pretty(pg_total_relation_size(quote_ident(table_name))),
pg_total_relation_size(quote_ident(table_name))
from information_schema.tables left join pg_class on information_schema.tables.table_name=pg_class.relname
where table_schema = 'public'
order by 4 desc;
EOF
REMAINING_ELMTS="${LIMIT}"
while [ "${REMAINING_ELMTS}" -gt 0 ]; do
OUTPUT=$(psql "${DSN}" <<EOF
DELETE
FROM hydra_oauth2_flow
WHERE login_challenge = ANY (
array(
SELECT login_challenge
FROM hydra_oauth2_flow
WHERE requested_at < '${BEFORE_DATE}'
LIMIT ${BATCH_SIZE}
)
);
EOF
)
log "${OUTPUT}"
if ! [[ "${OUTPUT}" =~ '^DELETE ' ]] ; then
log "Output doesn't seems 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
select
table_name, reltuples as estimate,
pg_size_pretty(pg_total_relation_size(quote_ident(table_name))),
pg_total_relation_size(quote_ident(table_name))
from information_schema.tables left join pg_class on information_schema.tables.table_name=pg_class.relname
where table_schema = 'public'
order by 4 desc;
EOF
trap - EXIT

View File

@ -0,0 +1,17 @@
apiVersion: kustomize.config.k8s.io/v1alpha1
kind: Component
resources:
- ./resources/hydra-cleaner-cronjob.yaml
configMapGenerator:
- name: hydra-cleaner-env
behavior: create
literals:
- RETENTION_HOURS="48"
- BATCH_SIZE="100"
- LIMIT="1000"
- name: hydra-cleaner-script
behavior: create
files:
- ./files/hydra-cleaner.sh

View File

@ -0,0 +1,54 @@
apiVersion: batch/v1
kind: CronJob
metadata:
name: hydra-cleaner
labels:
app.kubernetes.io/name: hydra-cleaner
spec:
concurrencyPolicy: Forbid
schedule: "30 */1 * * *"
jobTemplate:
spec:
template:
metadata:
labels:
app.kubernetes.io/name: hydra-cleaner
spec:
restartPolicy: OnFailure
serviceAccountName: hydra-sa
containers:
- name: hydra-cleaner
image: reg.cadoles.com/proxy_cache/alpine/psql:17.4
envFrom:
- configMapRef:
name: hydra-env
- configMapRef:
name: hydra-cleaner-env
imagePullPolicy: IfNotPresent
command: ["/hydra-cleaner.sh"]
env:
- name: HYDRA_DATABASE_USER
valueFrom:
secretKeyRef:
name: hydra-postgres-app
key: username
- name: HYDRA_DATABASE_PASSWORD
valueFrom:
secretKeyRef:
name: hydra-postgres-app
key: password
- name: HYDRA_DATABASE_SERVICE_NAME
valueFrom:
secretKeyRef:
name: hydra-postgres-app
key: host
args: []
volumeMounts:
- name: hydra-cleaner-script
mountPath: "/hydra-cleaner.sh"
subPath: "hydra-cleaner.sh"
volumes:
- name: hydra-cleaner-script
configMap:
name: hydra-cleaner-script
defaultMode: 0544

View File

@ -7,6 +7,7 @@ resources:
configMapGenerator:
- name: hydra-ldap-env
behavior: create
literals:
- WERTHER_DEV_MODE=false
- WERTHER_LDAP_ROLE_CLAIM="https://hydra/claims/roles"
@ -21,6 +22,7 @@ configMapGenerator:
secretGenerator:
- name: hydra-ldap-sc
behavior: create
literals:
- WERTHER_LDAP_BINDDN="cn=reader,o=test,c=fr"
- WERTHER_LDAP_BINDPW=ThisMustBeAbsolutelyChanged

View File

@ -0,0 +1,5 @@
nameReference:
- kind: ConfigMap
fieldSpecs:
- kind: Redis
path: spec/redisConfig/additionalRedisConfig

View File

@ -0,0 +1,3 @@
maxmemory-policy allkeys-lru
maxmemory 1536mb
tcp-keepalive 90

View File

@ -1,9 +1,17 @@
apiVersion: kustomize.config.k8s.io/v1alpha1
kind: Component
configurations:
- ./configurations/redis-conf.yaml
resources:
- ./resources/redis-sso.yaml
configMapGenerator:
- name: redis-sso-extra-conf
files:
- ./files/redis-additional.conf
patches:
- path: ./patches/hydra-apps.yaml
target:

View File

@ -6,6 +6,15 @@ spec:
kubernetesConfig:
image: reg.cadoles.com/quay/opstree/redis:v7.0.15
imagePullPolicy: IfNotPresent
resources:
requests:
cpu: 500m
memory: 1024Mi
limits:
cpu: 2000m
memory: 2048Mi
redisConfig:
additionalRedisConfig: redis-sso-extra-conf
storage:
volumeClaimTemplate:
spec:
@ -16,4 +25,3 @@ spec:
storage: 1Gi
securityContext:
runAsUser: 1000
fsGroup: 1000

View File

@ -14,6 +14,7 @@ components:
- ../../components/hydra-ldap
- ../../components/oidc-test
- ../../components/redis
- ../../components/hydra-cleaner
patchesJson6902:
- target:
@ -51,6 +52,16 @@ patchesJson6902:
kind: OAuth2Client
name: oidc-test-oauth2-client
path: patches/oidc-test-oauth2-client.yaml
- target:
version: v1
kind: ConfigMap
name: hydra-cleaner-env
path: patches/hydra-cleaner-env.yaml
- target:
version: v1
kind: CronJob
name: hydra-cleaner
path: patches/hydra-cleaner.yaml
configMapGenerator:
- name: hydra-dispatcher-apps

View File

@ -0,0 +1,9 @@
- op: replace
path: "/data/RETENTION_HOURS"
value: "1" # 1 HOUR
- op: replace
path: "/data/BATCH_SIZE"
value: "100"
- op: replace
path: "/data/LIMIT"
value: "1000"

View File

@ -0,0 +1,3 @@
- op: replace
path: "/spec/schedule"
value: "* * * * *"

View File

@ -31,6 +31,7 @@ configMapGenerator:
- URLS_LOGOUT=http://hydra-logout-app/logout
- HYDRA_SERVE_ALL_ARGS=--dev
- HYDRA_DATABASE_MAX_CONN="10"
- SERVE_ADMIN_REQUEST_LOG_DISABLE_FOR_HEALTH="true"
- LOG_LEVEL=info
replacements:

View File

@ -46,10 +46,31 @@ spec:
- wget
- --spider
- -q
- http://127.0.0.1:4444/.well-known/openid-configuration
- http://127.0.0.1:4445/health/alive
failureThreshold: 6
periodSeconds: 10
timeoutSeconds: 10
readinessProbe:
exec:
command:
- wget
- --spider
- -q
- http://127.0.0.1:4445/health/ready
failureThreshold: 6
periodSeconds: 10
timeoutSeconds: 10
startupProbe:
exec:
command:
- wget
- --spider
- -q
- http://127.0.0.1:4445/health/ready
failureThreshold: 60
successThreshold: 1
periodSeconds: 1
timeoutSeconds: 1
ports:
- containerPort: 4444
name: hydra-public