Documentation
¶
Overview ¶
Package firewallstate provides authoritative, scoped shared counters. SQLite is a fenced singleton; optional PostgreSQL coordinates active-active replicas.
Index ¶
- Constants
- func Bearer(r *http.Request) string
- func Decode(raw []byte, v any) error
- func Digest(v string) string
- func Endpoint(raw string) (*url.URL, error)
- func Fail(status int, message string) error
- func HTTPClient(timeout time.Duration, transport http.RoundTripper) *http.Client
- func MatchToken(got, want string) bool
- func PrivateDir(dir string) error
- func PrivateFile(path string) error
- func RequestJSON(ctx context.Context, client *http.Client, method, endpoint, token string, ...) error
- func Restore(ctx context.Context, backup, dir, name string) error
- func ValidID(v string) bool
- func WriteError(w http.ResponseWriter, err error)
- func WriteJSON(w http.ResponseWriter, status int, v any)
- type Client
- type ClientConfig
- type Config
- type CountRequest
- type CountResult
- type Database
- func (d *Database) AuthNamespace() string
- func (d *Database) AuthTransaction(ctx context.Context, f func(firewallauth.SQLTransaction) error) error
- func (d *Database) Backup(ctx context.Context, destination string) error
- func (d *Database) Begin(ctx context.Context) (*Transaction, error)
- func (d *Database) Bootstrap(ctx context.Context, fingerprint string, statements []string) error
- func (d *Database) CheckBootstrap(ctx context.Context) error
- func (d *Database) Close() error
- func (d *Database) Coordination() string
- func (d *Database) IsPostgres() bool
- func (d *Database) Rebind(query string) string
- type Error
- type Guard
- type GuardConfig
- type Key
- type Principal
- type Scope
- type Service
- type Store
- type Transaction
- func (t *Transaction) Clock(ctx context.Context, fallback int64) (int64, error)
- func (t *Transaction) Commit() error
- func (t *Transaction) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
- func (t *Transaction) QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
- func (t *Transaction) QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
- func (t *Transaction) Rollback() error
- type Window
Constants ¶
const MaxKeys = 4096
const MaxWindow = 24 * time.Hour
Variables ¶
This section is empty.
Functions ¶
func Endpoint ¶
Endpoint rejects credentials in URLs, redirects, and cleartext nonloopback peers. Loopback HTTP is only for local trusted deployments/tests.
func HTTPClient ¶
HTTPClient owns its timeout and redirect policy; transport customization may supply a trusted TLS root, but must not disable certificate verification.
func MatchToken ¶
func PrivateDir ¶
func PrivateFile ¶
func RequestJSON ¶
func Restore ¶
Restore is offline: acquires the destination singleton lock and refuses an existing database. New/validation must succeed before exposing a restored service.
func WriteError ¶
func WriteError(w http.ResponseWriter, err error)
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClient ¶
func NewClient(cfg ClientConfig) (*Client, error)
type ClientConfig ¶
type CountRequest ¶
type CountResult ¶
type Database ¶
Database holds a separate SQLite lifetime lock or a PostgreSQL connection pool. Stop listeners and users before Close. Copying a SQLite database does not fence its old host; PostgreSQL writers must use Begin's namespace transaction lock.
func OpenDatabase ¶
func OpenPostgres ¶
OpenPostgres opens an independent connection pool. Namespace is a dedicated schema and serialization domain, shared by all replicas of one service. Database URLs are bootstrap secrets and are never included in returned errors.
func (*Database) AuthNamespace ¶
func (*Database) AuthTransaction ¶
func (d *Database) AuthTransaction(ctx context.Context, f func(firewallauth.SQLTransaction) error) error
func (*Database) Backup ¶
Backup uses a consistent SQLite snapshot. Destination is an operator-supplied local path, never bundle input, and must not exist. Protect the backup as secrets.
func (*Database) Bootstrap ¶
Bootstrap atomically creates the service schema and pins its canonical hashed bootstrap configuration. Mismatched replicas fail before touching service state.
func (*Database) Coordination ¶
func (*Database) IsPostgres ¶
type Guard ¶
type Guard struct {
Operations *runtimeobs.Monitor
// contains filtered or unexported fields
}
func NewGuard ¶
func NewGuard(cfg GuardConfig) (*Guard, error)
func NewGuardWithStore ¶
func NewGuardWithStore(cfg GuardConfig, store Store) (*Guard, error)
type GuardConfig ¶
type GuardConfig struct {
URL string `json:"url"`
Token string `json:"token"`
Window time.Duration `json:"window"`
Limit int64 `json:"limit"`
GroupBy string `json:"group_by"`
ID string `json:"id"`
Unit string `json:"unit,omitempty"`
}
GuardConfig is runtime configuration, separate from native policy thresholds. The remote principal owns tenant/app scope. GroupBy supports only these bounded scalar fields: empty (global), ClientIP, Host, Method, Path. Unit defaults to request; message counts only request-phase inspection messages.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
type Transaction ¶
Transaction uses READ COMMITTED plus a transaction-scoped exclusive advisory lock. Reads happen AFTER lock acquisition and see the preceding writer's commit. No ambiguous commit is retried, and no process-local lock provides PG safety.
func (*Transaction) Clock ¶
PostgreSQL owns counter time; the caller's process clock is not authoritative.
func (*Transaction) Commit ¶
func (t *Transaction) Commit() error
func (*Transaction) ExecContext ¶
func (*Transaction) QueryContext ¶
func (*Transaction) QueryRowContext ¶
func (*Transaction) Rollback ¶
func (t *Transaction) Rollback() error