
Security News
Cline CLI npm Package Compromised via Suspected Cache Poisoning Attack
A compromised npm publish token was used to push a malicious postinstall script in cline@2.3.0, affecting the popular AI coding agent CLI with 90k weekly downloads.
toolman.org/net/peercred/grpcpeer
Advanced tools
import "toolman.org/net/peercred/grpcpeer"
go get toolman.org/net/peercred/grpcpeer
Package grpcpeer adds gRPC support to toolman.org/net/peercred with a ServerOption that helps gRPC recognize peercred Listeners and a helper function for extracting foreign process credentials from a service method's Context.
The following example illustrates how to use a peercred.Listener with a gRPC server over a Unix domain socket:
// As with a simple unix-domain socket server, we'll first create
// a new peercred.Listener listening on socketName
lsnr, err := peercred.Listen(ctx, socketName)
if err != nil {
return err
}
// We'll need to tell gRPC how to deal with the process credentials
// acquired by the peercred Listener. This is easily accomplished by
// passing this package's TransportCredentials ServerOption as we
// create the gRPC Server.
svr := grpc.NewServer(grpcpeer.TransportCredentials())
// Next, we'll install your service implementation into the gRPC
// Server we just created...
urpb.RegisterYourService(svr, svcImpl)
// ...and start the gRPC Server using the peercred.Listener created
// above.
svr.Serve(lsnr)
Finally, when you need to access the client's process creds from one of
your service's methods, pass the method's Context to this package's
FromContext function.
func (s *svcImpl) SomeMethod(ctx context.Context, req *SomeRequest, opts ...grpc.CallOption) (*SomeResponse, error) {
creds, err := grpcpeer.FromContext(ctx)
// (Unless there's an error) creds now holds a *unix.Ucred
// containing the PID, UID and GID of the calling client process.
}
var ErrNoCredentials = errors.New("context contains no credentials")
ErrNoCredentials is returned by FromContext if the provided Context contains no peer process credentials.
var ErrNoPeer = errors.New("context has no grpc peer")
ErrNoPeer is returned by FromContext if the provided Context contains no gRPC peer.
func TransportCredentials() grpc.ServerOption
TransportCredentials returns a grpc.ServerOption that exposes the peer process credentials (i.e. PID, UID, GID) extracted by a peercred Listener. The peer credentials are available by passing a server method's Context to this package's FromContext function.
func FromContext(ctx context.Context) (*unix.Ucred, error)
FromContext extracts peer process credentials, if any, from the given Context. This is only possible if the gRPC server was creating with the ServerOption provided by this package's TransportCredentials function.
If the provided Context has no gRPC peer, ErrNoPeer is returned. If the Context's peer is of the wrong type (i.e. contains no peer process credentials), ErrNoCredentials will be returned.
FAQs
Unknown package
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
A compromised npm publish token was used to push a malicious postinstall script in cline@2.3.0, affecting the popular AI coding agent CLI with 90k weekly downloads.

Product
Socket is now scanning AI agent skills across multiple languages and ecosystems, detecting malicious behavior before developers install, starting with skills.sh's 60,000+ skills.

Product
Socket now supports PHP with full Composer and Packagist integration, enabling developers to search packages, generate SBOMs, and protect their PHP dependencies from supply chain threats.