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.
29 lines
999 B
Go
29 lines
999 B
Go
package servicekit
|
|
|
|
import (
|
|
"github.com/samcharles93/archie-core/internal/config"
|
|
"github.com/samcharles93/archie-core/internal/infrastructure/rpctls"
|
|
"github.com/samcharles93/archie-core/internal/infrastructure/staterpc"
|
|
)
|
|
|
|
// Identity loads service's certificate from [tls]; nil means plaintext,
|
|
// loopback only.
|
|
func Identity(cfg config.TLS, service string) (*rpctls.Identity, error) {
|
|
return rpctls.Load(cfg.CAFile, cfg.CertDir, service)
|
|
}
|
|
|
|
// StateStoreClient dials the State Store gRPC service as the caller service.
|
|
// Calls wait for the State Store rather than fail while it is down, so boot
|
|
// order between services does not matter.
|
|
func StateStoreClient(caller string, cfg config.Config) (*staterpc.Client, func(), error) {
|
|
target, err := cfg.Services.RequireTarget(config.ServiceNameState)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
id, err := Identity(cfg.TLS, caller)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
return staterpc.Dial(target, caller, id, staterpc.WaitForPeer)
|
|
}
|