Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthenticationStatus ¶
type AuthenticationStatus uint32
AuthenticationStatus is a generic status response representing auth or guard results.
It is returned by the custom authentication or guard functions on the GuardedBeaconProxy, and mapped to an appropriate HTTP or gRPC error as needed.
const ( Allowed AuthenticationStatus = iota BadRequest Forbidden Conflict TooManyRequests InternalError )
These constants are the only allowable AuthenticationStatus values
type GRPCAuthenticator ¶
GRPCAuthenticator is a function type that authenticates gRPC traffic. The authentication method must be based on gRPC Metadata, as gRPC does not support BasicAuth out of box.
Returning an AuthenticationStatus other than Allowed will prevent the request from being proxied. You may optionally return a Context, which will be passed to the PrepareBeaconProposerGuard/RegisterValidatorGuard functions provided. In particular, conext.WithValue allows the authentication method to share state with the guard methods.
Any error returned will be sent back to the client, so do not encode sensitive information.
type GuardedBeaconProxy ¶
type GuardedBeaconProxy struct { // URL of the upstream beacon node BeaconURL *url.URL // Optional GRPC URL of the upstream beacon node (prysm grpc port) GRPCBeaconURL string // Optional TLS certificates for gRPC TLS struct { // Path to certificate file CertFile string // Path to key file KeyFile string } // Address to listen for requests on Addr string // Optional GRPC address to listen on GRPCAddr string // Pass-through HTTP server settings ReadTimeout time.Duration ReadHeaderTimeout time.Duration WriteTimeout time.Duration IdleTimeout time.Duration MaxHeaderBytes int ErrorLog *log.Logger // Optional authentication function for HTTP requests HTTPAuthenticator HTTPAuthenticator // Optional authentication function for GRPC requests GRPCAuthenticator GRPCAuthenticator // Optional PrepareBeaconProposerGuard PrepareBeaconProposerGuard PrepareBeaconProposerGuard // Optional RegisterValidatorGuard RegisterValidatorGuard RegisterValidatorGuard // contains filtered or unexported fields }
GuardedBeaconProxy is a reverse proxy for guarding beacon nodes with custom logic.
The main goal is to provide easy hooks for custom request authentication and fee recipient validation, which is achieved through the Authenticator and Guard callbacks.
Since Prysm uses gRPC, GuardedBeaconProxy can optionally run a gRPC reverse proxy in addition to an HTTP reverse proxy.
If GRPCBeaconURL is set, all GRPC fields are required except the TLS block. TLS is currently only supported for gRPC.
Fields in GuardedBeaconProxy should be set prior to calling ListenAndServe.
func (*GuardedBeaconProxy) ListenAndServe ¶
func (gbp *GuardedBeaconProxy) ListenAndServe() error
ListenAndServe binds the GuardedBeaconProxy to its HTTP port, and optionally its gRPC port, and prepares to receive and proxy traffic from validators.
ListenAndServe blocks until Stop is called or an error is encountered.
func (*GuardedBeaconProxy) Serve ¶
Serve attaches the proxy to the provided listener(s)
Serve blocks until Stop is called or an error is encountered.
func (*GuardedBeaconProxy) Stop ¶
func (gbp *GuardedBeaconProxy) Stop(ctx context.Context)
Stop attempts to gracefully shut down the GuardedBeaconProxy.
Canceling the provided context will trigger an immediate stop.
type HTTPAuthenticator ¶
HTTPAuthenticator is a function type which can authenticate HTTP requests. For example, by checking the contents of the BasicAuth header.
Returning an AuthenticationStatus other than Allowed will prevent the request from being proxied. You may optionally return a Context, which will be passed to the PrepareBeaconProposerGuard/RegisterValidatorGuard functions provided. In particular, conext.WithValue allows the authentication method to share state with the guard methods.
Any error returned will be sent back to the client, so do not encode sensitive information.
type PrepareBeaconProposerGuard ¶
type PrepareBeaconProposerGuard func(PrepareBeaconProposerRequest, context.Context) (AuthenticationStatus, error)
PrepareBeaconProposerGuard is a function that validates whether or not a PrepareBeaconProposer call should be proxied. The provided Context is whatever was returned by the authenticator.
type PrepareBeaconProposerRequest ¶
type PrepareBeaconProposerRequest []struct { ValidatorIndex string `json:"validator_index"` FeeRecipient string `json:"fee_recipient"` }
PrepareBeaconProposerRequest is the in-memory representation of a prepare_beacon_proposer API call, be it gRPC or HTTP.
type RegisterValidatorGuard ¶
type RegisterValidatorGuard func(RegisterValidatorRequest, context.Context) (AuthenticationStatus, error)
RegisterValidatorGuard is a function that validates whether or not a RegisterValidator call should be proxied. The provided Context is whatever was returned by the authenticator.
type RegisterValidatorMessage ¶
type RegisterValidatorMessage struct { FeeRecipient string `json:"fee_recipient"` GasLimit string `json:"gas_limit"` Timestamp string `json:"timestamp"` Pubkey string `json:"pubkey"` }
RegisterValidatorMessage is the in-memory representation of a register_validator API call entry, be it gRPC or HTTP.
type RegisterValidatorRequest ¶
type RegisterValidatorRequest []struct { Message RegisterValidatorMessage `json:"message"` Signature string `json:"signature"` }
RegisterValidatorRequest is the in-memory representation of a register_validator API call, be it gRPC or HTTP.