setup-sshd-ldap.sh: Abfrage für Server/Bind-User, Bind-User nur als Name, Standards für URI, Base-DN und kein TLS (--starttls)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
bfb1b45845
commit
e19b02dfbd
2 files changed
+43
-29
No files matched your search
+30
-19
@@ -5,10 +5,10 @@
|
||||
# Siehe docs/authentik-ldap-sshd.md.
|
||||
#
|
||||
# Verwendung:
|
||||
# sudo ./setup-sshd-ldap.sh --ldap-uri ldaps://ldap.example.org:636 \
|
||||
# --base-dn dc=ldap,dc=goauthentik,dc=io \
|
||||
# --bind-dn cn=ldapsvc,ou=users,dc=ldap,dc=goauthentik,dc=io \
|
||||
# [--server H1] [--ca-cert /pfad/ca.pem] [--bind-password-file /pfad]
|
||||
# sudo ./setup-sshd-ldap.sh
|
||||
# fragt Server, Bind-User und Passwort ab; Standard ist ldap://127.0.0.1:389 ohne TLS.
|
||||
# sudo ./setup-sshd-ldap.sh --server H1 --bind-dn ldapsvc [--bind-password-file /pfad]
|
||||
# sudo ./setup-sshd-ldap.sh --ldap-uri ldaps://ldap.example.org:636 --ca-cert /pfad/ca.pem ...
|
||||
set -Eeuo pipefail
|
||||
IFS=$'\n\t'
|
||||
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
||||
@@ -19,10 +19,12 @@ readonly SUDOERS_FILE="/etc/sudoers.d/docker-deploy"
|
||||
readonly DEPLOY_CONF="/etc/docker-deploy.conf"
|
||||
readonly CA_TARGET="/etc/sssd/authentik-ldap-ca.pem"
|
||||
|
||||
SERVER="H1"
|
||||
LDAP_URI="" BASE_DN="" BIND_DN="" CA_CERT="" PW_FILE=""
|
||||
DEFAULT_SERVER="H1"
|
||||
DEFAULT_LDAP_URI="ldap://127.0.0.1:389"
|
||||
DEFAULT_BASE_DN="dc=ldap,dc=goauthentik,dc=io"
|
||||
SERVER="" LDAP_URI="$DEFAULT_LDAP_URI" BASE_DN="$DEFAULT_BASE_DN" BIND_DN="" CA_CERT="" PW_FILE=""
|
||||
INSTALL_SUDOERS=true
|
||||
NO_TLS=false
|
||||
NO_TLS=true
|
||||
ACCESS_FILTER="(objectClass=posixAccount)"
|
||||
|
||||
log() { printf '[%(%H:%M:%S)T] %s\n' -1 "$*"; }
|
||||
@@ -30,20 +32,22 @@ die() { printf '❌ %s\n' "$*" >&2; exit 1; }
|
||||
|
||||
usage() {
|
||||
cat >&2 <<EOF
|
||||
Verwendung: sudo $(basename "$0") --ldap-uri URI --base-dn DN --bind-dn DN [Optionen]
|
||||
Verwendung: sudo $(basename "$0") [Optionen]
|
||||
|
||||
Pflicht:
|
||||
--ldap-uri URI z. B. ldaps://ldap.example.org:636 oder ldap://ldap.example.org:389 (StartTLS)
|
||||
--base-dn DN Base-DN des Outposts (authentik-Standard: dc=ldap,dc=goauthentik,dc=io)
|
||||
--bind-dn DN Bind-DN des LDAP-Service-Accounts
|
||||
Fehlende Angaben (Server, Bind-User, Passwort) werden abgefragt.
|
||||
|
||||
Optional:
|
||||
Optionen:
|
||||
--server NAME Servername -> server_NAME_ssh_access / server_NAME_docker_compose (Standard: $DEFAULT_SERVER)
|
||||
--bind-dn USER|DN Bind-Account: nur der Username (wird zu cn=USER,<base-dn>) oder ein vollständiger DN
|
||||
--bind-password-file FILE Passwort/Token des Bind-Accounts (sonst Abfrage)
|
||||
--server NAME Servername, Standard H1 -> server_H1_ssh_access / server_H1_docker_compose
|
||||
--ca-cert FILE CA-Zertifikat für das LDAPS-Zertifikat des Outposts
|
||||
--ldap-uri URI Standard: $DEFAULT_LDAP_URI; auch ldaps://host:636
|
||||
--base-dn DN Standard: $DEFAULT_BASE_DN
|
||||
--starttls bei ldap:// StartTLS verwenden statt Klartext (Outpost braucht ein Zertifikat)
|
||||
--ca-cert FILE CA-Zertifikat für LDAPS/StartTLS
|
||||
--access-filter FILTER LDAP-Filter für erlaubte User (Standard: (objectClass=posixAccount); sonst steuert authentik den Zugriff)
|
||||
--no-tls ldap:// ganz ohne TLS (Outpost ohne Zertifikat); NUR in vertrauenswürdigen Netzen
|
||||
--no-sudoers sudoers-Regel für docker-deploy.sh nicht anlegen
|
||||
|
||||
Standard ist Klartext-LDAP (ldap://, kein TLS): nur für Loopback/vertrauenswürdige Netze.
|
||||
EOF
|
||||
exit 1
|
||||
}
|
||||
@@ -58,16 +62,23 @@ while [[ $# -gt 0 ]]; do
|
||||
--ca-cert) CA_CERT="${2:?}"; shift 2 ;;
|
||||
--no-sudoers) INSTALL_SUDOERS=false; shift ;;
|
||||
--access-filter) ACCESS_FILTER="${2:?}"; shift 2 ;;
|
||||
--no-tls) NO_TLS=true; shift ;;
|
||||
--starttls) NO_TLS=false; shift ;;
|
||||
-h|--help) usage ;;
|
||||
*) usage ;;
|
||||
esac
|
||||
done
|
||||
|
||||
[[ $EUID -eq 0 ]] || die "Muss als root laufen"
|
||||
[[ -n "$LDAP_URI" && -n "$BASE_DN" && -n "$BIND_DN" ]] || usage
|
||||
[[ "$LDAP_URI" == ldaps://* || "$LDAP_URI" == ldap://* ]] || die "ldap-uri muss mit ldaps:// oder ldap:// beginnen"
|
||||
[[ "$LDAP_URI" == ldap://* || $NO_TLS == false ]] || die "--no-tls ist nur mit ldap:// sinnvoll"
|
||||
if [[ -z "$SERVER" ]]; then
|
||||
read -rp "Server [$DEFAULT_SERVER]: " SERVER
|
||||
SERVER="${SERVER:-$DEFAULT_SERVER}"
|
||||
fi
|
||||
if [[ -z "$BIND_DN" ]]; then
|
||||
read -rp "Bind-User (z. B. server_APPS_systemaccount): " BIND_DN
|
||||
fi
|
||||
[[ -n "$BIND_DN" ]] || die "Kein Bind-User angegeben"
|
||||
[[ "$BIND_DN" == *=* ]] || BIND_DN="cn=$BIND_DN,$BASE_DN"
|
||||
[[ "$SERVER" =~ ^[A-Za-z0-9_-]+$ ]] || die "Ungültiger Servername: '$SERVER'"
|
||||
[[ -z "$CA_CERT" || -r "$CA_CERT" ]] || die "CA-Zertifikat nicht lesbar: $CA_CERT"
|
||||
command -v apt-get >/dev/null || die "Nur Debian/Ubuntu (apt) unterstützt"
|
||||
|
||||
Reference in new issue
Block a user