Documentation
¶
Overview ¶
Package server implements the lsqlited daemon: a TCP server that serves SQLite databases using the lsqlited wire protocol.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthConfig ¶
type AuthConfig struct {
// Users maps account names to their credentials.
Users map[string]UserConfig `yaml:"users"`
}
AuthConfig configures challenge-response authentication.
type Config ¶
type Config struct {
Listen ListenConfig `yaml:"listen"`
// Limits bound the work a single statement may do.
Limits `yaml:",inline"`
// MaxConnections bounds the SQLite connections one database may have open at a time, which is how many statements it
// can run in parallel. Zero leaves it unbounded.
MaxConnections int `yaml:"max_connections"`
// Params are SQLite DSN query parameters appended to the "file:" URI of every database, e.g. mode=ro. See the
// go-sqlite3 documentation for the supported set.
Params Params `yaml:"params"`
// Extensions are loadable SQLite extensions registered on every connection to every database.
Extensions Extensions `yaml:"extensions"`
// TLS configures transport security. Omitted, the protocol travels in cleartext.
TLS TLSConfig `yaml:"tls"`
Auth AuthConfig `yaml:"auth"`
// Databases maps the logical name a client connects to onto the path of the SQLite file serving it. Every database is
// opened the same way, from the settings above.
Databases map[string]string `yaml:"databases"`
}
Config is the top-level server configuration, usually loaded from a YAML file. See config.example.yaml for the full set of keys.
func LoadConfig ¶
LoadConfig reads and validates a YAML configuration file.
type Extension ¶
type Extension struct {
// Path is the shared library to load, resolved by the platform's dynamic loader, so a bare file name is looked up
// along the usual search path.
Path string `yaml:"path"`
// Entrypoint is the initialization symbol to call. When empty, SQLite picks sqlite3_extension_init, falling back to a
// name derived from the file name.
Entrypoint string `yaml:"entrypoint"`
}
Extension identifies an external SQLite extension to load into every connection of a database. In YAML it is written either as a plain path or as a mapping naming the entry point:
extensions: - /usr/lib/sqlite3/vector0.so - path: /usr/lib/sqlite3/misc.so entrypoint: sqlite3_misc_init
type Limits ¶
type Limits struct {
// QueryTimeout is the upper bound on how long a single statement may run, in seconds. Zero leaves statements
// unbounded.
QueryTimeout int64 `yaml:"query_timeout"`
// TransactionTimeout is how long a transaction may sit without a request, in seconds, before the daemon rolls it back
// and drops the session. Zero waits forever.
TransactionTimeout int64 `yaml:"transaction_timeout"`
// MaxRows is the upper bound on the rows one query result may carry. Zero leaves results unbounded.
MaxRows int64 `yaml:"max_rows"`
}
Limits bound the work a single statement may do. They are the daemon's own safety net: a client may ask for a tighter bound, but never for a looser one.
type ListenConfig ¶
ListenConfig configures the TCP listener. An empty host binds to all interfaces.
type Option ¶
type Option func(*Server)
Option customizes a Server.
func WithLogger ¶
WithLogger sets the logger used by the server.
func WithTLSConfig ¶
WithTLSConfig serves TLS using the given configuration, overriding the `tls` section of the configuration file. It is meant for callers that embed the server and manage certificates themselves.
type Params ¶
Params holds extra SQLite DSN query parameters. In YAML it is written either as a mapping or as a URL-style query string:
params: mode: ro immutable: true params: mode=ro&immutable=true
func ParseParams ¶
ParseParams parses a query string such as "mode=ro&immutable=true".
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server serves SQLite databases over TCP.
func (*Server) Close ¶
Close stops accepting connections, terminates active ones, waits for handlers to finish, and closes all open databases.
func (*Server) Start ¶
Start binds the listener and begins accepting connections in the background. Use Close to shut the server down.
func (*Server) TLSEnabled ¶
TLSEnabled reports whether the server encrypts its connections. It is only meaningful once Start has returned.
type TLSConfig ¶
type TLSConfig struct {
// Cert is a PEM certificate, with any intermediates appended so that clients can build the chain. Key is the matching
// private key.
Cert string `yaml:"cert"`
Key string `yaml:"key"`
// ClientCA is a PEM bundle of authorities allowed to sign client certificates. Setting it turns on mutual TLS, which
// authenticates the connection, not the account; accounts are configured under `auth`.
ClientCA string `yaml:"client_ca"`
// MinVersion is the lowest TLS version to negotiate, "1.2" (default) or "1.3".
MinVersion string `yaml:"min_version"`
}
TLSConfig configures transport security for the listener. Leaving the section out serves the wire protocol over plaintext TCP.
type UserConfig ¶
type UserConfig struct {
// Verifier is the credential produced by "lsqlited -hash-password", which also decides the PBKDF2 cost.
Verifier string `yaml:"verifier"`
// Databases lists the database names the account may use; every name must match an entry under Config.Databases.
Databases []string `yaml:"databases"`
}
UserConfig holds the credential of a single account and the databases it may access.