forked from mtusi2026/mtusi2026lab5
Embed the checked lab 5 preparation: RabbitMQ 4.1.8 pinned by digest with a fixed node hostname, a volume, a read-only root and 512 MiB, whose topology (vhost messenger, exchange attachments, quorum queue attachments.process with a dead letter exchange, delivery limit 10 and reject-publish overflow) and users come from definitions imported on every boot. The relay may only write to the exchange, the worker may only read the queue, configure belongs to the operator, there is no guest, and the management UI is published on 127.0.0.1 only. The relay and the worker run from the application image with a heartbeat health check, init, a read-only root and their own limits; the worker gets its own S3 user that reads staging and writes originals and variants, and s3-init creates it idempotently. The API has no broker credentials. make secrets also creates the broker passwords, URLs, hashed users and the worker S3 keys; the restart hook now stops the balancer, the API, the relay and the worker and restarts PostgreSQL, Valkey, S3 and the broker with their volumes; worker.sh and broker.sh stop, start and inspect the processes for the failure demonstrations; the limits policy covers the new services and the loopback UI port. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
61 lines
2.0 KiB
Bash
Executable File
61 lines
2.0 KiB
Bash
Executable File
#!/bin/sh
|
|
set -eu
|
|
cd "$(dirname "$0")/.."
|
|
umask 077
|
|
mkdir -p secrets
|
|
|
|
for role in api worker ops; do
|
|
file="secrets/rabbitmq_${role}_password"
|
|
[ -s "$file" ] || od -An -tx1 -N24 /dev/urandom | tr -d ' \n' >"$file"
|
|
done
|
|
|
|
[ -s secrets/s3_worker_access_key_id ] || printf 'worker%s' "$(od -An -tx1 -N8 /dev/urandom | tr -d ' \n')" >secrets/s3_worker_access_key_id
|
|
[ -s secrets/s3_worker_secret_access_key ] || od -An -tx1 -N32 /dev/urandom | tr -d ' \n' >secrets/s3_worker_secret_access_key
|
|
|
|
for role in api worker; do
|
|
file="secrets/broker_url_${role}"
|
|
[ -s "$file" ] || printf 'amqp://messenger-%s:%s@%s:5672/messenger' \
|
|
"$role" "$(cat "secrets/rabbitmq_${role}_password")" "${BROKER_HOST:-broker}" >"$file"
|
|
done
|
|
|
|
python3 - <<'PY'
|
|
import base64
|
|
import hashlib
|
|
import json
|
|
import os
|
|
|
|
|
|
def user(role, tags):
|
|
salt = os.urandom(4)
|
|
with open("secrets/rabbitmq_%s_password" % role, "rb") as source:
|
|
secret = source.read().strip()
|
|
digest = hashlib.sha256(salt + secret).digest()
|
|
return {
|
|
"name": "messenger-" + role,
|
|
"password_hash": base64.b64encode(salt + digest).decode(),
|
|
"hashing_algorithm": "rabbit_password_hashing_sha256",
|
|
"tags": tags,
|
|
}
|
|
|
|
|
|
def grant(role, configure, write, read):
|
|
return {"user": "messenger-" + role, "vhost": "messenger", "configure": configure, "write": write, "read": read}
|
|
|
|
|
|
definitions = {
|
|
"users": [user("api", []), user("worker", []), user("ops", ["administrator"])],
|
|
"permissions": [
|
|
grant("api", "^$", "^attachments$", "^$"),
|
|
grant("worker", "^$", "^$", "^attachments\\.process$"),
|
|
grant("ops", ".*", ".*", ".*"),
|
|
],
|
|
}
|
|
with open("secrets/rabbitmq_users.json", "w") as target:
|
|
json.dump(definitions, target, indent=2)
|
|
target.write("\n")
|
|
PY
|
|
chmod 700 secrets
|
|
chmod 644 secrets/rabbitmq_users.json secrets/rabbitmq_ops_password secrets/broker_url_api secrets/broker_url_worker \
|
|
secrets/s3_worker_access_key_id secrets/s3_worker_secret_access_key
|
|
echo "broker and S3 worker secrets ready in secrets/ (values not printed)"
|