#!/bin/sh set -eu # Operator-run: create the two mTLS service identities in RabbitMQ and give them # least-privilege ACLs. RabbitMQ maps the client-certificate CN to a username # (EXTERNAL auth), so the users must exist beforehand. # # api-broker configure + write the pipeline queue (it only publishes) # worker-broker configure + read the pipeline queue (it only consumes) # # Neither identity can touch any other queue or exchange. Re-running is safe. cd "$(dirname "$0")/.." compose() { docker compose --env-file .env "$@"; } rmq() { compose exec -T broker rabbitmqctl "$@"; } Q='attachment\.process\.v1' rand() { head -c 24 /dev/urandom | od -An -tx1 | tr -d ' \n'; } rmq add_user api-broker "$(rand)" >/dev/null 2>&1 || true rmq add_user worker-broker "$(rand)" >/dev/null 2>&1 || true # EXTERNAL auth sends no password; disable password login so the TLS identity is # the only way to use these accounts. rmq clear_password api-broker >/dev/null 2>&1 || true rmq clear_password worker-broker >/dev/null 2>&1 || true # Publishing to the default exchange (amq.default) with the queue name as the # routing key requires write on BOTH the exchange and the routing key, so the # API is granted exactly those two names. The worker may only read its queue. # configure write read rmq set_permissions -p / api-broker "^${Q}$" "^(amq\.default|${Q})$" "^$" rmq set_permissions -p / worker-broker "^${Q}$" "^$" "^${Q}$" echo "broker identities ready: api-broker (configure+write), worker-broker (configure+read), queue $Q"