Compare commits
3
Commits
v1.0.0
..
c2add5e660
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c2add5e660 | ||
|
|
9122259f55 | ||
|
|
5cb8c6b67a |
No files matched your search
@@ -1,12 +0,0 @@
|
|||||||
# Beispiel für create-deploy-user.py – kopieren nach .env (wird nicht eingecheckt):
|
|
||||||
# cp .env.example .env && chmod 600 .env
|
|
||||||
# Ausführen: ./create-deploy-user.py --project-path owner/repo
|
|
||||||
# Das Skript lädt .env neben sich selbst automatisch (gesetzte Umgebungsvariablen haben Vorrang);
|
|
||||||
# fehlen die Tokens, wird interaktiv gefragt.
|
|
||||||
|
|
||||||
# authentik-API-Token (authentik → Benutzer-Einstellungen → Tokens und App-Passwörter)
|
|
||||||
AUTHENTIK_TOKEN=
|
|
||||||
|
|
||||||
# Gitea-Access-Token mit Scope write:repository
|
|
||||||
# (https://git.share-fix.de/user/settings/applications)
|
|
||||||
GITEA_TOKEN=
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
name: lint
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [main]
|
|
||||||
pull_request:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
shell:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- name: bash -n
|
|
||||||
run: for f in *.sh; do bash -n "$f"; done
|
|
||||||
- name: shellcheck
|
|
||||||
run: |
|
|
||||||
sudo apt-get update -qq && sudo apt-get install -y -qq shellcheck
|
|
||||||
shellcheck --severity=warning *.sh
|
|
||||||
|
|
||||||
python:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- uses: actions/setup-python@v5
|
|
||||||
with:
|
|
||||||
python-version: "3.12"
|
|
||||||
- name: Syntax-Check
|
|
||||||
run: python -m py_compile create-deploy-user.py
|
|
||||||
- name: ruff
|
|
||||||
run: pip install -q ruff && ruff check create-deploy-user.py
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
__pycache__/
|
|
||||||
*.pyc
|
|
||||||
.claude/
|
|
||||||
.codegraph/
|
|
||||||
.env
|
|
||||||
-74
@@ -1,74 +0,0 @@
|
|||||||
name: docker-deploy
|
|
||||||
description: Synchronisiert das Repo per rsync nach ~/deployment und startet docker-deploy.sh auf dem Zielserver
|
|
||||||
|
|
||||||
# Verwendung (siehe examples/deploy.yml):
|
|
||||||
# - uses: actions/checkout@v4
|
|
||||||
# - uses: https://git.share-fix.de/jochen/admin-toolsuite@v1
|
|
||||||
# with:
|
|
||||||
# deploy_user: ${{ vars.deploy_user }}
|
|
||||||
# deploy_host: ${{ vars.deploy_host }}
|
|
||||||
# deploy_pass: ${{ secrets.deploy_pass }}
|
|
||||||
|
|
||||||
inputs:
|
|
||||||
deploy_user:
|
|
||||||
description: Deploy-User auf dem Zielserver
|
|
||||||
required: true
|
|
||||||
deploy_host:
|
|
||||||
description: Hostname/IP des Zielservers
|
|
||||||
required: true
|
|
||||||
deploy_pass:
|
|
||||||
description: Passwort/App-Token des Deploy-Users
|
|
||||||
required: true
|
|
||||||
compose_file:
|
|
||||||
description: Compose-Datei, die vor dem Deploy validiert wird
|
|
||||||
default: docker-compose.yml
|
|
||||||
|
|
||||||
runs:
|
|
||||||
using: composite
|
|
||||||
steps:
|
|
||||||
- name: Compose-Datei validieren
|
|
||||||
shell: bash
|
|
||||||
run: docker compose -f "$COMPOSE_FILE" config --quiet
|
|
||||||
env:
|
|
||||||
COMPOSE_FILE: ${{ inputs.compose_file }}
|
|
||||||
|
|
||||||
- name: Tools installieren
|
|
||||||
shell: bash
|
|
||||||
run: sudo apt-get update -qq && sudo apt-get install -y -qq sshpass rsync
|
|
||||||
|
|
||||||
- name: Dateien nach ~/deployment synchronisieren
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
sshpass -e rsync -az --delete \
|
|
||||||
--exclude '.git' --exclude '.gitea' --exclude '.env' \
|
|
||||||
--filter=':- .gitignore' \
|
|
||||||
-e "ssh $SSH_OPTS" \
|
|
||||||
./ "$DEPLOY_USER@$DEPLOY_HOST:deployment/"
|
|
||||||
env:
|
|
||||||
DEPLOY_USER: ${{ inputs.deploy_user }}
|
|
||||||
DEPLOY_HOST: ${{ inputs.deploy_host }}
|
|
||||||
SSHPASS: ${{ inputs.deploy_pass }}
|
|
||||||
SSH_OPTS: -o StrictHostKeyChecking=accept-new -o PubkeyAuthentication=no
|
|
||||||
|
|
||||||
- name: Deploy (pull → build → up)
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
sshpass -e ssh $SSH_OPTS "$DEPLOY_USER@$DEPLOY_HOST" \
|
|
||||||
"sudo /usr/local/bin/docker-deploy.sh $DEPLOY_USER deploy"
|
|
||||||
env:
|
|
||||||
DEPLOY_USER: ${{ inputs.deploy_user }}
|
|
||||||
DEPLOY_HOST: ${{ inputs.deploy_host }}
|
|
||||||
SSHPASS: ${{ inputs.deploy_pass }}
|
|
||||||
SSH_OPTS: -o StrictHostKeyChecking=accept-new -o PubkeyAuthentication=no
|
|
||||||
|
|
||||||
- name: Logs bei Fehler
|
|
||||||
if: failure()
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
sshpass -e ssh $SSH_OPTS "$DEPLOY_USER@$DEPLOY_HOST" \
|
|
||||||
"sudo /usr/local/bin/docker-deploy.sh $DEPLOY_USER logs" || true
|
|
||||||
env:
|
|
||||||
DEPLOY_USER: ${{ inputs.deploy_user }}
|
|
||||||
DEPLOY_HOST: ${{ inputs.deploy_host }}
|
|
||||||
SSHPASS: ${{ inputs.deploy_pass }}
|
|
||||||
SSH_OPTS: -o StrictHostKeyChecking=accept-new -o PubkeyAuthentication=no
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
# check-sshd-ldap.sh <username> [server]
|
|
||||||
#
|
|
||||||
# Diagnose der Kette authentik-LDAP-Outpost → SSSD → NSS/PAM → sshd.
|
|
||||||
set -uo pipefail
|
|
||||||
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
|
||||||
|
|
||||||
USER_NAME="${1:-}"
|
|
||||||
SERVER="${2:-H1}"
|
|
||||||
[[ -n "$USER_NAME" ]] || { echo "Verwendung: $(basename "$0") <username> [server]" >&2; exit 1; }
|
|
||||||
|
|
||||||
fail=0
|
|
||||||
check() { # check "Beschreibung" befehl...
|
|
||||||
local desc="$1"; shift
|
|
||||||
if "$@" >/dev/null 2>&1; then printf '✅ %s\n' "$desc"; else printf '❌ %s\n' "$desc"; fail=1; fi
|
|
||||||
}
|
|
||||||
|
|
||||||
check "sssd läuft" systemctl is-active --quiet sssd
|
|
||||||
check "sssd.conf: Rechte 0600 root" test "$(stat -c '%a %u' /etc/sssd/sssd.conf)" = "600 0"
|
|
||||||
check "sshd-Konfiguration gültig" sshd -t
|
|
||||||
check "sshd: AuthorizedKeysCommand gesetzt" bash -c "sshd -T | grep -qi '^authorizedkeyscommand .*sss_ssh_authorizedkeys'"
|
|
||||||
check "NSS: passwd enthält sss" bash -c "grep -Eq '^passwd:.*\bsss\b' /etc/nsswitch.conf"
|
|
||||||
check "User '$USER_NAME' per NSS auflösbar" getent passwd "$USER_NAME"
|
|
||||||
check "Gruppe server_${SERVER}_ssh_access" bash -c "id -nG '$USER_NAME' | tr ' ' '\n' | grep -qx 'server_${SERVER}_ssh_access'"
|
|
||||||
check "Gruppe server_${SERVER}_docker_compose" bash -c "id -nG '$USER_NAME' | tr ' ' '\n' | grep -qx 'server_${SERVER}_docker_compose'"
|
|
||||||
check "SSH-Keys-Abfrage funktioniert (Aufruf)" sss_ssh_authorizedkeys "$USER_NAME"
|
|
||||||
|
|
||||||
echo
|
|
||||||
echo "── getent passwd $USER_NAME"; getent passwd "$USER_NAME" || true
|
|
||||||
echo "── id $USER_NAME"; id "$USER_NAME" 2>&1 || true
|
|
||||||
if command -v sssctl >/dev/null; then
|
|
||||||
echo "── sssctl domain-status authentik"; sssctl domain-status authentik 2>&1 | head -n 15 || true
|
|
||||||
else
|
|
||||||
echo "── sssctl fehlt (apt install sssd-tools)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Direkte LDAP-Abfrage mit den Daten aus sssd.conf: trennt Outpost-/Bind-Probleme von SSSD-Problemen
|
|
||||||
conf() { sed -n "s/^$1 *= *//p" /etc/sssd/sssd.conf 2>/dev/null | head -n 1; } # Wert darf selbst '=' enthalten (DN, Passwort)
|
|
||||||
if command -v ldapsearch >/dev/null && [[ -r /etc/sssd/sssd.conf ]]; then
|
|
||||||
echo "── ldapsearch (cn=$USER_NAME)"
|
|
||||||
LDAPTLS_CACERT="$(conf ldap_tls_cacert)" ldapsearch -LLL -H "$(conf ldap_uri)" -D "$(conf ldap_default_bind_dn)" \
|
|
||||||
-y <(printf %s "$(conf ldap_default_authtok)") -b "$(conf ldap_search_base)" \
|
|
||||||
"(cn=$USER_NAME)" dn cn memberOf homeDirectory 2>&1 | head -n 20 || true
|
|
||||||
fi
|
|
||||||
echo "── sssd-Log (letzte Zeilen)"; journalctl -u sssd -n 15 --no-pager 2>&1 | tail -n 15 || true
|
|
||||||
|
|
||||||
if [[ $fail -ne 0 ]]; then
|
|
||||||
echo
|
|
||||||
echo "Hinweis: Debug mit 'sssctl debug-level 6' und 'journalctl -u sssd -u ssh -f'."
|
|
||||||
fi
|
|
||||||
exit "$fail"
|
|
||||||
+15
-45
@@ -1,11 +1,4 @@
|
|||||||
#!/usr/bin/env -S uv run --script
|
#!/usr/bin/env python3
|
||||||
# /// script
|
|
||||||
# requires-python = ">=3.13"
|
|
||||||
# dependencies = [
|
|
||||||
# "authentik-client>=2026.8.5",
|
|
||||||
# "requests>=2.34.2",
|
|
||||||
# ]
|
|
||||||
# ///
|
|
||||||
"""Legt in authentik einen Deploy-User für ein Gitea-Repository an und hinterlegt
|
"""Legt in authentik einen Deploy-User für ein Gitea-Repository an und hinterlegt
|
||||||
die Zugangsdaten als Gitea-Actions-Secrets/-Variablen."""
|
die Zugangsdaten als Gitea-Actions-Secrets/-Variablen."""
|
||||||
|
|
||||||
@@ -14,16 +7,15 @@ import os
|
|||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
from getpass import getpass
|
from getpass import getpass
|
||||||
from pathlib import Path
|
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
import authentik_client
|
import authentik_client
|
||||||
import requests
|
import requests
|
||||||
from authentik_client.rest import ApiException
|
from authentik_client.rest import ApiException
|
||||||
|
|
||||||
DEFAULT_AUTHENTIK_URL = "https://auth.share-fix.de/api/v3"
|
DEFAULT_AUTHENTIK_URL = "https://auth.systems.cogsys.wiai.uni-bamberg.de/api/v3"
|
||||||
DEFAULT_GITEA_URL = "https://git.share-fix.de"
|
DEFAULT_GITEA_URL = "https://git.share-fix.de"
|
||||||
DEFAULT_SERVER = "H1"
|
DEFAULT_DOCKER_GROUP = "server_APPS_docker_compose"
|
||||||
HOME_DIR_BASE = "/home"
|
HOME_DIR_BASE = "/home"
|
||||||
USERNAME_RE = re.compile(r"^[a-z_][a-z0-9_-]{0,31}$")
|
USERNAME_RE = re.compile(r"^[a-z_][a-z0-9_-]{0,31}$")
|
||||||
|
|
||||||
@@ -80,18 +72,12 @@ def authentik_get_group_by_name(client: authentik_client.CoreApi, name: str):
|
|||||||
raise RuntimeError(f"Gruppe '{name}' nicht gefunden")
|
raise RuntimeError(f"Gruppe '{name}' nicht gefunden")
|
||||||
|
|
||||||
|
|
||||||
def authentik_create_user(client: authentik_client.CoreApi, username: str, home_directory: str, groups, repo_url: str) -> str:
|
def authentik_create_user(client: authentik_client.CoreApi, username: str, home_directory: str, groups) -> str:
|
||||||
print(f"Creating user: {username}")
|
print(f"Creating user: {username}")
|
||||||
users = client.core_users_list(username=username)
|
users = client.core_users_list(username=username)
|
||||||
if users.results:
|
if users.results:
|
||||||
print(f"User {username} already exists")
|
print(f"User {username} already exists")
|
||||||
user = users.results[0]
|
user = users.results[0]
|
||||||
client.core_users_partial_update(
|
|
||||||
id=user.pk,
|
|
||||||
patched_user_request=authentik_client.PatchedUserRequest(
|
|
||||||
attributes={**(user.attributes or {}), "notes": repo_url, "homeDirectory": home_directory}
|
|
||||||
),
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
user = client.core_users_create(
|
user = client.core_users_create(
|
||||||
user_request=authentik_client.UserRequest(
|
user_request=authentik_client.UserRequest(
|
||||||
@@ -101,7 +87,6 @@ def authentik_create_user(client: authentik_client.CoreApi, username: str, home_
|
|||||||
is_active=True,
|
is_active=True,
|
||||||
path="goauthentik.io/service-accounts",
|
path="goauthentik.io/service-accounts",
|
||||||
attributes={
|
attributes={
|
||||||
"notes": repo_url,
|
|
||||||
"homeDirectory": home_directory,
|
"homeDirectory": home_directory,
|
||||||
"goauthentik.io/user/token-expires": False,
|
"goauthentik.io/user/token-expires": False,
|
||||||
},
|
},
|
||||||
@@ -134,12 +119,12 @@ def authentik_create_user(client: authentik_client.CoreApi, username: str, home_
|
|||||||
# ── CLI ──────────────────────────────────────────────────────────────────────
|
# ── CLI ──────────────────────────────────────────────────────────────────────
|
||||||
def parse_args() -> argparse.Namespace:
|
def parse_args() -> argparse.Namespace:
|
||||||
p = argparse.ArgumentParser(description="Deploy-User für ein Gitea-Repository in authentik anlegen")
|
p = argparse.ArgumentParser(description="Deploy-User für ein Gitea-Repository in authentik anlegen")
|
||||||
p.add_argument("--server", default=DEFAULT_SERVER,
|
p.add_argument("--server", required=True,
|
||||||
help=f"Zielserver; bestimmt server_<SERVER>_ssh_access und server_<SERVER>_docker_compose (Standard: {DEFAULT_SERVER})")
|
help="Zielserver; bestimmt die Gruppe server_<SERVER>_ssh_access (z. B. APPS -> server_APPS_ssh_access)")
|
||||||
p.add_argument("--project-path", help="Gitea-Repository: 'owner/repo' oder URL")
|
p.add_argument("--project-path", help="Gitea-Repository: 'owner/repo' oder URL")
|
||||||
p.add_argument("--username", help="Username des Deploy-Users (Standard: deploy_<repo-id>_<repo>, max. 32 Zeichen)")
|
p.add_argument("--username", help="Username des Deploy-Users (Standard: deploy_<owner>_<repo>)")
|
||||||
p.add_argument("--docker-group",
|
p.add_argument("--docker-group", default=DEFAULT_DOCKER_GROUP,
|
||||||
help="Gruppe für Docker-Deploys (Standard: server_<SERVER>_docker_compose)")
|
help=f"Zusätzliche Gruppe für Docker-Deploys (Standard: {DEFAULT_DOCKER_GROUP})")
|
||||||
p.add_argument("--no-docker-group", action="store_true", help="Docker-Deploy-Gruppe nicht zuweisen")
|
p.add_argument("--no-docker-group", action="store_true", help="Docker-Deploy-Gruppe nicht zuweisen")
|
||||||
p.add_argument("--authentik-url", default=DEFAULT_AUTHENTIK_URL)
|
p.add_argument("--authentik-url", default=DEFAULT_AUTHENTIK_URL)
|
||||||
p.add_argument("--authentik-token", default=os.environ.get("AUTHENTIK_TOKEN"),
|
p.add_argument("--authentik-token", default=os.environ.get("AUTHENTIK_TOKEN"),
|
||||||
@@ -152,26 +137,12 @@ def parse_args() -> argparse.Namespace:
|
|||||||
return p.parse_args()
|
return p.parse_args()
|
||||||
|
|
||||||
|
|
||||||
def make_username(repo_id: int, repo_name: str) -> str:
|
def make_username(repo_path: str) -> str:
|
||||||
"""deploy_<id>_<reponame>; die ID bleibt immer erhalten, der Name wird auf 32 Zeichen gekürzt."""
|
name = "deploy_" + re.sub(r"[^a-z0-9]+", "_", repo_path.lower()).strip("_")
|
||||||
slug = re.sub(r"[^a-z0-9]+", "_", repo_name.lower()).strip("_")
|
return name[:32].rstrip("_")
|
||||||
return f"deploy_{repo_id}_{slug}"[:32].rstrip("_")
|
|
||||||
|
|
||||||
|
|
||||||
def load_env_file(path: Path) -> None:
|
|
||||||
"""Liest KEY=VALUE-Zeilen aus einer .env; bereits gesetzte Variablen haben Vorrang."""
|
|
||||||
if not path.is_file():
|
|
||||||
return
|
|
||||||
for line in path.read_text().splitlines():
|
|
||||||
line = line.strip()
|
|
||||||
if not line or line.startswith("#") or "=" not in line:
|
|
||||||
continue
|
|
||||||
key, _, value = line.removeprefix("export ").partition("=")
|
|
||||||
os.environ.setdefault(key.strip(), value.strip().strip("\"'"))
|
|
||||||
|
|
||||||
|
|
||||||
def main() -> int:
|
def main() -> int:
|
||||||
load_env_file(Path(__file__).resolve().parent / ".env")
|
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
|
|
||||||
if not re.fullmatch(r"[A-Za-z0-9_-]+", args.server):
|
if not re.fullmatch(r"[A-Za-z0-9_-]+", args.server):
|
||||||
@@ -190,20 +161,19 @@ def main() -> int:
|
|||||||
repo = gitea.get_repo(repo_path)
|
repo = gitea.get_repo(repo_path)
|
||||||
repo_path = repo["full_name"] # kanonische Schreibweise
|
repo_path = repo["full_name"] # kanonische Schreibweise
|
||||||
|
|
||||||
username = args.username or make_username(repo["id"], repo["name"])
|
username = args.username or make_username(repo_path)
|
||||||
if not USERNAME_RE.match(username):
|
if not USERNAME_RE.match(username):
|
||||||
sys.exit(f"Ungültiger Username '{username}' (erlaubt: ^[a-z_][a-z0-9_-]{{0,31}}$)")
|
sys.exit(f"Ungültiger Username '{username}' (erlaubt: ^[a-z_][a-z0-9_-]{{0,31}}$)")
|
||||||
home_dir = f"{HOME_DIR_BASE}/{username}"
|
home_dir = f"{HOME_DIR_BASE}/{username}"
|
||||||
|
|
||||||
group_names = [f"server_{args.server}_ssh_access"]
|
group_names = [f"server_{args.server}_ssh_access"]
|
||||||
if not args.no_docker_group:
|
if not args.no_docker_group:
|
||||||
group_names.append(args.docker_group or f"server_{args.server}_docker_compose")
|
group_names.append(args.docker_group)
|
||||||
|
|
||||||
print(f"\nRepository: {repo_path} (id {repo['id']})")
|
print(f"\nRepository: {repo_path} (id {repo['id']})")
|
||||||
print(f"Deploy-User: {username}")
|
print(f"Deploy-User: {username}")
|
||||||
print(f"Home-Verz.: {home_dir}")
|
print(f"Home-Verz.: {home_dir}")
|
||||||
print(f"Gruppen: {', '.join(group_names)}")
|
print(f"Gruppen: {', '.join(group_names)}")
|
||||||
print(f"Notes: {repo['html_url']}")
|
|
||||||
print(f"Gitea-Secrets: deploy_user, deploy_pass")
|
print(f"Gitea-Secrets: deploy_user, deploy_pass")
|
||||||
if args.dry_run:
|
if args.dry_run:
|
||||||
print("\n[dry-run] Es wurde nichts angelegt.")
|
print("\n[dry-run] Es wurde nichts angelegt.")
|
||||||
@@ -216,7 +186,7 @@ def main() -> int:
|
|||||||
core_api = authentik_client.CoreApi(api_client)
|
core_api = authentik_client.CoreApi(api_client)
|
||||||
try:
|
try:
|
||||||
groups = [authentik_get_group_by_name(core_api, n) for n in group_names]
|
groups = [authentik_get_group_by_name(core_api, n) for n in group_names]
|
||||||
key = authentik_create_user(core_api, username, home_dir, groups, repo["html_url"])
|
key = authentik_create_user(core_api, username, home_dir, groups)
|
||||||
except (ApiException, RuntimeError) as e:
|
except (ApiException, RuntimeError) as e:
|
||||||
sys.exit(f"Fehler in authentik: {e}")
|
sys.exit(f"Fehler in authentik: {e}")
|
||||||
|
|
||||||
|
|||||||
Executable → Regular
+4
-27
@@ -6,30 +6,11 @@ set -Eeuo pipefail
|
|||||||
IFS=$'\n\t'
|
IFS=$'\n\t'
|
||||||
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
||||||
|
|
||||||
SCRIPT_NAME="$(basename "$0")"
|
readonly SCRIPT_NAME="$(basename "$0")"
|
||||||
readonly SCRIPT_NAME
|
readonly DEPLOY_SUBDIR="its-deploy"
|
||||||
readonly DEPLOY_SUBDIR="deployment"
|
readonly DEPLOY_GROUP="server_APPS_docker_compose"
|
||||||
readonly CONFIG_FILE="/etc/docker-deploy.conf"
|
|
||||||
readonly ALLOWED_ACTIONS=(build up down restart logs pull deploy)
|
readonly ALLOWED_ACTIONS=(build up down restart logs pull deploy)
|
||||||
|
|
||||||
# ── Konfiguration ────────────────────────────────────────────────────────────
|
|
||||||
# Optional: /etc/docker-deploy.conf (root-owned, nicht group/world-writable) mit
|
|
||||||
# DEPLOY_SERVER=H1
|
|
||||||
# Berechtigte Gruppe: server_${DEPLOY_SERVER}_docker_compose.
|
|
||||||
# Bewusst keine Umgebungsvariable/kein Parameter: sudo-Aufrufer sollen die
|
|
||||||
# Berechtigungsprüfung nicht selbst umstellen können.
|
|
||||||
DEPLOY_SERVER="H1"
|
|
||||||
if [[ -e "$CONFIG_FILE" ]]; then
|
|
||||||
IFS=' ' read -r cfg_owner cfg_mode < <(stat -c '%u %a' "$CONFIG_FILE")
|
|
||||||
if [[ "$cfg_owner" != 0 ]] || (( 8#$cfg_mode & 8#022 )); then
|
|
||||||
echo "❌ $CONFIG_FILE muss root gehören und darf nicht group/world-writable sein" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
DEPLOY_SERVER="$(sed -n 's/^DEPLOY_SERVER=//p' "$CONFIG_FILE" | tail -n1 | tr -d "\"' ")"
|
|
||||||
fi
|
|
||||||
[[ "$DEPLOY_SERVER" =~ ^[A-Za-z0-9_-]+$ ]] || { echo "❌ Ungültiger DEPLOY_SERVER: '$DEPLOY_SERVER'" >&2; exit 1; }
|
|
||||||
readonly DEPLOY_GROUP="server_${DEPLOY_SERVER}_docker_compose"
|
|
||||||
|
|
||||||
# ── Hilfsfunktionen ──────────────────────────────────────────────────────────
|
# ── Hilfsfunktionen ──────────────────────────────────────────────────────────
|
||||||
log() { printf '[%(%Y-%m-%d %H:%M:%S)T] %s\n' -1 "$*"; }
|
log() { printf '[%(%Y-%m-%d %H:%M:%S)T] %s\n' -1 "$*"; }
|
||||||
die() { printf '❌ %s\n' "$*" >&2; exit 1; }
|
die() { printf '❌ %s\n' "$*" >&2; exit 1; }
|
||||||
@@ -55,7 +36,7 @@ in_array() {
|
|||||||
|
|
||||||
user_in_group() {
|
user_in_group() {
|
||||||
local -a groups
|
local -a groups
|
||||||
IFS=' ' read -ra groups <<<"$(id -nG "$1")"
|
read -ra groups <<<"$(id -nG "$1")"
|
||||||
in_array "$2" "${groups[@]}"
|
in_array "$2" "${groups[@]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,10 +66,6 @@ fi
|
|||||||
[[ "$APP_USER" =~ ^[a-z_][a-z0-9_-]{0,31}$ ]] || die "Ungültiger Username: '$APP_USER'"
|
[[ "$APP_USER" =~ ^[a-z_][a-z0-9_-]{0,31}$ ]] || die "Ungültiger Username: '$APP_USER'"
|
||||||
id "$APP_USER" &>/dev/null || die "User '$APP_USER' existiert nicht auf diesem System"
|
id "$APP_USER" &>/dev/null || die "User '$APP_USER' existiert nicht auf diesem System"
|
||||||
user_in_group "$APP_USER" "$DEPLOY_GROUP" || die "User '$APP_USER' ist nicht in Gruppe '$DEPLOY_GROUP'"
|
user_in_group "$APP_USER" "$DEPLOY_GROUP" || die "User '$APP_USER' ist nicht in Gruppe '$DEPLOY_GROUP'"
|
||||||
# Per sudo darf jeder nur für sich selbst deployen (sudoers erlaubt die ganze Gruppe)
|
|
||||||
if [[ -n "${SUDO_USER:-}" && "$SUDO_USER" != "root" && "$SUDO_USER" != "$APP_USER" ]]; then
|
|
||||||
die "'$SUDO_USER' darf nicht für '$APP_USER' deployen"
|
|
||||||
fi
|
|
||||||
in_array "$ACTION" "${ALLOWED_ACTIONS[@]}" || die "Unbekannte Aktion: '$ACTION' (erlaubt: ${ALLOWED_ACTIONS[*]})"
|
in_array "$ACTION" "${ALLOWED_ACTIONS[@]}" || die "Unbekannte Aktion: '$ACTION' (erlaubt: ${ALLOWED_ACTIONS[*]})"
|
||||||
if $USE_CACHE && [[ "$ACTION" != "build" && "$ACTION" != "deploy" ]]; then
|
if $USE_CACHE && [[ "$ACTION" != "build" && "$ACTION" != "deploy" ]]; then
|
||||||
die "--cache ist nur bei build/deploy sinnvoll"
|
die "--cache ist nur bei build/deploy sinnvoll"
|
||||||
|
|||||||
@@ -1,105 +0,0 @@
|
|||||||
# authentik-LDAP-Outpost ↔ sshd
|
|
||||||
|
|
||||||
Anmeldung per SSH gegen authentik: **sshd → PAM/NSS → SSSD → LDAP-Outpost (LDAPS) → authentik**.
|
|
||||||
Die Deploy-User aus `create-deploy-user.py` (Service-Accounts) melden sich mit ihrem
|
|
||||||
App-Passwort an, normale User per Passwort oder SSH-Key.
|
|
||||||
|
|
||||||
```
|
|
||||||
Client ──ssh──▶ sshd ──PAM/NSS──▶ SSSD ──ldaps:636──▶ LDAP-Outpost ──API──▶ authentik
|
|
||||||
│ (Bind: Service-Account)
|
|
||||||
└─ AuthorizedKeysCommand: sss_ssh_authorizedkeys
|
|
||||||
```
|
|
||||||
|
|
||||||
| Baustein | Aufgabe |
|
|
||||||
|---|---|
|
|
||||||
| `setup-sshd-ldap.sh` | Konfiguriert SSSD, NSS, PAM, sshd, `docker-deploy.sh`-Gruppe und sudoers |
|
|
||||||
| `check-sshd-ldap.sh` | Diagnose der gesamten Kette |
|
|
||||||
| `create-deploy-user.py` | Legt Deploy-User + Gruppenmitgliedschaften in authentik an |
|
|
||||||
| `docker-deploy.sh` | Deployt per sudo; Berechtigung über `server_<SERVER>_docker_compose` |
|
|
||||||
|
|
||||||
## 1. authentik vorbereiten
|
|
||||||
|
|
||||||
1. **Gruppen** anlegen (Verzeichnis *Gruppen*):
|
|
||||||
- `server_<SERVER>_ssh_access` (Login auf dem Server erlaubt)
|
|
||||||
- `server_<SERVER>_docker_compose` (darf `docker-deploy.sh` nutzen)
|
|
||||||
- Server-Standard ist `H1`.
|
|
||||||
2. **Bind-Account** für SSSD: Service-Account `ldapsvc` anlegen (*Verzeichnis → User → Service-Account*), Token/Passwort notieren.
|
|
||||||
Eine Gruppe `ldap-search` anlegen, den Account hinzufügen und dieser Gruppe die
|
|
||||||
Berechtigung *Search full LDAP directory* geben. Ohne diese Berechtigung sieht SSSD keine Gruppen.
|
|
||||||
3. **LDAP-Provider** anlegen (*Anwendungen → Provider → LDAP Provider*):
|
|
||||||
- Bind-Flow: `default-authentication-flow` (oder ein Flow ohne MFA, wenn Service-Accounts per App-Passwort binden – MFA lässt sich per LDAP nicht beantworten)
|
|
||||||
- Search-Group: `ldap-search`
|
|
||||||
- Base-DN: z. B. `dc=ldap,dc=goauthentik,dc=io`
|
|
||||||
- *Bind mode* / *Search mode*: Direct (keine Cached-Variante, damit Gruppenänderungen sofort greifen)
|
|
||||||
4. **Application** zum Provider anlegen, dann einen **LDAP-Outpost** erstellen und die Application zuweisen.
|
|
||||||
5. **TLS:** Standard des Setups ist Klartext-LDAP auf `ldap://127.0.0.1:389` (Outpost auf demselben Host). Bind-Passwort und Anmeldedaten laufen dann unverschlüsselt – nur über Loopback oder in einem vertrauenswürdigen Netz (z. B. Docker-Netz) verwenden.
|
|
||||||
Für ein anderes Netz dem Outpost ein Zertifikat zuweisen (Provider → *TLS Server name* / Zertifikat), die CA auf dem SSH-Server hinterlegen (`--ca-cert`) und `--ldap-uri ldaps://host:636` oder `--starttls` (bei `ldap://`) verwenden.
|
|
||||||
6. **User-Attribute** (setzt `create-deploy-user.py` für Deploy-User automatisch):
|
|
||||||
- `homeDirectory`: Home-Verzeichnis, Standard `/home/<username>`
|
|
||||||
- `notes`: Link zum Gitea-Repo
|
|
||||||
- `sshPublicKey` (optional): öffentlicher SSH-Schlüssel für Key-Login
|
|
||||||
- `uidNumber`/`gidNumber` berechnet authentik selbst.
|
|
||||||
|
|
||||||
## 2. SSH-Server einrichten
|
|
||||||
|
|
||||||
Voraussetzung: Debian/Ubuntu, root-Zugriff, Outpost erreichbar (Standard `127.0.0.1:389`).
|
|
||||||
|
|
||||||
```bash
|
|
||||||
sudo ./setup-sshd-ldap.sh
|
|
||||||
```
|
|
||||||
|
|
||||||
Das Skript fragt Server (Standard `H1`), Bind-User und Passwort ab. Beim Bind-User genügt der Username,
|
|
||||||
daraus wird `cn=<user>,<base-dn>`. Standards: `--ldap-uri ldap://127.0.0.1:389`,
|
|
||||||
`--base-dn dc=ldap,dc=goauthentik,dc=io`, kein TLS. Alles lässt sich per Option vorgeben:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
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/zur/ca.pem
|
|
||||||
```
|
|
||||||
|
|
||||||
Das Skript (idempotent, sichert vorhandene `sssd.conf`):
|
|
||||||
|
|
||||||
- installiert `sssd`, `sssd-ldap`, `libnss-sss`, `libpam-sss`
|
|
||||||
- schreibt `/etc/sssd/sssd.conf` (0600) im authentik-Schema (`rfc2307bis`, Objektklassen `user`/`group`, Suche ab der Base-DN)
|
|
||||||
mit Zugriffsfilter `(objectClass=posixAccount)` (änderbar mit `--access-filter`). Wer sich anmelden darf, steuert authentik
|
|
||||||
(Application-Bindings, Gruppen); `server_<SERVER>_ssh_access` wird nicht mehr von SSSD geprüft
|
|
||||||
- ergänzt `sss` in `/etc/nsswitch.conf` und aktiviert `pam_sss` sowie `pam_mkhomedir`
|
|
||||||
(Home wird beim ersten Login angelegt; `/etc/skel/deployment` legt das Deploy-Verzeichnis gleich mit an)
|
|
||||||
- schreibt `/etc/ssh/sshd_config.d/50-authentik-ldap.conf` (`UsePAM`, `AuthorizedKeysCommand sss_ssh_authorizedkeys`)
|
|
||||||
- schreibt `/etc/docker-deploy.conf` (`DEPLOY_SERVER=<SERVER>`) und `/etc/sudoers.d/docker-deploy`
|
|
||||||
(`%server_<SERVER>_docker_compose ALL=(root) NOPASSWD: /usr/local/bin/docker-deploy.sh`; abschaltbar mit `--no-sudoers`)
|
|
||||||
|
|
||||||
Danach `docker-deploy.sh` nach `/usr/local/bin/` kopieren (`install -m 0755 docker-deploy.sh /usr/local/bin/`).
|
|
||||||
|
|
||||||
## 3. Prüfen
|
|
||||||
|
|
||||||
```bash
|
|
||||||
./check-sshd-ldap.sh <username> [server]
|
|
||||||
ssh <username>@<host>
|
|
||||||
```
|
|
||||||
|
|
||||||
Typische Fehler:
|
|
||||||
|
|
||||||
| Symptom | Ursache / Lösung |
|
|
||||||
|---|---|
|
|
||||||
| `getent passwd <user>` leer | Bind-Account ohne *Search full LDAP directory*; falsche Base-DN; Outpost nicht erreichbar → `sssctl domain-status authentik` |
|
|
||||||
| Gruppen fehlen in `id` | Nutzer nicht in der Gruppe; `ldap_group_*`-Suchbasis falsch; Cache: `sss_cache -E` |
|
|
||||||
| Login abgelehnt trotz korrektem Passwort | User in authentik nicht freigegeben (Application-Bindings/Gruppe) oder `--access-filter` trifft nicht zu |
|
|
||||||
| TLS-Fehler | CA fehlt oder Hostname passt nicht zum Zertifikat (`ldap_tls_reqcert = demand`) |
|
|
||||||
| Key-Login klappt nicht | Attribut `sshPublicKey` fehlt/falsch benannt; `sss_ssh_authorizedkeys <user>` testen |
|
|
||||||
| `sudo`: *darf nicht für … deployen* | Gewollt: Aufrufer darf nur für sich selbst deployen (Admins als echter root) |
|
|
||||||
|
|
||||||
Debug: `sssctl debug-level 6`, `journalctl -u sssd -u ssh -f`.
|
|
||||||
|
|
||||||
## 4. Deploy-Ablauf
|
|
||||||
|
|
||||||
1. `create-deploy-user.py --project-path owner/repo [--server H1]` legt User und Gruppen an und setzt `deploy_user`/`deploy_pass` im Gitea-Repo.
|
|
||||||
2. Die CI meldet sich per SSH als Deploy-User an, lädt `docker-compose.yml` nach `~/deployment/` und ruft
|
|
||||||
`sudo docker-deploy.sh <username> deploy` auf.
|
|
||||||
|
|
||||||
## Sicherheitshinweise
|
|
||||||
|
|
||||||
- Bind-Passwort steht in `/etc/sssd/sssd.conf` (0600, root) – für den Bind-Account nur minimale Rechte vergeben.
|
|
||||||
- Wer `docker compose` als root aus einem User-Verzeichnis ausführen lässt, gibt dem User faktisch root-Rechte (Compose-Datei kann beliebige Mounts definieren). Die Gruppe `server_<SERVER>_docker_compose` nur an vertrauenswürdige Projekte vergeben.
|
|
||||||
- Passwort-Login ist für Service-Accounts nötig; für normale User sollte zusätzlich Key-Login bevorzugt und MFA auf einem separaten Flow gehalten werden.
|
|
||||||
- Die genauen Attributnamen (`sshPublicKey`, `homeDirectory`, `memberOf`) und die Berechtigung des Search-Accounts hängen von der authentik-Version ab. Beim ersten Einsatz mit `ldapsearch -H ldaps://… -D <bind-dn> -W -b <base-dn> "(cn=<user>)"` verifizieren.
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
# Beispiel: .gitea/workflows/deploy.yml im Repo eines Dienstes
|
|
||||||
#
|
|
||||||
# Die eigentliche Logik liegt als Composite Action in diesem Repo (action.yml).
|
|
||||||
# Die Version (@v1.0.0) wird von Renovate per PR aktualisiert (siehe renovate.json).
|
|
||||||
#
|
|
||||||
# Voraussetzungen (Setup mit create-deploy-user.py --project-path owner/repo):
|
|
||||||
# Variable deploy_user - Deploy-User (wird vom Skript gesetzt)
|
|
||||||
# Secret deploy_pass - Passwort/App-Token des Users (wird vom Skript gesetzt)
|
|
||||||
# Variable deploy_host - Hostname/IP des Zielservers (manuell setzen)
|
|
||||||
#
|
|
||||||
# Das Repo enthält docker-compose.yml (und optional docker-compose.override.yml)
|
|
||||||
# im Wurzelverzeichnis; sie landen in ~/deployment auf dem Server.
|
|
||||||
name: deploy
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [main]
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
# Nie zwei Deploys gleichzeitig für denselben Dienst
|
|
||||||
concurrency:
|
|
||||||
group: deploy-${{ gitea.repository }}
|
|
||||||
cancel-in-progress: false
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
deploy:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- uses: https://git.share-fix.de/jochen/admin-toolsuite@v1.0.0
|
|
||||||
with:
|
|
||||||
deploy_user: ${{ vars.deploy_user }}
|
|
||||||
deploy_host: ${{ vars.deploy_host }}
|
|
||||||
deploy_pass: ${{ secrets.deploy_pass }}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
# Beispiel: .gitea/workflows/renovate.yml (einmal zentral oder pro Repo)
|
|
||||||
#
|
|
||||||
# Voraussetzungen:
|
|
||||||
# Secret RENOVATE_TOKEN - Gitea-Token des Bot-Users (Rechte: repository r/w, issue r/w, user r)
|
|
||||||
# Secret GITHUB_COM_TOKEN - optional, nur für Release-Notes/Rate-Limits von github.com
|
|
||||||
name: renovate
|
|
||||||
|
|
||||||
on:
|
|
||||||
schedule:
|
|
||||||
- cron: "0 4 * * *"
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
renovate:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
container:
|
|
||||||
image: renovate/renovate:latest
|
|
||||||
steps:
|
|
||||||
- name: Renovate ausführen
|
|
||||||
run: renovate
|
|
||||||
env:
|
|
||||||
RENOVATE_PLATFORM: gitea
|
|
||||||
RENOVATE_ENDPOINT: https://git.share-fix.de/api/v1
|
|
||||||
RENOVATE_TOKEN: ${{ secrets.RENOVATE_TOKEN }}
|
|
||||||
GITHUB_COM_TOKEN: ${{ secrets.GITHUB_COM_TOKEN }}
|
|
||||||
RENOVATE_AUTODISCOVER: "true"
|
|
||||||
LOG_LEVEL: info
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
{
|
|
||||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
|
||||||
"extends": ["config:recommended"],
|
|
||||||
"enabledManagers": ["github-actions"]
|
|
||||||
}
|
|
||||||
@@ -1,230 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
# setup-sshd-ldap.sh
|
|
||||||
#
|
|
||||||
# Bindet sshd über SSSD an den authentik-LDAP-Outpost an (Debian/Ubuntu).
|
|
||||||
# Siehe docs/authentik-ldap-sshd.md.
|
|
||||||
#
|
|
||||||
# Verwendung:
|
|
||||||
# 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"
|
|
||||||
|
|
||||||
readonly SSSD_CONF="/etc/sssd/sssd.conf"
|
|
||||||
readonly SSHD_DROPIN="/etc/ssh/sshd_config.d/50-authentik-ldap.conf"
|
|
||||||
readonly SUDOERS_FILE="/etc/sudoers.d/docker-deploy"
|
|
||||||
readonly DEPLOY_CONF="/etc/docker-deploy.conf"
|
|
||||||
readonly CA_TARGET="/etc/sssd/authentik-ldap-ca.pem"
|
|
||||||
|
|
||||||
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=true
|
|
||||||
ACCESS_FILTER="(objectClass=posixAccount)"
|
|
||||||
|
|
||||||
log() { printf '[%(%H:%M:%S)T] %s\n' -1 "$*"; }
|
|
||||||
die() { printf '❌ %s\n' "$*" >&2; exit 1; }
|
|
||||||
|
|
||||||
usage() {
|
|
||||||
cat >&2 <<EOF
|
|
||||||
Verwendung: sudo $(basename "$0") [Optionen]
|
|
||||||
|
|
||||||
Fehlende Angaben (Server, Bind-User, Passwort) werden abgefragt.
|
|
||||||
|
|
||||||
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)
|
|
||||||
--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-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
|
|
||||||
}
|
|
||||||
|
|
||||||
while [[ $# -gt 0 ]]; do
|
|
||||||
case "$1" in
|
|
||||||
--ldap-uri) LDAP_URI="${2:?}"; shift 2 ;;
|
|
||||||
--base-dn) BASE_DN="${2:?}"; shift 2 ;;
|
|
||||||
--bind-dn) BIND_DN="${2:?}"; shift 2 ;;
|
|
||||||
--bind-password-file) PW_FILE="${2:?}"; shift 2 ;;
|
|
||||||
--server) SERVER="${2:?}"; shift 2 ;;
|
|
||||||
--ca-cert) CA_CERT="${2:?}"; shift 2 ;;
|
|
||||||
--no-sudoers) INSTALL_SUDOERS=false; shift ;;
|
|
||||||
--access-filter) ACCESS_FILTER="${2:?}"; shift 2 ;;
|
|
||||||
--starttls) NO_TLS=false; shift ;;
|
|
||||||
-h|--help) usage ;;
|
|
||||||
*) usage ;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
[[ $EUID -eq 0 ]] || die "Muss als root laufen"
|
|
||||||
[[ "$LDAP_URI" == ldaps://* || "$LDAP_URI" == ldap://* ]] || die "ldap-uri muss mit ldaps:// oder ldap:// beginnen"
|
|
||||||
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"
|
|
||||||
|
|
||||||
if [[ -n "$PW_FILE" ]]; then
|
|
||||||
[[ -r "$PW_FILE" ]] || die "Passwortdatei nicht lesbar: $PW_FILE"
|
|
||||||
BIND_PW="$(<"$PW_FILE")"
|
|
||||||
else
|
|
||||||
read -rsp "Bind-Passwort für $BIND_DN: " BIND_PW; echo
|
|
||||||
fi
|
|
||||||
[[ -n "$BIND_PW" ]] || die "Leeres Bind-Passwort"
|
|
||||||
|
|
||||||
DOCKER_GROUP="server_${SERVER}_docker_compose"
|
|
||||||
|
|
||||||
# ── Pakete ───────────────────────────────────────────────────────────────────
|
|
||||||
log "📦 Pakete installieren"
|
|
||||||
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
|
|
||||||
sssd sssd-ldap libnss-sss libpam-sss libsss-sudo sssd-tools openssh-server ldap-utils >/dev/null
|
|
||||||
|
|
||||||
# ── CA ───────────────────────────────────────────────────────────────────────
|
|
||||||
TLS_CACERT_LINE="# ldap_tls_cacert: System-CA-Store"
|
|
||||||
if [[ -n "$CA_CERT" ]]; then
|
|
||||||
install -m 0644 -o root -g root "$CA_CERT" "$CA_TARGET"
|
|
||||||
TLS_CACERT_LINE="ldap_tls_cacert = $CA_TARGET"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# ── TLS-Modus ────────────────────────────────────────────────────────────────
|
|
||||||
if [[ "$LDAP_URI" == ldaps://* ]]; then
|
|
||||||
TLS_OPTIONS="ldap_tls_reqcert = demand
|
|
||||||
$TLS_CACERT_LINE"
|
|
||||||
elif $NO_TLS; then
|
|
||||||
log "⚠️ Klartext-LDAP: Bind-Passwort und Anmeldedaten laufen unverschlüsselt über das Netz"
|
|
||||||
TLS_OPTIONS="ldap_auth_disable_tls_never_use_in_production = true"
|
|
||||||
else
|
|
||||||
TLS_OPTIONS="ldap_id_use_start_tls = true
|
|
||||||
ldap_tls_reqcert = demand
|
|
||||||
$TLS_CACERT_LINE"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# ── Bind testen (bevor die vorhandene Konfiguration überschrieben wird) ──────
|
|
||||||
log "🔎 Bind als $BIND_DN testen"
|
|
||||||
pw_tmp="$(mktemp)"
|
|
||||||
trap 'rm -f "$pw_tmp"' EXIT
|
|
||||||
printf %s "$BIND_PW" >"$pw_tmp"
|
|
||||||
ldap_args=(-LLL -x -H "$LDAP_URI" -D "$BIND_DN" -y "$pw_tmp" -b "$BASE_DN" -s base dn)
|
|
||||||
[[ "$LDAP_URI" == ldap://* ]] && ! $NO_TLS && ldap_args+=(-ZZ)
|
|
||||||
if ! bind_out="$(LDAPTLS_CACERT="${CA_CERT:-}" ldapsearch "${ldap_args[@]}" 2>&1)"; then
|
|
||||||
die "Bind fehlgeschlagen: $bind_out
|
|
||||||
Bind-DN, Passwort (bei authentik-Service-Accounts das App-Passwort/Token) und Outpost-Erreichbarkeit prüfen; sssd.conf wurde nicht geändert."
|
|
||||||
fi
|
|
||||||
rm -f "$pw_tmp"
|
|
||||||
|
|
||||||
# ── SSSD ─────────────────────────────────────────────────────────────────────
|
|
||||||
log "🔧 $SSSD_CONF schreiben"
|
|
||||||
install -d -m 0711 /etc/sssd
|
|
||||||
[[ -e "$SSSD_CONF" ]] && cp -a "$SSSD_CONF" "${SSSD_CONF}.bak.$(date +%s)"
|
|
||||||
umask 077
|
|
||||||
cat >"$SSSD_CONF" <<EOF
|
|
||||||
# Verwaltet von setup-sshd-ldap.sh
|
|
||||||
[sssd]
|
|
||||||
services = nss, pam, ssh
|
|
||||||
domains = authentik
|
|
||||||
|
|
||||||
[domain/authentik]
|
|
||||||
id_provider = ldap
|
|
||||||
auth_provider = ldap
|
|
||||||
chpass_provider = none
|
|
||||||
access_provider = ldap
|
|
||||||
|
|
||||||
ldap_uri = $LDAP_URI
|
|
||||||
ldap_search_base = $BASE_DN
|
|
||||||
ldap_default_bind_dn = $BIND_DN
|
|
||||||
ldap_default_authtok_type = password
|
|
||||||
ldap_default_authtok = $BIND_PW
|
|
||||||
$TLS_OPTIONS
|
|
||||||
|
|
||||||
# authentik-Outpost-Schema
|
|
||||||
ldap_schema = rfc2307bis
|
|
||||||
ldap_user_search_base = $BASE_DN
|
|
||||||
ldap_group_search_base = $BASE_DN
|
|
||||||
ldap_user_object_class = user
|
|
||||||
ldap_group_object_class = group
|
|
||||||
ldap_user_name = cn
|
|
||||||
ldap_group_name = cn
|
|
||||||
ldap_user_gecos = name
|
|
||||||
ldap_user_home_directory = homeDirectory
|
|
||||||
ldap_user_ssh_public_key = sshPublicKey
|
|
||||||
ldap_group_member = member
|
|
||||||
|
|
||||||
# Wer sich anmelden darf, steuert authentik (Application-Bindings/Gruppen des Bind-Accounts)
|
|
||||||
ldap_access_order = filter
|
|
||||||
ldap_access_filter = $ACCESS_FILTER
|
|
||||||
|
|
||||||
fallback_homedir = /home/%u
|
|
||||||
default_shell = /bin/bash
|
|
||||||
enumerate = false
|
|
||||||
cache_credentials = true
|
|
||||||
entry_cache_timeout = 300
|
|
||||||
use_fully_qualified_names = false
|
|
||||||
EOF
|
|
||||||
chown root:root "$SSSD_CONF"
|
|
||||||
chmod 0600 "$SSSD_CONF"
|
|
||||||
umask 022
|
|
||||||
|
|
||||||
# ── NSS / PAM ────────────────────────────────────────────────────────────────
|
|
||||||
log "🔧 NSS/PAM konfigurieren"
|
|
||||||
for db in passwd group; do
|
|
||||||
grep -Eq "^${db}:.*\bsss\b" /etc/nsswitch.conf || sed -i -E "s/^(${db}:.*)$/\1 sss/" /etc/nsswitch.conf
|
|
||||||
done
|
|
||||||
install -d -m 0755 /etc/skel/deployment
|
|
||||||
pam-auth-update --enable sss mkhomedir >/dev/null
|
|
||||||
|
|
||||||
# ── sshd ─────────────────────────────────────────────────────────────────────
|
|
||||||
log "🔧 $SSHD_DROPIN schreiben"
|
|
||||||
install -d -m 0755 /etc/ssh/sshd_config.d
|
|
||||||
grep -Eq '^\s*Include\s+/etc/ssh/sshd_config.d/\*\.conf' /etc/ssh/sshd_config \
|
|
||||||
|| sed -i '1i Include /etc/ssh/sshd_config.d/*.conf' /etc/ssh/sshd_config
|
|
||||||
cat >"$SSHD_DROPIN" <<EOF
|
|
||||||
# Verwaltet von setup-sshd-ldap.sh
|
|
||||||
UsePAM yes
|
|
||||||
PubkeyAuthentication yes
|
|
||||||
# Service-Accounts (CI/CD) melden sich mit dem authentik-App-Passwort an
|
|
||||||
PasswordAuthentication yes
|
|
||||||
AuthorizedKeysCommand /usr/bin/sss_ssh_authorizedkeys %u
|
|
||||||
AuthorizedKeysCommandUser nobody
|
|
||||||
EOF
|
|
||||||
sshd -t || die "sshd-Konfiguration ungültig - Drop-in $SSHD_DROPIN prüfen"
|
|
||||||
|
|
||||||
# ── docker-deploy.sh ─────────────────────────────────────────────────────────
|
|
||||||
log "🔧 $DEPLOY_CONF schreiben"
|
|
||||||
printf 'DEPLOY_SERVER=%s\n' "$SERVER" >"$DEPLOY_CONF"
|
|
||||||
chown root:root "$DEPLOY_CONF"; chmod 0644 "$DEPLOY_CONF"
|
|
||||||
|
|
||||||
if $INSTALL_SUDOERS; then
|
|
||||||
log "🔧 $SUDOERS_FILE schreiben"
|
|
||||||
tmp="$(mktemp)"
|
|
||||||
printf '%%%s ALL=(root) NOPASSWD: /usr/local/bin/docker-deploy.sh\n' "$DOCKER_GROUP" >"$tmp"
|
|
||||||
visudo -cf "$tmp" >/dev/null || { rm -f "$tmp"; die "sudoers-Regel ungültig"; }
|
|
||||||
install -m 0440 -o root -g root "$tmp" "$SUDOERS_FILE"
|
|
||||||
rm -f "$tmp"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# ── Dienste ──────────────────────────────────────────────────────────────────
|
|
||||||
log "🔄 Dienste (neu) starten"
|
|
||||||
systemctl enable --now sssd >/dev/null
|
|
||||||
systemctl restart sssd
|
|
||||||
systemctl reload ssh 2>/dev/null || systemctl reload sshd
|
|
||||||
|
|
||||||
log "✅ Fertig. Prüfen mit: ./check-sshd-ldap.sh <username>"
|
|
||||||
Reference in new issue
Block a user