forked from mtusi2026/mtusi2026lab7
76 lines
2.4 KiB
Python
76 lines
2.4 KiB
Python
import json
|
|
import ssl
|
|
import urllib.error
|
|
import urllib.request
|
|
|
|
import boto3
|
|
import psycopg
|
|
from botocore.exceptions import ClientError
|
|
|
|
from tls_matrix import BASE, broker, context, deny_http, http
|
|
|
|
|
|
def main():
|
|
before = json.loads((BASE / "operator/worker-before.json").read_text())
|
|
assert deny_http("otel-collector", 4318, "/v1/traces", "revoked-worker", "POST", b"{}") in (
|
|
400,
|
|
"tls_rejected",
|
|
)
|
|
try:
|
|
assert not broker("revoked-worker")
|
|
except (ssl.SSLError, ConnectionResetError):
|
|
pass
|
|
req = urllib.request.Request(
|
|
"https://openbao:8200/v1/auth/cert/login",
|
|
json.dumps({"name": "worker"}).encode(),
|
|
{"Content-Type": "application/json"},
|
|
)
|
|
try:
|
|
urllib.request.urlopen(req, context=context("revoked-worker"), timeout=3)
|
|
except urllib.error.HTTPError as error:
|
|
assert error.code == 400 or error.code == 403
|
|
else:
|
|
raise AssertionError("Revoked worker authenticated to OpenBao")
|
|
try:
|
|
psycopg.connect(
|
|
host="db",
|
|
dbname="messenger",
|
|
user=before["postgres_user"],
|
|
password=before["postgres_password"],
|
|
sslmode="verify-full",
|
|
sslrootcert=str(BASE / "public/ca.crt"),
|
|
connect_timeout=3,
|
|
)
|
|
except psycopg.OperationalError as error:
|
|
assert "password authentication failed" in str(error)
|
|
else:
|
|
raise AssertionError("Old database secret accepted")
|
|
s3 = boto3.client(
|
|
"s3",
|
|
endpoint_url="https://minio:9000",
|
|
aws_access_key_id=before["s3_access_key_id"],
|
|
aws_secret_access_key=before["s3_secret_access_key"],
|
|
verify=str(BASE / "public/ca.crt"),
|
|
)
|
|
try:
|
|
s3.list_objects_v2(Bucket="messenger-attachments", MaxKeys=1)
|
|
except ClientError as error:
|
|
assert error.response["ResponseMetadata"]["HTTPStatusCode"] == 403
|
|
else:
|
|
raise AssertionError("Disabled S3 credentials accepted")
|
|
result = {
|
|
"status": "PASS",
|
|
"fresh_connections": True,
|
|
"old_certificate_collector_denied": True,
|
|
"old_certificate_broker_with_current_password_denied": True,
|
|
"old_certificate_bao_auth_denied": True,
|
|
"old_postgres_password_denied": True,
|
|
"disabled_s3_key_denied": True,
|
|
"tls_resumption": "gateway tickets and cache disabled",
|
|
}
|
|
print(json.dumps(result))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|