From 1115f7d0a8aa14462d7f1cb24f67f31266b03e47 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Thu, 29 Apr 2021 15:12:28 +0200 Subject: [PATCH] NTP client/server, prepare slapd Signed-off-by: Yohann D'ANELLO --- group_vars/{ => all}/all.yml | 0 group_vars/all/ntp.yml | 3 + group_vars/slapd.yml | 7 + hosts | 3 + plays/base.yml | 3 +- plays/ntp.yml | 13 ++ .../handlers/main.yml | 0 roles/{ntp => ntp-client-arch}/tasks/main.yml | 0 .../templates/ntp.conf.j2 | 0 roles/ntp-client/handlers/main.yml | 5 + roles/ntp-client/tasks/main.yml | 29 +++ .../templates/systemd/timesyncd.conf.j2 | 2 + roles/ntp-server/tasks/main.yml | 27 +++ roles/ntp-server/templates/ntp.conf.j2 | 62 ++++++ roles/slapd/README.md | 13 ++ roles/slapd/handlers/main.yml | 6 + roles/slapd/tasks/main.yml | 35 +++ roles/slapd/templates/ldap/ldap.key.j2 | 1 + roles/slapd/templates/ldap/ldap.pem.j2 | 1 + roles/slapd/templates/ldap/slapd.conf.j2 | 202 ++++++++++++++++++ 20 files changed, 411 insertions(+), 1 deletion(-) rename group_vars/{ => all}/all.yml (100%) create mode 100644 group_vars/all/ntp.yml create mode 100644 group_vars/slapd.yml create mode 100755 plays/ntp.yml rename roles/{ntp => ntp-client-arch}/handlers/main.yml (100%) rename roles/{ntp => ntp-client-arch}/tasks/main.yml (100%) rename roles/{ntp => ntp-client-arch}/templates/ntp.conf.j2 (100%) create mode 100644 roles/ntp-client/handlers/main.yml create mode 100644 roles/ntp-client/tasks/main.yml create mode 100644 roles/ntp-client/templates/systemd/timesyncd.conf.j2 create mode 100644 roles/ntp-server/tasks/main.yml create mode 100644 roles/ntp-server/templates/ntp.conf.j2 create mode 100644 roles/slapd/README.md create mode 100644 roles/slapd/handlers/main.yml create mode 100644 roles/slapd/tasks/main.yml create mode 100644 roles/slapd/templates/ldap/ldap.key.j2 create mode 100644 roles/slapd/templates/ldap/ldap.pem.j2 create mode 100644 roles/slapd/templates/ldap/slapd.conf.j2 diff --git a/group_vars/all.yml b/group_vars/all/all.yml similarity index 100% rename from group_vars/all.yml rename to group_vars/all/all.yml diff --git a/group_vars/all/ntp.yml b/group_vars/all/ntp.yml new file mode 100644 index 0000000..aecda4b --- /dev/null +++ b/group_vars/all/ntp.yml @@ -0,0 +1,3 @@ +glob_ntp_client: + servers: + - ntp.crans.org diff --git a/group_vars/slapd.yml b/group_vars/slapd.yml new file mode 100644 index 0000000..46fd880 --- /dev/null +++ b/group_vars/slapd.yml @@ -0,0 +1,7 @@ +--- +glob_slapd: + master_ip: "{{ query('ldap', 'ip', 'tealc', 'adm') | ipv4 | first }}" + regex: "^(role:(dhcp|dns|dns-primary|dns-secondary|ftp|gitlab|miroir|ntp|pve|radius|backup)|ecdsa-sha2-nistp256:.*|ssh-(ed25519|dss|rsa):.*)$" + replication_credentials: "{{ vault.ldap_replication_credentials }}" + private_key: "{{ vault.ldap_private_key }}" + certificate: "{{ vault.ldap_certificate }}" diff --git a/hosts b/hosts index 9057abe..c4e6db6 100644 --- a/hosts +++ b/hosts @@ -13,6 +13,9 @@ localhost templier.adh.crans.org dt.adh.crans.org +[slapd] +dt.adh.crans.org + [virtu] dt.adh.crans.org diff --git a/plays/base.yml b/plays/base.yml index 9bae46d..fb18917 100755 --- a/plays/base.yml +++ b/plays/base.yml @@ -2,6 +2,7 @@ --- - import_playbook: apt.yml +- import_playbook: ntp.yml - hosts: all roles: @@ -20,7 +21,7 @@ - sudo - systemd - pacman - - ntp + - ntp-client-arch - texlive - xorg - i3 diff --git a/plays/ntp.yml b/plays/ntp.yml new file mode 100755 index 0000000..c4fb2bf --- /dev/null +++ b/plays/ntp.yml @@ -0,0 +1,13 @@ +#!/usr/bin/env ansible-playbook +--- +- hosts: ntp_server + vars: + ntp_server: '{{ glob_ntp_server | combine(loc_ntp_server | default({})) }}' + roles: + - ntp-server + +- hosts: debian + vars: + ntp_client: '{{ glob_ntp_client | combine(loc_ntp_client | default({})) }}' + roles: + - ntp-client diff --git a/roles/ntp/handlers/main.yml b/roles/ntp-client-arch/handlers/main.yml similarity index 100% rename from roles/ntp/handlers/main.yml rename to roles/ntp-client-arch/handlers/main.yml diff --git a/roles/ntp/tasks/main.yml b/roles/ntp-client-arch/tasks/main.yml similarity index 100% rename from roles/ntp/tasks/main.yml rename to roles/ntp-client-arch/tasks/main.yml diff --git a/roles/ntp/templates/ntp.conf.j2 b/roles/ntp-client-arch/templates/ntp.conf.j2 similarity index 100% rename from roles/ntp/templates/ntp.conf.j2 rename to roles/ntp-client-arch/templates/ntp.conf.j2 diff --git a/roles/ntp-client/handlers/main.yml b/roles/ntp-client/handlers/main.yml new file mode 100644 index 0000000..ffd2754 --- /dev/null +++ b/roles/ntp-client/handlers/main.yml @@ -0,0 +1,5 @@ +--- +- name: Restart systemd-timesyncd + service: + name: systemd-timesyncd + state: restarted diff --git a/roles/ntp-client/tasks/main.yml b/roles/ntp-client/tasks/main.yml new file mode 100644 index 0000000..7e7d69b --- /dev/null +++ b/roles/ntp-client/tasks/main.yml @@ -0,0 +1,29 @@ +--- +- name: Clean up ntp + apt: + state: absent + name: ntp + purge: true + register: apt_result + retries: 3 + until: apt_result is succeeded + when: "'ntp_server' not in group_names" + +- name: Install systemd-timesyncd (bullseye) + apt: + name: systemd-timesyncd + update_cache: true + install_recommends: false + register: apt_result + retries: 3 + until: apt_result is succeeded + when: + - "'ntp_server' not in group_names" + - ansible_distribution_release == "bullseye" + +- name: Configure NTP + template: + src: systemd/timesyncd.conf.j2 + dest: /etc/systemd/timesyncd.conf + notify: Restart systemd-timesyncd + when: "'ntp_server' not in group_names" diff --git a/roles/ntp-client/templates/systemd/timesyncd.conf.j2 b/roles/ntp-client/templates/systemd/timesyncd.conf.j2 new file mode 100644 index 0000000..ffef2b8 --- /dev/null +++ b/roles/ntp-client/templates/systemd/timesyncd.conf.j2 @@ -0,0 +1,2 @@ +[Time] +NTP={{ ntp_client.servers | join(' ') }} diff --git a/roles/ntp-server/tasks/main.yml b/roles/ntp-server/tasks/main.yml new file mode 100644 index 0000000..0bc25d2 --- /dev/null +++ b/roles/ntp-server/tasks/main.yml @@ -0,0 +1,27 @@ +--- +- name: Install NTP + apt: + update_cache: true + name: ntp + register: apt_result + retries: 3 + until: apt_result is succeeded + +- name: Configure NTP daemon + lineinfile: + path: /etc/default/ntp + regexp: '^NTPD_OPTS' + line: NTPD_OPTS='-g -x' + check_mode: no + +- name: Configure NTP + template: + src: ntp.conf.j2 + dest: /etc/ntp.conf + mode: 0644 + +- name: Start ntp service + systemd: + name: ntp + enabled: true + state: started diff --git a/roles/ntp-server/templates/ntp.conf.j2 b/roles/ntp-server/templates/ntp.conf.j2 new file mode 100644 index 0000000..15f57e7 --- /dev/null +++ b/roles/ntp-server/templates/ntp.conf.j2 @@ -0,0 +1,62 @@ +{{ ansible_header | comment }} +# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help + +driftfile /var/lib/ntp/ntp.drift + +# Leap seconds definition provided by tzdata +leapfile /usr/share/zoneinfo/leap-seconds.list + +# Enable this if you want statistics to be logged. +#statsdir /var/log/ntpstats/ + +statistics loopstats peerstats clockstats +filegen loopstats file loopstats type day enable +filegen peerstats file peerstats type day enable +filegen clockstats file clockstats type day enable + + +# pool.ntp.org maps to about 1000 low-stratum NTP servers. Your server will +# pick a different set every time it starts up. Please consider joining the +# pool: +pool ntp.crans.org iburst +pool 0.debian.pool.ntp.org iburst +pool 1.debian.pool.ntp.org iburst +pool 2.debian.pool.ntp.org iburst +pool 3.debian.pool.ntp.org iburst + + +# Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for +# details. The web page +# might also be helpful. +# +# Note that "restrict" applies to both servers and clients, so a configuration +# that might be intended to block requests from certain clients could also end +# up blocking replies from your own upstream servers. + +# By default, exchange time with everybody, but don't allow configuration. +restrict -4 default kod notrap nomodify nopeer noquery limited +restrict -6 default kod notrap nomodify nopeer noquery limited + +# Local users may interrogate the ntp server more closely. +restrict 127.0.0.1 +restrict ::1 + +# Needed for adding pool entries +restrict source notrap nomodify noquery + +# Server on adm can sync +restrict 172.16.42.0 mask 255.255.255.0 notrap nomodify + +# Clients from this (example!) subnet have unlimited access, but only if +# cryptographically authenticated. +#restrict 192.168.123.0 mask 255.255.255.0 notrust + + +# If you want to provide time to your local subnet, change the next line. +# (Again, the address is an example only.) +#broadcast 192.168.123.255 + +# If you want to listen to time broadcasts on your local subnet, de-comment the +# next lines. Please do this only if you trust everybody on the network! +#disable auth +#broadcastclient diff --git a/roles/slapd/README.md b/roles/slapd/README.md new file mode 100644 index 0000000..45b7b02 --- /dev/null +++ b/roles/slapd/README.md @@ -0,0 +1,13 @@ +# SLAPD + +Deploie un serveur ldap master ou replica + +## VARS + +slapd: + - ip : l'ip sur lequel il va installer le serveur ldap + - replica : s'il s'agit d'un master ou d'une replica + - replica_rid : le numéro de replica du serveur + - master_ip : l'ip du master + - replication_credentials : les credientials pour authentifier les replicas + auprès du master diff --git a/roles/slapd/handlers/main.yml b/roles/slapd/handlers/main.yml new file mode 100644 index 0000000..c8b9f3c --- /dev/null +++ b/roles/slapd/handlers/main.yml @@ -0,0 +1,6 @@ +--- + +- name: Restart slapd + service: + name: slapd.service + state: restarted diff --git a/roles/slapd/tasks/main.yml b/roles/slapd/tasks/main.yml new file mode 100644 index 0000000..f377a77 --- /dev/null +++ b/roles/slapd/tasks/main.yml @@ -0,0 +1,35 @@ +--- +- name: Install slapd + apt: + update_cache: true + name: + - slapd + register: apt_result + retries: 3 + until: apt_result is succeeded + +- name: Remove slapd config directory + file: + path: /etc/ldap/slapd.d/ + state: absent + +- name: Deploy slapd configuration + template: + src: "ldap/{{ item.dest }}.j2" + dest: "/etc/ldap/{{ item.dest }}" + mode: "{{ item.mode }}" + owner: openldap + group: openldap + loop: + - { dest: slapd.conf, mode: "0600" } + - { dest: ldap.key, mode: "0600" } + - { dest: ldap.pem, mode: "0644" } + notify: Restart slapd + +- name: Deploy ldap services + lineinfile: + path: /etc/default/slapd + regexp: '^SLAPD_SERVICES=' + line: 'SLAPD_SERVICES="ldaps://{{ slapd.ip }}/ ldapi:///"' + notify: Restart slapd + check_mode: no diff --git a/roles/slapd/templates/ldap/ldap.key.j2 b/roles/slapd/templates/ldap/ldap.key.j2 new file mode 100644 index 0000000..e165a54 --- /dev/null +++ b/roles/slapd/templates/ldap/ldap.key.j2 @@ -0,0 +1 @@ +{{ slapd.private_key }} diff --git a/roles/slapd/templates/ldap/ldap.pem.j2 b/roles/slapd/templates/ldap/ldap.pem.j2 new file mode 100644 index 0000000..cabc323 --- /dev/null +++ b/roles/slapd/templates/ldap/ldap.pem.j2 @@ -0,0 +1 @@ +{{ slapd.certificate }} diff --git a/roles/slapd/templates/ldap/slapd.conf.j2 b/roles/slapd/templates/ldap/slapd.conf.j2 new file mode 100644 index 0000000..ec6d631 --- /dev/null +++ b/roles/slapd/templates/ldap/slapd.conf.j2 @@ -0,0 +1,202 @@ +# This is the main slapd configuration file. See slapd.conf(5) for more +# info on the configuration options. + +####################################################################### +# Global Directives: + +# Schema and objectClass definitions +include /etc/ldap/schema/core.schema +include /etc/ldap/schema/cosine.schema +include /etc/ldap/schema/nis.schema +include /etc/ldap/schema/inetorgperson.schema + +# Where the pid file is put. The init.d script +# will not stop the server if you change this. +pidfile /var/run/slapd/slapd.pid + +# List of arguments that were passed to the server +argsfile /var/run/slapd/slapd.args + +# Read slapd.conf(5) for possible values +loglevel none + +# Where the dynamically loaded modules are stored +modulepath /usr/lib/ldap +moduleload back_mdb +{% if not slapd.replica %} +moduleload auditlog + +overlay auditlog +auditlog /var/log/openldap/auditlog.log + +moduleload constraint +overlay constraint +constraint_attribute description regex {{ slapd.regex }} + restrict=ldap:///ou=hosts,dc=ynerant,dc=fr??one?(objectClass=device) +constraint_attribute uid regex ^_ + restrict=ldap:///ou=passwd,dc=ynerant,dc=fr??one?(objectClass=posixAccount) + +moduleload syncprov +{% endif %} + +# TLS Certificates +#TLSCipherSuite HIGH:MEDIUM:-SSLv2:-SSLv3 +TLSCertificateFile /etc/ldap/ldap.pem +TLSCertificateKeyFile /etc/ldap/ldap.key + +# The maximum number of entries that is returned for a search operation +sizelimit 500 + +# The tool-threads parameter sets the actual amount of cpu's that is used +# for indexing. +tool-threads 1 + +####################################################################### +# Specific Backend Directives for mdb: +# Backend specific directives apply to this backend until another +# 'backend' directive occurs +backend mdb + +####################################################################### +# Specific Backend Directives for 'other': +# Backend specific directives apply to this backend until another +# 'backend' directive occurs +#backend + +####################################################################### +# Specific Directives for database #1, of type mdb: +# Database specific directives apply to this databasse until another +# 'database' directive occurs +database mdb + +# The base of your directory in database #1 +suffix "dc=ynerant,dc=fr" + +# rootdn directive for specifying a superuser on the database. This is needed +# for syncrepl. +rootdn "cn=admin,dc=ynerant,dc=fr" + +# Where the database file are physically stored for database #1 +directory "/var/lib/ldap" + +# The dbconfig settings are used to generate a DB_CONFIG file the first +# time slapd starts. They do NOT override existing an existing DB_CONFIG +# file. You should therefore change these settings in DB_CONFIG directly +# or remove DB_CONFIG and restart slapd for changes to take effect. + +# For the Debian package we use 2MB as default but be sure to update this +# value if you have plenty of RAM +#dbconfig set_cachesize 0 2097152 0 + +# Sven Hartge reported that he had to set this value incredibly high +# to get slapd running at all. See http://bugs.debian.org/303057 for more +# information. + +# Number of objects that can be locked at the same time. +#dbconfig set_lk_max_objects 1500 +# Number of locks (both requested and granted) +#dbconfig set_lk_max_locks 1500 +# Number of lockers +#dbconfig set_lk_max_lockers 1500 + +# Indexing options for database #1 +index objectClass eq + +# Save the time that the entry gets modified, for database #1 +lastmod on + +# Checkpoint the BerkeleyDB database periodically in case of system +# failure and to speed slapd shutdown. +checkpoint 512 30 + +{% if slapd.replica %} +syncrepl + rid={{ slapd.replica_rid }} + provider=ldaps://{{ slapd.master_ip }}:636 + bindmethod=simple + binddn="cn=replicator,dc=ynerant,dc=fr" + credentials={{ slapd.replication_credentials }} + searchbase="dc=ynerant,dc=fr" + scope=sub + schemachecking=on + type=refreshAndPersist + timeout=0 + network-timeout=0 + retry="30 20 300 +" + tls_reqcert=allow +{% endif %} + +{% if slapd.replica %} +# The userPassword by default can be changed +# by the entry owning it if they are authenticated. +# Others should not be able to see it, except the +# admin entry below +# These access lines apply to database #1 only +access to attrs=userPassword,shadowLastChange + by anonymous auth + by * none + +# Ensure read access to the base for things like +# supportedSASLMechanisms. Without this you may +# have problems with SASL not knowing what +# mechanisms are available and the like. +# Note that this is covered by the 'access to *' +# ACL below too but if you change that as people +# are wont to do you'll still need this if you +# want SASL (and possible other things) to work +# happily. +access to dn.base="" by * read + +# The admin dn has full write access, everyone else +# can read everything. +access to * + by * read +{% else %} +overlay syncprov + +# The userPassword by default can be changed +# by the entry owning it if they are authenticated. +# Others should not be able to see it, except the +# admin entry below +# These access lines apply to database #1 only +access to attrs=userPassword,shadowLastChange + by anonymous auth + by self write + by set="[cn=nounou,ou=group,dc=ynerant,dc=fr]/memberUid & user/uid" write + by dn="cn=replicator,dc=ynerant,dc=fr" read + by * none + +access to attrs=loginShell,mail,telephoneNumber + by self write + by set="[cn=nounou,ou=group,dc=ynerant,dc=fr]/memberUid & user/uid" write + by dn="cn=replicator,dc=ynerant,dc=fr" read + by * read + +# Ensure read access to the base for things like +# supportedSASLMechanisms. Without this you may +# have problems with SASL not knowing what +# mechanisms are available and the like. +# Note that this is covered by the 'access to *' +# ACL below too but if you change that as people +# are wont to do you'll still need this if you +# want SASL (and possible other things) to work +# happily. +access to dn.base="" by * read + +# The admin dn has full write access, everyone else +# can read everything. +access to * + by set="[cn=nounou,ou=group,dc=ynerant,dc=fr]/memberUid & user/uid" write + by dn="cn=replicator,dc=ynerant,dc=fr" read + by * read +{% endif %} + + +####################################################################### +# Specific Directives for database #2, of type 'other' (can be mdb too): +# Database specific directives apply to this databasse until another +# 'database' directive occurs +#database + +# The base of your directory for database #2 +#suffix "dc=debian,dc=org"