From 1d8e10d586b1444b1d976246ecf32f17739164c1 Mon Sep 17 00:00:00 2001 From: vibe-agent Date: Wed, 11 Nov 2026 20:51:18 +0100 Subject: [PATCH] M6: Modell-Sync + public read grant idempotent in open_webui-Rolle (#14) Co-authored-by: vibe-agent --- .../llm/ansible/roles/open_webui/README.md | 7 ++++ .../roles/open_webui/defaults/main.yml | 5 +++ .../ansible/roles/open_webui/tasks/main.yml | 37 +++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/llm-server/llm/ansible/roles/open_webui/README.md b/llm-server/llm/ansible/roles/open_webui/README.md index dfdb7f5..917bc29 100644 --- a/llm-server/llm/ansible/roles/open_webui/README.md +++ b/llm-server/llm/ansible/roles/open_webui/README.md @@ -17,3 +17,10 @@ milestone 6). Deployed by `playbooks/webui.yml` against - Daten: `/var/lib/ghostnet-ai/production/openwebui-data`. - Interne Phase: lokaler Auth (erster User = Admin). Die öffentliche OIDC-Phase (NPM-Route + Keycloak-Client) folgt in M6. + +## Modellsichtbarkeit (v0.13 access control) + +OpenWebUI zeigt Connection-Modelle Nicht-Admins nur, wenn ein DB-Model-Eintrag +existiert UND ein public read access_grant (principal `user`/`*`) greift. Die +Rolle stellt beides idempotent sicher (`open_webui_engine_model_id`), daher +sehen alle authentifizierten OIDC-User das Modell im Chat-Dropdown. diff --git a/llm-server/llm/ansible/roles/open_webui/defaults/main.yml b/llm-server/llm/ansible/roles/open_webui/defaults/main.yml index 95dc2b8..8f70dcb 100644 --- a/llm-server/llm/ansible/roles/open_webui/defaults/main.yml +++ b/llm-server/llm/ansible/roles/open_webui/defaults/main.yml @@ -24,6 +24,11 @@ open_webui_network_name: gnai-production-llama # internal network only. open_webui_egress_network_name: gnai-production-egress +# Engine model exposed in the chat UI. The model is synced into the OpenWebUI +# DB and granted public read access (access_grant principal user "*"), so +# every authenticated OIDC user sees it (GNAI-005: anwendungsbezogene Rechte). +open_webui_engine_model_id: swift-1.5-qwen3.8-27b-q6k + # Engine endpoint inside the shared Production network. llama.cpp itself # has no auth; OpenWebUI just needs a non-empty key value, supplied via a # Podman secret (never in git). diff --git a/llm-server/llm/ansible/roles/open_webui/tasks/main.yml b/llm-server/llm/ansible/roles/open_webui/tasks/main.yml index b84d3e7..307e687 100644 --- a/llm-server/llm/ansible/roles/open_webui/tasks/main.yml +++ b/llm-server/llm/ansible/roles/open_webui/tasks/main.yml @@ -233,6 +233,43 @@ - not ansible_check_mode - open_webui_unit_state.rc != 0 +- name: Ensure the engine model is synced and publicly readable in OpenWebUI + # OpenWebUI shows connection models to non-admin users only when a DB model + # row exists and a public read access_grant covers it (v0.13 access control). + # Idempotent; touches only the app DB, no secrets. + ansible.builtin.shell: | + set -euo pipefail + python3 - "{{ open_webui_data_dir }}/webui.db" "{{ open_webui_engine_model_id }}" <<'PYEOF' + import sqlite3, sys, time, uuid + db, model_id = sys.argv[1], sys.argv[2] + con = sqlite3.connect(db) + now = int(time.time()) + row = con.execute("select id from model where id=?", (model_id,)).fetchone() + if not row: + con.execute( + "insert into model (id, user_id, base_model_id, name, params, meta, is_active, version_id, created_at, updated_at)" + " values (?,?,?,?,?,?,?,?,?,?)", + (model_id, "openwebui", None, model_id, "{}", "{}", 1, str(uuid.uuid4()), now, now), + ) + grant = con.execute( + "select id from access_grant where resource_type='model' and resource_id=? and principal_type='user' and principal_id='*' and permission='read'", + (model_id,), + ).fetchone() + if not grant: + con.execute( + "insert into access_grant (id, resource_type, resource_id, principal_type, principal_id, permission, created_at)" + " values (?,?,?,?,?,?,?)", + (str(uuid.uuid4()), "model", model_id, "user", "*", "read", now), + ) + con.commit() + print("CHANGED" if (not row or not grant) else "UNCHANGED") + PYEOF + args: + executable: /bin/bash + when: not ansible_check_mode + register: open_webui_model_sync + changed_when: open_webui_model_sync.stdout_lines | first == 'CHANGED' + - name: Wait for the OpenWebUI health endpoint ansible.builtin.uri: url: "http://{{ open_webui_host_addr }}:{{ open_webui_host_port }}/health"