feat(bootstrap): validate suffix and replication hosts count

Fail with an explicit error when the suffix does not start with dc=
(the root entry was created with an empty dc) and when more than 9
replication hosts are set (the generated rid would exceed 999).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Bertrand Gouny
2026-10-13 22:06:15 +02:00
co-authored by Claude Opus 5.5
parent 99633c18bc
commit 08e98c89c4
2 changed files with 8 additions and 0 deletions
@@ -37,6 +37,10 @@ if [ "${TYPE}" = "env" ]; then
OPENLDAP_BOOTSTRAP_ORGANIZATION_DC=$(get_dn_attr dc "${OPENLDAP_BOOTSTRAP_SUFFIX}")
if [ -z "${OPENLDAP_BOOTSTRAP_ORGANIZATION_DC}" ]; then
container log fatal "OPENLDAP_BOOTSTRAP_SUFFIX must start with dc= (got ${OPENLDAP_BOOTSTRAP_SUFFIX})"
fi
prepare_env_file "${ENV_FILE}" OPENLDAP_GROUP_GID OPENLDAP_USER_UID OPENLDAP_BOOTSTRAP_CONFIG_ROOT_PASSWORD_HASHED OPENLDAP_BOOTSTRAP_DATA_ROOT_PASSWORD_HASHED OPENLDAP_BOOTSTRAP_MODULES_LDIF OPENLDAP_BOOTSTRAP_SCHEMAS_LDIF OPENLDAP_BOOTSTRAP_MONITOR_ENABLED OPENLDAP_BOOTSTRAP_ORGANIZATION_DC
elif [ "${TYPE}" = "ldif" ]; then
@@ -44,6 +44,10 @@ if [ "${OPENLDAP_BOOTSTRAP_REPLICATION}" = "true" ]; then
container log fatal "OPENLDAP_BOOTSTRAP_REPLICATION_HOSTS must contain at least 2 hosts, got $((i - 1)) (${OPENLDAP_BOOTSTRAP_REPLICATION_HOSTS})"
fi
if [ "${i}" -gt 10 ]; then
container log fatal "OPENLDAP_BOOTSTRAP_REPLICATION_HOSTS must contain at most 9 hosts, got $((i - 1))"
fi
if [ "${current_host_id}" -eq 0 ]; then
container log fatal "Current host ${current_fqdn} not found in OPENLDAP_BOOTSTRAP_REPLICATION_HOSTS=${OPENLDAP_BOOTSTRAP_REPLICATION_HOSTS}"
fi