29 lines
999 B
Python
29 lines
999 B
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 = """
|
|
SELECT p.name, ep.expression
|
|
FROM authentik_policies_expression_expressionpolicy ep
|
|
JOIN authentik_policies_policy p ON ep.policy_ptr_id = p.policy_uuid;
|
|
"""
|
|
|
|
stdin, stdout, stderr = c.exec_command("cat > /tmp/query_policies.sql")
|
|
stdin.write(sql)
|
|
stdin.close()
|
|
stdout.channel.recv_exit_status()
|
|
|
|
c.exec_command("kubectl cp /tmp/query_policies.sql infra/authentik-postgresql-0:/tmp/query_policies.sql")
|
|
cmd = f"kubectl exec -n infra authentik-postgresql-0 -- env PGPASSWORD='{pw}' psql -U authentik -d authentik -f /tmp/query_policies.sql"
|
|
_, o, e = c.exec_command(cmd)
|
|
print(o.read().decode())
|
|
|
|
c.close()
|
|
|