Compare commits
26
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
75c9ced16f | ||
|
|
3600af1c6d | ||
|
|
d2c31901e1 | ||
|
|
95ca0108a0 | ||
|
|
0c9631de4d | ||
|
|
a5a3fab167 | ||
|
|
be80074390 | ||
|
|
0334711b8e | ||
|
|
3b915d3483 | ||
|
|
fd89217856 | ||
|
|
d19dae1f71 | ||
|
|
47b82efb4c | ||
|
|
fc560982b2 | ||
|
|
cd1891a2fd | ||
|
|
24406b59e5 | ||
|
|
ee61604e3e | ||
|
|
6cd676f31a | ||
|
|
f3579549b4 | ||
|
|
59cc0f8100 | ||
|
|
faffee6410 | ||
|
|
282d82dfb4 | ||
|
|
85fd4f1c3d | ||
|
|
12d4fc3cb9 | ||
|
|
781ca46713 | ||
|
|
7d0e8eb800 | ||
|
|
a49f2d1055 |
No files matched your search
@@ -0,0 +1,12 @@
|
|||||||
|
# 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=
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
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
|
||||||
@@ -2,3 +2,4 @@ __pycache__/
|
|||||||
*.pyc
|
*.pyc
|
||||||
.claude/
|
.claude/
|
||||||
.codegraph/
|
.codegraph/
|
||||||
|
.env
|
||||||
+74
@@ -0,0 +1,74 @@
|
|||||||
|
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
|
||||||
@@ -28,7 +28,21 @@ check "SSH-Keys-Abfrage funktioniert (Aufruf)" sss_ssh_authorizedkeys "$USER_NA
|
|||||||
echo
|
echo
|
||||||
echo "── getent passwd $USER_NAME"; getent passwd "$USER_NAME" || true
|
echo "── getent passwd $USER_NAME"; getent passwd "$USER_NAME" || true
|
||||||
echo "── id $USER_NAME"; id "$USER_NAME" 2>&1 || 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
|
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
|
if [[ $fail -ne 0 ]]; then
|
||||||
echo
|
echo
|
||||||
|
|||||||
+71
-8
@@ -1,21 +1,36 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env -S uv run --script
|
||||||
|
# /// 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."""
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import base64
|
||||||
import os
|
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.systems.cogsys.wiai.uni-bamberg.de/api/v3"
|
DEFAULT_AUTHENTIK_URL = "https://auth.share-fix.de/api/v3"
|
||||||
DEFAULT_GITEA_URL = "https://git.share-fix.de"
|
DEFAULT_GITEA_URL = "https://git.share-fix.de"
|
||||||
DEFAULT_SERVER = "H1"
|
DEFAULT_SERVER = "H1"
|
||||||
|
SERVER_HOSTS = {
|
||||||
|
"H1": "host-1.futcloud.de",
|
||||||
|
"H2": "host-2.futcloud.de",
|
||||||
|
}
|
||||||
|
WORKFLOW_SOURCE = Path(__file__).resolve().parent / "examples" / "deploy.yml"
|
||||||
|
WORKFLOW_TARGET = ".gitea/workflows/deploy.yml"
|
||||||
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}$")
|
||||||
|
|
||||||
@@ -50,6 +65,22 @@ class Gitea:
|
|||||||
raise
|
raise
|
||||||
self._request("POST", url, json={"value": value})
|
self._request("POST", url, json={"value": value})
|
||||||
|
|
||||||
|
def create_file(self, repo_path: str, file_path: str, content: str, message: str) -> bool:
|
||||||
|
"""Legt eine Datei im Default-Branch an. False, wenn sie bereits existiert."""
|
||||||
|
url = f"/repos/{repo_path}/contents/{file_path}"
|
||||||
|
try:
|
||||||
|
self._request("GET", url)
|
||||||
|
return False
|
||||||
|
except requests.HTTPError as e:
|
||||||
|
if e.response is None or e.response.status_code != 404:
|
||||||
|
raise
|
||||||
|
print(f"Creating {file_path} in {repo_path}")
|
||||||
|
self._request("POST", url, json={
|
||||||
|
"content": base64.b64encode(content.encode()).decode(),
|
||||||
|
"message": message,
|
||||||
|
})
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def normalize_repo_path(raw: str, gitea_url: str) -> str:
|
def normalize_repo_path(raw: str, gitea_url: str) -> str:
|
||||||
"""Akzeptiert 'owner/repo', Web-URLs und Clone-URLs (mit/ohne .git)."""
|
"""Akzeptiert 'owner/repo', Web-URLs und Clone-URLs (mit/ohne .git)."""
|
||||||
@@ -129,10 +160,15 @@ def parse_args() -> argparse.Namespace:
|
|||||||
p.add_argument("--server", default=DEFAULT_SERVER,
|
p.add_argument("--server", default=DEFAULT_SERVER,
|
||||||
help=f"Zielserver; bestimmt server_<SERVER>_ssh_access und server_<SERVER>_docker_compose (Standard: {DEFAULT_SERVER})")
|
help=f"Zielserver; bestimmt server_<SERVER>_ssh_access und server_<SERVER>_docker_compose (Standard: {DEFAULT_SERVER})")
|
||||||
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_<owner>_<repo>)")
|
p.add_argument("--username", help="Username des Deploy-Users (Standard: deploy_<repo-id>_<repo>, max. 32 Zeichen)")
|
||||||
p.add_argument("--docker-group",
|
p.add_argument("--docker-group",
|
||||||
help="Gruppe für Docker-Deploys (Standard: server_<SERVER>_docker_compose)")
|
help="Gruppe für Docker-Deploys (Standard: server_<SERVER>_docker_compose)")
|
||||||
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("--deploy-host",
|
||||||
|
help="Hostname des Zielservers für die Variable deploy_host "
|
||||||
|
f"(Standard: Mapping {', '.join(f'{k}→{v}' for k, v in SERVER_HOSTS.items())})")
|
||||||
|
p.add_argument("--no-workflow", action="store_true",
|
||||||
|
help=f"{WORKFLOW_TARGET} nicht im Repo anlegen")
|
||||||
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"),
|
||||||
help="Bearer-Token für die authentik-API (oder Env AUTHENTIK_TOKEN)")
|
help="Bearer-Token für die authentik-API (oder Env AUTHENTIK_TOKEN)")
|
||||||
@@ -144,16 +180,33 @@ def parse_args() -> argparse.Namespace:
|
|||||||
return p.parse_args()
|
return p.parse_args()
|
||||||
|
|
||||||
|
|
||||||
def make_username(repo_path: str) -> str:
|
def make_username(repo_id: int, repo_name: str) -> str:
|
||||||
name = "deploy_" + re.sub(r"[^a-z0-9]+", "_", repo_path.lower()).strip("_")
|
"""deploy_<id>_<reponame>; die ID bleibt immer erhalten, der Name wird auf 32 Zeichen gekürzt."""
|
||||||
return name[:32].rstrip("_")
|
slug = re.sub(r"[^a-z0-9]+", "_", repo_name.lower()).strip("_")
|
||||||
|
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):
|
||||||
sys.exit(f"Ungültiger Servername: '{args.server}'")
|
sys.exit(f"Ungültiger Servername: '{args.server}'")
|
||||||
|
deploy_host = args.deploy_host or SERVER_HOSTS.get(args.server)
|
||||||
|
if not deploy_host:
|
||||||
|
sys.exit(f"Kein Host für Server '{args.server}' bekannt (SERVER_HOSTS: {', '.join(SERVER_HOSTS)}); --deploy-host angeben")
|
||||||
if not args.dry_run and not args.authentik_token:
|
if not args.dry_run and not args.authentik_token:
|
||||||
print(f"Authentik-API-Token erstellen unter {args.authentik_url.split('/api')[0]}/if/user/#/settings;page=page-tokens")
|
print(f"Authentik-API-Token erstellen unter {args.authentik_url.split('/api')[0]}/if/user/#/settings;page=page-tokens")
|
||||||
args.authentik_token = getpass("Enter authentik token: ")
|
args.authentik_token = getpass("Enter authentik token: ")
|
||||||
@@ -168,7 +221,7 @@ 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_path)
|
username = args.username or make_username(repo["id"], repo["name"])
|
||||||
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}"
|
||||||
@@ -182,7 +235,10 @@ def main() -> int:
|
|||||||
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"Notes: {repo['html_url']}")
|
||||||
print(f"Gitea-Secrets: deploy_user, deploy_pass")
|
print("Gitea-Secrets: deploy_user, deploy_pass")
|
||||||
|
print(f"Gitea-Variable: deploy_host={deploy_host}")
|
||||||
|
if not args.no_workflow:
|
||||||
|
print(f"Workflow: {WORKFLOW_TARGET} (direkt im Default-Branch, falls nicht vorhanden)")
|
||||||
if args.dry_run:
|
if args.dry_run:
|
||||||
print("\n[dry-run] Es wurde nichts angelegt.")
|
print("\n[dry-run] Es wurde nichts angelegt.")
|
||||||
return 0
|
return 0
|
||||||
@@ -200,7 +256,14 @@ def main() -> int:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
gitea.set_variable(repo_path, "deploy_user", username)
|
gitea.set_variable(repo_path, "deploy_user", username)
|
||||||
|
gitea.set_variable(repo_path, "deploy_host", deploy_host)
|
||||||
gitea.set_secret(repo_path, "deploy_pass", key)
|
gitea.set_secret(repo_path, "deploy_pass", key)
|
||||||
|
# Zuletzt: der Commit löst den ersten Deploy aus, dafür muss alles gesetzt sein
|
||||||
|
if not args.no_workflow:
|
||||||
|
created = gitea.create_file(repo_path, WORKFLOW_TARGET, WORKFLOW_SOURCE.read_text(),
|
||||||
|
"Deploy-Workflow hinzugefügt")
|
||||||
|
if not created:
|
||||||
|
print(f"{WORKFLOW_TARGET} existiert bereits, übersprungen")
|
||||||
except requests.RequestException as e:
|
except requests.RequestException as e:
|
||||||
sys.exit(f"Fehler in Gitea: {e}")
|
sys.exit(f"Fehler in Gitea: {e}")
|
||||||
|
|
||||||
|
|||||||
Regular → Executable
+3
-2
@@ -6,7 +6,8 @@ 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"
|
||||||
|
|
||||||
readonly SCRIPT_NAME="$(basename "$0")"
|
SCRIPT_NAME="$(basename "$0")"
|
||||||
|
readonly SCRIPT_NAME
|
||||||
readonly DEPLOY_SUBDIR="deployment"
|
readonly DEPLOY_SUBDIR="deployment"
|
||||||
readonly CONFIG_FILE="/etc/docker-deploy.conf"
|
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)
|
||||||
@@ -54,7 +55,7 @@ in_array() {
|
|||||||
|
|
||||||
user_in_group() {
|
user_in_group() {
|
||||||
local -a groups
|
local -a groups
|
||||||
read -ra groups <<<"$(id -nG "$1")"
|
IFS=' ' read -ra groups <<<"$(id -nG "$1")"
|
||||||
in_array "$2" "${groups[@]}"
|
in_array "$2" "${groups[@]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+17
-11
@@ -32,7 +32,8 @@ App-Passwort an, normale User per Passwort oder SSH-Key.
|
|||||||
- Base-DN: z. B. `dc=ldap,dc=goauthentik,dc=io`
|
- Base-DN: z. B. `dc=ldap,dc=goauthentik,dc=io`
|
||||||
- *Bind mode* / *Search mode*: Direct (keine Cached-Variante, damit Gruppenänderungen sofort greifen)
|
- *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.
|
4. **Application** zum Provider anlegen, dann einen **LDAP-Outpost** erstellen und die Application zuweisen.
|
||||||
5. **TLS:** Der Outpost liefert LDAPS auf 636. Für ein vertrauenswürdiges Zertifikat dem Outpost ein Zertifikat zuweisen (Provider → *TLS Server name* / Zertifikat) und die CA auf dem SSH-Server hinterlegen (`--ca-cert`). Klartext-LDAP wird vom Setup-Skript abgelehnt.
|
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):
|
6. **User-Attribute** (setzt `create-deploy-user.py` für Deploy-User automatisch):
|
||||||
- `homeDirectory`: Home-Verzeichnis, Standard `/home/<username>`
|
- `homeDirectory`: Home-Verzeichnis, Standard `/home/<username>`
|
||||||
- `notes`: Link zum Gitea-Repo
|
- `notes`: Link zum Gitea-Repo
|
||||||
@@ -41,22 +42,27 @@ App-Passwort an, normale User per Passwort oder SSH-Key.
|
|||||||
|
|
||||||
## 2. SSH-Server einrichten
|
## 2. SSH-Server einrichten
|
||||||
|
|
||||||
Voraussetzung: Debian/Ubuntu, root-Zugriff, Netzwerkzugang zum Outpost auf Port 636.
|
Voraussetzung: Debian/Ubuntu, root-Zugriff, Outpost erreichbar (Standard `127.0.0.1:389`).
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
sudo ./setup-sshd-ldap.sh \
|
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 \
|
Das Skript fragt Server (Standard `H1`), Bind-User und Passwort ab. Beim Bind-User genügt der Username,
|
||||||
--server H1 \
|
daraus wird `cn=<user>,<base-dn>`. Standards: `--ldap-uri ldap://127.0.0.1:389`,
|
||||||
--ca-cert /pfad/zur/ca.pem
|
`--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`):
|
Das Skript (idempotent, sichert vorhandene `sssd.conf`):
|
||||||
|
|
||||||
- installiert `sssd`, `sssd-ldap`, `libnss-sss`, `libpam-sss`
|
- installiert `sssd`, `sssd-ldap`, `libnss-sss`, `libpam-sss`
|
||||||
- schreibt `/etc/sssd/sssd.conf` (0600) mit Zugriffsfilter
|
- schreibt `/etc/sssd/sssd.conf` (0600) im authentik-Schema (`rfc2307bis`, Objektklassen `user`/`group`, Suche ab der Base-DN)
|
||||||
`(memberOf=cn=server_<SERVER>_ssh_access,ou=groups,<BASE_DN>)` – nur Gruppenmitglieder dürfen sich per LDAP anmelden
|
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`
|
- 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)
|
(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/ssh/sshd_config.d/50-authentik-ldap.conf` (`UsePAM`, `AuthorizedKeysCommand sss_ssh_authorizedkeys`)
|
||||||
@@ -78,7 +84,7 @@ Typische Fehler:
|
|||||||
|---|---|
|
|---|---|
|
||||||
| `getent passwd <user>` leer | Bind-Account ohne *Search full LDAP directory*; falsche Base-DN; Outpost nicht erreichbar → `sssctl domain-status authentik` |
|
| `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` |
|
| Gruppen fehlen in `id` | Nutzer nicht in der Gruppe; `ldap_group_*`-Suchbasis falsch; Cache: `sss_cache -E` |
|
||||||
| Login abgelehnt trotz korrektem Passwort | Nicht in `server_<SERVER>_ssh_access` (SSSD-Access-Filter) |
|
| 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`) |
|
| 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 |
|
| 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) |
|
| `sudo`: *darf nicht für … deployen* | Gewollt: Aufrufer darf nur für sich selbst deployen (Admins als echter root) |
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
# 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.1) 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 des Zielservers (wird vom Skript aus --server gesetzt)
|
||||||
|
#
|
||||||
|
# Das Skript legt diese Datei auch selbst als .gitea/workflows/deploy.yml im Repo an.
|
||||||
|
#
|
||||||
|
# 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.1
|
||||||
|
with:
|
||||||
|
deploy_user: ${{ vars.deploy_user }}
|
||||||
|
deploy_host: ${{ vars.deploy_host }}
|
||||||
|
deploy_pass: ${{ secrets.deploy_pass }}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
# .gitea/workflows/renovate.yaml
|
||||||
|
# Liegt in einem eigenen Repo, z. B. "infra/renovate-bot".
|
||||||
|
# Renovate findet per Autodiscover alle Repos, auf die der Bot-User Zugriff hat.
|
||||||
|
#
|
||||||
|
# Voraussetzung: Secret RENOVATE_TOKEN (Gitea-Token des Bot-Users)
|
||||||
|
|
||||||
|
name: renovate
|
||||||
|
|
||||||
|
on:
|
||||||
|
schedule:
|
||||||
|
- cron: "17 3 * * *" # täglich 03:17
|
||||||
|
workflow_dispatch: # manuell auslösbar
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: renovate
|
||||||
|
cancel-in-progress: false # nie zwei Läufe parallel
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
renovate:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container: ghcr.io/renovatebot/renovate:latest@sha256:823dc5036b911696c27faacf7664219b28e6e15826405720df29aad208d19f25
|
||||||
|
timeout-minutes: 60
|
||||||
|
steps:
|
||||||
|
- name: Run Renovate
|
||||||
|
run: renovate
|
||||||
|
env:
|
||||||
|
# --- Plattform ---
|
||||||
|
RENOVATE_PLATFORM: gitea
|
||||||
|
RENOVATE_ENDPOINT: https://git.share-fix.de/api/v1
|
||||||
|
RENOVATE_TOKEN: ${{ secrets.RENOVATE_TOKEN }}
|
||||||
|
RENOVATE_GIT_AUTHOR: "Renovate Bot <4lzkkgpo@futmail.de>"
|
||||||
|
|
||||||
|
# --- Autodiscover ---
|
||||||
|
RENOVATE_AUTODISCOVER: "true"
|
||||||
|
# Nur bestimmte Orgs/Repos (Glob oder /Regex/), Rest ignorieren.
|
||||||
|
|
||||||
|
# --- Onboarding ---
|
||||||
|
# Neue Repos bekommen einen Onboarding-PR mit dieser renovate.json.
|
||||||
|
RENOVATE_ONBOARDING: "true"
|
||||||
|
RENOVATE_ONBOARDING_CONFIG: >-
|
||||||
|
{
|
||||||
|
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||||
|
"extends": ["config:recommended", "docker:pinDigests"],
|
||||||
|
"timezone": "Europe/Berlin",
|
||||||
|
"schedule": ["before 6am"],
|
||||||
|
"automerge": false,
|
||||||
|
"packageRules": [
|
||||||
|
{
|
||||||
|
"matchDatasources": ["docker"],
|
||||||
|
"matchUpdateTypes": ["patch", "digest"],
|
||||||
|
"automerge": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"matchDatasources": ["docker"],
|
||||||
|
"matchUpdateTypes": ["major"],
|
||||||
|
"dependencyDashboardApproval": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
# Repos ohne gemergte renovate.json nicht anfassen (nur Onboarding-PR).
|
||||||
|
RENOVATE_REQUIRE_CONFIG: required
|
||||||
|
|
||||||
|
# --- Grenzen & Logging ---
|
||||||
|
RENOVATE_PR_HOURLY_LIMIT: "5"
|
||||||
|
RENOVATE_PR_CONCURRENT_LIMIT: "15"
|
||||||
|
LOG_LEVEL: info
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||||
|
"extends": ["config:recommended", "docker:pinDigests"],
|
||||||
|
"timezone": "Europe/Berlin",
|
||||||
|
"schedule": ["before 6am"],
|
||||||
|
"automerge": false,
|
||||||
|
"packageRules": [
|
||||||
|
{
|
||||||
|
"matchDatasources": ["docker"],
|
||||||
|
"matchUpdateTypes": ["patch", "digest"],
|
||||||
|
"automerge": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"matchDatasources": ["docker"],
|
||||||
|
"matchUpdateTypes": ["major"],
|
||||||
|
"dependencyDashboardApproval": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
+72
-28
@@ -5,10 +5,10 @@
|
|||||||
# Siehe docs/authentik-ldap-sshd.md.
|
# Siehe docs/authentik-ldap-sshd.md.
|
||||||
#
|
#
|
||||||
# Verwendung:
|
# Verwendung:
|
||||||
# sudo ./setup-sshd-ldap.sh --ldap-uri ldaps://ldap.example.org:636 \
|
# sudo ./setup-sshd-ldap.sh
|
||||||
# --base-dn dc=ldap,dc=goauthentik,dc=io \
|
# fragt Server, Bind-User und Passwort ab; Standard ist ldap://127.0.0.1:389 ohne TLS.
|
||||||
# --bind-dn cn=ldapsvc,ou=users,dc=ldap,dc=goauthentik,dc=io \
|
# sudo ./setup-sshd-ldap.sh --server H1 --bind-dn ldapsvc [--bind-password-file /pfad]
|
||||||
# [--server H1] [--ca-cert /pfad/ca.pem] [--bind-password-file /pfad]
|
# sudo ./setup-sshd-ldap.sh --ldap-uri ldaps://ldap.example.org:636 --ca-cert /pfad/ca.pem ...
|
||||||
set -Eeuo pipefail
|
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"
|
||||||
@@ -19,27 +19,35 @@ readonly SUDOERS_FILE="/etc/sudoers.d/docker-deploy"
|
|||||||
readonly DEPLOY_CONF="/etc/docker-deploy.conf"
|
readonly DEPLOY_CONF="/etc/docker-deploy.conf"
|
||||||
readonly CA_TARGET="/etc/sssd/authentik-ldap-ca.pem"
|
readonly CA_TARGET="/etc/sssd/authentik-ldap-ca.pem"
|
||||||
|
|
||||||
SERVER="H1"
|
DEFAULT_SERVER="H1"
|
||||||
LDAP_URI="" BASE_DN="" BIND_DN="" CA_CERT="" PW_FILE=""
|
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
|
INSTALL_SUDOERS=true
|
||||||
|
NO_TLS=true
|
||||||
|
ACCESS_FILTER="(objectClass=posixAccount)"
|
||||||
|
|
||||||
log() { printf '[%(%H:%M:%S)T] %s\n' -1 "$*"; }
|
log() { printf '[%(%H:%M:%S)T] %s\n' -1 "$*"; }
|
||||||
die() { printf '❌ %s\n' "$*" >&2; exit 1; }
|
die() { printf '❌ %s\n' "$*" >&2; exit 1; }
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
cat >&2 <<EOF
|
cat >&2 <<EOF
|
||||||
Verwendung: sudo $(basename "$0") --ldap-uri URI --base-dn DN --bind-dn DN [Optionen]
|
Verwendung: sudo $(basename "$0") [Optionen]
|
||||||
|
|
||||||
Pflicht:
|
Fehlende Angaben (Server, Bind-User, Passwort) werden abgefragt.
|
||||||
--ldap-uri URI z. B. ldaps://ldap.example.org:636
|
|
||||||
--base-dn DN Base-DN des Outposts (authentik-Standard: dc=ldap,dc=goauthentik,dc=io)
|
|
||||||
--bind-dn DN Bind-DN des LDAP-Service-Accounts
|
|
||||||
|
|
||||||
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)
|
--bind-password-file FILE Passwort/Token des Bind-Accounts (sonst Abfrage)
|
||||||
--server NAME Servername, Standard H1 -> server_H1_ssh_access / server_H1_docker_compose
|
--ldap-uri URI Standard: $DEFAULT_LDAP_URI; auch ldaps://host:636
|
||||||
--ca-cert FILE CA-Zertifikat für das LDAPS-Zertifikat des Outposts
|
--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
|
--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
|
EOF
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
@@ -53,14 +61,24 @@ while [[ $# -gt 0 ]]; do
|
|||||||
--server) SERVER="${2:?}"; shift 2 ;;
|
--server) SERVER="${2:?}"; shift 2 ;;
|
||||||
--ca-cert) CA_CERT="${2:?}"; shift 2 ;;
|
--ca-cert) CA_CERT="${2:?}"; shift 2 ;;
|
||||||
--no-sudoers) INSTALL_SUDOERS=false; shift ;;
|
--no-sudoers) INSTALL_SUDOERS=false; shift ;;
|
||||||
|
--access-filter) ACCESS_FILTER="${2:?}"; shift 2 ;;
|
||||||
|
--starttls) NO_TLS=false; shift ;;
|
||||||
-h|--help) usage ;;
|
-h|--help) usage ;;
|
||||||
*) usage ;;
|
*) usage ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
[[ $EUID -eq 0 ]] || die "Muss als root laufen"
|
[[ $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" == ldaps://* ]] || die "Nur ldaps:// ist erlaubt (Passwörter dürfen nicht im Klartext übertragen werden)"
|
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'"
|
[[ "$SERVER" =~ ^[A-Za-z0-9_-]+$ ]] || die "Ungültiger Servername: '$SERVER'"
|
||||||
[[ -z "$CA_CERT" || -r "$CA_CERT" ]] || die "CA-Zertifikat nicht lesbar: $CA_CERT"
|
[[ -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"
|
command -v apt-get >/dev/null || die "Nur Debian/Ubuntu (apt) unterstützt"
|
||||||
@@ -73,13 +91,12 @@ else
|
|||||||
fi
|
fi
|
||||||
[[ -n "$BIND_PW" ]] || die "Leeres Bind-Passwort"
|
[[ -n "$BIND_PW" ]] || die "Leeres Bind-Passwort"
|
||||||
|
|
||||||
SSH_GROUP="server_${SERVER}_ssh_access"
|
|
||||||
DOCKER_GROUP="server_${SERVER}_docker_compose"
|
DOCKER_GROUP="server_${SERVER}_docker_compose"
|
||||||
|
|
||||||
# ── Pakete ───────────────────────────────────────────────────────────────────
|
# ── Pakete ───────────────────────────────────────────────────────────────────
|
||||||
log "📦 Pakete installieren"
|
log "📦 Pakete installieren"
|
||||||
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
|
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
|
||||||
sssd sssd-ldap libnss-sss libpam-sss libsss-sudo openssh-server ldap-utils >/dev/null
|
sssd sssd-ldap libnss-sss libpam-sss libsss-sudo sssd-tools openssh-server ldap-utils >/dev/null
|
||||||
|
|
||||||
# ── CA ───────────────────────────────────────────────────────────────────────
|
# ── CA ───────────────────────────────────────────────────────────────────────
|
||||||
TLS_CACERT_LINE="# ldap_tls_cacert: System-CA-Store"
|
TLS_CACERT_LINE="# ldap_tls_cacert: System-CA-Store"
|
||||||
@@ -88,6 +105,32 @@ if [[ -n "$CA_CERT" ]]; then
|
|||||||
TLS_CACERT_LINE="ldap_tls_cacert = $CA_TARGET"
|
TLS_CACERT_LINE="ldap_tls_cacert = $CA_TARGET"
|
||||||
fi
|
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 ─────────────────────────────────────────────────────────────────────
|
# ── SSSD ─────────────────────────────────────────────────────────────────────
|
||||||
log "🔧 $SSSD_CONF schreiben"
|
log "🔧 $SSSD_CONF schreiben"
|
||||||
install -d -m 0711 /etc/sssd
|
install -d -m 0711 /etc/sssd
|
||||||
@@ -110,23 +153,24 @@ ldap_search_base = $BASE_DN
|
|||||||
ldap_default_bind_dn = $BIND_DN
|
ldap_default_bind_dn = $BIND_DN
|
||||||
ldap_default_authtok_type = password
|
ldap_default_authtok_type = password
|
||||||
ldap_default_authtok = $BIND_PW
|
ldap_default_authtok = $BIND_PW
|
||||||
ldap_tls_reqcert = demand
|
$TLS_OPTIONS
|
||||||
$TLS_CACERT_LINE
|
|
||||||
|
|
||||||
ldap_schema = rfc2307
|
# authentik-Outpost-Schema
|
||||||
ldap_user_search_base = ou=users,$BASE_DN
|
ldap_schema = rfc2307bis
|
||||||
ldap_group_search_base = ou=groups,$BASE_DN
|
ldap_user_search_base = $BASE_DN
|
||||||
ldap_user_object_class = posixAccount
|
ldap_group_search_base = $BASE_DN
|
||||||
ldap_group_object_class = posixGroup
|
ldap_user_object_class = user
|
||||||
|
ldap_group_object_class = group
|
||||||
ldap_user_name = cn
|
ldap_user_name = cn
|
||||||
|
ldap_group_name = cn
|
||||||
ldap_user_gecos = name
|
ldap_user_gecos = name
|
||||||
ldap_user_home_directory = homeDirectory
|
ldap_user_home_directory = homeDirectory
|
||||||
ldap_user_ssh_public_key = sshPublicKey
|
ldap_user_ssh_public_key = sshPublicKey
|
||||||
ldap_group_member = member
|
ldap_group_member = member
|
||||||
|
|
||||||
# Nur Mitglieder der Server-Gruppe dürfen sich anmelden
|
# Wer sich anmelden darf, steuert authentik (Application-Bindings/Gruppen des Bind-Accounts)
|
||||||
ldap_access_order = filter
|
ldap_access_order = filter
|
||||||
ldap_access_filter = (memberOf=cn=$SSH_GROUP,ou=groups,$BASE_DN)
|
ldap_access_filter = $ACCESS_FILTER
|
||||||
|
|
||||||
fallback_homedir = /home/%u
|
fallback_homedir = /home/%u
|
||||||
default_shell = /bin/bash
|
default_shell = /bin/bash
|
||||||
@@ -161,7 +205,7 @@ PasswordAuthentication yes
|
|||||||
AuthorizedKeysCommand /usr/bin/sss_ssh_authorizedkeys %u
|
AuthorizedKeysCommand /usr/bin/sss_ssh_authorizedkeys %u
|
||||||
AuthorizedKeysCommandUser nobody
|
AuthorizedKeysCommandUser nobody
|
||||||
EOF
|
EOF
|
||||||
sshd -t || die "sshd-Konfiguration ungültig – Drop-in $SSHD_DROPIN prüfen"
|
sshd -t || die "sshd-Konfiguration ungültig - Drop-in $SSHD_DROPIN prüfen"
|
||||||
|
|
||||||
# ── docker-deploy.sh ─────────────────────────────────────────────────────────
|
# ── docker-deploy.sh ─────────────────────────────────────────────────────────
|
||||||
log "🔧 $DEPLOY_CONF schreiben"
|
log "🔧 $DEPLOY_CONF schreiben"
|
||||||
|
|||||||
Reference in new issue
Block a user