This commit is contained in:
pampixz
2026-12-03 19:25:38 +03:00
parent 20afc2c790
commit 38d908afc9
47 changed files with 2065 additions and 24 deletions
+60
View File
@@ -0,0 +1,60 @@
import ssl
import json
import urllib.request
import urllib.error
base = "https://localhost:8200/v1/"
for role in ("api", "worker"):
ctx = ssl.create_default_context(cafile="secrets/ca.crt")
ctx.load_cert_chain(
f"secrets/{role}/cert.crt",
f"secrets/{role}/cert.key"
)
req = urllib.request.Request(
base + "auth/cert/login",
data=json.dumps({"name": role}).encode(),
headers={"Content-Type": "application/json"}
)
with urllib.request.urlopen(req, context=ctx) as r:
auth = json.load(r)["auth"]
token = auth["client_token"]
print(f"\n{role}: login OK, TTL={auth['lease_duration']}")
for target in ("api", "worker", "operator"):
req = urllib.request.Request(
base + "secret/data/" + target,
headers={"X-Vault-Token": token}
)
try:
with urllib.request.urlopen(req, context=ctx) as r:
print(f"{role} -> {target}: {r.status}")
except urllib.error.HTTPError as e:
print(f"{role} -> {target}: {e.code}")
req = urllib.request.Request(
base + "auth/token/revoke-self",
data=b"{}",
headers={"X-Vault-Token": token}
)
with urllib.request.urlopen(req, context=ctx) as r:
print(f"{role}: revoke -> {r.status}")
req = urllib.request.Request(
base + "secret/data/" + role,
headers={"X-Vault-Token": token}
)
try:
urllib.request.urlopen(req, context=ctx)
print("FAIL: revoked token still works")
except urllib.error.HTTPError as e:
print(f"{role}: after revoke -> {e.code}")
assert e.code == 403