lab7: PKI, mTLS infra, OpenBao non-dev, hardening, lifecycle scripts
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
{
|
||||
"rabbit_version": "4.1.8",
|
||||
"vhosts": [
|
||||
{
|
||||
"name": "messenger"
|
||||
}
|
||||
],
|
||||
"exchanges": [
|
||||
{
|
||||
"name": "attachments.dlx",
|
||||
"vhost": "messenger",
|
||||
"type": "fanout",
|
||||
"durable": true,
|
||||
"auto_delete": false,
|
||||
"internal": false,
|
||||
"arguments": {}
|
||||
},
|
||||
{
|
||||
"name": "attachments.jobs",
|
||||
"vhost": "messenger",
|
||||
"type": "direct",
|
||||
"durable": true,
|
||||
"auto_delete": false,
|
||||
"internal": false,
|
||||
"arguments": {}
|
||||
}
|
||||
],
|
||||
"queues": [
|
||||
{
|
||||
"name": "attachments.process.dlq",
|
||||
"vhost": "messenger",
|
||||
"durable": true,
|
||||
"auto_delete": false,
|
||||
"arguments": {
|
||||
"x-queue-type": "quorum"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "attachments.process",
|
||||
"vhost": "messenger",
|
||||
"durable": true,
|
||||
"auto_delete": false,
|
||||
"arguments": {
|
||||
"x-queue-type": "quorum",
|
||||
"x-dead-letter-exchange": "attachments.dlx",
|
||||
"x-delivery-limit": 10
|
||||
}
|
||||
}
|
||||
],
|
||||
"bindings": [
|
||||
{
|
||||
"source": "attachments.dlx",
|
||||
"vhost": "messenger",
|
||||
"destination": "attachments.process.dlq",
|
||||
"destination_type": "queue",
|
||||
"routing_key": "",
|
||||
"arguments": {}
|
||||
},
|
||||
{
|
||||
"source": "attachments.jobs",
|
||||
"vhost": "messenger",
|
||||
"destination": "attachments.process",
|
||||
"destination_type": "queue",
|
||||
"routing_key": "attachment.process.v1",
|
||||
"arguments": {}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1 +1 @@
|
||||
[rabbitmq_prometheus].
|
||||
[rabbitmq_prometheus,rabbitmq_auth_mechanism_ssl].
|
||||
|
||||
@@ -1,21 +1,41 @@
|
||||
#!/bin/sh
|
||||
# Runs as a one-shot sidecar against rabbit@broker. The broker data volume is
|
||||
# mounted read-only only to share the Erlang cookie; no queue data is modified.
|
||||
# Lab 7 idempotent RabbitMQ EXTERNAL (X.509 CN) user & ACL convergence helper.
|
||||
# Invoked inside the broker container by scripts/openbao-bootstrap.sh.
|
||||
# Passwordless users match exact client certificate CNs:
|
||||
# - API (producer only): configure=^$ write=^attachments\.jobs$ read=^attachments\.jobs$
|
||||
# - Worker (consumer only): configure=^$ write=^$ read=^attachments\.process$
|
||||
set -eu
|
||||
|
||||
password=$(cat /run/secrets/broker_worker_password)
|
||||
configure='^(attachments\.jobs|attachments\.process|attachments\.dlx|attachments\.process\.dlq)$'
|
||||
write='^attachments\.(jobs|process|dlx|process\.dlq)$'
|
||||
all_read='^attachments\.(jobs|process|dlx|process\.dlq)$'
|
||||
api_read='^attachments\.(jobs|dlx)$'
|
||||
api_cn="${1:-messenger-api-g1}"
|
||||
worker_cn="${2:-messenger-worker-g1}"
|
||||
|
||||
if ! rabbitmqctl -n rabbit@broker -p messenger add_user messenger-worker "$password" 2>/dev/null; then
|
||||
rabbitmqctl -n rabbit@broker -q -p messenger change_password messenger-worker "$password"
|
||||
ensure_external_user() {
|
||||
user=$1
|
||||
if ! rabbitmqctl -q list_users | awk '{print $1}' | grep -Fxq "$user"; then
|
||||
# Password is cleared immediately; SASL EXTERNAL authenticates by verified TLS cert CN only.
|
||||
rabbitmqctl -q add_user "$user" "tmp-$(head -c 16 /dev/urandom | od -An -tx1 | tr -d ' \n')"
|
||||
fi
|
||||
rabbitmqctl -q clear_password "$user"
|
||||
rabbitmqctl -q set_user_tags "$user"
|
||||
}
|
||||
|
||||
# Remove default guest user if present so no default credential exists.
|
||||
if rabbitmqctl -q list_users | awk '{print $1}' | grep -Fxq "guest"; then
|
||||
rabbitmqctl -q delete_user guest
|
||||
fi
|
||||
rabbitmqctl -n rabbit@broker -q -p messenger set_permissions messenger-worker \
|
||||
"$configure" "$write" "$all_read"
|
||||
# The API may publish and declare the topology, but must not consume the job
|
||||
# queue. The worker identity is used by the worker process.
|
||||
rabbitmqctl -n rabbit@broker -q -p messenger set_permissions messenger \
|
||||
"$configure" "$write" "$api_read"
|
||||
echo "broker init ok: publisher and consumer identities separated"
|
||||
|
||||
# Ensure vhost exists (also pre-declared in definitions.json).
|
||||
if ! rabbitmqctl -q list_vhosts | grep -Fxq "messenger"; then
|
||||
rabbitmqctl -q add_vhost messenger
|
||||
fi
|
||||
|
||||
ensure_external_user "$api_cn"
|
||||
ensure_external_user "$worker_cn"
|
||||
|
||||
rabbitmqctl -q set_permissions -p messenger "$api_cn" \
|
||||
'^$' '^attachments\.jobs$' '^attachments\.jobs$'
|
||||
|
||||
rabbitmqctl -q set_permissions -p messenger "$worker_cn" \
|
||||
'^$' '^$' '^attachments\.process$'
|
||||
|
||||
echo "broker external ACLs converged: api=${api_cn} worker=${worker_cn}"
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
# Lab 7 RabbitMQ 4.1.8 configuration:
|
||||
# - Plaintext AMQP (5672) and plaintext Prometheus (15692) disabled.
|
||||
# - Mandatory AMQPS mTLS (5671) + SASL EXTERNAL bound to client cert CN.
|
||||
# - TLS session resumption disabled so revoked identities fail on new connections.
|
||||
# - Durable topology pre-declared in definitions.json (ZERO users in file).
|
||||
|
||||
listeners.tcp = none
|
||||
listeners.ssl.default = 5671
|
||||
|
||||
ssl_options.cacertfile = /run/certs/ca.crt
|
||||
ssl_options.certfile = /run/certs/server.crt
|
||||
ssl_options.keyfile = /run/certs/server.key
|
||||
ssl_options.verify = verify_peer
|
||||
ssl_options.fail_if_no_peer_cert = true
|
||||
ssl_options.versions.1 = tlsv1.3
|
||||
ssl_options.versions.2 = tlsv1.2
|
||||
ssl_options.reuse_sessions = false
|
||||
|
||||
auth_mechanisms.1 = EXTERNAL
|
||||
ssl_cert_login_from = common_name
|
||||
|
||||
definitions.local.path = /etc/rabbitmq/definitions.json
|
||||
|
||||
prometheus.tcp.listener = none
|
||||
prometheus.ssl.port = 15691
|
||||
prometheus.ssl.cacertfile = /run/certs/ca.crt
|
||||
prometheus.ssl.certfile = /run/certs/server.crt
|
||||
prometheus.ssl.keyfile = /run/certs/server.key
|
||||
prometheus.ssl.verify = verify_peer
|
||||
prometheus.ssl.fail_if_no_peer_cert = true
|
||||
Reference in New Issue
Block a user