Replace the service bearer tokens with [tls] ca_file and cert_dir. Caller identity comes from the verified certificate, not metadata. Without TLS, services listen and dial on loopback only. Task containers get only the CA and keep their grant.
48 lines
1.7 KiB
Go
48 lines
1.7 KiB
Go
package archied
|
|
|
|
import (
|
|
"google.golang.org/grpc"
|
|
|
|
"github.com/samcharles93/archie-core/internal/app/servicekit"
|
|
"github.com/samcharles93/archie-core/internal/config"
|
|
"github.com/samcharles93/archie-core/internal/domain/presence"
|
|
"github.com/samcharles93/archie-core/internal/gateway"
|
|
"github.com/samcharles93/archie-core/internal/infrastructure/gatewayrpc"
|
|
"github.com/samcharles93/archie-core/internal/infrastructure/messagingrpc"
|
|
)
|
|
|
|
// composeChatContract dials the standalone archie-gateway, the sole owner of
|
|
// ChatContract, from the daemon's own configuration key.
|
|
func composeChatContract(cfg config.Config, options ...grpc.DialOption) (gateway.ChatContract, func(), error) {
|
|
target, err := cfg.Services.RequireTarget(config.ServiceNameGateway)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
id, err := servicekit.Identity(cfg.TLS, presence.Daemon)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
// Assigned through a typed variable rather than returned directly: a
|
|
// direct forward would hand a failed dial's nil *Client back as a
|
|
// non-nil ChatContract interface.
|
|
client, cleanup, err := gatewayrpc.Dial(target, id, options...)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
return client, cleanup, nil
|
|
}
|
|
|
|
// composeMessaging builds the Messaging Service client. The connection is
|
|
// lazy, so an absent Messaging Service fails each delivery, not the daemon.
|
|
func composeMessaging(cfg config.Config) (*messagingrpc.Client, func(), error) {
|
|
target, err := cfg.Services.RequireTarget(config.ServiceNameMessaging)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
id, err := servicekit.Identity(cfg.TLS, presence.Daemon)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
return messagingrpc.Dial(target, id)
|
|
}
|