Documentation
¶
Index ¶
- Constants
- func BufferingOptions() []grpc.ServerOption
- func NewClientFrom(h *Handler, opts ...grpc.DialOption) []grpc.DialOption
- func TLSAuthMiddlewareOptions(s *server.Server) ([]grpc.ServerOption, error)
- type ContextKey
- type Handler
- func (h *Handler) Close() error
- func (h *Handler) Init(serv *server.Server) (err error)
- func (h *Handler) Listen(addr string) (ln net.Listener, err error)
- func (h *Handler) Name() string
- func (h *Handler) PostServe(hooks ...func(*grpc.Server) error)
- func (h *Handler) ServeOn(ln net.Listener)
- func (h *Handler) WithAuthorizer(a team.Authorizer)
- func (h *Handler) WithCoreServices()
Constants ¶
const (
// ServerMaxMessageSize is the server-side max gRPC message size (~2GB).
ServerMaxMessageSize = 2*gb - 1
)
Variables ¶
This section is empty.
Functions ¶
func BufferingOptions ¶
func BufferingOptions() []grpc.ServerOption
BufferingOptions returns gRPC server options raising the max send/receive message size to ServerMaxMessageSize (~2GB).
func NewClientFrom ¶
func NewClientFrom(h *Handler, opts ...grpc.DialOption) []grpc.DialOption
NewClientFrom primes an existing gRPC Handler with an in-memory (bufconn) connection and returns the dial options a teamclient must use to reach it. The returned options set up a context dialer over the shared bufconn with TLS disabled: in-memory connections are trusted and neither encrypted nor authenticated. Pass the options to the transport's client dialer.
func TLSAuthMiddlewareOptions ¶
func TLSAuthMiddlewareOptions(s *server.Server) ([]grpc.ServerOption, error)
TLSAuthMiddlewareOptions returns transport-security options that authenticate incoming client connections with the teamserver's Mutual-TLS configuration. All teamclients connect with a known client certificate, so the server can require and verify it.
Types ¶
type ContextKey ¶
type ContextKey int
ContextKey is the type of the values this transport injects into a request context. Applications reading the authenticated identity should use the exported keys below.
const ( // Transport is the context key under which the transport stores the raw // authenticated identity (a *team.User for remote calls, the string // "server" for in-memory calls). Transport ContextKey = iota // User is the context key under which the transport stores the // authenticated *team.User (nil-typed "server" identity for in-memory). // An application's own middleware may overwrite this with a richer, // app-specific identity resolved from user.Name. User )
type Handler ¶
Handler is a ready-to-use gRPC team/server.Handler (a "listener/server/RPC" transport stack). It is the supported, importable evolution of the code that used to live under example/transports/grpc, distilled from the production Sliver teamserver transport.
The handler embeds a team/server.Server core and uses it for fetching server-side TLS credentials, authenticating users, audit/logging, and job control. Out of the box it provides, on every served listener:
- message buffering (2GB),
- panic recovery (a handler panic becomes codes.Internal, not a crash),
- audit logging of every request through the core AuditLogger(),
- Mutual-TLS transport credentials for remote listeners,
- token AUTHENTICATION for remote listeners (core Server.Authenticate), injecting the resolved *team.User into the request context.
It deliberately ships NO application services and NO authorization policy. Applications compose those in via:
- PostServe(hook): register your own gRPC services on the server.
- WithAuthorizer(a): install an authorization interceptor built on your policy (team.Authorizer), consulted AFTER authentication resolves identity.
A single Handler value serves both remote (real net.Listener + mTLS + auth) and in-memory (bufconn, no encryption/auth) connections; which one is decided by whether the handler was primed with an in-memory conn (see NewClientFrom).
func NewListener ¶
func NewListener(opts ...grpc.ServerOption) *Handler
NewListener returns a gRPC teamserver handler loaded with the provided gRPC server options (message buffering is always added on top). By default the handler serves remote clients over TCP+mTLS. Register it with the teamserver via server.WithHandler().
func (*Handler) Close ¶
Close implements team/server.Handler.Close(). The underlying net.Listener is owned and closed by the core teamserver job control, and the per-listener gRPC server is stopped by serve() when Serve returns, so there is nothing to close here.
func (*Handler) Init ¶
Init implements team/server.Handler.Init(). It binds the core teamserver and assembles the transport-agnostic middleware (buffering already set, plus logging/audit, recovery, and authentication). Transport-specific TLS credentials are added later in Listen(), only for remote listeners.
func (*Handler) Listen ¶
Listen implements team/server.Handler.Listen(). For a remote listener it binds a TCP socket and adds Mutual-TLS credentials; for an in-memory listener it returns the primed bufconn unencrypted. In both cases it starts serving a gRPC server (with application services registered via PostServe) on the listener and returns immediately (non-blocking), as the Handler contract requires.
func (*Handler) PostServe ¶
PostServe registers one or more hooks to run against the *grpc.Server just before it starts serving, so applications can register their own gRPC services on it. Hooks run in registration order; a hook error aborts the listen. This is the primary seam for wiring application RPC onto the shared transport (the counterpart to the client dialer's PostDial/Conn()).
func (*Handler) WithAuthorizer ¶
func (h *Handler) WithAuthorizer(a team.Authorizer)
WithAuthorizer installs an application authorization policy. When set, remote listeners gain an authorization interceptor that, after authentication has resolved the caller identity, calls Authorize(user, fullMethod) and rejects the call with codes.PermissionDenied on a non-nil error. In-memory (local, trusted) connections bypass authorization. Passing nil is a no-op.
func (*Handler) WithCoreServices ¶
func (h *Handler) WithCoreServices()
WithCoreServices registers the built-in teamserver Team service (users and version) on the served gRPC server, so a connected teamclient can query them remotely (e.g. the `teamserver client users` / version commands). It is opt-in: applications that expose their own users/version RPC (as Sliver does) leave it off. The transport's client dialer answers Users()/VersionServer() against this service.