Skip to content
Commits on Source (3)
  • nimrod's avatar
    Backup refactor. · b29af5e0
    nimrod authored
    - Change from a single backup that's overwritten everytime to a
      multiple, dated backups.
    - Save the last 30 days of backups.
    - Save backups under the host's /var/backups instead of a Docker volume.
      Easier to backup.
    - Add a restore script so that at least I would have some idea on how to
      restore this backup. Last thing I want to do when I need this backup
    is to try and figure out how to restore it.
    b29af5e0
  • nimrod's avatar
    Update slapd image to Debian Bullseye. · 7d7ea1ba
    nimrod authored
    There's an update to OpenLDAP 2.5 or maybe 2.6 coming down the pipe. But
    I'm kicking the can down the road for now. Keeping up with Debian
    releases is enough for today.
    7d7ea1ba
  • nimrod's avatar
    Some YAML formatting. · fe064fad
    nimrod authored
    fe064fad
@weekly docker exec ldap_ldap_1 backup || wget --spider https://notify.shore.co.il/send?message=LDAP%20backup%20failed. @weekly docker exec ldap_ldap_1 backup || wget --spider https://notify.shore.co.il/send?message=LDAP%20backup%20failed.
@daily docker exec ldap_ldap_1 find /var/backups/ldap -atime +30 -delete
# vim:ff=unix:ts=2:sw=2:ai:expandtab
--- ---
version: '3.5' version: '3.5'
services: services:
...@@ -6,7 +5,7 @@ services: ...@@ -6,7 +5,7 @@ services:
environment: environment:
LDAP_BASE_DN: "ou=People,${LDAP_BASE_DN:-dc=shore,dc=co,dc=il}" LDAP_BASE_DN: "ou=People,${LDAP_BASE_DN:-dc=shore,dc=co,dc=il}"
LDAP_OBJECTS_DN: "dn" LDAP_OBJECTS_DN: "dn"
LDAP_OPENLDAP: !!str true LDAP_OPENLDAP: 'true'
LDAP_REALM_NAME: shore.co.il authentication LDAP_REALM_NAME: shore.co.il authentication
LDAP_USER_OBJECT_FILTER: "(&(objectclass=inetOrgPerson)(uid=%s))" LDAP_USER_OBJECT_FILTER: "(&(objectclass=inetOrgPerson)(uid=%s))"
SECRET_KEY: "${SECRET_KEY:-qwerty123}" SECRET_KEY: "${SECRET_KEY:-qwerty123}"
...@@ -37,7 +36,7 @@ services: ...@@ -37,7 +36,7 @@ services:
volumes: volumes:
- _run_slapd:/run/slapd - _run_slapd:/run/slapd
- ldap:/var/lib/ldap - ldap:/var/lib/ldap
- backup_ldap:/var/backups/ldap - /var/backups/ldap:/var/backups/ldap
- /var/ssl/dhparams:/var/ssl/dhparams:ro - /var/ssl/dhparams:/var/ssl/dhparams:ro
ldap-account-manager: ldap-account-manager:
...@@ -68,9 +67,6 @@ volumes: ...@@ -68,9 +67,6 @@ volumes:
_run_slapd: _run_slapd:
name: run_slapd name: run_slapd
ldap: ldap:
backup_ldap:
labels:
snapshot: 'true'
networks: networks:
default: default:
......
FROM debian:buster-slim FROM debian:bullseye-slim
# hadolint ignore=DL3008 # hadolint ignore=DL3008
RUN apt-get update && \ RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
...@@ -30,6 +30,7 @@ COPY --chown=root:root config.ldif /usr/share/slapd/ ...@@ -30,6 +30,7 @@ COPY --chown=root:root config.ldif /usr/share/slapd/
COPY --chown=root:root skel.ldif /usr/share/slapd/ COPY --chown=root:root skel.ldif /usr/share/slapd/
COPY --chown=root:root entrypoint /usr/local/sbin/ COPY --chown=root:root entrypoint /usr/local/sbin/
COPY --chown=root:root backup /usr/local/sbin/ COPY --chown=root:root backup /usr/local/sbin/
COPY --chown=root:root restore /usr/local/sbin/
EXPOSE 389 636 EXPOSE 389 636
VOLUME [ "/var/lib/ldap" ] VOLUME [ "/var/lib/ldap" ]
VOLUME [ "/run/slapd" ] VOLUME [ "/run/slapd" ]
......
#!/bin/sh #!/bin/sh
set -eux set -eux
cleanup () {
rm -rf "$tempdir"
}
alias slapcat='slapcat -vF /var/lib/ldap/config' alias slapcat='slapcat -vF /var/lib/ldap/config'
slapcat -n0 -l /var/backups/ldap/config.ldif now="$(date --utc --iso-8601=seconds)"
trap 'cleanup' INT QUIT EXIT TERM
tempdir="$(mktemp -d)"
slapcat -n0 -l "$tempdir/config.ldif"
for dn in $(ldapsearch -Y EXTERNAL -LLL -s base -b '' o namingContexts | sed -n '/namingContexts/ s/namingContexts: //gp') for dn in $(ldapsearch -Y EXTERNAL -LLL -s base -b '' o namingContexts | sed -n '/namingContexts/ s/namingContexts: //gp')
do do
slapcat -b "$dn" -l "/var/backups/ldap/$dn.ldif" slapcat -b "$dn" -l "$tempdir/$dn.ldif"
done done
tar -zcf "/var/backups/ldap/$now.tar.gz" -C "$tempdir" .
#!/bin/sh
set -eux
cleanup () {
rm -rf "$tempdir"
}
alias slapadd='slapadd -vF /var/lib/ldap/config'
src="$1"
trap 'cleanup' INT QUIT EXIT TERM
tempdir="$(mktemp -d)"
tar -xzf "$src" -C "$tempdir"
slapadd -c -n0 -l "$tempdir/config.ldif"
# shellcheck disable=SC2044
for file in $(find "$tempdir" -type f -name '*.ldif' \! -name config.ldif -printf '%f\n')
do
dn="${file%.ldif}"
slapadd -c -b "$dn" -l "$tempdir/$file"
done