feat(creds): retrieve peer credentials when using unix socket

Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
This commit is contained in:
2025-11-23 12:42:01 +01:00
parent 4b64efb327
commit 6829ab5bbc
4 changed files with 75 additions and 0 deletions

View File

@@ -29,6 +29,7 @@ import (
"google.golang.org/grpc/health/grpc_health_v1"
greflect "google.golang.org/grpc/reflection"
"go.linka.cloud/grpc-toolkit/creds/peercreds"
"go.linka.cloud/grpc-toolkit/interceptors/chain"
"go.linka.cloud/grpc-toolkit/internal/injectlogger"
"go.linka.cloud/grpc-toolkit/logger"
@@ -138,6 +139,9 @@ func newService(opts ...Option) (*service, error) {
grpc.StreamInterceptor(si),
grpc.UnaryInterceptor(ui),
}
if _, ok := s.opts.lis.(*net.UnixListener); ok || strings.HasPrefix(s.opts.address, "unix://") {
gopts = append(gopts, grpc.Creds(peercreds.New()))
}
s.server = grpc.NewServer(append(gopts, s.opts.serverOpts...)...)
if s.opts.reflection {
greflect.Register(s.server)