Documentation
¶
Index ¶
- Constants
- Variables
- func AccountsOf(store db.DataStore, cfg *settings.Settings) *accounts.Manager
- func AuthorTokenFromCookies(cookie func(key string, defaultValue ...string) string, cfg *settings.Settings) string
- func CheckAccess(ctx fiber.Ctx, logger *zap.SugaredLogger, retrievedSettings *settings.Settings, ...) error
- func CheckAccessWithHooks(ctx fiber.Ctx, logger *zap.SugaredLogger, retrievedSettings *settings.Settings, ...) error
- func CreateNewPad(ds db.DataStore) *pad.Pad
- func EnsureAuthorTokenCookie(c fiber.Ctx, cfg *settings.Settings) string
- func GetTxtFromAText(retrievedPad *pad.Pad, atext apool.AText) (*string, error)
- func IntegratorSessionIDCookie(cookie func(key string, defaultValue ...string) string, prefix string) string
- func NeedsUser(path string) bool
- func NormalizeAuthzLevel(level interface{}) (*string, error)
- func RequestUser(ctx fiber.Ctx) *webaccess.SocketClientRequest
- func ResolvePadAuthorization(store db.DataStore, user *webaccess.SocketClientRequest, padId string, ...) string
- func SetAuthorTokenCookie(c fiber.Ctx, cfg *settings.Settings, token string)
- func SetAuthorTokenCookieLax(c fiber.Ctx, cfg *settings.Settings, token string)
- func SetLoginPage(fn func(redirect string) string)
- func SplitRemoveLastRune(s string) []string
- func UserCanModify(padId *string, req *webaccess.SocketClientRequest, ...) bool
- type ApiSessionInfo
- type ClientType
- type DeletionTokens
- type GlobalPadCache
- type GrantedAccess
- type IdRequest
- type LineModel
- type List
- type Manager
- func (m *Manager) CanOpenPadId(padID string) (bool, error)
- func (m *Manager) CatchUp(id string, fn func(p *pad.Pad)) bool
- func (m *Manager) DoesPadExist(padID string) (*bool, error)
- func (m *Manager) GetPad(padID string, text *string, authorId *string) (*pad.Pad, error)
- func (m *Manager) GetTypedPad(padID string, documentType string, authorId *string) (*pad.Pad, error)
- func (m *Manager) IsValidPadId(padID string) bool
- func (m *Manager) LockPad(ids ...string) (unlock func(), err error)
- func (m *Manager) PurgePad(padID string) error
- func (m *Manager) RLockPad(ids ...string) (unlock func(), err error)
- func (m *Manager) RemovePad(padID string) error
- func (m *Manager) SanitizePadId(padID string) (string, error)
- func (m *Manager) SetLowerCasePadIds(enabled func() bool)
- func (m *Manager) UnloadPad(id string)
- type ReadOnlyManager
- type Retention
- type RetentionNotice
- type SecurityManager
- func (s *SecurityManager) CheckAccess(padId *string, sessionCookie *string, token *string, ...) (*GrantedAccess, error)
- func (s *SecurityManager) CheckRequestAccess(ctx fiber.Ctx, padId string) (*GrantedAccess, error)
- func (s *SecurityManager) HasPadAccess(ctx fiber.Ctx) bool
- func (s *SecurityManager) RequestCanModify(ctx fiber.Ctx, padId string) bool
- type SessionManager
- func (sm *SessionManager) CreateSession(groupID string, authorID string, validUntil int64) (string, error)
- func (sm *SessionManager) DeleteSession(sessionID string) (bool, error)
- func (sm *SessionManager) DoesSessionExist(sessionID string) (bool, error)
- func (sm *SessionManager) FindAuthorID(groupID string, sessionCookie *string) *string
- func (sm *SessionManager) GetSessionInfo(sessionID string) (*ApiSessionInfo, error)
- func (sm *SessionManager) ListSessionsOfAuthor(authorID string) (map[string]ApiSessionInfo, error)
- func (sm *SessionManager) ListSessionsOfGroup(groupID string) (map[string]ApiSessionInfo, error)
- type UserSettings
Constants ¶
UnavailableStatus is the HTTP status for ErrPadUnavailable: the client may retry, and a load balancer may send the retry to another instance.
Variables ¶
ErrPadUnavailable is returned by LockPad and RLockPad when the pad cannot be locked or brought up to the stored state, typically because the database is unreachable. The caller must not touch the pad then: its cached copy may be behind what other instances stored.
Functions ¶
func AccountsOf ¶ added in v0.7.0
AccountsOf returns the account manager of store, set up from cfg on first use.
func AuthorTokenFromCookies ¶ added in v0.7.0
func AuthorTokenFromCookies(cookie func(key string, defaultValue ...string) string, cfg *settings.Settings) string
AuthorTokenFromCookies is the author token of the request's cookies, or "" when there is none or it is malformed: the prefixed name first, then the plain "token" earlier versions wrote from JavaScript.
func CheckAccess ¶
func CheckAccess(ctx fiber.Ctx, logger *zap.SugaredLogger, retrievedSettings *settings.Settings, readOnlyManager *ReadOnlyManager) error
CheckAccess keeps the historical signature (no hook system) and runs without any plugin preAuthorize/preAuthzFailure hooks. New callers should prefer CheckAccessWithHooks so that plugins get a chance to permit or deny early.
func CheckAccessWithHooks ¶ added in v0.6.3
func CheckAccessWithHooks(ctx fiber.Ctx, logger *zap.SugaredLogger, retrievedSettings *settings.Settings, readOnlyManager *ReadOnlyManager, hookSystem *hooks.Hook) error
func EnsureAuthorTokenCookie ¶ added in v0.7.0
EnsureAuthorTokenCookie makes sure the browser has an HttpOnly author token cookie and returns the token (etherpad-lite's ensureAuthorTokenCookie). The token is the author's identity; set from JavaScript, as before, any script running in the page could read it and act as the author (delete pads they created, for one). A valid token the browser already has is kept, so authors keep their identity; a cookie that is not HttpOnly yet is rewritten as HttpOnly with the same value.
func GetTxtFromAText ¶ added in v0.0.2
func IntegratorSessionIDCookie ¶ added in v0.7.0
func IntegratorSessionIDCookie(cookie func(key string, defaultValue ...string) string, prefix string) string
IntegratorSessionIDCookie reads the sessionID cookie an integrator set through the HTTP API's createSession (etherpad-lite #7045, #7755): the prefixed name first, then the plain one. The value is percent-decoded; one that cannot be decoded counts as absent.
func NeedsUser ¶ added in v0.7.0
NeedsUser reports whether the access check of path looks at who is logged in; health probes, public assets and the login's own pages do not, so a login session need not be read for them.
func NormalizeAuthzLevel ¶
NormalizeAuthzLevel mirrors the original webaccess.normalizeAuthzLevel: `true` normalizes to "create", the three known levels pass through, and everything else (false, empty, unknown strings) is denied.
func RequestUser ¶ added in v0.7.0
func RequestUser(ctx fiber.Ctx) *webaccess.SocketClientRequest
RequestUser is the user webaccess authenticated for this request, or nil.
func ResolvePadAuthorization ¶ added in v0.7.0
func ResolvePadAuthorization(store db.DataStore, user *webaccess.SocketClientRequest, padId string, cfg *settings.Settings, hookSystem *hooks.Hook) string
ResolvePadAuthorization decides the level of user (nil: a visitor who is not logged in) for the real pad padId like webaccess does for "/p/<padId>": by the grants of the account management, admins always "create", and with requireAuthorization the authorize hooks limit a logged-in person's level ("" = no access).
func SetAuthorTokenCookie ¶ added in v0.7.0
SetAuthorTokenCookie writes token as the HttpOnly author token cookie (and drops the older JavaScript-readable one).
func SetAuthorTokenCookieLax ¶ added in v0.7.0
SetAuthorTokenCookieLax is SetAuthorTokenCookie with SameSite=Lax always: for a token the browser takes over (a session transfer), which no other site may trigger.
func SetLoginPage ¶ added in v0.7.0
SetLoginPage sets the pads' login page (lib/api/padlogin); nil turns the redirect to it off.
func SplitRemoveLastRune ¶ added in v0.0.2
func UserCanModify ¶
func UserCanModify(padId *string, req *webaccess.SocketClientRequest, readOnlyManager ReadOnlyManager, cfg *settings.Settings) bool
UserCanModify tells whether the request user (nil: a visitor) may change the pad: never through a read-only id; otherwise by the level webaccess remembered for the pad, or the level the account management gives.
Types ¶
type ApiSessionInfo ¶ added in v0.6.3
type ApiSessionInfo struct {
GroupID string `json:"groupID"`
AuthorID string `json:"authorID"`
ValidUntil int64 `json:"validUntil"`
}
ApiSessionInfo is the stored payload of an API session.
type ClientType ¶
type ClientType interface {
}
type DeletionTokens ¶ added in v0.7.0
type DeletionTokens struct {
// contains filtered or unexported fields
}
DeletionTokens manages the deletion tokens of pads.
func NewDeletionTokens ¶ added in v0.7.0
func NewDeletionTokens(store db.DataStore) *DeletionTokens
func (*DeletionTokens) CreateIfAbsent ¶ added in v0.7.0
func (d *DeletionTokens) CreateIfAbsent(padID string) (*string, error)
CreateIfAbsent returns a new token for the pad, or nil when the pad already has one: the plaintext is handed out exactly once. The insert is atomic, so two instances creating at once cannot both hand out a token.
func (*DeletionTokens) IsValid ¶ added in v0.7.0
func (d *DeletionTokens) IsValid(padID, token string) bool
IsValid reports whether token is the pad's deletion token.
func (*DeletionTokens) Remove ¶ added in v0.7.0
func (d *DeletionTokens) Remove(padID string) error
Remove drops the pad's token; called when the pad is removed.
func (*DeletionTokens) Transfer ¶ added in v0.7.0
func (d *DeletionTokens) Transfer(srcPadID, dstPadID string) error
Transfer hands the source pad's token to a moved pad, unless the destination already has one (it may have been handed out meanwhile). The source's token is removed with the source pad.
type GlobalPadCache ¶
type GlobalPadCache struct {
// contains filtered or unexported fields
}
func (*GlobalPadCache) DeletePad ¶
func (g *GlobalPadCache) DeletePad(padID string)
type GrantedAccess ¶
type LineModel ¶ added in v0.0.2
LineModel is an alias for models.LineModel for backwards compatibility
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
func (*Manager) CanOpenPadId ¶ added in v0.7.0
CanOpenPadId reports whether a pad with this id may be opened: either the id is valid for a new pad, or a pad with exactly this id already exists (ids with ":" were allowed before, see pad.IsLegacyPadId).
func (*Manager) CatchUp ¶ added in v0.7.0
CatchUp brings the cached pad id up to the stored state under the pad's local write lock and calls fn with it, to send its clients what other instances stored. It reports false if the pad is not cached here (then it has no clients here) or was deleted.
func (*Manager) GetTypedPad ¶ added in v0.6.5
func (m *Manager) GetTypedPad(padID string, documentType string, authorId *string) (*pad.Pad, error)
GetTypedPad loads or creates a pad of a specific document type. For an existing pad the stored type is kept; documentType only applies on first creation (it is set before Init so Init -> AppendRevision -> Save persists it via CreatePad).
func (*Manager) IsValidPadId ¶
func (*Manager) LockPad ¶ added in v0.6.8
LockPad takes the write lock of every given pad and returns a function that releases them. Use it around any change to a pad.
Besides the lock within this process it takes the pads' locks in the database, all or none, which excludes writers in other Etherpad instances on the same database, and then brings the cached pads up to the stored state. If any of that fails nothing is held and the error wraps ErrPadUnavailable.
func (*Manager) PurgePad ¶ added in v0.7.0
PurgePad removes a pad's records without loading it: for pads that cannot be loaded any more (damaged, or an id that is no longer valid).
func (*Manager) RLockPad ¶ added in v0.6.8
RLockPad takes the read lock of every given pad and returns a function that releases them. Use it around reads of a live pad's text, pool or revisions. Readers share the lock: a cached pad is compared with the stored version under the read lock, and only a pad that is behind (another instance wrote to it) is refreshed under the write lock first.
func (*Manager) SanitizePadId ¶
SanitizePadId maps a requested pad id to the one to use, like etherpad-lite's sanitizePadId: an existing pad keeps its id; otherwise whitespace and then ":" are replaced by "_", stopping as soon as a pad with the id exists. The result may still be invalid ("a$b"); callers check it with CanOpenPadId.
func (*Manager) SetLowerCasePadIds ¶ added in v0.7.0
SetLowerCasePadIds connects the lowerCasePadIds setting (etherpad-lite): when it reports true, a requested id that names no existing pad is lower-cased, so "/p/Foo" opens (or creates) "foo"; pads created before with upper-case letters stay reachable under their id.
type ReadOnlyManager ¶
func NewReadOnlyManager ¶
func NewReadOnlyManager(db db.DataStore) *ReadOnlyManager
func (*ReadOnlyManager) GetPadId ¶ added in v0.0.2
func (r *ReadOnlyManager) GetPadId(readonlyId string) (*string, error)
func (*ReadOnlyManager) GetReadOnlyId ¶
func (r *ReadOnlyManager) GetReadOnlyId(pad string) string
func (*ReadOnlyManager) IsReadOnlyID ¶ added in v0.0.2
func (r *ReadOnlyManager) IsReadOnlyID(id *string) bool
type Retention ¶ added in v0.6.8
type Retention struct {
// contains filtered or unexported fields
}
Retention removes pads that have not been edited for the configured period. The feature is deliberately opt-in and dry-run by default.
func NewRetention ¶ added in v0.6.8
func (*Retention) CheckOnOpen ¶ added in v0.6.8
func (r *Retention) CheckOnOpen(padID string) *RetentionNotice
CheckOnOpen checks retention immediately before a pad is loaded. It returns a notice for the browser and leaves the normal pad-loading path unchanged. The caller must hold the pad's write lock (see Manager.LockPad), since an expired pad is deleted right here.
func (*Retention) SetLeader ¶ added in v0.7.0
SetLeader makes the periodic sweep run only while isLeader returns true. Call it before Start.
type RetentionNotice ¶ added in v0.6.8
RetentionNotice is sent to the pad client when a pad is close to, or has reached, its configured retention limit.
type SecurityManager ¶
type SecurityManager struct {
ReadOnlyManager *ReadOnlyManager
PadManager *Manager
AuthorManager *author.Manager
SessionManager *SessionManager
// contains filtered or unexported fields
}
func NewSecurityManager ¶
func NewSecurityManager(db db.DataStore, hooks *hooks.Hook, padManager *Manager, cfg *settings.Settings) *SecurityManager
NewSecurityManager creates a SecurityManager that reads its access rules from cfg instead of the global settings, so tests can run in parallel with different settings.
func (*SecurityManager) CheckAccess ¶
func (s *SecurityManager) CheckAccess(padId *string, sessionCookie *string, token *string, userSettings *webaccess.SocketClientRequest) (*GrantedAccess, error)
func (*SecurityManager) CheckRequestAccess ¶ added in v0.7.0
func (s *SecurityManager) CheckRequestAccess(ctx fiber.Ctx, padId string) (*GrantedAccess, error)
CheckRequestAccess is CheckAccess for an HTTP request on a pad: with the user webaccess authenticated, the token cookie and the integrator's sessionID cookie, as etherpad-lite's import and export routes do.
func (*SecurityManager) HasPadAccess ¶ added in v0.0.2
func (s *SecurityManager) HasPadAccess(ctx fiber.Ctx) bool
func (*SecurityManager) RequestCanModify ¶ added in v0.7.0
func (s *SecurityManager) RequestCanModify(ctx fiber.Ctx, padId string) bool
RequestCanModify tells whether the request may change the pad: not through a read-only id and not with a read-only authorization.
type SessionManager ¶
type SessionManager struct {
// contains filtered or unexported fields
}
func NewSessionManager ¶
func NewSessionManager(db db.DataStore) *SessionManager
func (*SessionManager) CreateSession ¶ added in v0.6.3
func (sm *SessionManager) CreateSession(groupID string, authorID string, validUntil int64) (string, error)
CreateSession stores a new API session and registers it in the group and author listings. Validation of group/author existence and expiry is the caller's responsibility (the API layer mirrors the original's checks).
func (*SessionManager) DeleteSession ¶ added in v0.6.3
func (sm *SessionManager) DeleteSession(sessionID string) (bool, error)
DeleteSession removes a session and its listing entries. The boolean reports whether the session existed.
func (*SessionManager) DoesSessionExist ¶ added in v0.6.3
func (sm *SessionManager) DoesSessionExist(sessionID string) (bool, error)
DoesSessionExist reports whether a session record exists.
func (*SessionManager) FindAuthorID ¶ added in v0.6.3
func (sm *SessionManager) FindAuthorID(groupID string, sessionCookie *string) *string
FindAuthorID mirrors the original SessionManager.findAuthorID: the cookie may be enclosed in double quotes (upstream #3819) and may carry a comma-separated list of session ids. The author of the first session that belongs to the given group and is not expired is returned.
func (*SessionManager) GetSessionInfo ¶ added in v0.6.3
func (sm *SessionManager) GetSessionInfo(sessionID string) (*ApiSessionInfo, error)
GetSessionInfo returns the session payload, or (nil, nil) if the session does not exist.
func (*SessionManager) ListSessionsOfAuthor ¶ added in v0.6.3
func (sm *SessionManager) ListSessionsOfAuthor(authorID string) (map[string]ApiSessionInfo, error)
ListSessionsOfAuthor returns all sessions registered for an author.
func (*SessionManager) ListSessionsOfGroup ¶ added in v0.6.3
func (sm *SessionManager) ListSessionsOfGroup(groupID string) (map[string]ApiSessionInfo, error)
ListSessionsOfGroup returns all sessions registered for a group.