Documentation
¶
Overview ¶
Package auth closes the Brevis interface behind an operator credential.
It exists for a concrete reason: in dev, an anonymous `POST /workflows/<slug>/trigger` answered 303 and started the pipeline. Anyone on the internet could run a `dbt build` that MERGEs into the warehouse. An orchestration interface is a remote control for the warehouse -- leaving it open is the same as publishing the terminal.
The scope is deliberately small: ONE operator credential, from the configuration. There is no user registry, no roles and no multi-user, because none of that exists in the product yet and inventing it here would be building the floor before the wall. What does exist has to be right: a slow derivation hash, a signed session, constant-time comparison.
All stdlib. `crypto/pbkdf2` landed in the standard library in Go 1.24, which removes the need for `x/crypto` for the one piece that was missing.
Index ¶
Constants ¶
const NomeDoCookie = "brevis_sessao"
NomeDoCookie is the session cookie's name.
const ValidadeDaSessao = 12 * time.Hour
ValidadeDaSessao is how long a login lasts. A working shift: short enough that a tab forgotten on a laptop does not become permanent access, long enough not to ask for a password in the middle of an investigation.
Variables ¶
This section is empty.
Functions ¶
func ConferirSenha ¶
ConferirSenha compara a senha com o hash em tempo constante.
Returns false -- and not an error -- for a malformed hash: the caller is on a login path, and the only safe answer there is "did not get in". The configuration error is caught at boot, by Credencial.Validar.
func EmContexto ¶
EmContexto stores the request's operator. The layout uses it to decide whether to show the sign-out button -- an installation with no credential should not display a botao que nao faz nada.
func GerarHash ¶
GerarHash produces the text that goes into the configuration, as `pbkdf2-sha256$<iterations>$<salt>$<key>`.
The format carries the iteration count with it because that number will change: when we double the cost a few years from now, old hashes have to keep verifying. A format that stores only the digest forces invalidating everyone.
Types ¶
type Credencial ¶
type Credencial struct {
Usuario string
Hash string
// Segredo signs the session cookie. Changing it drops every session, which
// is the emergency lever when a leak is suspected.
Segredo []byte
}
Credencial e o operador unico da instalacao, vindo da configuracao.
func (Credencial) Ativa ¶
func (c Credencial) Ativa() bool
Ativa says whether a credential is configured.
func (Credencial) Validar ¶
func (c Credencial) Validar() error
Validar refuses a half-finished configuration.
Half configured is worse than nothing: whoever filled in the username believes they closed the door. Failing at boot is the only way that belief does not last until the incident.
type Portao ¶
type Portao struct {
Cred Credencial
Proximo http.Handler
Login http.Handler // renderiza a tela de login
Inseguro bool // http puro: manda o cookie sem a flag Secure
}
Portao envolve um handler exigindo sessao valida.
The routes that need no session are few and explicit. Kubernetes probes are on that list out of necessity -- a /health that asks for a password kills the pod.