Kubernetes port of Harmony 1.9.6's self-host compose stack (Supabase Postgres, GoTrue, PostgREST, Realtime, storage-api, imgproxy, Kong; Harmony web, federation server/worker, Redis, media cache, Caddy router; LiveKit) at harmony.eom.dev, api.harmony.eom.dev and voice.harmony.eom.dev. - Dex is the only sign-in (GoTrue custom OIDC provider custom:dex); e-mail login off; listed addresses become instance admins. - Upstream bootstrap.sh runs unchanged in a Job through a docker shim. - Catppuccin Mocha/Latte stylesheet injected into the stock web image. - Secrets generated once and kept in Secret/harmony. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
109 lines
4.5 KiB
YAML
109 lines
4.5 KiB
YAML
# SPDX-License-Identifier: MIT-0
|
|
# What `harmony auth add-provider`, `harmony registration open` and
|
|
# `harmony admin create` do in the compose stack, done through Kong's Service
|
|
# from the control-plane node (ClusterIPs are reachable from every node).
|
|
---
|
|
- name: Find Kong
|
|
kubernetes.core.k8s_info:
|
|
kubeconfig: "{{ harmony_kubeconfig | default(omit, true) }}"
|
|
context: "{{ harmony_kube_context | default(omit, true) }}"
|
|
kind: Service
|
|
namespace: "{{ harmony_namespace }}"
|
|
name: supabase-kong
|
|
register: _harmony_kong
|
|
|
|
- name: Set the API endpoint
|
|
ansible.builtin.set_fact:
|
|
_harmony_api: "{{ harmony_admin_api_url or ('http://' ~ (_harmony_kong.resources | first).spec.clusterIP ~ ':8000') }}"
|
|
_harmony_api_headers:
|
|
apikey: "{{ _harmony_secrets.SERVICE_ROLE_KEY }}"
|
|
Authorization: "Bearer {{ _harmony_secrets.SERVICE_ROLE_KEY }}"
|
|
_harmony_provider: "custom:{{ harmony_oidc_provider_id }}"
|
|
no_log: true
|
|
|
|
# GoTrue keeps custom providers, client secret included, in its own tables.
|
|
- name: List the sign-in providers
|
|
ansible.builtin.uri:
|
|
url: "{{ _harmony_api }}/auth/v1/admin/custom-providers"
|
|
headers: "{{ _harmony_api_headers }}"
|
|
return_content: true
|
|
register: _harmony_providers
|
|
retries: 10
|
|
delay: 6
|
|
until: _harmony_providers.status == 200
|
|
no_log: true
|
|
|
|
- name: Add or update the Dex sign-in provider
|
|
ansible.builtin.uri:
|
|
url: "{{ _harmony_api }}/auth/v1/admin/custom-providers{{ ('/' ~ _harmony_provider) if _exists else '' }}"
|
|
method: "{{ 'PUT' if _exists else 'POST' }}"
|
|
headers: "{{ _harmony_api_headers }}"
|
|
body_format: json
|
|
body: >-
|
|
{{ ({} if _exists else {'provider_type': 'oidc', 'identifier': _harmony_provider}) | combine({
|
|
'name': harmony_oidc_name,
|
|
'issuer': harmony_oidc_issuer,
|
|
'client_id': harmony_oidc_client_id,
|
|
'client_secret': harmony_oidc_client_secret,
|
|
'scopes': harmony_oidc_scopes,
|
|
'pkce_enabled': true,
|
|
}) }}
|
|
status_code: [200, 201]
|
|
vars:
|
|
_exists: "{{ (_harmony_providers.json.providers | default([])) | selectattr('identifier', 'equalto', _harmony_provider) | list | length > 0 }}"
|
|
changed_when: not _exists
|
|
no_log: true
|
|
|
|
# The sign-in page shows a button per entry. Registration stays open: Dex
|
|
# decides who gets in, and a first sign-in makes the account.
|
|
- name: Show the Dex button and keep registration open
|
|
ansible.builtin.uri:
|
|
url: "{{ _harmony_api }}/rest/v1/instance_config?on_conflict=config_key"
|
|
method: POST
|
|
headers: "{{ _harmony_api_headers | combine({'Prefer': 'resolution=merge-duplicates,return=minimal'}) }}"
|
|
body_format: json
|
|
body:
|
|
- config_key: custom_oauth_providers
|
|
config_value: [{id: "{{ _harmony_provider }}", name: "{{ harmony_oidc_name }}", icon: "{{ harmony_oidc_icon }}"}]
|
|
- config_key: open_registration
|
|
config_value: true
|
|
- config_key: approval_required
|
|
config_value: false
|
|
status_code: [200, 201, 204]
|
|
changed_when: false
|
|
no_log: true
|
|
|
|
- name: Find the database pod
|
|
kubernetes.core.k8s_info:
|
|
kubeconfig: "{{ harmony_kubeconfig | default(omit, true) }}"
|
|
context: "{{ harmony_kube_context | default(omit, true) }}"
|
|
kind: Pod
|
|
namespace: "{{ harmony_namespace }}"
|
|
label_selectors:
|
|
- app.kubernetes.io/instance={{ harmony_name }}
|
|
- app.kubernetes.io/component=db
|
|
field_selectors:
|
|
- status.phase=Running
|
|
register: _harmony_db_pods
|
|
failed_when: _harmony_db_pods.resources | length == 0
|
|
|
|
# Accounts appear on a person's first sign-in; until then this changes nothing.
|
|
- name: Make the listed people instance admins
|
|
kubernetes.core.k8s_exec:
|
|
kubeconfig: "{{ harmony_kubeconfig | default(omit, true) }}"
|
|
context: "{{ harmony_kube_context | default(omit, true) }}"
|
|
namespace: "{{ harmony_namespace }}"
|
|
pod: "{{ (_harmony_db_pods.resources | first).metadata.name }}"
|
|
container: postgres
|
|
command: >-
|
|
psql -U supabase_admin -h 127.0.0.1 -d postgres -v ON_ERROR_STOP=1 -tA -c
|
|
"WITH promoted AS (UPDATE public.profiles p SET is_admin = true FROM auth.users u
|
|
WHERE u.id = p.id AND lower(u.email) IN ({{ _emails }})
|
|
AND NOT p.is_admin RETURNING 1) SELECT count(*) FROM promoted"
|
|
vars:
|
|
# Plain addresses only (asserted in main.yml), so quoting is enough.
|
|
_emails: "{{ harmony_admin_emails | map('lower') | map('regex_replace', '^(.*)$', \"'\\1'\") | join(',') }}"
|
|
register: _harmony_admins
|
|
changed_when: (_harmony_admins.stdout | trim | int) > 0
|
|
when: harmony_admin_emails | length > 0
|