Skip to content
Snippets Groups Projects
Verified Commit 39e13b98 authored by Martin Weise's avatar Martin Weise
Browse files

Improved broker handling

- Added OAuth2.0 workflow to broker
- Added rabbitmq-client
- Updated client scopes default scopes
- Updated broker healthcheck
parent 0427d260
No related branches found
No related tags found
2 merge requests!163Relase 1.3.0,!155Added readme to authentication service and added eureka service
#!/bin/env python3
import os
import pika
from dotenv import load_dotenv
load_dotenv()
if __name__ == "__main__":
token = os.getenv("TOKEN")
credentials = pika.credentials.PlainCredentials("mweise", token)
parameters = pika.ConnectionParameters('localhost', 5672, '/', credentials)
connection = pika.BlockingConnection(parameters)
channel = connection.channel()
channel.queue_declare(queue='test', durable=True)
channel.basic_publish(exchange='',
routing_key='test',
body=b'Hello World!')
print(" [x] Sent 'Hello World!'")
connection.close()
File moved
pika==1.3.1
python-dotenv==1.0.0
\ No newline at end of file
...@@ -146,8 +146,6 @@ services: ...@@ -146,8 +146,6 @@ services:
depends_on: depends_on:
fda-discovery-service: fda-discovery-service:
condition: service_healthy condition: service_healthy
fda-broker-service:
condition: service_started
fda-metadata-db: fda-metadata-db:
condition: service_healthy condition: service_healthy
logging: logging:
...@@ -198,7 +196,7 @@ services: ...@@ -198,7 +196,7 @@ services:
fda-search-service: fda-search-service:
condition: service_started condition: service_started
fda-broker-service: fda-broker-service:
condition: service_started condition: service_healthy
logging: logging:
driver: json-file driver: json-file
...@@ -303,6 +301,8 @@ services: ...@@ -303,6 +301,8 @@ services:
depends_on: depends_on:
fda-discovery-service: fda-discovery-service:
condition: service_healthy condition: service_healthy
fda-authentication-service:
condition: service_healthy
volumes: volumes:
- broker-service-data:/var/lib/rabbitmq/ - broker-service-data:/var/lib/rabbitmq/
logging: logging:
......
This diff is collapsed.
...@@ -8,15 +8,18 @@ FROM rabbitmq:3-management-alpine as runtime ...@@ -8,15 +8,18 @@ FROM rabbitmq:3-management-alpine as runtime
ENV PYTHONUNBUFFERED=1 ENV PYTHONUNBUFFERED=1
COPY ./rabbitmq.conf /etc/rabbitmq/ COPY ./rabbitmq.conf /etc/rabbitmq/
COPY ./docker-entrypoint.sh ./docker-entrypoint.sh
RUN chmod +x ./docker-entrypoint.sh
RUN apk --no-cache add python3 py3-pip RUN apk --no-cache add python3 py3-pip
COPY ./requirements.txt ./requirements.txt COPY ./requirements.txt ./requirements.txt
RUN pip3 install -r ./requirements.txt RUN pip3 install -r ./requirements.txt
WORKDIR /app
COPY ./init.py ./init.py COPY ./init.py ./init.py
COPY ./register.py ./register.py
COPY ./service_ready /usr/bin/service_ready
COPY ./docker-entrypoint.sh ./docker-entrypoint.sh
EXPOSE 15692 HEALTHCHECK --interval=10s --timeout=5s --retries=12 CMD service_ready
ENTRYPOINT [ "./docker-entrypoint.sh" ] ENTRYPOINT [ "bash", "/app/docker-entrypoint.sh" ]
\ No newline at end of file \ No newline at end of file
#!/bin/bash #!/bin/bash
# load jwt certificates
python3 ./init.py
# enable prometheus plugin # enable prometheus plugin
(sleep 10; rabbitmq-plugins enable rabbitmq_prometheus rabbitmq_mqtt) & (sleep 10; rabbitmq-plugins enable rabbitmq_prometheus rabbitmq_mqtt; touch /ready) &
# register with discovery service # register with discovery service
python3 ./init.py python3 ./register.py
(while sleep 60; do python3 ./init.py; done) & (while sleep 60; do python3 ./register.py; done) &
rabbitmq-server rabbitmq-server
\ No newline at end of file
from py_eureka_client import eureka_client import requests as rq
import py_eureka_client.logger as logger import py_eureka_client.logger as logger
import datetime import datetime
logger.set_level("ERROR") logger.set_level("ERROR")
def register(): def get_cert() -> str:
eureka_client.init(eureka_server="http://discovery-service:9090/eureka/", body = rq.get("http://gateway-service:9095/api/auth/realms/dbrepo/protocol/openid-connect/certs").json()
app_name="broker-service", for key in body["keys"]:
instance_ip="broker-service", if key["alg"] != "RS256":
instance_host="broker-service", continue
instance_port=15672) cert = "-----BEGIN CERTIFICATE-----\n"
log("Service registered") cert += key["x5c"][0]
cert += "\n-----END CERTIFICATE-----"
return cert
def get_pubkey() -> str:
body = rq.get("http://gateway-service:9095/api/auth/realms/dbrepo").json()
pubkey = "-----BEGIN RSA PUBLIC KEY-----\n"
pubkey += body["public_key"]
pubkey += "\n-----END RSA PUBLIC KEY-----"
return pubkey
def write_file(path, content):
with open(path, 'w') as f:
f.write(content)
def log(message): def log(message):
...@@ -20,5 +35,10 @@ def log(message): ...@@ -20,5 +35,10 @@ def log(message):
if __name__ == "__main__": if __name__ == "__main__":
log("Registering at discovery service ...") log("Retrieving certificate ...")
register() pem = get_cert()
pubkey = get_pubkey()
write_file("/app/cert.pem", pem)
log("saved cert to /app/cert.pem")
write_file("/app/pubkey.pem", pubkey)
log("saved cert to /app/pubkey.pem")
...@@ -12,3 +12,17 @@ listeners.tcp.1 = 0.0.0.0:5672 ...@@ -12,3 +12,17 @@ listeners.tcp.1 = 0.0.0.0:5672
# logging # logging
log.file.level = warning log.file.level = warning
# authentication backends
auth_backends.1 = internal
auth_backends.2 = oauth2
# OAuth 2.0 files
auth_oauth2.resource_server_id = rabbitmq
#auth_oauth2.additional_scopes_key = my_custom_scope_key
auth_oauth2.preferred_username_claims = preferred_username
auth_oauth2.default_key = id1
auth_oauth2.signing_keys.id1 = /app/pubkey.pem
auth_oauth2.signing_keys.id2 = /app/cert.pem
auth_oauth2.algorithms.1 = HS256
auth_oauth2.algorithms.2 = RS256
\ No newline at end of file
from py_eureka_client import eureka_client
import py_eureka_client.logger as logger
import datetime
logger.set_level("ERROR")
def register():
eureka_client.init(eureka_server="http://discovery-service:9090/eureka/",
app_name="broker-service",
instance_ip="broker-service",
instance_host="broker-service",
instance_port=15672)
if __name__ == "__main__":
register()
py-eureka-client==0.11.3 py-eureka-client==0.11.3
requests==2.28.2
\ No newline at end of file
#!/bin/bash
if [ -f /ready ]; then
echo "service is ready and accepting connections"
exit 0
fi
exit 1
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment