Compare commits

..

3 Commits
0.1.2 ... main

Author SHA1 Message Date
c66df72e8d
fix: include TLS config in initial cn=config entry
Some checks failed
CI Pipeline / lint (push) Successful in 20s
CI Pipeline / build (push) Successful in 1m2s
CI Pipeline / test (push) Successful in 1m2s
CI Pipeline / security-scan (push) Successful in 1m32s
CI Pipeline / autotag (push) Successful in 25s
CI Pipeline / push (push) Successful in 22s
CI Pipeline / update-cd (push) Failing after 17s
slapadd doesn't understand LDIF change records (changetype: modify).
Move TLS configuration attributes directly into the cn=config entry
instead of using a separate modify operation.
2025-12-28 02:06:15 +01:00
9b15cc31cb
feat: trigger CD pipeline after image push
Some checks failed
CI Pipeline / lint (push) Successful in 17s
CI Pipeline / build (push) Successful in 40s
CI Pipeline / test (push) Successful in 1m5s
CI Pipeline / security-scan (push) Successful in 1m22s
CI Pipeline / autotag (push) Successful in 17s
CI Pipeline / push (push) Successful in 19s
CI Pipeline / update-cd (push) Failing after 16s
Add stage 7 to trigger terraform-docker-openldap pipeline via Gitea API
after successfully pushing a new image to the registry. This enables
automatic deployment of new container versions.

Requires GITEA_TOKEN secret and GITEA_URL variable to be configured.
2025-12-28 01:12:13 +01:00
d5405f3bba
fix: handle first-time syncrepl configuration
All checks were successful
CI Pipeline / lint (push) Successful in 28s
CI Pipeline / build (push) Successful in 1m12s
CI Pipeline / test (push) Successful in 1m8s
CI Pipeline / security-scan (push) Successful in 1m38s
CI Pipeline / autotag (push) Successful in 24s
CI Pipeline / push (push) Successful in 21s
CI Pipeline / update-cd (push) Successful in 15s
Check if olcSyncRepl and olcMirrorMode attributes exist before
deciding whether to use 'add' or 'replace' operation. Previously
the script always used 'replace' which fails on first-time setup
when the attributes don't exist yet.
2025-12-28 01:00:33 +01:00
3 changed files with 55 additions and 39 deletions

View File

@ -273,23 +273,36 @@ jobs:
if: always() if: always()
run: docker logout ${{ env.REGISTRY }} || true run: docker logout ${{ env.REGISTRY }} || true
# Stage 7: Update CD pipeline (trigger deployment) # Stage 7: Trigger CD pipeline for terraform-docker-openldap
update-cd: update-cd:
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: push needs: push
if: needs.push.result == 'success' if: needs.push.result == 'success'
steps: steps:
- name: Trigger CD pipeline - name: Trigger terraform-docker-openldap pipeline
run: | run: |
echo "==============================================" echo "=============================================="
echo " Ready to update CD pipeline" echo " Triggering CD pipeline"
echo "==============================================" echo "=============================================="
echo "New version: ${{ needs.push.outputs.version }}" echo "New version: ${{ needs.push.outputs.version }}"
echo "Full image: ${{ needs.push.outputs.full_image }}" echo "Full image: ${{ needs.push.outputs.full_image }}"
echo "" echo ""
echo "TODO: Add step to update version in CD repository"
echo "This could be:" # Trigger the Gitea Actions workflow via repository dispatch
echo " - Update docker-compose.yml in infra repo" curl -X POST \
echo " - Update Helm values" -H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \
echo " - Trigger ArgoCD sync" -H "Content-Type: application/json" \
"${{ vars.GITEA_URL }}/api/v1/repos/wbyc/terraform-docker-openldap/actions/workflows/pipeline.yaml/dispatches" \
-d '{
"ref": "main",
"inputs": {
"image_tag": "${{ needs.push.outputs.version }}"
}
}' || {
echo "::warning::Failed to trigger CD pipeline"
exit 1
}
echo "=============================================="
echo " CD pipeline triggered successfully"
echo "==============================================" echo "=============================================="

View File

@ -13,6 +13,20 @@ export LDAP_ADMIN_PASSWORD_HASH LDAP_CONFIG_PASSWORD_HASH
# Create initial slapd.d configuration # Create initial slapd.d configuration
rm -rf /etc/openldap/slapd.d/* rm -rf /etc/openldap/slapd.d/*
# Build TLS attributes if enabled
TLS_CONFIG=""
if [ "$LDAP_TLS_ENABLED" = "true" ] && [ -f "$LDAP_TLS_CERT_FILE" ] && [ -f "$LDAP_TLS_KEY_FILE" ]; then
log_info "Adding TLS configuration..."
TLS_CONFIG="olcTLSCertificateFile: ${LDAP_TLS_CERT_FILE}
olcTLSCertificateKeyFile: ${LDAP_TLS_KEY_FILE}"
if [ -f "$LDAP_TLS_CA_FILE" ]; then
TLS_CONFIG="${TLS_CONFIG}
olcTLSCACertificateFile: ${LDAP_TLS_CA_FILE}"
fi
TLS_CONFIG="${TLS_CONFIG}
olcTLSVerifyClient: ${LDAP_TLS_VERIFY_CLIENT}"
fi
# Create base cn=config LDIF # Create base cn=config LDIF
cat > /tmp/init-config.ldif << EOF cat > /tmp/init-config.ldif << EOF
dn: cn=config dn: cn=config
@ -21,6 +35,7 @@ cn: config
olcArgsFile: /run/openldap/slapd.args olcArgsFile: /run/openldap/slapd.args
olcPidFile: /run/openldap/slapd.pid olcPidFile: /run/openldap/slapd.pid
olcLogLevel: ${LDAP_LOG_LEVEL} olcLogLevel: ${LDAP_LOG_LEVEL}
${TLS_CONFIG}
dn: cn=module{0},cn=config dn: cn=module{0},cn=config
objectClass: olcModuleList objectClass: olcModuleList
@ -68,35 +83,6 @@ olcDbIndex: entryUUID eq
olcDbMaxSize: 1073741824 olcDbMaxSize: 1073741824
EOF EOF
# Add TLS configuration if enabled and certs exist
if [ "$LDAP_TLS_ENABLED" = "true" ] && [ -f "$LDAP_TLS_CERT_FILE" ] && [ -f "$LDAP_TLS_KEY_FILE" ]; then
log_info "Adding TLS configuration..."
cat >> /tmp/init-config.ldif << EOF
dn: cn=config
changetype: modify
add: olcTLSCertificateFile
olcTLSCertificateFile: ${LDAP_TLS_CERT_FILE}
-
add: olcTLSCertificateKeyFile
olcTLSCertificateKeyFile: ${LDAP_TLS_KEY_FILE}
EOF
if [ -f "$LDAP_TLS_CA_FILE" ]; then
cat >> /tmp/init-config.ldif << EOF
-
add: olcTLSCACertificateFile
olcTLSCACertificateFile: ${LDAP_TLS_CA_FILE}
EOF
fi
cat >> /tmp/init-config.ldif << EOF
-
add: olcTLSVerifyClient
olcTLSVerifyClient: ${LDAP_TLS_VERIFY_CLIENT}
EOF
fi
# Import the configuration # Import the configuration
log_info "Importing cn=config with slapadd..." log_info "Importing cn=config with slapadd..."
/usr/sbin/slapadd -n 0 -F /etc/openldap/slapd.d -l /tmp/init-config.ldif /usr/sbin/slapadd -n 0 -F /etc/openldap/slapd.d -l /tmp/init-config.ldif

View File

@ -91,13 +91,30 @@ IFS="$OLD_IFS"
# Configure syncrepl and mirrormode on the database # Configure syncrepl and mirrormode on the database
log_info "Configuring syncrepl and mirrormode..." log_info "Configuring syncrepl and mirrormode..."
# Check if olcSyncRepl attribute already exists
if ldapsearch -Y EXTERNAL -H "$LDAPI_SOCKET" -b "olcDatabase={1}mdb,cn=config" -s base "(olcSyncRepl=*)" olcSyncRepl 2>/dev/null | grep -q "olcSyncRepl:"; then
SYNCREPL_OP="replace"
log_info "Updating existing syncrepl configuration..."
else
SYNCREPL_OP="add"
log_info "Adding new syncrepl configuration..."
fi
# Check if olcMirrorMode attribute already exists
if ldapsearch -Y EXTERNAL -H "$LDAPI_SOCKET" -b "olcDatabase={1}mdb,cn=config" -s base "(olcMirrorMode=*)" olcMirrorMode 2>/dev/null | grep -q "olcMirrorMode:"; then
MIRRORMODE_OP="replace"
else
MIRRORMODE_OP="add"
fi
cat > /tmp/repl-syncrepl.ldif << EOF cat > /tmp/repl-syncrepl.ldif << EOF
dn: olcDatabase={1}mdb,cn=config dn: olcDatabase={1}mdb,cn=config
changetype: modify changetype: modify
replace: olcSyncRepl ${SYNCREPL_OP}: olcSyncRepl
${SYNCREPL_CONFIG} ${SYNCREPL_CONFIG}
- -
replace: olcMirrorMode ${MIRRORMODE_OP}: olcMirrorMode
olcMirrorMode: TRUE olcMirrorMode: TRUE
EOF EOF