Files
SnarfCode/scripts/check_authentik_fixed.py

47 lines
1.4 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)
def k8s(cmd):
full_cmd = f"kubectl {cmd}"
_, o, e = c.exec_command(full_cmd)
return o.read().decode().strip(), e.read().decode().strip()
pod = "authentik-server-cd7d9b949-vfl2m"
script = '''
from authentik.core.models import Application
from authentik.providers.proxy.models import ProxyProvider
from authentik.policies.expression.models import ExpressionPolicy
print("=== APPLICATIONS ===")
for app in Application.objects.all():
print(f"{app.name} (slug: {app.slug}) | Provider: {app.provider}")
print("=== PROXY PROVIDERS ===")
for p in ProxyProvider.objects.all():
print(f"{p.name} | Host: {p.external_host} | Mode: {p.mode}")
print("=== EXPRESSION POLICIES ===")
for ep in ExpressionPolicy.objects.all():
print(f"Policy: {ep.name}")
print(ep.expression)
'''
# Write script to /tmp/ak_query.py on 140.44.4.11
stdin, stdout, stderr = c.exec_command("cat > /tmp/ak_query.py")
stdin.write(script)
stdin.close()
stdout.channel.recv_exit_status()
# Copy into pod and execute
k8s(f"cp /tmp/ak_query.py infra/{pod}:/tmp/ak_query.py -c server")
out, err = k8s(f"exec -n infra {pod} -c server -- /lifecycle/ak shell < /tmp/ak_query.py")
print("Authentik query output:\n", out)
if err: print("ERR:\n", err)
c.close()