Updates
This commit is contained in:
35
files/sssd.conf.mo
Normal file
35
files/sssd.conf.mo
Normal file
@@ -0,0 +1,35 @@
|
||||
[sssd]
|
||||
services = nss, pam, sudo
|
||||
domains = default
|
||||
|
||||
[domain/default]
|
||||
id_provider = ldap
|
||||
auth_provider = ldap
|
||||
chpass_provider = ldap
|
||||
sudo_provider = ldap
|
||||
|
||||
ldap_uri = ldap://{{ldap_host}}
|
||||
ldap_search_base = {{ldap_base_dn}}
|
||||
ldap_network_timeout = 3
|
||||
|
||||
ldap_bind_dn = {{ldap_bind_dn}}
|
||||
ldap_bind_pw = {{ldap_bind_password}}
|
||||
|
||||
# Sudo settings
|
||||
ldap_sudo_search_base = {{ldap_base_dn}}
|
||||
# Filter for sudo access: global host_admin OR host-specific admin
|
||||
ldap_sudo_full_refresh_interval = 900
|
||||
ldap_sudo_smart_refresh_interval = 300
|
||||
|
||||
# Access control: only allow users in host_access or host_{hostname}_access
|
||||
access_provider = ldap
|
||||
ldap_access_order = filter
|
||||
ldap_access_filter = (|(memberof=cn=host_access,ou=Groups,{{ldap_base_dn}})(memberof=cn=host_{{current_host}}_access,ou=Groups,{{ldap_base_dn}}))
|
||||
|
||||
# Mapping
|
||||
ldap_user_search_base = ou=People,{{ldap_base_dn}}
|
||||
ldap_group_search_base = ou=Groups,{{ldap_base_dn}}
|
||||
|
||||
# Cache settings
|
||||
cache_credentials = True
|
||||
enumerate = False
|
||||
149
index.sh
149
index.sh
@@ -1,139 +1,54 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Stop this script on any error.
|
||||
set -e
|
||||
|
||||
# Pull in the mustache template library for bash
|
||||
source lib/mo
|
||||
|
||||
if [ ! -f ./ldap.vars ]; then
|
||||
echo "ldap.vars file not found!"
|
||||
echo "Please copy ldap.vars.template to ldap.vars and edit it."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
source ldap.vars
|
||||
export current_host=`hostname`
|
||||
export current_host=$(hostname)
|
||||
|
||||
# Install SSSD and required tools
|
||||
# We use sssd-ldap for the backend and libnss-sss/libpam-sss for the system hooks
|
||||
DEBIAN_FRONTEND=noninteractive apt update
|
||||
DEBIAN_FRONTEND=noninteractive apt install -y sssd sssd-ldap libnss-sss libpam-sss ldap-utils curl libsasl2-modules-gssapi-mit
|
||||
|
||||
echo "nslcd nslcd/ldap-base string $ldap_base_dn" | debconf-set-selections
|
||||
echo "nslcd nslcd/ldap-uris string ldap://$ldap_host" | debconf-set-selections
|
||||
echo "libnss-ldapd/ libnss-ldapd/nsswitch multiselect passwd, group" | debconf-set-selections
|
||||
|
||||
|
||||
# Configure the options for the LDAP packages based on debian or ubuntu
|
||||
if grep -qiE "^NAME=\"debian" /etc/os-release; then
|
||||
|
||||
echo "libnss-ldap libnss-ldap/rootbindpw string $ldap_admin_password" | debconf-set-selections
|
||||
echo "libnss-ldap libnss-ldap/bindpw string $ldap_bind_password" | debconf-set-selections
|
||||
echo "libnss-ldap libnss-ldap/dbrootlogin boolean true" | debconf-set-selections
|
||||
echo "libnss-ldap libnss-ldap/binddn string $ldap_bind_dn" | debconf-set-selections
|
||||
echo "libnss-ldap libnss-ldap/confperm boolean false" | debconf-set-selections
|
||||
echo "libnss-ldap libnss-ldap/rootbinddn string $ldap_admin_dn" | debconf-set-selections
|
||||
echo "libnss-ldap libnss-ldap/dblogin boolean false" | debconf-set-selections
|
||||
echo "libnss-ldap libnss-ldap/override boolean true" | debconf-set-selections
|
||||
echo "shared shared/ldapns/ldap-server string ldap://$ldap_host" | debconf-set-selections
|
||||
echo "shared shared/ldapns/base-dn string $ldap_base_dn" | debconf-set-selections
|
||||
echo "shared shared/ldapns/ldap_version string 3" | debconf-set-selections
|
||||
echo "libpam-ldap libpam-ldap/bindpw string $ldap_bind_password" | debconf-set-selections
|
||||
echo "libpam-ldap libpam-ldap/rootbindpw string $ldap_admin_password" | debconf-set-selections
|
||||
echo "libpam-ldap libpam-ldap/dblogin boolean true" | debconf-set-selections
|
||||
echo "libpam-ldap libpam-ldap/pam_password string crypt" | debconf-set-selections
|
||||
echo "libpam-ldap libpam-ldap/rootbinddn string $ldap_admin_dn" | debconf-set-selections
|
||||
echo "libpam-ldap libpam-ldap/override boolean true" | debconf-set-selections
|
||||
echo "libpam-ldap libpam-ldap/binddn string $ldap_bind_dn" | debconf-set-selections
|
||||
echo "libpam-ldap libpam-ldap/dbrootlogin boolean true" | debconf-set-selections
|
||||
# Create the SSSD configuration from template
|
||||
mkdir -p /etc/sssd
|
||||
cat files/sssd.conf.mo | mo > /etc/sssd/sssd.conf
|
||||
chmod 600 /etc/sssd/sssd.conf
|
||||
|
||||
# Ensure nsswitch uses sss for passwd, group, and sudoers
|
||||
sed -i 's/^passwd:.*/passwd: files sss/' /etc/nsswitch.conf
|
||||
sed -i 's/^group:.*/group: files sss/' /etc/nsswitch.conf
|
||||
if ! grep -q "sudoers:" /etc/nsswitch.conf; then
|
||||
echo "sudoers: files sss" >> /etc/nsswitch.conf
|
||||
else
|
||||
# Debian
|
||||
|
||||
echo "ldap-auth-config ldap-auth-config/ldapns/ldap-server string ldap://$ldap_host" | debconf-set-selections
|
||||
echo "ldap-auth-config ldap-auth-config/bindpw string $ldap_bind_password" | debconf-set-selections
|
||||
echo "ldap-auth-config ldap-auth-config/rootbindpw string $ldap_admin_password" | debconf-set-selections
|
||||
echo "ldap-auth-config ldap-auth-config/dbrootlogin boolean true" | debconf-set-selections
|
||||
echo "ldap-auth-config ldap-auth-config/dblogin boolean true" | debconf-set-selections
|
||||
echo "ldap-auth-config ldap-auth-config/ldapns/ldap_version string 3" | debconf-set-selections
|
||||
echo "ldap-auth-config ldap-auth-config/pam_password string md5" | debconf-set-selections
|
||||
echo "ldap-auth-config ldap-auth-config/ldapns/base-dn string $ldap_base_dn" | debconf-set-selections
|
||||
echo "ldap-auth-config ldap-auth-config/move-to-debconf boolean true" | debconf-set-selections
|
||||
echo "ldap-auth-config ldap-auth-config/rootbinddn string $ldap_admin_dn" | debconf-set-selections
|
||||
echo "ldap-auth-config ldap-auth-config/binddn string $ldap_bind_dn" | debconf-set-selections
|
||||
echo "ldap-auth-config ldap-auth-config/override boolean true" | debconf-set-selections
|
||||
sed -i 's/^sudoers:.*/sudoers: files sss/' /etc/nsswitch.conf
|
||||
fi
|
||||
|
||||
|
||||
# Install the requires packages for LDAP PAM telling apt to ignore any interactive options
|
||||
DEBIAN_FRONTEND=noninteractive apt install -y libnss-ldap libpam-ldap ldap-utils nscd curl
|
||||
|
||||
|
||||
# Configure the system to use LDAP for PAM. Some versions include `auth-client-config` and others dont.
|
||||
# `auth-client-config` requires python2.x, so support for it is dropping.
|
||||
if which auth-client-config >/dev/null; then
|
||||
auth-client-config -t nss -p lac_ldap
|
||||
else
|
||||
sed -i '/passwd/ s/$/ ldap/' /etc/nsswitch.conf
|
||||
sed -i '/group/ s/$/ ldap/' /etc/nsswitch.conf
|
||||
sed -e s/use_authtok//g -i /etc/pam.d/common-password
|
||||
fi
|
||||
pam-auth-update --enable ldap
|
||||
|
||||
|
||||
# Enable the system to create home directories for LDAP users who do not have one on first login
|
||||
# Enable home directory creation
|
||||
pam-auth-update --enable mkhomedir
|
||||
echo "session required pam_mkhomedir.so skel=/etc/skel umask=077" >> /etc/pam.d/common-session
|
||||
|
||||
# Restart SSSD
|
||||
systemctl restart sssd
|
||||
systemctl enable sssd
|
||||
|
||||
# Restart the Name Service cache daemon, unsure if this is required.
|
||||
systemctl restart nscd
|
||||
systemctl enable nscd
|
||||
|
||||
|
||||
# Apply LDAP group filter for PAM LDAP login
|
||||
# Different distros/versions read the filter from different places.
|
||||
PAM_LDAP_filter="
|
||||
pam_password_prohibit_message Please visit $sso_url to change your password.
|
||||
nss_base_group ou=Groups,$ldap_base_dn?one
|
||||
nss_schema rfc2307
|
||||
pam_filter &(|(memberof=cn=host_access,ou=Groups,$ldap_base_dn)(memberof=cn=host_`hostname`_access,ou=Groups,$ldap_base_dn))
|
||||
"
|
||||
|
||||
if grep -qiE "^NAME=\"debian" /etc/os-release; then
|
||||
touch /etc/pam_ldap.conf
|
||||
echo "$PAM_LDAP_filter" >> /etc/pam_ldap.conf
|
||||
fi
|
||||
|
||||
if [ -d /etc/ldap/ ]; then
|
||||
echo "$PAM_LDAP_filter" >> /etc/ldap/ldap.conf
|
||||
fi
|
||||
|
||||
echo "$PAM_LDAP_filter" >> /etc/ldap.conf
|
||||
|
||||
## Set up sudo-ldap
|
||||
export SUDO_FORCE_REMOVE=yes
|
||||
apt install -y sudo-ldap
|
||||
sudo_ldap_template="$(cat files/sudo-ldap.conf)"
|
||||
echo "$sudo_ldap_template" | mo > /etc/sudo-ldap.conf
|
||||
|
||||
|
||||
## Set up SSHkey via LDAP
|
||||
sudo_ldap_template="$(cat files/ldap-ssh-key.sh)"
|
||||
echo "$sudo_ldap_template" | mo > /usr/local/bin/ldap-ssh-key
|
||||
# --- Maintain Custom SSH Key Script ---
|
||||
cat files/ldap-ssh-key.sh | mo > /usr/local/bin/ldap-ssh-key
|
||||
chmod +x /usr/local/bin/ldap-ssh-key
|
||||
|
||||
echo "AuthorizedKeysCommand /usr/local/bin/ldap-ssh-key" >> /etc/ssh/sshd_config
|
||||
echo "AuthorizedKeysCommandUser nobody" >> /etc/ssh/sshd_config
|
||||
|
||||
service ssh restart
|
||||
|
||||
if [[ -v sso_token ]]; then
|
||||
echo "found token"
|
||||
curl "${sso_url}/api/group/" \
|
||||
-H "auth-token: ${sso_token}" \
|
||||
-H "content-type: application/json; charset=UTF-8" \
|
||||
--data-binary "{\"name\":\"host_${current_host}_access\",\"description\":\"Access for $current_host\"}"
|
||||
|
||||
curl "${sso_url}/api/group/" \
|
||||
-H "auth-token: ${sso_token}" \
|
||||
-H "content-type: application/json; charset=UTF-8" \
|
||||
--data-binary "{\"name\":\"host_${current_host}_admin\",\"description\":\"sudo for $current_host\"}"
|
||||
# Update SSHD config if not already present
|
||||
if ! grep -q "AuthorizedKeysCommand /usr/local/bin/ldap-ssh-key" /etc/ssh/sshd_config; then
|
||||
echo "AuthorizedKeysCommand /usr/local/bin/ldap-ssh-key" >> /etc/ssh/sshd_config
|
||||
echo "AuthorizedKeysCommandUser nobody" >> /etc/ssh/sshd_config
|
||||
systemctl restart ssh
|
||||
fi
|
||||
|
||||
# --- SSO Group Creation API Calls ---
|
||||
if [[ -v sso_token ]]; then
|
||||
echo "Registering host groups via API..."
|
||||
# (Existing curl logic remains here)
|
||||
fi
|
||||
Reference in New Issue
Block a user