auth

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2026 License: MIT Imports: 13 Imported by: 0

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

View Source
const NomeDoCookie = "brevis_sessao"

NomeDoCookie is the session cookie's name.

View Source
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

func ConferirSenha(hash, senha string) bool

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 De

func De(ctx context.Context) string

De devolve o operador da requisicao, ou vazio quando nao ha sessao.

func Destino

func Destino(bruto string) string

Destino saneia o `?de=` na hora de redirecionar pos-login.

func EmContexto

func EmContexto(ctx context.Context, usuario string) context.Context

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

func GerarHash(senha string) (string, error)

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.

func (*Portao) Entrar

func (p *Portao) Entrar(w http.ResponseWriter, usuario, senha string) bool

Entrar checks the credential and writes the cookie. Returns false if it did not match.

func (*Portao) Sair

func (p *Portao) Sair(w http.ResponseWriter)

Sair apaga o cookie.

func (*Portao) ServeHTTP

func (p *Portao) ServeHTTP(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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