auth: add Debian/Ubuntu PAM service skd
This commit is contained in:
@ -7,6 +7,7 @@
|
||||
|
||||
## Build, Test, and Development Commands
|
||||
- `bash -n sk.sh` — Syntax check to catch parsing errors early.
|
||||
- `sudo ./scripts/install.sh` — On Ubuntu/Debian creates `/etc/pam.d/skd` and sets `SKD_AUTH_PAM_SERVICE=skd` if unset.
|
||||
- `shellcheck sk.sh` — Linting for style, safety, and portability; fix or suppress with clear rationale.
|
||||
- `./sk.sh <user> disable|enable [countdown] [sound] [seconds]` — Run the tool; requires root. Use a test account when iterating.
|
||||
- `sudo ./sk.sh demo_user disable countdown sound 90` — Example invocation combining optional modes.
|
||||
|
||||
@ -25,6 +25,7 @@ Set in `/etc/skd/env` (see `env.example`):
|
||||
- `SKD_TOKEN_TTL_SECONDS`: token lifetime (default 900s).
|
||||
- `SKD_AUTH_ALLOWED_USERS`: optional comma list of accounts allowed to log in (used for PAM and as an allowlist for OIDC claims).
|
||||
- `SKD_AUTH_ALLOWED_GROUPS`: groups whose members may log in (PAM only, default `sudo`).
|
||||
- `SKD_AUTH_PAM_SERVICE`: PAM service name; Ubuntu/Debian uses `/etc/pam.d/skd` (created by `scripts/install.sh`), other distros may prefer `login` or `sshd`.
|
||||
- `SKD_OIDC_*`: `ISSUER`, `CLIENT_ID`, `CLIENT_SECRET`, `REDIRECT_URI`, `SCOPES` to point at your OIDC provider; set `SKD_SESSION_COOKIE_SECURE=true` for HTTPS.
|
||||
- OIDC dynamic registration helper: `scripts/register_oidc_client.sh` (requires `OIDC_INITIAL_ACCESS_TOKEN` and `SKD_OIDC_ISSUER`; uses `SKD_OIDC_REDIRECT_URI` for the redirect). Run once during setup if your provider issues initial access tokens for client creation.
|
||||
- `SKD_ALLOWED_USERS`: optional comma list to limit manageable accounts (must exist on the system).
|
||||
|
||||
@ -8,7 +8,8 @@ SKD_TOKEN_TTL_SECONDS=900
|
||||
SKD_AUTH_MODE=pam
|
||||
SKD_AUTH_ALLOWED_USERS=
|
||||
SKD_AUTH_ALLOWED_GROUPS=sudo
|
||||
SKD_AUTH_PAM_SERVICE=login
|
||||
# Ubuntu/Debian: install.sh creates /etc/pam.d/skd; adjust for other distros.
|
||||
SKD_AUTH_PAM_SERVICE=skd
|
||||
SKD_OIDC_ISSUER=
|
||||
SKD_OIDC_CLIENT_ID=
|
||||
SKD_OIDC_CLIENT_SECRET=
|
||||
|
||||
@ -56,6 +56,40 @@ if [[ ! -f "${ENV_FILE}" ]]; then
|
||||
sudo chown root:"${SERVICE_GROUP}" "${ENV_FILE}"
|
||||
fi
|
||||
|
||||
is_debian_like() {
|
||||
if [[ ! -r /etc/os-release ]]; then
|
||||
return 1
|
||||
fi
|
||||
# shellcheck disable=SC1091
|
||||
. /etc/os-release
|
||||
if [[ "${ID:-}" == "ubuntu" || "${ID:-}" == "debian" ]]; then
|
||||
return 0
|
||||
fi
|
||||
if [[ "${ID_LIKE:-}" == *"ubuntu"* || "${ID_LIKE:-}" == *"debian"* ]]; then
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
if is_debian_like; then
|
||||
PAM_DIR="/etc/pam.d"
|
||||
PAM_SERVICE_NAME="skd"
|
||||
PAM_SERVICE_FILE="${PAM_DIR}/${PAM_SERVICE_NAME}"
|
||||
if [[ -d "${PAM_DIR}" && ! -f "${PAM_SERVICE_FILE}" ]]; then
|
||||
log "Creating PAM service ${PAM_SERVICE_NAME} for Debian/Ubuntu..."
|
||||
sudo tee "${PAM_SERVICE_FILE}" >/dev/null <<'EOF'
|
||||
# PAM configuration for Safe Kiddo Daemon
|
||||
auth include common-auth
|
||||
account include common-account
|
||||
password include common-password
|
||||
session include common-session
|
||||
EOF
|
||||
fi
|
||||
if ! sudo grep -q "^SKD_AUTH_PAM_SERVICE=" "${ENV_FILE}"; then
|
||||
echo "SKD_AUTH_PAM_SERVICE=${PAM_SERVICE_NAME}" | sudo tee -a "${ENV_FILE}" >/dev/null
|
||||
fi
|
||||
fi
|
||||
|
||||
log "Ensuring minimal ENV defaults (PAM always on, allowed user)..."
|
||||
DEFAULT_USER="${SUDO_USER:-}"
|
||||
if [[ -n "${DEFAULT_USER}" ]]; then
|
||||
|
||||
Reference in New Issue
Block a user