Files
SnarfCode/scripts/check_authentik_db.py

36 lines
1.3 KiB
Python

import paramiko
SSH_KEY = r"C:\Users\Snarf\.ssh\id_ed25519_snarfnet"
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect("140.44.4.11", username="root", key_filename=SSH_KEY, timeout=10)
_, o, _ = c.exec_command("kubectl exec -n infra authentik-postgresql-0 -- cat /opt/bitnami/postgresql/secrets/password")
pw = o.read().decode().strip()
def psql(query):
cmd = f'kubectl exec -n infra authentik-postgresql-0 -- sh -c "PGPASSWORD={pw} psql -U authentik -d authentik -c \\"{query}\\""'
_, o, e = c.exec_command(cmd)
res = o.read().decode().strip()
err = e.read().decode().strip()
if err and not res:
return f"[ERR: {err}]"
return res
print("--- APPLICATIONS ---")
print(psql("SELECT name, slug FROM authentik_core_application;"))
print("\n--- PROXY PROVIDERS ---")
print(psql("SELECT name, external_host, mode FROM authentik_providers_proxy_proxyprovider;"))
print("\n--- EXPRESSION POLICIES ---")
print(psql("SELECT name, expression FROM authentik_policies_expression_expressionpolicy;"))
print("\n--- POLICY BINDINGS ---")
print(psql("SELECT target_id, enabled FROM authentik_policies_policybinding;"))
print("\n--- AUTHENTIK SETTINGS / SESSIONS ---")
print(psql("SELECT key, value FROM authentik_tenants_tenant;"))
c.close()