forked from mtusi2026/mtusi2026lab7
feat: complete lab 7 grade 4 security controls and report
This commit is contained in:
@@ -2,6 +2,8 @@ package repositories
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"os"
|
||||
|
||||
"errors"
|
||||
"messenger/src/backend/telemetry"
|
||||
@@ -20,12 +22,21 @@ type JobBroker struct {
|
||||
}
|
||||
|
||||
func NewJobBroker(ctx context.Context, address string) (*JobBroker, error) {
|
||||
connection, err := amqp.DialConfig(address, amqp.Config{
|
||||
config := amqp.Config{
|
||||
Heartbeat: 10 * time.Second,
|
||||
Dial: func(network, address string) (net.Conn, error) {
|
||||
return (&net.Dialer{Timeout: 5 * time.Second}).DialContext(ctx, network, address)
|
||||
},
|
||||
})
|
||||
}
|
||||
if os.Getenv("BROKER_MTLS") == "1" {
|
||||
cert, err := tls.LoadX509KeyPair("/run/broker/client.crt", "/run/broker/client.key")
|
||||
if err != nil {
|
||||
return nil, errors.New("RabbitMQ client certificate unavailable")
|
||||
}
|
||||
config.TLSClientConfig = &tls.Config{MinVersion: tls.VersionTLS12, Certificates: []tls.Certificate{cert}}
|
||||
config.SASL = []amqp.Authentication{&amqp.ExternalAuth{}}
|
||||
}
|
||||
connection, err := amqp.DialConfig(address, config)
|
||||
if err != nil {
|
||||
return nil, errors.New("RabbitMQ connection unavailable")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user