client

package
v0.33.29 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 14 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package client

The aserto package provides access to the Aserto authorizer and supporting service.

Authorization requests are performed using an AuthorizerClient. A client can be used on its own to make authorization calls or, more commonly, it can be used to create server middleware.

AuthorizerClient

The AuthorizerClient interface, defined in "github.com/aserto-dev/go-authorizer/aserto/authorizer/v2", describes the operations exposed by the Aserto authorizer service.

Two implementation of AuthorizerClient are available:

1. `authorizer/grpc` provides a client that communicates with the authorizer using gRPC.

2. `authorizer/http` provides a client that communicates with the authorizer over its REST HTTP endpoints.

Middleware

Two middleware implementations are available in subpackages:

1. middleware/grpc provides middleware for gRPC servers.

2. middleware/http provides middleware for HTTP REST servers.

When authorization middleware is configured and attached to a server, it examines incoming requests, extracts authorization parameters like the caller's identity, calls the Aserto authorizers, and rejects messages if their access is denied.

Other Services

In addition to the authorizer service, go-aserto provides gRPC clients for Aserto's administrative services, allowing users to programmatically manage their aserto account.

There are two top-level services, each with its own set of sub-services.

1. `client/authorizer` defines a client for services run at the edge and used to serve authorization requests.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidConfig = errors.New("invalid configuration")
View Source
var ErrInvalidOptions = errors.New("invalid connection options")

Functions

func Connect

func Connect(options *ConnectionOptions) (*grpc.ClientConn, error)

Connect creates a gRPC connection with the given options.

func NewConnection

func NewConnection(opts ...ConnectionOption) (*grpc.ClientConn, error)

NewConnection creates a gRPC connection with the given options.

Types

type Config

type Config struct {
	// Address of the service to connect to.
	//
	// Address is typically in the form "hostname:port" but may also be a Unix socket or DNS URI.
	// See https://github.com/grpc/grpc/blob/master/doc/naming.md#name-syntax for more details.
	Address string `json:"address"`

	// A JWT to be used for authentication with the service.
	//
	// Token and APIKey are mutually exclusive.
	Token string `json:"token"`

	// An API key to be used for authentication with the service.
	APIKey string `json:"api_key"`

	// In mTLS connections, ClientCertPath is the path of the client's
	// certificate file.
	ClientCertPath string `json:"client_cert_path"`

	// In mTLS connections, ClientKeyPath is the path of the client's
	// private key file.
	ClientKeyPath string `json:"client_key_path"`

	// In TLS connections, CACertPath is the path of a CA certificate to
	// validate the server's certificate against.
	CACertPath string `json:"ca_cert_path"`

	// In TLS connections, skip verification of the server certificate.
	Insecure bool `json:"insecure"`

	// Disable TLS and use a plaintext connection.
	NoTLS bool `json:"no_tls"`

	// NoProxy bypasses any configured HTTP proxy.
	NoProxy bool `json:"no_proxy"`

	// Additional headers to include in requests to the service.
	Headers map[string]string `json:"headers"`
}

Config contains the gRPC client configuration.

func (*Config) Connect

func (cfg *Config) Connect(opts ...ConnectionOption) (*grpc.ClientConn, error)

Connect connects to the service specified in Config, possibly with additional connection options.

func (*Config) ToConnectionOptions

func (cfg *Config) ToConnectionOptions() ([]ConnectionOption, error)

ToConnectionOptions converts the Config into a ConnectionOption slice that can be passed to NewConnection().

type ConnectionOption

type ConnectionOption func(*ConnectionOptions) error

ConnectionOption functions are used to configure ConnectionOptions instances.

func WithAPIKeyAuth

func WithAPIKeyAuth(key string) ConnectionOption

WithAPIKeyAuth uses an authorization API key to authenticate with the authorizer service.

func WithAddr

func WithAddr(addr string) ConnectionOption

WithAddr overrides the default authorizer server address.

Note: WithAddr and WithURL are mutually exclusive.

func WithCACertPath

func WithCACertPath(path string) ConnectionOption

WithCACertPath treats the specified certificate file as a trusted root CA.

Include it when calling a service that uses a self-issued SSL certificate.

func WithChainStreamInterceptor

func WithChainStreamInterceptor(mw ...grpc.StreamClientInterceptor) ConnectionOption

WithChainStreamInterceptor adds a stream interceptor to grpc dial options.

func WithChainUnaryInterceptor

func WithChainUnaryInterceptor(mw ...grpc.UnaryClientInterceptor) ConnectionOption

WithChainUnaryInterceptor adds a unary interceptor to grpc dial options.

func WithClientCert

func WithClientCert(certPath, keyPath string) ConnectionOption

WithClientCert configure the client certificate for mTLS connections.

func WithDialOptions

func WithDialOptions(opts ...grpc.DialOption) ConnectionOption

WithDialOptions add custom dial options to the grpc connection.

func WithHeader

func WithHeader(key, value string) ConnectionOption

WithHeader adds an header to the client config instance.

func WithInsecure

func WithInsecure(insecure bool) ConnectionOption

WithInsecure disables TLS verification.

func WithNoProxy

func WithNoProxy(noProxy bool) ConnectionOption

WithNoProxy returns a ConnectionOption that bypasses any configured HTTP proxy.

func WithNoTLS

func WithNoTLS(noTLS bool) ConnectionOption

WithNoTLS disables transport security. The connection is established in plaintext.

func WithTokenAuth

func WithTokenAuth(token string) ConnectionOption

WithTokenAuth uses an OAuth2.0 token to authenticate with the authorizer service.

func WithURL

func WithURL(svcURL *url.URL) ConnectionOption

WithURL overrides the default authorizer server URL. Unlike WithAddr, WithURL lets gRPC users to connect to communicate with a locally running authorizer over Unix sockets. See https://github.com/grpc/grpc/blob/master/doc/naming.md#grpc-name-resolution for more details about gRPC name resolution.

Note: WithURL and WithAddr are mutually exclusive.

type ConnectionOptions

type ConnectionOptions struct {
	Config

	// Credentials used to authenticate with the authorizer service. Either API Key or OAuth Token.
	Creds credentials.PerRPCCredentials

	// UnaryClientInterceptors passed to the grpc client.
	UnaryClientInterceptors []grpc.UnaryClientInterceptor

	// StreamClientInterceptors passed to the grpc client.
	StreamClientInterceptors []grpc.StreamClientInterceptor

	// DialOptions passed to the grpc client.
	DialOptions []grpc.DialOption
}

ConnectionOptions holds settings used to establish a connection to the authorizer service.

func NewConnectionOptions

func NewConnectionOptions(opts ...ConnectionOption) (*ConnectionOptions, error)

NewConnectionOptions creates a ConnectionOptions object from a collection of ConnectionOption functions.

func (*ConnectionOptions) Apply

func (o *ConnectionOptions) Apply(opts ...ConnectionOption) error

Apply additional options.

func (*ConnectionOptions) ToDialOptions

func (o *ConnectionOptions) ToDialOptions() ([]grpc.DialOption, error)

type TLSConfig

type TLSConfig struct {
	Cert string `json:"tls_cert_path"`
	Key  string `json:"tls_key_path"`
	CA   string `json:"tls_ca_cert_path"`
}

TLSConfig contains paths to an X509 certificate's key-pair and CA files. It can be used to create client or server tls.Config or grpc TransportCredentials.

func (*TLSConfig) ClientConfig

func (c *TLSConfig) ClientConfig(skipVerify bool) (*tls.Config, error)

ClientConfig returns TLS configuration for a client.

func (*TLSConfig) ClientCredentials

func (c *TLSConfig) ClientCredentials(skipVerify bool) (credentials.TransportCredentials, error)

ClientCredentials returns transport credentials for a GRPC client.

func (*TLSConfig) HasCA

func (c *TLSConfig) HasCA() bool

func (*TLSConfig) HasCert

func (c *TLSConfig) HasCert() bool

func (*TLSConfig) ServerConfig

func (c *TLSConfig) ServerConfig() (*tls.Config, error)

ServerConfig returns TLS configuration for a server.

func (*TLSConfig) ServerCredentials

func (c *TLSConfig) ServerCredentials() (credentials.TransportCredentials, error)

ServerCredentials returns transport credentials for a GRPC server.

Directories

Path Synopsis
ds
v3
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL