Skip to content
Snippets Groups Projects
Commit 2afe411f authored by nimrod's avatar nimrod
Browse files

Updates.

A lot of different fixes. What I have in production right now.
parent 7da51307
No related branches found
No related tags found
No related merge requests found
Pipeline #82 passed
---
image: adarnimrod/ci-images:docker
stages:
- test
- build
- run
pre-commit:
stage: test
image: adarnimrod/ci-images:pre-commit
variables:
XDG_CACHE_HOME: "$CI_PROJECT_DIR/.cache"
# Disabled until https://github.com/pre-commit/pre-commit/issues/1387 is
# resolved.
SKIP: "hadolint,docker-compose"
script:
- pre-commit run --all-files
cache:
paths:
- .cache/
build:
stage: build
tags: ["host01.shore.co.il"]
variables:
# COMPOSE_DOCKER_CLI_BUILD: "1"
# DOCKER_BUILDKIT: "1"
script:
- docker-compose build --no-cache --pull
- docker-compose pull --quiet
run:
stage: run
tags: ["host01.shore.co.il"]
when: manual
script:
- docker-compose up --detach --remove-orphans
# yamllint disable rule:line-length
- |
for i in $(seq 12)
do
docker container inspect --format '{{ .State.Health.Status }}' $(docker-compose ps -q) | grep -v '^healthy$' || break
sleep 10
done
! docker container inspect --format '{{ .State.Health.Status }}' $(docker-compose ps -q) | grep -v '^healthy$'
...@@ -19,14 +19,19 @@ repos: ...@@ -19,14 +19,19 @@ repos:
hooks: hooks:
- id: proselint - id: proselint
types: [plain-text] types: [plain-text]
exclude: LICENSE|requirements exclude: LICENSE
- repo: https://www.shore.co.il/git/shell-pre-commit/ - repo: https://git.shore.co.il/nimrod/shell-pre-commit.git/
rev: v0.6.0 rev: v0.6.0
hooks: hooks:
- id: shell-lint - id: shell-lint
- id: shellcheck - id: shellcheck
- repo: https://www.shore.co.il/git/docker-pre-commit - repo: https://git.shore.co.il/nimrod/docker-pre-commit.git/
rev: v0.3.0 rev: v0.3.0
hooks: hooks:
- id: hadolint - id: hadolint
- id: docker-compose - id: docker-compose
- repo: https://github.com/Yelp/detect-secrets
rev: v0.13.0
hooks:
- id: detect-secrets
exclude: \.diff$
...@@ -10,53 +10,50 @@ services: ...@@ -10,53 +10,50 @@ services:
ldap: ldap:
build: build:
cache_from:
- adarnimrod/slapd
context: slapd/ context: slapd/
domainname: "${LDAP_HOSTNAME:-ldap}.${LDAP_DOMAIN:-nowhere.com}"
environment: environment:
LDAP_ROOTPASS: &password "${LDAP_ROOTPASS:-foo}" LDAP_ROOTPASS: &password "${LDAP_ROOTPASS:-foo}"
LDAP_DOMAIN: "${LDAP_DOMAIN:-nowhere.com}" LDAP_DOMAIN: "${LDAP_DOMAIN:-shore.co.il}"
LDAP_ORGANIZATION: "${LDAP_ORGANIZATION:-none}" LDAP_ORGANIZATION: "${LDAP_ORGANIZATION:-shore}"
hostname: "${LDAP_HOSTNAME:-ldap}" #SLAPD_DEBUG_LEVEL: "any"
SSL_DHPARAMS_FILE: /var/ssl/dhparams
hostname: "${LDAP_HOSTNAME:-ldap}.${LDAP_DOMAIN:-shore.co.il}"
image: adarnimrod/slapd image: adarnimrod/slapd
restart: always restart: always
volumes: volumes:
- _run_slapd:/run/slapd - _run_slapd:/run/slapd
- ldap:/var/lib/ldap - ldap:/var/lib/ldap
- backup_ldap:/var/backups/ldap - backup_ldap:/var/backups/ldap
- /var/ssl/dhparams:/var/ssl/dhparams:ro
nss-pam-ldapd:
build:
context: nss-pam-ldapd/
command: /usr/sbin/nslcd --debug --nofork
depends_on:
- ldap
environment:
LDAP_BASE_DN: &base_dn "${LDAP_BASE_DN:-dc=nowhere,dc=com}"
volumes:
- _run_slapd:/run/slapd
ldap-account-manager: ldap-account-manager:
build: build:
cache_from:
- adarnimrod/ldap-account-manager
context: ldap-account-manager/ context: ldap-account-manager/
depends_on: depends_on:
- ldap - ldap
environment: environment:
LAM_PASSWORD: *password LAM_PASSWORD: *password # pragma: allowlist secret
LDAP_ADMIN_DN: "cn=admin,${LDAP_BASE_DN:-dc=nowhere,dc=com}" LDAP_ADMIN_DN: "cn=admin,${LDAP_BASE_DN:-dc=shore,dc=co,dc=il}"
LDAP_BASE_DN: *base_dn LDAP_BASE_DN: &base_dn "${LDAP_BASE_DN:-dc=shore,dc=co,dc=il}"
image: adarnimrod/ldap-account-manager image: adarnimrod/ldap-account-manager
ports:
- 80:80
restart: always restart: always
volumes: volumes:
- _run_slapd:/run/slapd - _run_slapd:/run/slapd
# nss-pam-ldapd:
# build:
# context: nss-pam-ldapd/
# command: /usr/sbin/nslcd --debug --nofork
# depends_on:
# - ldap
# environment:
# LDAP_BASE_DN: *base_dn
# volumes:
# - _run_slapd:/run/slapd
volumes: volumes:
_run_slapd: _run_slapd:
name: run_slapd
ldap: ldap:
backup_ldap: backup_ldap:
labels: labels:
......
FROM debian:sid-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 \
...@@ -15,7 +15,6 @@ RUN apt-get update && \ ...@@ -15,7 +15,6 @@ RUN apt-get update && \
a2enmod status && \ a2enmod status && \
ln -sf /dev/stdout /var/log/apache2/access.log && \ ln -sf /dev/stdout /var/log/apache2/access.log && \
ln -sf /dev/stderr /var/log/apache2/error.log && \ ln -sf /dev/stderr /var/log/apache2/error.log && \
ln -sf /dev/stdout /var/log/apache2/lam.log && \
ln -sf /dev/stdout /var/log/apache2/other_vhosts_access.log && \ ln -sf /dev/stdout /var/log/apache2/other_vhosts_access.log && \
rm -rf /tmp/* /var/tmp/* /var/lib/apt/lists/* /var/cache/apt/archives/* rm -rf /tmp/* /var/tmp/* /var/lib/apt/lists/* /var/cache/apt/archives/*
ENV APACHE_RUN_DIR=/run/apache2 \ ENV APACHE_RUN_DIR=/run/apache2 \
...@@ -28,8 +27,7 @@ COPY --chown=root:root entrypoint /usr/local/bin/ ...@@ -28,8 +27,7 @@ COPY --chown=root:root entrypoint /usr/local/bin/
COPY --chown=root:root lam-setpass /usr/local/bin/ COPY --chown=root:root lam-setpass /usr/local/bin/
RUN patch --strip 0 --verbose --directory / --input /root/patch.diff && \ RUN patch --strip 0 --verbose --directory / --input /root/patch.diff && \
apache2 -t apache2 -t
ENV LDAP_URI=ldapi:/// \ ENV LDAP_URI=ldapi:///
LAM_PASSWORD=lam
EXPOSE 80 EXPOSE 80
USER "www-data" USER "www-data"
WORKDIR /var/www WORKDIR /var/www
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
Name | Description | Default value Name | Description | Default value
--- | --- | --- --- | --- | ---
`LAM_PASSWORD` | Password for administrating LAM | `lam` `LAM_PASSWORD` | Password for administering LAM | `lam`
`LDAP_URI` | URI of the LDAP service | `ldapi:///` `LDAP_URI` | URI of the LDAP service | `ldapi:///`
`LDAP_ADMIN_DN` | DN of the admin account `LDAP_ADMIN_DN` | DN of the admin account
`LDAP_BASE_DN` | Base DN `LDAP_BASE_DN` | Base DN
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
# log destination # log destination
-logDestination: SYSLOG -logDestination: SYSLOG
+logDestination: /var/log/apache2/lam.log +logDestination: /dev/stdout
--- /etc/apache2/sites-available/000-default.conf 2018-11-03 13:34:33.000000000 +0200 --- /etc/apache2/sites-available/000-default.conf 2018-11-03 13:34:33.000000000 +0200
+++ /etc/apache2/sites-available/000-default.conf 2019-06-25 14:55:43.956626591 +0300 +++ /etc/apache2/sites-available/000-default.conf 2019-06-25 14:55:43.956626591 +0300
@@ -18,7 +18,7 @@ @@ -18,7 +18,7 @@
......
...@@ -43,5 +43,5 @@ WORKDIR /var/lib/ldap ...@@ -43,5 +43,5 @@ WORKDIR /var/lib/ldap
USER openldap USER openldap
ENTRYPOINT [ "entrypoint" ] ENTRYPOINT [ "entrypoint" ]
CMD [ "slapd", "-F", "/var/lib/ldap/config", "-u", "openldap", "-g", "openldap", "-h", "\"$LDAP_URLS\"", "-d", "$SLAPD_DEBUG_LEVEL" ] CMD [ "slapd", "-F", "/var/lib/ldap/config", "-u", "openldap", "-g", "openldap", "-h", "\"$LDAP_URLS\"", "-d", "$SLAPD_DEBUG_LEVEL" ]
HEALTHCHECK CMD ldapsearch -b cn=config > /dev/null || exit 1 HEALTHCHECK --start-period=5m CMD ldapsearch -b cn=config > /dev/null || exit 1
STOPSIGNAL INT STOPSIGNAL INT
#!/bin/sh #!/bin/sh
set -eux set -eux
alias slapcat='slapcat -vF /var/lib/ldap/config'
slapcat -n0 -v -l /var/backups/ldap/config.ldif slapcat -n0 -v -l /var/backups/ldap/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" -v -l "/var/backups/$dn.ldif" slapcat -b "$dn" -v -l "/var/backups/ldap/$dn.ldif"
done done
...@@ -18,7 +18,7 @@ olcTLSCertificateFile: ${SSL_CERT_FILE} ...@@ -18,7 +18,7 @@ olcTLSCertificateFile: ${SSL_CERT_FILE}
olcTLSCertificateKeyFile: ${SSL_KEY_FILE} olcTLSCertificateKeyFile: ${SSL_KEY_FILE}
olcTLSCipherSuite: SECURE256:+SECURE128 olcTLSCipherSuite: SECURE256:+SECURE128
olcTLSProtocolMin: 3.1 olcTLSProtocolMin: 3.1
olcTLSDHParamFile: /usr/share/slapd/dh.pem olcTLSDHParamFile: ${SSL_DHPARAMS_FILE}
# Frontend settings # Frontend settings
dn: olcDatabase={-1}frontend,cn=config dn: olcDatabase={-1}frontend,cn=config
...@@ -29,16 +29,20 @@ olcDatabase: {-1}frontend ...@@ -29,16 +29,20 @@ olcDatabase: {-1}frontend
olcSizeLimit: 500 olcSizeLimit: 500
# Allow unlimited access to local connection from the local root user # Allow unlimited access to local connection from the local root user
olcAccess: {0}to * by dn.exact=gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth manage by * break olcAccess: {0}to * by dn.exact=gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth manage by * break
# Allow unlimited access to local connection from the local slapd user
olcAccess: {1}to * by dn.exact=gidNumber=${SLAPD_GID}+uidNumber=${SLAPD_UID},cn=peercred,cn=external,cn=auth manage by * break
# Allow unauthenticated read access for schema and base DN autodiscovery # Allow unauthenticated read access for schema and base DN autodiscovery
olcAccess: {1}to dn.exact="" by * read olcAccess: {2}to dn.exact="" by * read
olcAccess: {2}to dn.base="cn=Subschema" by * read olcAccess: {3}to dn.base="cn=Subschema" by * read
# Config db settings # Config db settings
dn: olcDatabase=config,cn=config dn: olcDatabase=config,cn=config
objectClass: olcDatabaseConfig objectClass: olcDatabaseConfig
olcDatabase: config olcDatabase: config
# Allow unlimited access to local connection from the local root user # Allow unlimited access to local connection from the local root user
olcAccess: to * by dn.exact=gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth manage by * break olcAccess: {0}to * by dn.exact=gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth manage by * break
# Allow unlimited access to local connection from the local slapd user
olcAccess: {1}to * by dn.exact=gidNumber=${SLAPD_GID}+uidNumber=${SLAPD_UID},cn=peercred,cn=external,cn=auth manage by * break
olcRootDN: cn=admin,cn=config olcRootDN: cn=admin,cn=config
# Load schemas # Load schemas
......
...@@ -27,8 +27,12 @@ then ...@@ -27,8 +27,12 @@ then
fi fi
# Generate random DH parameters. # Generate random DH parameters.
if [ -z "${SSL_DHPARAMS_FILE:-}" ] || [ ! -f "${SSL_DHPARAMS_FILE:-}" ]
then
echo Generating DH parameters, this will take a while. >&2 echo Generating DH parameters, this will take a while. >&2
time openssl dhparam -out /usr/share/slapd/dh.pem 2048 export SSL_DHPARAMS_FILE='/usr/share/slapd/dh.pem'
time openssl dhparam -out "$SSL_DHPARAMS_FILE" 2048
fi
# Run slapadd with the correct user and location of the config directory. # Run slapadd with the correct user and location of the config directory.
alias slapadd='slapadd -gv -F /var/lib/ldap/config' alias slapadd='slapadd -gv -F /var/lib/ldap/config'
...@@ -37,6 +41,10 @@ alias slapadd='slapadd -gv -F /var/lib/ldap/config' ...@@ -37,6 +41,10 @@ alias slapadd='slapadd -gv -F /var/lib/ldap/config'
if [ -z "$(find /var/lib/ldap/config -maxdepth 1 -mindepth 1)" ] if [ -z "$(find /var/lib/ldap/config -maxdepth 1 -mindepth 1)" ]
then then
echo No configuration found, generating a new one. >&2 echo No configuration found, generating a new one. >&2
SLAPD_UID="$(id -u openldap)"
export SLAPD_UID
SLAPD_GID="$(id -g openldap)"
export SLAPD_GID
# shellcheck disable=SC2002 # shellcheck disable=SC2002
cat /usr/share/slapd/config.ldif | envsubst | slapadd -b 'cn=config' cat /usr/share/slapd/config.ldif | envsubst | slapadd -b 'cn=config'
fi fi
...@@ -50,7 +58,7 @@ then ...@@ -50,7 +58,7 @@ then
fi fi
# Configure the client. # Configure the client.
cat << EOF >> /etc/ldap/ldap.conf cat >> /etc/ldap/ldap.conf <<EOF
URI ldapi:/// URI ldapi:///
SASL_MECH EXTERNAL SASL_MECH EXTERNAL
BASE $BASE_DN BASE $BASE_DN
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment