forked from mtusi2026/mtusi2026lab7
test(security): verify mTLS permissions and use direct local HTTPS
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
export NO_PROXY := localhost,127.0.0.1
|
||||||
|
export no_proxy := localhost,127.0.0.1
|
||||||
PYTHON ?= python3
|
PYTHON ?= python3
|
||||||
BASE_URL ?= https://localhost:8443
|
BASE_URL ?= https://localhost:8443
|
||||||
CA_FILE ?=
|
CA_FILE ?=
|
||||||
|
|||||||
@@ -0,0 +1,132 @@
|
|||||||
|
{
|
||||||
|
"complete": true,
|
||||||
|
"tls": [
|
||||||
|
{
|
||||||
|
"host": "api",
|
||||||
|
"port": 8443,
|
||||||
|
"address": "172.23.0.33",
|
||||||
|
"authorized": true,
|
||||||
|
"no_certificate_denied": true,
|
||||||
|
"foreign_ca_denied": true,
|
||||||
|
"trusted_wrong_identity_denied": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"host": "api",
|
||||||
|
"port": 8443,
|
||||||
|
"address": "172.23.0.34",
|
||||||
|
"authorized": true,
|
||||||
|
"no_certificate_denied": true,
|
||||||
|
"foreign_ca_denied": true,
|
||||||
|
"trusted_wrong_identity_denied": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"host": "otel",
|
||||||
|
"port": 4438,
|
||||||
|
"address": null,
|
||||||
|
"authorized": true,
|
||||||
|
"no_certificate_denied": true,
|
||||||
|
"foreign_ca_denied": true,
|
||||||
|
"trusted_wrong_identity_denied": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"host": "broker",
|
||||||
|
"port": 6380,
|
||||||
|
"address": null,
|
||||||
|
"authorized": true,
|
||||||
|
"no_certificate_denied": true,
|
||||||
|
"foreign_ca_denied": true,
|
||||||
|
"trusted_wrong_identity_denied": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"bypass": [
|
||||||
|
{
|
||||||
|
"host": "api",
|
||||||
|
"port": 8080,
|
||||||
|
"closed": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"host": "postgres",
|
||||||
|
"port": 5432,
|
||||||
|
"closed": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"host": "broker",
|
||||||
|
"port": 6379,
|
||||||
|
"closed": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"host": "cache",
|
||||||
|
"port": 6379,
|
||||||
|
"closed": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"host": "s3",
|
||||||
|
"port": 9000,
|
||||||
|
"closed": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"host": "otel",
|
||||||
|
"port": 4318,
|
||||||
|
"closed": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"host": "otel",
|
||||||
|
"port": 8889,
|
||||||
|
"closed": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"host": "prometheus",
|
||||||
|
"port": 9090,
|
||||||
|
"closed": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"host": "loki",
|
||||||
|
"port": 3100,
|
||||||
|
"closed": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"host": "tempo",
|
||||||
|
"port": 3200,
|
||||||
|
"closed": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"host": "grafana",
|
||||||
|
"port": 3000,
|
||||||
|
"closed": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"host": "lb",
|
||||||
|
"port": 8404,
|
||||||
|
"closed": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"database": {
|
||||||
|
"user_passwords_denied": true,
|
||||||
|
"session_hashes_denied": true,
|
||||||
|
"create_role_denied": true
|
||||||
|
},
|
||||||
|
"tls_server_ca_denied": true,
|
||||||
|
"tls_server_hostname_denied": true,
|
||||||
|
"broker_admin_denied": true,
|
||||||
|
"openbao": {
|
||||||
|
"service_policies": [
|
||||||
|
"messenger-worker"
|
||||||
|
],
|
||||||
|
"token_ttl_seconds": 120,
|
||||||
|
"foreign_secret_denied": true,
|
||||||
|
"policy_write_denied": true,
|
||||||
|
"foreign_pki_role_denied": true
|
||||||
|
},
|
||||||
|
"s3": {
|
||||||
|
"api_staging_write": true,
|
||||||
|
"worker_source_read": true,
|
||||||
|
"worker_derived_write": true,
|
||||||
|
"api_derived_write_denied": true,
|
||||||
|
"worker_staging_write_denied": true,
|
||||||
|
"worker_list_all_buckets_denied": true,
|
||||||
|
"worker_delete_denied": true
|
||||||
|
},
|
||||||
|
"probe_exit_code": 0,
|
||||||
|
"date": "2026-11-20T16:38:07.810251+00:00",
|
||||||
|
"source_commit": "7f6e8cbd27005ff66b4f63e5c085e5c9facdb994"
|
||||||
|
}
|
||||||
@@ -93,8 +93,8 @@ def duplicate(job, count=5):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def inspect_effect(job, *, pending=False):
|
def effect_code(job, *, pending=False):
|
||||||
return inside(f"""with db.connection() as c:
|
return f"""with db.connection() as c:
|
||||||
j=c.execute('SELECT * FROM jobs WHERE id=%s',({job!r},)).fetchone()
|
j=c.execute('SELECT * FROM jobs WHERE id=%s',({job!r},)).fetchone()
|
||||||
v=c.execute('SELECT name,object_key,sha256,size_bytes FROM attachment_variants WHERE attachment_id=%s AND pipeline_version=%s ORDER BY name',(j['attachment_id'],j['pipeline_version'])).fetchall()
|
v=c.execute('SELECT name,object_key,sha256,size_bytes FROM attachment_variants WHERE attachment_id=%s AND pipeline_version=%s ORDER BY name',(j['attachment_id'],j['pipeline_version'])).fetchall()
|
||||||
p=c.execute('SELECT count(*) n FROM effect_publications WHERE attachment_id=%s AND pipeline_version=%s',(j['attachment_id'],j['pipeline_version'])).fetchone()['n']
|
p=c.execute('SELECT count(*) n FROM effect_publications WHERE attachment_id=%s AND pipeline_version=%s',(j['attachment_id'],j['pipeline_version'])).fetchone()['n']
|
||||||
@@ -106,7 +106,24 @@ if {pending!r}:
|
|||||||
entry=item['message_id']
|
entry=item['message_id']
|
||||||
messages=queue.xrange(STREAM,min=entry,max=entry)
|
messages=queue.xrange(STREAM,min=entry,max=entry)
|
||||||
if messages and json.loads(messages[0][1].get('job','{{}}')).get('job_id')==str(j['id']): pending_entries.append(entry)
|
if messages and json.loads(messages[0][1].get('job','{{}}')).get('job_id')==str(j['id']): pending_entries.append(entry)
|
||||||
print(json.dumps({{'job':j,'variants':v,'publications':p,'physical_keys':keys,'events':e,'pending_stream_entries':pending_entries}},default=str))""")
|
print(json.dumps({{'job':j,'variants':v,'publications':p,'physical_keys':keys,'events':e,'pending_stream_entries':pending_entries}},default=str))"""
|
||||||
|
|
||||||
|
|
||||||
|
def inspect_effect(job, *, pending=False):
|
||||||
|
return inside(effect_code(job, pending=pending))
|
||||||
|
|
||||||
|
|
||||||
|
def observe_fault(job, marker, *, pending=False):
|
||||||
|
code = f"""from src.pipeline import event
|
||||||
|
with db.connection() as c: event(c,UUID({job!r}),'crash_observer_ready')
|
||||||
|
end=time.monotonic()+60
|
||||||
|
while True:
|
||||||
|
with db.connection() as c: hit=c.execute('SELECT hit_at FROM pipeline_faults WHERE id=%s',({marker},)).fetchone()['hit_at']
|
||||||
|
if hit: break
|
||||||
|
if time.monotonic()>end: raise TimeoutError('Crash hook not hit')
|
||||||
|
time.sleep(.025)
|
||||||
|
"""
|
||||||
|
return inside(code + effect_code(job, pending=pending))
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@@ -380,10 +397,31 @@ def main():
|
|||||||
stop("worker")
|
stop("worker")
|
||||||
a, j = upload()
|
a, j = upload()
|
||||||
marker = inject(j, phase, "wait")
|
marker = inject(j, phase, "wait")
|
||||||
start("worker")
|
# Start observation before the child timeout begins.
|
||||||
wait(lambda marker=marker: hit(marker))
|
# Polling through a new Python/Docker process at each
|
||||||
at_crash = inspect_effect(
|
# step can miss the actual COMMIT-before-ACK window.
|
||||||
j, pending=phase == "after_commit"
|
with ThreadPoolExecutor(max_workers=1) as hot:
|
||||||
|
observer = hot.submit(
|
||||||
|
observe_fault,
|
||||||
|
j,
|
||||||
|
marker,
|
||||||
|
pending=phase == "after_commit",
|
||||||
|
)
|
||||||
|
wait(
|
||||||
|
lambda j=j: inside(
|
||||||
|
f"with db.connection() as c: n=c.execute(\"SELECT count(*) n FROM pipeline_events WHERE job_id=%s AND event='crash_observer_ready'\",({j!r},)).fetchone()['n']\nprint(json.dumps(n>0))"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
start("worker")
|
||||||
|
at_crash = observer.result(timeout=60)
|
||||||
|
report["active_case"] = {
|
||||||
|
"phase": phase,
|
||||||
|
"repeat": repeat + 1,
|
||||||
|
"at_crash": at_crash,
|
||||||
|
}
|
||||||
|
output.write_text(
|
||||||
|
json.dumps(report, ensure_ascii=False, indent=2)
|
||||||
|
+ "\n"
|
||||||
)
|
)
|
||||||
assert at_crash["job"]["state"] == (
|
assert at_crash["job"]["state"] == (
|
||||||
"ready"
|
"ready"
|
||||||
@@ -423,6 +461,7 @@ def main():
|
|||||||
effect = inspect_effect(j)
|
effect = inspect_effect(j)
|
||||||
else:
|
else:
|
||||||
assert effect["job"]["attempt"] >= 2
|
assert effect["job"]["attempt"] >= 2
|
||||||
|
report.pop("active_case", None)
|
||||||
save(
|
save(
|
||||||
f"{phase}_sigkill_repeat_{repeat + 1}",
|
f"{phase}_sigkill_repeat_{repeat + 1}",
|
||||||
{"at_crash": at_crash, "effect": effect},
|
{"at_crash": at_crash, "effect": effect},
|
||||||
|
|||||||
Reference in New Issue
Block a user