Проверить уровень 3, устойчивость и отрицательные сценарии, оформить отчёт

This commit is contained in:
2026-12-04 07:15:24 +03:00
parent d4f64bed85
commit 06459d3eed
54 changed files with 1934 additions and 126 deletions
+12 -3
View File
@@ -24,7 +24,9 @@ def write(path, data):
return
path.write_bytes(data if isinstance(data, bytes) else data.encode())
if os.name != 'nt':
path.chmod(0o600)
# Host root secrets directory is 0700. A role container receives ONLY
# its own files; read-only bind mounts must be readable by its nonroot UID.
path.chmod(0o600 if 'operator' in path.parts else 0o444)
def password(name):
@@ -47,6 +49,8 @@ def cert(name, ca_key, ca, foreign=False):
.not_valid_before(now-timedelta(minutes=5)).not_valid_after(now+timedelta(days=30))
.add_extension(x509.SubjectAlternativeName([x509.DNSName(n) for n in names]), False)
.add_extension(x509.BasicConstraints(ca=False, path_length=None), True)
.add_extension(x509.AuthorityKeyIdentifier.from_issuer_public_key(ca_key.public_key()),False)
.add_extension(x509.SubjectKeyIdentifier.from_public_key(key.public_key()),False)
.add_extension(x509.ExtendedKeyUsage([ExtendedKeyUsageOID.SERVER_AUTH,ExtendedKeyUsageOID.CLIENT_AUTH]),False)
.sign(ca_key, hashes.SHA256()))
key_bytes = key.private_bytes(serialization.Encoding.PEM, serialization.PrivateFormat.PKCS8, serialization.NoEncryption())
@@ -71,6 +75,9 @@ def main():
subprocess.run(['icacls',str(PRIVATE),'/inheritance:r','/grant:r',account+':(OI)(CI)F'],check=True,stdout=subprocess.DEVNULL)
else:
PRIVATE.chmod(0o700)
(PRIVATE/'operator').mkdir(exist_ok=True)
if os.name != 'nt':
(PRIVATE/'operator').chmod(0o700)
keypath = PRIVATE/'operator/ca.key'
capath = PRIVATE/'ca.crt'
if not keypath.exists():
@@ -83,12 +90,14 @@ def main():
.public_key(key.public_key()).serial_number(x509.random_serial_number())
.not_valid_before(now-timedelta(minutes=5)).not_valid_after(now+timedelta(days=365))
.add_extension(x509.BasicConstraints(ca=True,path_length=0),True)
.add_extension(x509.KeyUsage(False,False,False,False,False,True,True,False,False),True)
.add_extension(x509.SubjectKeyIdentifier.from_public_key(key.public_key()),False)
.sign(key,hashes.SHA256()))
write(keypath,key.private_bytes(serialization.Encoding.PEM,serialization.PrivateFormat.PKCS8,serialization.NoEncryption()))
write(capath,ca.public_bytes(serialization.Encoding.PEM))
key = serialization.load_pem_private_key(keypath.read_bytes(),password=None)
ca = x509.load_pem_x509_certificate(capath.read_bytes())
for name in ('lb','api1','api2','api','worker','dispatcher','cleaner','db','s3','broker','otel-collector','prometheus','loki','tempo','grafana','probe'):
for name in ('lb','api1','api2','api','worker','dispatcher','cleaner','openbao','db','s3','broker','otel-collector','prometheus','loki','tempo','grafana','probe'):
cert(name,key,ca)
foreign_key = rsa.generate_private_key(public_exponent=65537,key_size=2048)
now=datetime.now(timezone.utc)
@@ -115,7 +124,7 @@ def main():
for role in ('dispatcher','worker'):
definitions['users'].append({'name':role,'password':password('broker_'+role),'tags':[]})
definitions['permissions'].append({'user':role,'vhost':'lab7','configure':'^attachment\\.process\\.v1$',
'write':'^attachment\\.process\\.v1$' if role=='dispatcher' else '^$',
'write':'^amq.default$' if role=='dispatcher' else '^$',
'read':'^attachment\\.process\\.v1$' if role=='worker' else '^$'})
write(PRIVATE/'broker.json',json.dumps(definitions))
for role in ('api','worker','dispatcher','cleaner'):