feat(rpc): mTLS between services from operator-issued certificates
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.
This commit is contained in:
51 files changed
+746
-689
No files matched your search
@@ -50,6 +50,8 @@ type Settings struct {
|
||||
// NATS storerpc path is deleted.
|
||||
StateStoreTarget string
|
||||
StateStoreToken string
|
||||
// StateStoreCA is the PEM CA the State Store's certificate chains to.
|
||||
StateStoreCA []byte
|
||||
|
||||
// ModelProxy, ModelProxyHosts and ModelProxyCA route model provider
|
||||
// requests through the daemon's egress proxy, which holds the keys.
|
||||
@@ -148,6 +150,7 @@ func run(ctx context.Context, settings Settings, log *slog.Logger, dependencies
|
||||
TaskID: taskID,
|
||||
StateStoreURL: settings.StateStoreTarget,
|
||||
StateStoreToken: settings.StateStoreToken,
|
||||
StateStoreCA: settings.StateStoreCA,
|
||||
}, log)
|
||||
if err != nil {
|
||||
operation := "nats connect failed"
|
||||
|
||||
@@ -108,7 +108,6 @@ type boot struct {
|
||||
// (daemon.RunCredentialIssuer), wrapping the same *staterpc.Client as
|
||||
// stateStore, which also verifies a credential for a worktree push.
|
||||
stateStoreGrants *staterpc.GrantIssuer
|
||||
stateStoreToken string
|
||||
controlPlane *controlplane.Client
|
||||
// controlPlaneRPC is the State Store's control-plane transport, kept so the
|
||||
// daemon root can build its workflow-definitions client from it
|
||||
@@ -273,7 +272,7 @@ func (b *boot) openStateStoreAdapter(ctx context.Context) error {
|
||||
if target == "" {
|
||||
return fmt.Errorf("services.state.target is required: archied/archie-gateway no longer own archie.db; the standalone archie-state-store process owns it (docs/prds/state-store-contract.md §12 step 7)")
|
||||
}
|
||||
client, cleanup, err := servicekit.StateStoreClient(presence.Daemon, b.cfg.Services, b.secrets)
|
||||
client, cleanup, err := servicekit.StateStoreClient(presence.Daemon, b.cfg)
|
||||
if err != nil {
|
||||
b.log.Error("state store adapter", "err", err)
|
||||
return err
|
||||
@@ -287,7 +286,6 @@ func (b *boot) openStateStoreAdapter(ctx context.Context) error {
|
||||
b.controlPlane = controlplane.NewRPCClient(b.controlPlaneRPC)
|
||||
b.applyStatus = applystatus.New(b.processName, client, b.log)
|
||||
b.stateStoreGrants = &staterpc.GrantIssuer{Client: client}
|
||||
b.stateStoreToken = b.cfg.Services.ResolvedToken(config.ServiceNameState, b.secrets.Getenv)
|
||||
b.addCleanup(cleanup)
|
||||
b.startSecretEngines(ctx, client)
|
||||
return nil
|
||||
@@ -478,13 +476,13 @@ func (b *boot) setupContainers(ctx context.Context) func() {
|
||||
// only enqueues the chat tasks scheduled workflows create.
|
||||
func (b *boot) setupGatewayClient(ctx context.Context) error {
|
||||
b.setupChatTasks(b.cfg)
|
||||
contract, cleanup, err := composeChatContract(b.cfg.Services, b.secrets)
|
||||
contract, cleanup, err := composeChatContract(b.cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
b.addCleanup(cleanup)
|
||||
b.chat = &webui.ChatService{Contract: contract}
|
||||
messaging, closeMessaging, err := composeMessaging(b.cfg.Services, b.secrets)
|
||||
messaging, closeMessaging, err := composeMessaging(b.cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -580,7 +578,7 @@ func (b *boot) buildDaemon() {
|
||||
b.d = &daemon.Daemon{
|
||||
Cfg: b.cfgHolder,
|
||||
ConnectedNATS: daemon.NATSEndpoint{URL: b.natsURL, Token: b.natsToken, Scoped: b.cfg.NATS.Mode != config.NATSModeExternal},
|
||||
ConnectedStateStore: daemon.StateStoreEndpoint{URL: strings.TrimSpace(b.cfg.Services.Get(config.ServiceNameState).Target), Token: b.stateStoreToken},
|
||||
ConnectedStateStore: daemon.StateStoreEndpoint{URL: strings.TrimSpace(b.cfg.Services.Get(config.ServiceNameState).Target), CA: b.stateStoreCA()},
|
||||
Store: b.stateStore,
|
||||
Bus: b.bus,
|
||||
Forge: b.forgeClient,
|
||||
@@ -873,3 +871,14 @@ func (b *boot) livePlaybooks() *controlplane.LivePlaybooks {
|
||||
// playbookRefreshInterval is how often archied re-reads the resources it
|
||||
// would otherwise load only on first use, so their apply status stays reported.
|
||||
const playbookRefreshInterval = 30 * time.Second
|
||||
|
||||
// stateStoreCA is the CA a task container verifies the State Store with;
|
||||
// nil without [tls].
|
||||
func (b *boot) stateStoreCA() []byte {
|
||||
id, err := servicekit.Identity(b.cfg.TLS, presence.Daemon)
|
||||
if err != nil {
|
||||
b.log.Warn("state store CA for containers", "err", err)
|
||||
return nil
|
||||
}
|
||||
return id.CAPEM()
|
||||
}
|
||||
@@ -3,27 +3,29 @@ 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"
|
||||
"github.com/samcharles93/archie-core/internal/secret"
|
||||
)
|
||||
|
||||
// composeChatContract dials the standalone archie-gateway, the sole owner of
|
||||
// ChatContract, from the daemon's own configuration key. Token resolution is
|
||||
// the daemon's (it owns the config keys and the secret registry); the dial
|
||||
// itself and the fail-closed non-loopback rule belong to the transport, so
|
||||
// they come from gatewayrpc.Dial.
|
||||
func composeChatContract(services config.Services, secrets *secret.Registry, options ...grpc.DialOption) (gateway.ChatContract, func(), error) {
|
||||
target, err := services.RequireTarget(config.ServiceNameGateway)
|
||||
// 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, services.ResolvedToken(config.ServiceNameGateway, secrets.Getenv), options...)
|
||||
client, cleanup, err := gatewayrpc.Dial(target, id, options...)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@@ -32,10 +34,14 @@ func composeChatContract(services config.Services, secrets *secret.Registry, opt
|
||||
|
||||
// composeMessaging builds the Messaging Service client. The connection is
|
||||
// lazy, so an absent Messaging Service fails each delivery, not the daemon.
|
||||
func composeMessaging(services config.Services, secrets *secret.Registry) (*messagingrpc.Client, func(), error) {
|
||||
target, err := services.RequireTarget(config.ServiceNameMessaging)
|
||||
func composeMessaging(cfg config.Config) (*messagingrpc.Client, func(), error) {
|
||||
target, err := cfg.Services.RequireTarget(config.ServiceNameMessaging)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
return messagingrpc.Dial(target, services.ResolvedToken(config.ServiceNameMessaging, secrets.Getenv))
|
||||
id, err := servicekit.Identity(cfg.TLS, presence.Daemon)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
return messagingrpc.Dial(target, id)
|
||||
}
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"io"
|
||||
"log/slog"
|
||||
"net"
|
||||
"os"
|
||||
"slices"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -19,7 +18,7 @@ import (
|
||||
"github.com/samcharles93/archie-core/internal/config"
|
||||
"github.com/samcharles93/archie-core/internal/container"
|
||||
pb "github.com/samcharles93/archie-core/internal/contracts/harness/v1"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/harnessrpc"
|
||||
"github.com/samcharles93/archie-core/internal/domain/presence"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/harnesssession"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/kitrun"
|
||||
)
|
||||
@@ -189,9 +188,18 @@ func (b *boot) setupHarness(ctx context.Context) {
|
||||
b.log.Warn("harness sessions disabled", "err", err)
|
||||
return
|
||||
}
|
||||
token := b.cfg.Services.ResolvedToken(config.ServiceNameHarness, os.Getenv)
|
||||
if token == "" {
|
||||
b.log.Warn("harness sessions disabled: [services.harness].target_token or HARNESS_TOKEN is required, even on loopback")
|
||||
id, err := servicekit.Identity(b.cfg.TLS, presence.Daemon)
|
||||
if err != nil {
|
||||
b.log.Warn("harness sessions disabled", "err", err)
|
||||
return
|
||||
}
|
||||
if id == nil {
|
||||
b.log.Warn("harness sessions disabled: a session is a shell holding an org's credential, so it needs [tls] ca_file and cert_dir")
|
||||
return
|
||||
}
|
||||
creds, err := id.ServerOption(listen, false)
|
||||
if err != nil {
|
||||
b.log.Warn("harness sessions disabled", "err", err)
|
||||
return
|
||||
}
|
||||
ln, err := (&net.ListenConfig{}).Listen(ctx, "tcp", listen)
|
||||
@@ -205,10 +213,7 @@ func (b *boot) setupHarness(ctx context.Context) {
|
||||
Profile: func(name string) (config.AgentProfile, error) { return b.cfgHolder.Get().Containers.Profile(name) },
|
||||
TTL: setupSessionTTL,
|
||||
}
|
||||
srv := grpc.NewServer(
|
||||
//nolint:contextcheck // grpc.StreamServerInterceptor has no context.Context parameter; the interceptor derives its context from stream.Context()
|
||||
grpc.StreamInterceptor(harnessrpc.StreamServerInterceptor(token)),
|
||||
)
|
||||
srv := grpc.NewServer(creds)
|
||||
pb.RegisterHarnessServiceServer(srv, &harnessServer{sessions: manager, runs: b.runView(), log: b.log})
|
||||
go func() {
|
||||
if err := srv.Serve(ln); err != nil && !errors.Is(err, grpc.ErrServerStopped) {
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
"github.com/samcharles93/archie-core/internal/app/servicekit"
|
||||
"github.com/samcharles93/archie-core/internal/domain/presence"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/configuration"
|
||||
"github.com/samcharles93/archie-core/internal/secret"
|
||||
)
|
||||
|
||||
// RunStatus prints one line per service from the State Store's presence
|
||||
@@ -31,7 +30,7 @@ func RunStatus(args []string, stdout, stderr io.Writer) int {
|
||||
fmt.Fprintf(stderr, "archied status: %v\n", err)
|
||||
return 1
|
||||
}
|
||||
client, cleanup, err := servicekit.StateStoreClient(presence.Daemon, doc.Config.Services, secret.NewRegistry())
|
||||
client, cleanup, err := servicekit.StateStoreClient(presence.Daemon, doc.Config)
|
||||
if err != nil {
|
||||
fmt.Fprintf(stderr, "archied status: %v\n", err)
|
||||
return 1
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
"github.com/samcharles93/archie-core/internal/app/servicekit"
|
||||
pb "github.com/samcharles93/archie-core/internal/contracts/controlplane/v1"
|
||||
"github.com/samcharles93/archie-core/internal/domain/presence"
|
||||
"github.com/samcharles93/archie-core/internal/secret"
|
||||
)
|
||||
|
||||
// imagePolicy is the control plane's agent image, reached through the State
|
||||
@@ -55,7 +54,7 @@ func (p imagePolicy) with(ctx context.Context, use func(pb.ControlPlaneServiceCl
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
client, cleanup, err := servicekit.StateStoreClient(presence.Daemon, doc.Config.Services, secret.NewRegistry())
|
||||
client, cleanup, err := servicekit.StateStoreClient(presence.Daemon, doc.Config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -15,15 +15,16 @@ import (
|
||||
"github.com/samcharles93/archie-core/internal/gateway"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/gatewayrpc"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/rpcidentity"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/rpctls"
|
||||
"github.com/samcharles93/archie-core/internal/plugin"
|
||||
)
|
||||
|
||||
// serveGatewayListener is the serving tail of Run: the listener is
|
||||
// bound, the process declares itself serving, and the chat contract answers
|
||||
// until ctx ends.
|
||||
func (b *server) serveGatewayListener(ctx context.Context, listener net.Listener, loopback bool, contract gateway.ChatContract, opts []grpc.ServerOption) error {
|
||||
func (b *server) serveGatewayListener(ctx context.Context, listener net.Listener, contract gateway.ChatContract, opts []grpc.ServerOption) error {
|
||||
defer listener.Close()
|
||||
b.log.Info("archie-gateway running", "addr", listener.Addr().String(), "token_required", !loopback)
|
||||
b.log.Info("archie-gateway running", "addr", listener.Addr().String(), "tls", b.id != nil)
|
||||
// Boot is over and this listener is about to accept: the same fact
|
||||
// systemd's READY=1 asserts, so the announcement goes out here rather than
|
||||
// from a second notion of "started". Not later: Serve
|
||||
@@ -90,37 +91,25 @@ func (b *server) startGatewayRuntime(ctx context.Context, actor gateway.ChatTask
|
||||
// rather than rejected as an oversized gRPC message.
|
||||
const inboundMessageHeadroomBytes = 1 << 20
|
||||
|
||||
// gatewayServerOpts applies the transport security boundary: a loopback
|
||||
// listener is served insecure with no token; any non-loopback address
|
||||
// requires a Bearer [REDACTED], else the process fails closed. It mirrors
|
||||
// stateStoreServerOpts, minus the State Store's task-scoped grants: the
|
||||
// Gateway has one administrative token for all callers.
|
||||
// gatewayServerOpts serves listen with id's credentials; every caller
|
||||
// presents a service certificate.
|
||||
//
|
||||
// The receive limit is raised above gRPC's 4 MB default because an inbound
|
||||
// request carries a channel attachment's bytes: the channel frontend
|
||||
// downloads the file, and this process -- which runs the turn -- holds no
|
||||
// platform credential to fetch it again.
|
||||
func gatewayServerOpts(listen, token string, principals access.PrincipalSource) (opts []grpc.ServerOption, loopback bool, err error) {
|
||||
callers := rpcidentity.Callers{Principals: principals}
|
||||
recv := grpc.MaxRecvMsgSize(messaging.MaxInboundAttachmentBytes + inboundMessageHeadroomBytes)
|
||||
loopback, err = gatewayrpc.TargetIsLoopback(listen)
|
||||
func gatewayServerOpts(listen string, id *rpctls.Identity, principals access.PrincipalSource) ([]grpc.ServerOption, error) {
|
||||
creds, err := id.ServerOption(listen, false)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
if loopback {
|
||||
return []grpc.ServerOption{recv, grpc.ChainUnaryInterceptor(callers.Unary()), grpc.ChainStreamInterceptor(callers.Stream())}, true, nil
|
||||
}
|
||||
if token == "" {
|
||||
return nil, false, fmt.Errorf(
|
||||
"gateway listen address %q is non-loopback; non-loopback exposure requires a Bearer [REDACTED] (--token / [services.gateway].target_token) or TLS",
|
||||
listen,
|
||||
)
|
||||
return nil, fmt.Errorf("gateway: %w", err)
|
||||
}
|
||||
callers := rpcidentity.Callers{Principals: principals}
|
||||
return []grpc.ServerOption{
|
||||
recv,
|
||||
grpc.ChainUnaryInterceptor(gatewayrpc.UnaryServerInterceptor(token), callers.Unary()),
|
||||
grpc.ChainStreamInterceptor(gatewayrpc.StreamServerInterceptor(token), callers.Stream()),
|
||||
}, false, nil
|
||||
creds,
|
||||
grpc.MaxRecvMsgSize(messaging.MaxInboundAttachmentBytes + inboundMessageHeadroomBytes),
|
||||
grpc.ChainUnaryInterceptor(callers.Unary()),
|
||||
grpc.ChainStreamInterceptor(callers.Stream()),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func serveGateway(ctx context.Context, listener net.Listener, contract gateway.ChatContract, sessions gateway.SessionStore, catalog gatewayrpc.Catalog, opts []grpc.ServerOption) error {
|
||||
|
||||
@@ -30,6 +30,7 @@ import (
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/controlplanerpc"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/modelcatalog"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/readiness"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/rpctls"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/secretengine"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/staterpc"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/taskactions"
|
||||
@@ -51,9 +52,6 @@ type Options struct {
|
||||
// Listen is the gRPC listen address. Empty falls back to
|
||||
// [services.gateway].listen.
|
||||
Listen string
|
||||
// Token is the bearer token a non-loopback listener requires. Empty falls
|
||||
// back to [services.gateway].target_token.
|
||||
Token string
|
||||
}
|
||||
|
||||
// server is the Gateway process: the owner of conversations and of every
|
||||
@@ -65,6 +63,7 @@ type server struct {
|
||||
log *slog.Logger
|
||||
|
||||
secrets *secret.Registry
|
||||
id *rpctls.Identity
|
||||
engines *secretengine.Runner
|
||||
stateStore *staterpc.Client
|
||||
controlPlane *controlplane.Client
|
||||
@@ -130,12 +129,7 @@ func Run(ctx context.Context, options Options) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
token := options.Token
|
||||
if token == "" {
|
||||
token = b.cfg.Services.ResolvedToken(config.ServiceNameGateway, b.secrets.Getenv)
|
||||
}
|
||||
//nolint:contextcheck // grpc.StreamServerInterceptor has no context.Context parameter; gatewayrpc.StreamServerInterceptor derives its context from stream.Context() instead
|
||||
opts, loopback, err := gatewayServerOpts(listen, token, b.stateStore)
|
||||
opts, err := gatewayServerOpts(listen, b.id, b.stateStore)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -143,7 +137,7 @@ func Run(ctx context.Context, options Options) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("listen for gateway: %w", err)
|
||||
}
|
||||
return b.serveGatewayListener(ctx, listener, loopback, contract, opts)
|
||||
return b.serveGatewayListener(ctx, listener, contract, opts)
|
||||
}
|
||||
|
||||
func (b *server) addCleanup(fn func()) { b.cleanups = append(b.cleanups, fn) }
|
||||
@@ -171,7 +165,8 @@ func (b *server) loadConfig(cfgPath, overlayPath string) error {
|
||||
b.log, b.logFeed = logs.Log, logs.Feed
|
||||
b.addCleanup(func() { _ = logs.Closer.Close() })
|
||||
b.secrets = secret.NewRegistry()
|
||||
return nil
|
||||
b.id, err = servicekit.Identity(b.cfg.TLS, presence.Gateway)
|
||||
return err
|
||||
}
|
||||
|
||||
// openState claims the conversation store, dials the State Store, starts the
|
||||
@@ -183,7 +178,7 @@ func (b *server) openState(ctx context.Context) error {
|
||||
if err := b.claimGatewayOwnership(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
client, cleanup, err := servicekit.StateStoreClient(presence.Gateway, b.cfg.Services, b.secrets)
|
||||
client, cleanup, err := servicekit.StateStoreClient(presence.Gateway, b.cfg)
|
||||
if err != nil {
|
||||
return fmt.Errorf("state store client: %w", err)
|
||||
}
|
||||
|
||||
@@ -8,13 +8,17 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/config"
|
||||
"github.com/samcharles93/archie-core/internal/domain/presence"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/configuration"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/rpctls"
|
||||
"github.com/samcharles93/archie-core/internal/secret"
|
||||
)
|
||||
|
||||
// ResolvedConfig contains the resolved inputs needed by the Messaging Service.
|
||||
type ResolvedConfig struct {
|
||||
Options Options
|
||||
Options Options
|
||||
// Identity is this process's certificate; nil is plaintext, loopback only.
|
||||
Identity *rpctls.Identity
|
||||
TelegramToken string
|
||||
Telegram config.TelegramConfig
|
||||
// WorkDir and BotUser are not channel transport settings. They locate
|
||||
@@ -28,6 +32,7 @@ type projection struct {
|
||||
gateway ServiceTarget
|
||||
stateStore ServiceTarget
|
||||
messaging config.ServiceConnection
|
||||
tls config.TLS
|
||||
telegram config.TelegramConfig
|
||||
workDir string
|
||||
botUser string
|
||||
@@ -51,13 +56,17 @@ func Resolve(o Options, log *slog.Logger) (ResolvedConfig, error) {
|
||||
}
|
||||
}
|
||||
o = withDefaults(o)
|
||||
o = withEnvTokens(o)
|
||||
if err := o.validate(); err != nil {
|
||||
return ResolvedConfig{}, err
|
||||
}
|
||||
id, err := rpctls.Load(proj.tls.CAFile, proj.tls.CertDir, presence.Messaging)
|
||||
if err != nil {
|
||||
return ResolvedConfig{}, err
|
||||
}
|
||||
|
||||
return ResolvedConfig{
|
||||
Options: o,
|
||||
Identity: id,
|
||||
Telegram: proj.telegram,
|
||||
WorkDir: proj.workDir,
|
||||
BotUser: proj.botUser,
|
||||
@@ -78,12 +87,10 @@ func readProjection(path, overlay string, log *slog.Logger) (projection, bool, e
|
||||
|
||||
func project(cfg config.Config) projection {
|
||||
return projection{
|
||||
gateway: ServiceTarget{
|
||||
Target: cfg.Services.Get(config.ServiceNameGateway).Target,
|
||||
Token: cfg.Services.Get(config.ServiceNameGateway).TargetToken,
|
||||
},
|
||||
stateStore: ServiceTarget{Target: cfg.Services.Get(config.ServiceNameState).Target, Token: cfg.Services.Get(config.ServiceNameState).TargetToken},
|
||||
gateway: ServiceTarget{Target: cfg.Services.Get(config.ServiceNameGateway).Target},
|
||||
stateStore: ServiceTarget{Target: cfg.Services.Get(config.ServiceNameState).Target},
|
||||
messaging: cfg.Services.Get(config.ServiceNameMessaging),
|
||||
tls: cfg.TLS,
|
||||
telegram: cfg.Chat.Telegram,
|
||||
workDir: cfg.WorkDir,
|
||||
botUser: cfg.BotUser,
|
||||
@@ -91,38 +98,16 @@ func project(cfg config.Config) projection {
|
||||
}
|
||||
}
|
||||
|
||||
func withEnvTokens(o Options) Options {
|
||||
if o.Gateway.Token == "" {
|
||||
o.Gateway.Token = os.Getenv("GATEWAY_TOKEN")
|
||||
}
|
||||
if o.StateStore.Token == "" {
|
||||
o.StateStore.Token = os.Getenv("STATE_STORE_TOKEN")
|
||||
}
|
||||
if o.Token == "" {
|
||||
o.Token = os.Getenv("MESSAGING_TOKEN")
|
||||
}
|
||||
return o
|
||||
}
|
||||
|
||||
func merge(o Options, p projection) Options {
|
||||
if o.Gateway.Target == "" {
|
||||
o.Gateway.Target = p.gateway.Target
|
||||
}
|
||||
if o.Gateway.Token == "" {
|
||||
o.Gateway.Token = p.gateway.Token
|
||||
}
|
||||
if o.StateStore.Target == "" {
|
||||
o.StateStore.Target = p.stateStore.Target
|
||||
}
|
||||
if o.StateStore.Token == "" {
|
||||
o.StateStore.Token = p.stateStore.Token
|
||||
}
|
||||
if o.Listen == "" {
|
||||
o.Listen = p.messaging.Listen
|
||||
}
|
||||
if o.Token == "" {
|
||||
o.Token = p.messaging.TargetToken
|
||||
}
|
||||
return o
|
||||
}
|
||||
|
||||
|
||||
@@ -4,9 +4,6 @@ package archiemessaging
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -18,11 +15,9 @@ const (
|
||||
defaultShutdownTimeout = 5 * time.Second
|
||||
)
|
||||
|
||||
// ServiceTarget is one remote contract's endpoint and the service-to-service
|
||||
// bearer token this process presents to it.
|
||||
// ServiceTarget is one remote contract's endpoint.
|
||||
type ServiceTarget struct {
|
||||
Target string
|
||||
Token string
|
||||
}
|
||||
|
||||
// Options contains the process inputs for the Messaging Service.
|
||||
@@ -32,10 +27,8 @@ type Options struct {
|
||||
|
||||
Gateway ServiceTarget
|
||||
StateStore ServiceTarget
|
||||
// Listen is where MessagingService is served; Token is the bearer token
|
||||
// its callers present on a non-loopback address.
|
||||
// Listen is where MessagingService is served.
|
||||
Listen string
|
||||
Token string
|
||||
DependencyTimeout time.Duration
|
||||
ShutdownTimeout time.Duration
|
||||
}
|
||||
@@ -60,35 +53,5 @@ func (o Options) validate() error {
|
||||
if o.Gateway.Target == "" {
|
||||
return errors.New("gateway target is required (pass -gateway-target or configure [services.gateway].target)")
|
||||
}
|
||||
if err := validateServiceTarget("gateway", o.Gateway); err != nil {
|
||||
return err
|
||||
}
|
||||
if o.StateStore.Target != "" {
|
||||
if err := validateServiceTarget("state store", o.StateStore); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return validateServiceTarget("messaging listen", ServiceTarget{Target: o.Listen, Token: o.Token})
|
||||
}
|
||||
|
||||
func validateServiceTarget(serviceName string, target ServiceTarget) error {
|
||||
host, _, err := net.SplitHostPort(target.Target)
|
||||
if err != nil {
|
||||
host = target.Target
|
||||
}
|
||||
if isLoopback(host) {
|
||||
return nil
|
||||
}
|
||||
if target.Token == "" {
|
||||
return fmt.Errorf("%s target %q is non-loopback and requires a bearer token", serviceName, target.Target)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func isLoopback(host string) bool {
|
||||
if host == "localhost" {
|
||||
return true
|
||||
}
|
||||
ip := net.ParseIP(strings.Trim(host, "[]"))
|
||||
return ip != nil && ip.IsLoopback()
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/extension"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/gatewayrpc"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/messagingrpc"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/rpctls"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/secretengine"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/staterpc"
|
||||
"github.com/samcharles93/archie-core/internal/logging"
|
||||
@@ -36,7 +37,7 @@ func Run(ctx context.Context, o Options) error {
|
||||
return fmt.Errorf("resolve messaging options: %w", err)
|
||||
}
|
||||
|
||||
chat, closeGateway, err := gatewayrpc.Dial(cfg.Options.Gateway.Target, cfg.Options.Gateway.Token)
|
||||
chat, closeGateway, err := gatewayrpc.Dial(cfg.Options.Gateway.Target, cfg.Identity)
|
||||
if err != nil {
|
||||
return fmt.Errorf("dial gateway (%s): %w", cfg.Options.Gateway.Target, err)
|
||||
}
|
||||
@@ -59,7 +60,7 @@ func Run(ctx context.Context, o Options) error {
|
||||
var updates *releaseupdate.Service
|
||||
var extensionChannels []*channelInstance
|
||||
if cfg.Options.StateStore.Target != "" {
|
||||
stateStore, closeClient, dialErr := staterpc.Dial(cfg.Options.StateStore.Target, presence.Messaging, cfg.Options.StateStore.Token, staterpc.WaitForPeer)
|
||||
stateStore, closeClient, dialErr := staterpc.Dial(cfg.Options.StateStore.Target, presence.Messaging, cfg.Identity, staterpc.WaitForPeer)
|
||||
if dialErr != nil {
|
||||
return fmt.Errorf("dial state store control plane (%s): %w", cfg.Options.StateStore.Target, dialErr)
|
||||
}
|
||||
@@ -112,18 +113,18 @@ func Run(ctx context.Context, o Options) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return serve(ctx, cfg.Options, srv, log, feed)
|
||||
return serve(ctx, cfg.Options.Listen, cfg.Identity, srv, log, feed)
|
||||
}
|
||||
|
||||
// serve runs srv and serves MessagingService over it until ctx is cancelled.
|
||||
func serve(ctx context.Context, o Options, srv *Service, log *slog.Logger, feed *logging.Feed) error {
|
||||
opts, err := messagingrpc.ServerOptions(o.Listen, o.Token)
|
||||
func serve(ctx context.Context, listen string, id *rpctls.Identity, srv *Service, log *slog.Logger, feed *logging.Feed) error {
|
||||
opts, err := messagingrpc.ServerOptions(listen, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
listener, err := (&net.ListenConfig{}).Listen(ctx, "tcp", o.Listen)
|
||||
listener, err := (&net.ListenConfig{}).Listen(ctx, "tcp", listen)
|
||||
if err != nil {
|
||||
return fmt.Errorf("listen messaging (%s): %w", o.Listen, err)
|
||||
return fmt.Errorf("listen messaging (%s): %w", listen, err)
|
||||
}
|
||||
server := grpc.NewServer(opts...)
|
||||
messagingrpc.RegisterServer(server, srv, feed)
|
||||
@@ -133,7 +134,7 @@ func serve(ctx context.Context, o Options, srv *Service, log *slog.Logger, feed
|
||||
}
|
||||
}()
|
||||
defer server.GracefulStop()
|
||||
log.Info("messaging service listening", "listen", o.Listen)
|
||||
log.Info("messaging service listening", "listen", listen)
|
||||
return srv.Start(ctx)
|
||||
}
|
||||
|
||||
|
||||
@@ -8,13 +8,16 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/config"
|
||||
"github.com/samcharles93/archie-core/internal/domain/presence"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/configuration"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/rpctls"
|
||||
"github.com/samcharles93/archie-core/internal/webui"
|
||||
)
|
||||
|
||||
// Resolve returns the effective Options: flags first, then the config file's
|
||||
// projection, then defaults, and validates the result.
|
||||
func Resolve(o Options, log *slog.Logger) (Options, error) {
|
||||
var tls config.TLS
|
||||
if o.Config != "" {
|
||||
cfg, found, err := readProjection(o.Config, o.Overlay, log)
|
||||
if err != nil {
|
||||
@@ -22,10 +25,15 @@ func Resolve(o Options, log *slog.Logger) (Options, error) {
|
||||
}
|
||||
if found {
|
||||
o = merge(o, cfg)
|
||||
tls = cfg.tls
|
||||
}
|
||||
}
|
||||
o = withDefaults(o)
|
||||
o = withEnvTokens(o)
|
||||
id, err := rpctls.Load(tls.CAFile, tls.CertDir, presence.UI)
|
||||
if err != nil {
|
||||
return Options{}, err
|
||||
}
|
||||
o.identity = id
|
||||
token, err := resolveToken(o)
|
||||
if err != nil {
|
||||
return Options{}, err
|
||||
@@ -60,6 +68,7 @@ type projection struct {
|
||||
state ServiceTarget
|
||||
messaging ServiceTarget
|
||||
harness ServiceTarget
|
||||
tls config.TLS
|
||||
capture CaptureOptions
|
||||
}
|
||||
|
||||
@@ -67,10 +76,11 @@ func project(cfg config.Config) projection {
|
||||
return projection{
|
||||
listen: cfg.Web.Listen,
|
||||
trustForwardedHeaders: cfg.Web.TrustForwardedHeaders,
|
||||
gateway: ServiceTarget{Target: cfg.Services.Get(config.ServiceNameGateway).Target, Token: cfg.Services.Get(config.ServiceNameGateway).TargetToken},
|
||||
messaging: ServiceTarget{Target: cfg.Services.Get(config.ServiceNameMessaging).Target, Token: cfg.Services.Get(config.ServiceNameMessaging).TargetToken},
|
||||
state: ServiceTarget{Target: cfg.Services.Get(config.ServiceNameState).Target, Token: cfg.Services.Get(config.ServiceNameState).TargetToken},
|
||||
harness: ServiceTarget{Target: cfg.Services.Get(config.ServiceNameHarness).Target, Token: cfg.Services.Get(config.ServiceNameHarness).TargetToken},
|
||||
gateway: ServiceTarget{Target: cfg.Services.Get(config.ServiceNameGateway).Target},
|
||||
messaging: ServiceTarget{Target: cfg.Services.Get(config.ServiceNameMessaging).Target},
|
||||
state: ServiceTarget{Target: cfg.Services.Get(config.ServiceNameState).Target},
|
||||
harness: ServiceTarget{Target: cfg.Services.Get(config.ServiceNameHarness).Target},
|
||||
tls: cfg.TLS,
|
||||
capture: CaptureOptions{
|
||||
Retention: cfg.Capture.Retention.Std(),
|
||||
MaxEvents: cfg.Capture.MaxEvents,
|
||||
@@ -81,23 +91,6 @@ func project(cfg config.Config) projection {
|
||||
}
|
||||
}
|
||||
|
||||
// withEnvTokens fills service tokens left unset from the environment.
|
||||
func withEnvTokens(o Options) Options {
|
||||
if o.Gateway.Token == "" {
|
||||
o.Gateway.Token = os.Getenv("GATEWAY_TOKEN")
|
||||
}
|
||||
if o.State.Token == "" {
|
||||
o.State.Token = os.Getenv("STATE_STORE_TOKEN")
|
||||
}
|
||||
if o.Messaging.Token == "" {
|
||||
o.Messaging.Token = os.Getenv("MESSAGING_TOKEN")
|
||||
}
|
||||
if o.Harness.Token == "" {
|
||||
o.Harness.Token = os.Getenv("HARNESS_TOKEN")
|
||||
}
|
||||
return o
|
||||
}
|
||||
|
||||
// merge fills only the fields the flags left empty.
|
||||
func merge(o Options, p projection) Options {
|
||||
if o.Listen == "" {
|
||||
@@ -187,8 +180,5 @@ func mergeTarget(o, p ServiceTarget) ServiceTarget {
|
||||
if o.Target == "" {
|
||||
o.Target = p.Target
|
||||
}
|
||||
if o.Token == "" {
|
||||
o.Token = p.Token
|
||||
}
|
||||
return o
|
||||
}
|
||||
@@ -23,7 +23,7 @@ func wireServiceLogs(opts Options, srv *webui.Server, tasks *staterpc.Client, ch
|
||||
return chat.RecentLogs(ctx, presence.Daemon, q)
|
||||
},
|
||||
}
|
||||
messaging, closeMessaging, dialErr := messagingrpc.Dial(opts.Messaging.Target, opts.Messaging.Token)
|
||||
messaging, closeMessaging, dialErr := messagingrpc.Dial(opts.Messaging.Target, opts.identity)
|
||||
if dialErr != nil {
|
||||
return nil, dialErr
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/configuration"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/rpctls"
|
||||
)
|
||||
|
||||
// Process defaults. Listen matches the dashboard's historical bind
|
||||
@@ -18,12 +19,9 @@ const (
|
||||
defaultShutdownTimeout = 5 * time.Second
|
||||
)
|
||||
|
||||
// ServiceTarget is one remote contract's endpoint and the service-to-service
|
||||
// bearer token this process presents to it. It is an endpoint reference, not
|
||||
// a resolved daemon credential: the UI authenticates each client itself.
|
||||
// ServiceTarget is one remote contract's endpoint.
|
||||
type ServiceTarget struct {
|
||||
Target string
|
||||
Token string
|
||||
}
|
||||
|
||||
// Options is the UI-owned input DTO. It carries process-local settings and
|
||||
@@ -83,6 +81,10 @@ type Options struct {
|
||||
// ReadHeaderTimeout and ShutdownTimeout bound the HTTP lifecycle.
|
||||
ReadHeaderTimeout time.Duration
|
||||
ShutdownTimeout time.Duration
|
||||
|
||||
// identity is this process's certificate, loaded by Resolve from
|
||||
// [tls]; nil is plaintext, loopback only.
|
||||
identity *rpctls.Identity
|
||||
}
|
||||
|
||||
// CaptureOptions carries the [capture] settings the capture receiver needs.
|
||||
|
||||
@@ -58,12 +58,12 @@ func Run(ctx context.Context, options Options) error {
|
||||
cleanup()
|
||||
}
|
||||
}()
|
||||
tasks, closeState, err := staterpc.Dial(opts.State.Target, presence.UI, opts.State.Token)
|
||||
tasks, closeState, err := staterpc.Dial(opts.State.Target, presence.UI, opts.identity)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cleanups = append(cleanups, closeState)
|
||||
chat, closeGateway, err := gatewayrpc.Dial(opts.Gateway.Target, opts.Gateway.Token)
|
||||
chat, closeGateway, err := gatewayrpc.Dial(opts.Gateway.Target, opts.identity)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -146,7 +146,7 @@ func wireHarness(opts Options, srv *webui.Server, cleanups *[]func()) error {
|
||||
if opts.Harness.Target == "" {
|
||||
return nil
|
||||
}
|
||||
harness, closeHarness, err := harnessrpc.Dial(opts.Harness.Target, opts.Harness.Token)
|
||||
harness, closeHarness, err := harnessrpc.Dial(opts.Harness.Target, opts.identity)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -2,20 +2,27 @@ 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"
|
||||
"github.com/samcharles93/archie-core/internal/secret"
|
||||
)
|
||||
|
||||
// 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.
|
||||
// Token resolution is the daemon's
|
||||
// (it owns the config keys and the secret registry); the dial itself and the
|
||||
// fail-closed non-loopback rule belong to the transport, so they come
|
||||
// from staterpc.Dial. 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, services config.Services, secrets *secret.Registry) (*staterpc.Client, func(), error) {
|
||||
target, err := services.RequireTarget(config.ServiceNameState)
|
||||
// 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
|
||||
}
|
||||
return staterpc.Dial(target, caller, services.ResolvedToken(config.ServiceNameState, secrets.Getenv), staterpc.WaitForPeer)
|
||||
id, err := Identity(cfg.TLS, caller)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
return staterpc.Dial(target, caller, id, staterpc.WaitForPeer)
|
||||
}
|
||||
@@ -42,13 +42,8 @@ import (
|
||||
type Options struct {
|
||||
Config string
|
||||
Overlay string
|
||||
// Listen is the gRPC listen address. Loopback binds (127.0.0.1, ::1,
|
||||
// localhost) serve insecure with no token; any non-loopback address
|
||||
// requires a non-empty token (or TLS), else the process fails closed
|
||||
// Listen is the gRPC listen address. Without [tls] it must be loopback.
|
||||
Listen string
|
||||
// Token is the bearer token the State Store server validates for a
|
||||
// non-loopback listener. Empty falls back to [services.state].target_token.
|
||||
Token string
|
||||
// ReadyAddr, when non-empty, starts an HTTP readiness surface on the
|
||||
// address: GET /healthz (liveness) and GET /health/detailed (the
|
||||
// state_db probe). Empty disables it.
|
||||
@@ -114,13 +109,12 @@ func Run(ctx context.Context, options Options) error { //nolint:cyclop // the co
|
||||
}
|
||||
b.reportUnseededResources(skipped)
|
||||
|
||||
token := b.instanceToken(options)
|
||||
grants, err := b.runCredentials(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
//nolint:contextcheck // grpc.StreamServerInterceptor has no context.Context parameter; TaskGrants.StreamInterceptor derives its context from stream.Context() instead
|
||||
opts, loopback, err := stateStoreServerOpts(listen, token, grants, b.callers())
|
||||
opts, err := stateStoreServerOpts(listen, b.cfg.TLS, grants, b.callers())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -129,7 +123,7 @@ func Run(ctx context.Context, options Options) error { //nolint:cyclop // the co
|
||||
return fmt.Errorf("listen for state store: %w", err)
|
||||
}
|
||||
defer listener.Close()
|
||||
b.log.Info("archie-state-store running", "addr", listener.Addr().String(), "token_required", !loopback)
|
||||
b.log.Info("archie-state-store running", "addr", listener.Addr().String(), "tls", b.cfg.TLS.CertDir != "")
|
||||
|
||||
if err := b.startOptionalSurfaces(ctx, options); err != nil {
|
||||
return err
|
||||
@@ -383,15 +377,6 @@ func (b *server) executionDeps(deps *staterpc.Deps) {
|
||||
}
|
||||
}
|
||||
|
||||
// instanceToken is the bearer token a non-loopback listener requires: the
|
||||
// flag, else [services.state].target_token.
|
||||
func (b *server) instanceToken(options Options) string {
|
||||
if options.Token != "" {
|
||||
return options.Token
|
||||
}
|
||||
return b.cfg.Services.ResolvedToken(config.ServiceNameState, b.secrets.Getenv)
|
||||
}
|
||||
|
||||
// runCredentials builds the run-credential check over this store and drops
|
||||
// the credentials that expired while nothing revoked them.
|
||||
func (b *server) runCredentials(ctx context.Context) (*staterpc.TaskGrants, error) {
|
||||
@@ -507,48 +492,28 @@ func (b *server) startOptionalSurfaces(ctx context.Context, options Options) err
|
||||
return nil
|
||||
}
|
||||
|
||||
// stateStoreServerOpts applies the transport security boundary: a
|
||||
// loopback listener is served insecure with no token; any non-loopback
|
||||
// address requires a bearer token, else the process fails closed. It cannot
|
||||
// enforce TLS/mTLS (an operator decision), so it narrows the non-loopback
|
||||
// path to token auth -- the same confinement philosophy as the gateway's
|
||||
// loopback-only --listen rule.
|
||||
// stateStoreServerOpts serves listen with this process's [tls] certificate. A client
|
||||
// certificate is optional here alone: a task container has none and is
|
||||
// confined by its grant. Authentication runs before attribution.
|
||||
//
|
||||
// The keepalive enforcement policy is not part of that boundary and is
|
||||
// installed on both listeners: a loopback State Store serves the same dialers
|
||||
// as a remote one (staterpc.Dial installs the client keepalive on every target,
|
||||
// loopback included), and grpc's default policy would answer their idle
|
||||
// watches with GOAWAY too_many_pings. See staterpc.ServerKeepaliveOption.
|
||||
func stateStoreServerOpts(listen, token string, grants *staterpc.TaskGrants, callers rpcidentity.Callers) (opts []grpc.ServerOption, loopback bool, err error) {
|
||||
loopback, err = staterpc.TargetIsLoopback(listen)
|
||||
// The keepalive enforcement policy matches staterpc.Dial's clients, whose
|
||||
// idle watches grpc's default policy would answer with GOAWAY
|
||||
// too_many_pings. See staterpc.ServerKeepaliveOption.
|
||||
func stateStoreServerOpts(listen string, tls config.TLS, grants *staterpc.TaskGrants, callers rpcidentity.Callers) ([]grpc.ServerOption, error) {
|
||||
id, err := servicekit.Identity(tls, presence.StateStore)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
return nil, err
|
||||
}
|
||||
keepalive := staterpc.ServerKeepaliveOption()
|
||||
if loopback {
|
||||
return []grpc.ServerOption{
|
||||
keepalive,
|
||||
grpc.ChainUnaryInterceptor(callers.Unary()),
|
||||
grpc.ChainStreamInterceptor(callers.Stream()),
|
||||
}, true, nil
|
||||
creds, err := id.ServerOption(listen, true)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("state store: %w", err)
|
||||
}
|
||||
if token == "" {
|
||||
return nil, false, fmt.Errorf(
|
||||
"state store listen address %q is non-loopback; non-loopback exposure requires a bearer token (--token / [services.state].target_token) or TLS, mirroring the gateway's --listen confinement (docs/prds/state-store-contract.md §9)",
|
||||
listen,
|
||||
)
|
||||
}
|
||||
// grants.UnaryInterceptor/StreamInterceptor separate the daemon's own
|
||||
// administrative token (full access) from a container's task-scoped
|
||||
// grant (Update/Transition/InsertEvent on its own task ID only), rather
|
||||
// than the single all-or-nothing token check this replaced.
|
||||
return []grpc.ServerOption{
|
||||
keepalive,
|
||||
// Authentication runs before attribution: callers trusts the metadata
|
||||
// only of a call the grants check admitted as the instance.
|
||||
grpc.ChainUnaryInterceptor(grants.UnaryInterceptor(token), callers.Unary()),
|
||||
grpc.ChainStreamInterceptor(grants.StreamInterceptor(token), callers.Stream()),
|
||||
}, false, nil
|
||||
creds,
|
||||
staterpc.ServerKeepaliveOption(),
|
||||
grpc.ChainUnaryInterceptor(grants.UnaryInterceptor(), callers.Unary()),
|
||||
grpc.ChainStreamInterceptor(grants.StreamInterceptor(), callers.Stream()),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// newPackageProjections builds the family projectors an installed package's
|
||||
|
||||
Reference in new issue
Block a user