Files
SnarfCode/scripts/check_authentik_file.py

33 lines
1.1 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()
sql = """
\\echo '=== APPS ==='
SELECT name, slug FROM authentik_core_application;
\\echo '=== PROVIDERS ==='
SELECT name, external_host, mode FROM authentik_providers_proxy_proxyprovider;
\\echo '=== POLICIES ==='
SELECT name, expression FROM authentik_policies_expression_expressionpolicy;
"""
stdin, stdout, stderr = c.exec_command("cat > /tmp/query.sql")
stdin.write(sql)
stdin.close()
stdout.channel.recv_exit_status()
c.exec_command("kubectl cp /tmp/query.sql infra/authentik-postgresql-0:/tmp/query.sql")
cmd = f"kubectl exec -n infra authentik-postgresql-0 -- env PGPASSWORD='{pw}' psql -U authentik -d authentik -f /tmp/query.sql"
_, o, e = c.exec_command(cmd)
print(o.read().decode())
print("ERR:", e.read().decode())
c.close()