Documentation
¶
Overview ¶
Package session holds the administrator sessions of the Admin API in memory and makes the random tokens the Admin API and the operator commands hand out.
Only the SHA-256 of a session token is kept; the token itself exists only in the administrator's cookie. Nothing is ever written to disk, so a restart ends every session. The table is bounded and refuses a new session when full. It imports no internal package. The controller ends an administrator's sessions inside its own lock when a credential changes; the Admin API creates, looks up and ends them.
Index ¶
- Constants
- Variables
- func Hash(token string) string
- func NewToken() string
- type Session
- type Table
- func (s *Table) Active(token string, now time.Time) bool
- func (s *Table) Count() int
- func (s *Table) Create(admin string, credential int64, now time.Time) (string, Session, error)
- func (s *Table) Lookup(token string, now time.Time) (Session, string)
- func (s *Table) Revoke(token string)
- func (s *Table) RevokeAdmin(name string)
Constants ¶
const Max = 64
Max is the most sessions held at once.
Variables ¶
var ErrFull = errors.New("session limit reached")
ErrFull is returned by Create when Max sessions are live.
Functions ¶
Types ¶
type Session ¶
type Session struct {
Admin string
Credential int64 // administrator credential version at login
CSRF string
Reference string // non-secret identifier recorded in audit events
Expires time.Time // absolute end of the session
// contains filtered or unexported fields
}
Session is one authenticated administrator session. The server keeps only the SHA-256 of the session token; the token itself exists only in the administrator's cookie.
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table holds the live administrator sessions in memory. A restart ends every session; nothing about them is ever written to the database.
func (*Table) Create ¶
Create starts a session and returns its token. Expired sessions are swept first; if the limit is still reached, no session is created.
func (*Table) Lookup ¶
Lookup returns the session for a token and records the activity. An unknown token is never adopted; an expired one is removed.
func (*Table) RevokeAdmin ¶
RevokeAdmin ends every session of one administrator, as a credential change requires.