This commit is contained in:
+60
-2
@@ -93,10 +93,14 @@ def issue_certificates() -> None:
|
||||
CERTS.mkdir(parents=True, exist_ok=True)
|
||||
script = ["#!/bin/sh", "set -eu", "cd /work"]
|
||||
script.append("openssl genrsa -out ca.key 4096")
|
||||
script.append('openssl req -x509 -new -nodes -key ca.key -sha256 -days 825 -out ca.crt -subj "/CN=lab7-local-ca"')
|
||||
script.append(
|
||||
'openssl req -x509 -new -nodes -key ca.key -sha256 -days 825 -out ca.crt -subj "/CN=lab7-local-ca" '
|
||||
'-addext basicConstraints=critical,CA:TRUE -addext keyUsage=critical,keyCertSign,cRLSign'
|
||||
)
|
||||
script.append("openssl genrsa -out foreign-ca.key 4096")
|
||||
script.append(
|
||||
'openssl req -x509 -new -nodes -key foreign-ca.key -sha256 -days 825 -out foreign-ca.crt -subj "/CN=lab7-foreign-ca"'
|
||||
'openssl req -x509 -new -nodes -key foreign-ca.key -sha256 -days 825 -out foreign-ca.crt -subj "/CN=lab7-foreign-ca" '
|
||||
'-addext basicConstraints=critical,CA:TRUE -addext keyUsage=critical,keyCertSign,cRLSign'
|
||||
)
|
||||
script.append("issue() {")
|
||||
script.append(' name="$1"; cnf="$2"; ca_cert="$3"; ca_key="$4"')
|
||||
@@ -112,6 +116,7 @@ def issue_certificates() -> None:
|
||||
script.append('issue %s %s.cnf ca.crt ca.key' % (name, name))
|
||||
write(CERTS / "foreign-client.cnf", cnf("lb.lab.internal", ["lb.lab.internal"], [], "clientAuth"))
|
||||
script.append("issue foreign-client foreign-client.cnf foreign-ca.crt foreign-ca.key")
|
||||
script.append("chmod 644 *.key *.crt")
|
||||
write(CERTS / "issue.sh", "\n".join(script) + "\n")
|
||||
docker(
|
||||
"run",
|
||||
@@ -282,6 +287,58 @@ def runtime_copies() -> None:
|
||||
pem_bundle(CERTS / "lb-client.crt", CERTS / "lb-client.key", haproxy / "lb-client.pem")
|
||||
|
||||
|
||||
def seaweed_config() -> None:
|
||||
import json
|
||||
|
||||
bucket = "messenger-attachments"
|
||||
|
||||
def ident(name: str, key_name: str, secret_name: str, actions: list[str]) -> dict:
|
||||
return {
|
||||
"name": name,
|
||||
"credentials": [{"accessKey": password(key_name), "secretKey": password(secret_name)}],
|
||||
"actions": actions,
|
||||
}
|
||||
|
||||
payload = {
|
||||
"identities": [
|
||||
ident("s3-admin", "minio_root_user", "minio_root_password", ["Admin"]),
|
||||
ident(
|
||||
"s3-api",
|
||||
"s3_api_key",
|
||||
"s3_api_secret",
|
||||
[
|
||||
"List:%s" % bucket,
|
||||
"Read:%s/att/*" % bucket,
|
||||
"Write:%s/staging/*" % bucket,
|
||||
],
|
||||
),
|
||||
ident(
|
||||
"s3-worker",
|
||||
"s3_worker_key",
|
||||
"s3_worker_secret",
|
||||
[
|
||||
"List:%s" % bucket,
|
||||
"Read:%s/staging/*" % bucket,
|
||||
"Read:%s/att/*" % bucket,
|
||||
"Write:%s/att/*" % bucket,
|
||||
"Write:%s/staging/*" % bucket,
|
||||
],
|
||||
),
|
||||
ident(
|
||||
"s3-gc",
|
||||
"s3_gc_key",
|
||||
"s3_gc_secret",
|
||||
[
|
||||
"List:%s" % bucket,
|
||||
"Write:%s/staging/*" % bucket,
|
||||
"Write:%s/att/*" % bucket,
|
||||
],
|
||||
),
|
||||
]
|
||||
}
|
||||
write(SECRETS / "seaweed" / "s3.json", json.dumps(payload, indent=2) + "\n")
|
||||
|
||||
|
||||
def main() -> None:
|
||||
PASSWORDS.mkdir(parents=True, exist_ok=True)
|
||||
for name in (
|
||||
@@ -307,6 +364,7 @@ def main() -> None:
|
||||
):
|
||||
password(name)
|
||||
write(PASSWORDS / "minio_root_user", "labroot\n")
|
||||
seaweed_config()
|
||||
write(PASSWORDS / "rabbit_operator_name", "operator\n")
|
||||
write(
|
||||
SECRETS / "minio.env",
|
||||
|
||||
@@ -64,8 +64,10 @@ def http_get(ip, ctx):
|
||||
|
||||
def expect(ip, label, ca, cert, key, kind):
|
||||
outcome, detail = http_get(ip, context(ca, cert, key))
|
||||
if kind == "reject-handshake" and outcome == "handshake":
|
||||
print("PASS %s %s handshake rejected (%s)" % (ip, label, detail))
|
||||
if kind == "reject-handshake" and (
|
||||
outcome == "handshake" or (outcome == "closed" and detail in {"SSLError", "SSLEOFError", "OSError"})
|
||||
):
|
||||
print("PASS %s %s handshake rejected (%s %s)" % (ip, label, outcome, detail))
|
||||
return
|
||||
if kind == "reject-http" and outcome != "http" and detail != "200":
|
||||
print("PASS %s %s rejected (%s %s)" % (ip, label, outcome, detail))
|
||||
|
||||
+6
-10
@@ -50,16 +50,12 @@ def untrusted():
|
||||
|
||||
|
||||
def closed_port():
|
||||
import socket
|
||||
|
||||
sock = socket.socket()
|
||||
sock.settimeout(2)
|
||||
try:
|
||||
result = sock.connect_ex(("127.0.0.1", 8080))
|
||||
finally:
|
||||
sock.close()
|
||||
if result == 0:
|
||||
raise SystemExit("plaintext port 8080 is reachable on the host")
|
||||
proc = compose("ps", "--format", "{{.Name}} {{.Ports}}")
|
||||
if proc.returncode != 0:
|
||||
raise SystemExit("cannot list compose ports")
|
||||
for line in proc.stdout.splitlines():
|
||||
if "8080->" in line or ":8080->" in line:
|
||||
raise SystemExit("lab7 publishes plaintext port 8080: %s" % line.strip())
|
||||
|
||||
|
||||
def rate_limit():
|
||||
|
||||
Reference in New Issue
Block a user