Реализовать лабораторную 7: mTLS, OpenBao и защита worker
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
"""Trusted incident responder proves stolen worker identity/credentials no longer work."""
|
||||
import json,os,socket,ssl,struct,urllib.request,urllib.error
|
||||
from pathlib import Path
|
||||
import psycopg,redis,boto3
|
||||
from botocore.config import Config
|
||||
from botocore.exceptions import ClientError
|
||||
old=json.loads(Path('/run/old-worker/values.json').read_text())
|
||||
ctx=ssl.create_default_context(cafile='/run/trust/ca.crt');ctx.load_cert_chain('/run/old-worker/service.pem')
|
||||
try:
|
||||
with socket.create_connection(('db',15432),timeout=3) as raw:
|
||||
with ctx.wrap_socket(raw,server_hostname='db') as s:
|
||||
s.sendall(struct.pack('!II',8,80877103));assert not s.recv(16),'revoked TLS accepted'
|
||||
except (OSError,ssl.SSLError):pass
|
||||
req=urllib.request.Request('https://openbao:8200/v1/auth/cert/login',data=b'{"name":"worker"}',headers={'Content-Type':'application/json'})
|
||||
try:urllib.request.urlopen(req,context=ctx,timeout=5);raise AssertionError('revoked Bao auth accepted')
|
||||
except urllib.error.HTTPError as e:assert e.code in (400,403)
|
||||
try:psycopg.connect(old['DATABASE_URL'],connect_timeout=3);raise AssertionError('old DB password accepted')
|
||||
except psycopg.OperationalError as e:assert 'password authentication failed' in str(e)
|
||||
try:redis.Redis.from_url(old['BROKER_URL']).ping();raise AssertionError('old broker password accepted')
|
||||
except redis.AuthenticationError:pass
|
||||
s=boto3.client('s3',endpoint_url='http://127.0.0.1:19000',aws_access_key_id=old['S3_ACCESS_KEY_ID'],aws_secret_access_key=old['S3_SECRET_ACCESS_KEY'],region_name='us-east-1',config=Config(signature_version='s3v4',s3={'addressing_style':'path'},retries={'max_attempts':0}))
|
||||
try:s.get_object(Bucket='messenger-attachments',Key='staging/security-probe');raise AssertionError('old S3 password accepted')
|
||||
except ClientError as e:assert e.response['ResponseMetadata']['HTTPStatusCode']==403
|
||||
s.close()
|
||||
print(json.dumps({'status':'PASS','revoked_tls':True,'revoked_bao_login':True,'old_db_password_denied':True,'old_broker_password_denied':True,'old_s3_password_denied':True}))
|
||||
Reference in New Issue
Block a user