Enable Authentik login and prefer arschrock for OCR
This commit is contained in:
1 parent
e265ed3f9d
commit
8c2af0de52
8 files changed
+135
-16
No files matched your search
@@ -6,18 +6,18 @@ on:
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
container: alpine/k8s:1.33.0
|
||||
container: node:22-alpine
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- run: apk add --no-cache bash jq && ./test.sh
|
||||
- run: apk add --no-cache bash python3 py3-yaml && ./test.sh
|
||||
deploy:
|
||||
if: github.event_name == 'push'
|
||||
needs: test
|
||||
runs-on: ubuntu-latest
|
||||
container: alpine/k8s:1.33.0
|
||||
container: node:22-alpine
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- run: apk add --no-cache bash jq
|
||||
- run: apk add --no-cache bash python3 py3-yaml kubectl
|
||||
- run: |
|
||||
umask 077
|
||||
echo "$KUBE_CONFIG_BASE64" | base64 -d > kubeconfig
|
||||
|
||||
+2
-2
@@ -4,7 +4,7 @@ test:
|
||||
stage: test
|
||||
image: alpine/k8s:1.33.0
|
||||
script:
|
||||
- apk add --no-cache bash jq
|
||||
- apk add --no-cache bash python3 py3-yaml
|
||||
- ./test.sh
|
||||
|
||||
deploy:
|
||||
@@ -13,7 +13,7 @@ deploy:
|
||||
rules:
|
||||
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
|
||||
script:
|
||||
- apk add --no-cache bash jq
|
||||
- apk add --no-cache bash python3 py3-yaml
|
||||
- umask 077
|
||||
- echo "$KUBE_CONFIG_BASE64" | base64 -d > kubeconfig
|
||||
- export KUBECONFIG="$CI_PROJECT_DIR/kubeconfig"
|
||||
|
||||
@@ -4,10 +4,14 @@ One Paperless-ngx instance, SQLite, and Valkey in the `paperless-ngx` namespace.
|
||||
|
||||
## Install
|
||||
|
||||
Run `./install.sh` from any directory. It creates the namespace and a random, persistent application secret on first install, checks the manifests with a server dry run, applies them, then waits for both deployments. Open the URL and create the first administrator account in the web UI. Drop scanned files in the web UI or into `/usr/src/paperless/consume` on the PVC.
|
||||
Run `./install.sh` from any directory. It creates the namespace and random, persistent application and OIDC secrets on first install, creates the Authentik OIDC application, checks the manifests with a server dry run, applies them, then waits for both deployments. Open the URL and sign in with the **authentik** button. Drop scanned files in the web UI or into `/usr/src/paperless/consume` on the PVC.
|
||||
|
||||
Change settings in `app.yaml`, then run `./test.sh` and `./install.sh`. The Paperless image is pinned there. The CephFS inbox uses polling because network filesystems may not deliver file notifications.
|
||||
|
||||
Paperless prefers the 24-core `arschrock` node for OCR. This is a scheduler preference, so it can run on an Odroid when `arschrock` is unavailable. The control-plane taint is tolerated only by Paperless, not Valkey. A node failure may briefly interrupt OCR while Kubernetes reschedules the single Paperless pod.
|
||||
|
||||
The 20 Gi PVC uses `rook-cephfs-ec`, whose CephFS data pool is erasure coded with three data and two coding chunks across hosts. CephFS metadata uses three replicas. The claim can be expanded if high-resolution scans outgrow it; erasure coding does not replace backups.
|
||||
|
||||
## CI/CD
|
||||
|
||||
`./test.sh` checks syntax and the deployment manifest. `./deploy.sh` updates the existing workloads, services, and ingress using `app.yaml`. The GitLab and Gitea workflows call these same scripts. Bootstrap once with `./create-ci-kubeconfig.sh`, then save its single output line as the protected CI variable / Gitea Actions secret `KUBE_CONFIG_BASE64`. Do not commit it. The deployer has named-object read and patch permissions and cannot read Secrets. Run `./install.sh` manually for first installation or changes to `storage.yaml`.
|
||||
@@ -16,7 +20,9 @@ The Git remote is `gitea@brunner.ninja:feedc0de/paperless-ngx-deployment.git`. N
|
||||
|
||||
## Authentik login
|
||||
|
||||
Paperless supports Authentik through OpenID Connect. In Authentik, create an OAuth2/OpenID Connect application/provider with a strict authorization redirect URI of `https://paper.brunner.ninja/accounts/oidc/authentik/login/callback/`. Save its client ID and secret outside Git. To enable it, add `PAPERLESS_APPS=allauth.socialaccount.providers.openid_connect` to the Paperless container environment in `app.yaml`, and set `PAPERLESS_SOCIALACCOUNT_PROVIDERS` from a Kubernetes Secret containing the JSON provider configuration described in [Authentik's Paperless guide](https://integrations.goauthentik.io/documentation/paperless-ngx/). Keep local login enabled until the Authentik flow has been tested. Existing Paperless users can link their Authentik account from **My Profile**.
|
||||
`./setup-authentik.sh` creates the OAuth2/OpenID Connect provider, application, and `Paperless Users` and `Paperless Admins` groups in Authentik, adds `feedc0de` to both groups, and stores the client secret in the `paperless-oidc` Kubernetes Secret. It preserves that secret on later runs. `./install.sh` invokes it automatically. To grant others access, add them to **Paperless Users** in Authentik's web UI; use **Paperless Admins** only for people who should see and administer all documents. Paperless syncs those Authentik group claims at login, including administrator status. Existing Paperless users can link their Authentik account from **My Profile**. Local login stays enabled as a recovery option. The callback is `https://paper.brunner.ninja/accounts/oidc/authentik/login/callback/` per [Authentik's Paperless guide](https://integrations.goauthentik.io/documentation/paperless-ngx/).
|
||||
|
||||
The first-visit create-user form is Paperless's bootstrap screen. Since the initial local account was created, link it from **My Profile → Connect new social account** before signing in with Authentik. At subsequent Authentik logins, the `Paperless Admins` claim grants administrator status.
|
||||
|
||||
## Recovery
|
||||
|
||||
|
||||
@@ -55,6 +55,19 @@ spec:
|
||||
spec:
|
||||
automountServiceAccountToken: false
|
||||
enableServiceLinks: false
|
||||
tolerations:
|
||||
- key: node-role.kubernetes.io/control-plane
|
||||
operator: Exists
|
||||
effect: NoSchedule
|
||||
affinity:
|
||||
nodeAffinity:
|
||||
preferredDuringSchedulingIgnoredDuringExecution:
|
||||
- weight: 100
|
||||
preference:
|
||||
matchExpressions:
|
||||
- key: kubernetes.io/hostname
|
||||
operator: In
|
||||
values: [arschrock]
|
||||
containers:
|
||||
- name: paperless
|
||||
image: ghcr.io/paperless-ngx/paperless-ngx:3.2.1
|
||||
@@ -65,6 +78,13 @@ spec:
|
||||
- {name: PAPERLESS_TIME_ZONE, value: "Europe/Vienna"}
|
||||
- {name: PAPERLESS_OCR_LANGUAGE, value: "deu+eng"}
|
||||
- {name: PAPERLESS_CONSUMER_POLLING_INTERVAL, value: "30"}
|
||||
- {name: PAPERLESS_APPS, value: "allauth.socialaccount.providers.openid_connect"}
|
||||
- {name: PAPERLESS_SOCIAL_AUTO_SIGNUP, value: "true"}
|
||||
- {name: PAPERLESS_SOCIAL_ACCOUNT_SYNC_GROUPS, value: "true"}
|
||||
- {name: PAPERLESS_SOCIAL_ACCOUNT_SYNC_SUPERUSER_GROUP, value: "Paperless Admins"}
|
||||
- name: PAPERLESS_SOCIALACCOUNT_PROVIDERS
|
||||
valueFrom:
|
||||
secretKeyRef: {name: paperless-oidc, key: providers}
|
||||
- name: PAPERLESS_SECRET_KEY
|
||||
valueFrom:
|
||||
secretKeyRef: {name: paperless-secret-key, key: secret-key}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
from django.db import transaction
|
||||
from authentik.core.models import Application, Group, User
|
||||
from authentik.policies.models import PolicyBinding
|
||||
from authentik.providers.oauth2.models import OAuth2Provider
|
||||
|
||||
with transaction.atomic():
|
||||
template = OAuth2Provider.objects.get(name="Argo CD")
|
||||
redirect = template.redirect_uris[0]
|
||||
provider, _ = OAuth2Provider.objects.get_or_create(
|
||||
name="Paperless-ngx",
|
||||
defaults={
|
||||
"authorization_flow": template.authorization_flow,
|
||||
"invalidation_flow": template.invalidation_flow,
|
||||
"client_type": "confidential",
|
||||
"grant_types": ["authorization_code", "refresh_token"],
|
||||
"client_id": "paperless-ngx",
|
||||
"client_secret": CLIENT_SECRET,
|
||||
"signing_key": template.signing_key,
|
||||
},
|
||||
)
|
||||
provider.authorization_flow = template.authorization_flow
|
||||
provider.invalidation_flow = template.invalidation_flow
|
||||
provider.client_type = "confidential"
|
||||
provider.grant_types = ["authorization_code", "refresh_token"]
|
||||
provider.client_id = "paperless-ngx"
|
||||
provider.client_secret = CLIENT_SECRET
|
||||
provider.signing_key = template.signing_key
|
||||
provider.redirect_uris = [
|
||||
type(redirect)(
|
||||
matching_mode=redirect.matching_mode,
|
||||
url="https://paper.brunner.ninja/accounts/oidc/authentik/login/callback/",
|
||||
redirect_uri_type=redirect.redirect_uri_type,
|
||||
)
|
||||
]
|
||||
provider.save()
|
||||
provider.property_mappings.set(
|
||||
template.property_mappings.filter(managed__startswith="goauthentik.io/providers/oauth2/scope-")
|
||||
)
|
||||
|
||||
app, _ = Application.objects.get_or_create(
|
||||
slug="paperless-ngx", defaults={"name": "Paperless-ngx", "provider": provider}
|
||||
)
|
||||
app.name = "Paperless-ngx"
|
||||
app.provider = provider
|
||||
app.meta_launch_url = "https://paper.brunner.ninja"
|
||||
app.save()
|
||||
|
||||
group, _ = Group.objects.get_or_create(name="Paperless Users")
|
||||
admin_group, _ = Group.objects.get_or_create(name="Paperless Admins")
|
||||
owner = User.objects.get(username="feedc0de")
|
||||
group.users.add(owner)
|
||||
admin_group.users.add(owner)
|
||||
binding, _ = PolicyBinding.objects.get_or_create(
|
||||
target=app, group=group, defaults={"order": 0, "enabled": True}
|
||||
)
|
||||
if not binding.enabled:
|
||||
binding.enabled = True
|
||||
binding.save(update_fields=["enabled"])
|
||||
|
||||
print("PAPERLESS_AUTHENTIK_READY")
|
||||
@@ -7,8 +7,10 @@ if ! kubectl -n paperless-ngx get secret paperless-secret-key >/dev/null 2>&1; t
|
||||
key=$(openssl rand -base64 64)
|
||||
kubectl -n paperless-ngx create secret generic paperless-secret-key --from-literal="secret-key=${key}"
|
||||
fi
|
||||
./setup-authentik.sh
|
||||
./test.sh
|
||||
kubectl apply --dry-run=server -f storage.yaml -f app.yaml
|
||||
kubectl apply -f storage.yaml -f app.yaml
|
||||
kubectl -n paperless-ngx rollout status deployment/valkey --timeout=5m
|
||||
kubectl -n paperless-ngx rollout status deployment/paperless --timeout=15m
|
||||
kubectl -n paperless-ngx exec deployment/paperless -- python manage.py shell -c 'from django.contrib.auth.models import Group; [Group.objects.get_or_create(name=name) for name in ("Paperless Users", "Paperless Admins")]'
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
umask 077
|
||||
cd "$(dirname "${BASH_SOURCE[0]}")"
|
||||
[[ $(kubectl config current-context) == kubernetes-admin@kubernetes ]] || { echo 'Wrong Kubernetes context' >&2; exit 1; }
|
||||
|
||||
workdir=$(mktemp -d)
|
||||
chmod 700 "$workdir"
|
||||
trap 'rm -rf "$workdir"' EXIT
|
||||
|
||||
if kubectl -n paperless-ngx get secret paperless-oidc -o jsonpath='{.data.providers}' 2>/dev/null | base64 -d > "$workdir/providers.json" && [[ -s "$workdir/providers.json" ]]; then
|
||||
echo 'Keeping the existing Paperless OIDC client secret.'
|
||||
else
|
||||
openssl rand -hex 32 | tr -d '\n' > "$workdir/client-secret"
|
||||
jq -n --rawfile secret "$workdir/client-secret" '{openid_connect:{OAUTH_PKCE_ENABLED:true,APPS:[{provider_id:"authentik",name:"authentik",client_id:"paperless-ngx",secret:$secret,settings:{server_url:"https://auth.brunner.ninja/application/o/paperless-ngx/.well-known/openid-configuration",fetch_userinfo:true}}],SCOPE:["openid","profile","email"]}}' > "$workdir/providers.json"
|
||||
kubectl -n paperless-ngx create secret generic paperless-oidc --from-file="providers=$workdir/providers.json"
|
||||
fi
|
||||
|
||||
jq -er '.openid_connect.APPS[] | select(.provider_id == "authentik") | .secret' "$workdir/providers.json" | tr -d '\n' > "$workdir/client-secret"
|
||||
{
|
||||
printf 'CLIENT_SECRET = '
|
||||
jq -Rs . < "$workdir/client-secret"
|
||||
cat authentik-setup.py
|
||||
} > "$workdir/setup.py"
|
||||
chmod 600 "$workdir"/*
|
||||
kubectl -n authentik exec -i deployment/authentik-worker -- ak shell --no-imports --interface python < "$workdir/setup.py"
|
||||
@@ -1,11 +1,16 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
cd "$(dirname "${BASH_SOURCE[0]}")"
|
||||
bash -n install.sh deploy.sh create-ci-kubeconfig.sh test.sh
|
||||
kubectl create --dry-run=client --validate=false -f storage.yaml -f app.yaml -f ci-deployer.yaml -o json >/dev/null
|
||||
images=$(kubectl create --dry-run=client --validate=false -f app.yaml -o json | jq -r 'select(.kind == "Deployment") | .spec.template.spec.containers[].image')
|
||||
[[ -n $images ]]
|
||||
while IFS= read -r image; do
|
||||
[[ $image == *:* && $image != *:latest ]]
|
||||
done <<<"${images}"
|
||||
echo 'Manifest valid; deployment images are pinned.'
|
||||
bash -n install.sh deploy.sh create-ci-kubeconfig.sh setup-authentik.sh test.sh
|
||||
python3 - <<'PY'
|
||||
import yaml
|
||||
|
||||
documents = []
|
||||
for path in ("storage.yaml", "app.yaml", "ci-deployer.yaml"):
|
||||
with open(path, encoding="utf-8") as stream:
|
||||
documents.extend(doc for doc in yaml.safe_load_all(stream) if doc)
|
||||
images = [container["image"] for doc in documents if doc["kind"] == "Deployment"
|
||||
for container in doc["spec"]["template"]["spec"]["containers"]]
|
||||
assert images and all(":" in image and not image.endswith(":latest") for image in images)
|
||||
print("Manifest valid; deployment images are pinned.")
|
||||
PY
|
||||
Reference in new issue
Block a user