Documentation
¶
Overview ¶
Package webui is the session, auth and rendering plumbing behind the reostream daemon's operator page -- one process, one page, covering both the fleet and the cameras on it. It holds no policy about that page, only the mechanism.
Index ¶
Constants ¶
const SessionTTL = 12 * time.Hour
SessionTTL is an absolute expiry from issue, not a sliding window: these pages can read and write camera credentials, so a session that lives forever on a shared machine is a real exposure, and there is no renewal on activity to defeat it. A long-lived response such as a log stream in particular must not count as activity; it is not evidence anyone is still at the keyboard.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Auth ¶
type Auth struct {
Store *SessionStore
Password string
AllowNoPassword bool
LoginPath string
CookieName string
}
Auth gates a handler on a session. LoginPath is where an unauthenticated request is sent.
CookieName is supplied by the consumer, not a shared package constant. There is one surface today, the daemon's operator page, and this package holds nothing that assumes it. Two surfaces on one host that shared a cookie name would each run their own SessionStore, so logging into one would silently log the other out, intermittently, whenever the browser resent whichever cookie it last set for that name. That is exactly what happened while this project had a second page, and making every caller name its own cookie is what stops a second one reintroducing it.
func (Auth) Check ¶
Check compares a submitted password in constant time, so a wrong one cannot be found a character at a time by measuring the reply.
Hashed first, rather than compared directly. subtle.ConstantTimeCompare returns 0 immediately when the two lengths differ, so comparing the raw strings is constant time in their CONTENT and not in their LENGTH: a guesser could learn how long the real password is by timing replies, and on a page with no rate limit that is a free head start. Two SHA-256 sums are always the same size, so the comparison below cannot short circuit on anything.
The claim token compare in internal/control was built to avoid exactly this and this one was not; they now agree.
type Renderer ¶
type Renderer struct {
// contains filtered or unexported fields
}
Renderer parses a set of page templates against a shared layout.
func NewRenderer ¶
NewRenderer parses every template matching glob in fsys as the base set. funcs is registered before parsing, so a template body may call anything in it; nil is fine for a caller with no functions to add.
type SessionStore ¶
type SessionStore struct {
// contains filtered or unexported fields
}
func NewSessionStore ¶
func NewSessionStore() *SessionStore
func (*SessionStore) Issue ¶
func (s *SessionStore) Issue() (string, error)
func (*SessionStore) Revoke ¶ added in v0.1.3
func (s *SessionStore) Revoke(tok string)
Revoke ends one session, for a sign out. A token that is not there is not an error: a cookie can outlive the session it names.
func (*SessionStore) RevokeAll ¶ added in v0.1.3
func (s *SessionStore) RevokeAll()
RevokeAll ends every session.
This is what a password change has to call. Changing the password without it leaves every browser that was already signed in signed in, including the one whose access was the reason for changing it, which makes the change worth very little.
func (*SessionStore) SetClock ¶
func (s *SessionStore) SetClock(now func() time.Time)
SetClock overrides the clock so a test can move time instead of sleeping out the TTL.
func (*SessionStore) Valid ¶
func (s *SessionStore) Valid(tok string) bool
Valid reports whether tok is a live session. Every call sweeps the whole map, not just tok: a token nobody ever presents again, an abandoned cookie or a browser that never returns, would otherwise never be checked and never removed, and the map would grow without bound.