Files
ArtyomandClaude Opus 5.5 5ae3d77152 Carry over the lab 5 solution
Bring the application, own tests, Dockerfile, toolchain, compose stack,
HAProxy, k6, RustFS and RabbitMQ configuration, migrations, hooks,
scenario scripts and the CI job from the lab 5 solution commit 64d5c67,
keep the lab 5 Makefile targets on top of the unchanged skeleton
targets, and append the lab 5 solution variables to the skeleton
.env.example. The package and the application follow the contract
version 1.6.0, and the image, the throwaway test containers and the
broker vhost description are tagged lab6 so they do not collide with a
lab 5 stand on the same host.

This is the starting point of the lab 6 cycle: lint, own tests and the
offline skeleton check pass before any lab 6 change.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-29 03:51:58 +03:00

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)"