Documentation
¶
Overview ¶
Package adminbackup serves the admin endpoints for the database backups (admin/backup/*, #3462). Every endpoint, including the listing, is guarded by strongauth: administrators only, native session tokens only, 2FA or a passkey registered, and a fresh re-authentication on every request.
Index ¶
- Constants
- Variables
- func Reauthenticate(v *strongauth.Verifier, c *echo.Context) (bool, error)
- type Forwarder
- type Handler
- func (h *Handler) Delete(c *echo.Context) error
- func (h *Handler) Download(c *echo.Context) error
- func (h *Handler) List(c *echo.Context) error
- func (h *Handler) ReauthChallenge(c *echo.Context) error
- func (h *Handler) RestoreAbort(c *echo.Context) error
- func (h *Handler) RestoreCandidates(c *echo.Context) error
- func (h *Handler) RestoreConfirm(c *echo.Context) error
- func (h *Handler) RestorePrepare(c *echo.Context) error
- func (h *Handler) RestoreStatus(c *echo.Context) error
- func (h *Handler) ServeDownload(c *echo.Context) error
- func (h *Handler) SetForwarder(f *Forwarder)
- func (h *Handler) Take(c *echo.Context) error
- func (h *Handler) Verify(c *echo.Context) error
- type ModLogger
- type RefusalResponse
Constants ¶
IDRestoreUnavailable is the error ID of RESTORE_UNAVAILABLE, shared by the backup service and the status forward.
const RestorePathPrefix = "/api/admin/backup/restore/"
RestorePathPrefix is where the restore endpoints live. They are forwarded to the backup service as they are, also while the server is in maintenance (#3463 (6c)).
const ServiceAuthChallenge = `Bearer realm="elythia-backup"`
ServiceAuthChallenge is the WWW-Authenticate the backup service sends when it refuses the service token. The forwarder tells it from a 401 about the administrator's own credentials by it.
Variables ¶
var RestoreOps = []string{"prepare", "confirm", "abort", "status", "candidates"}
RestoreOps are the forwarded operations. prepare also starts a rollback (kind "rollback", #3463 (6d)); candidates lists the databases a rollback can swap back in.
Functions ¶
func Reauthenticate ¶
Reauthenticate checks the strong authentication of the request as admin/backup/* does: administrators only, native session tokens only, 2FA or a passkey registered, and the re-authentication in the body (`password` and either `token` or `credential`). When the request may not proceed, it writes the response and returns false. Other admin endpoints doing an irreversible operation use it too (#4184).
Types ¶
type Forwarder ¶
type Forwarder struct {
// contains filtered or unexported fields
}
Forwarder relays the restore requests to the backup service.
**本体では照合しない。** 再認証は daemon が行う (本体で照合すると、同じ TOTP の コードを本体と daemon で二重に消費して落ちる)。本体が見るのは、本文の上限と形、 daemon の設定の有無だけ。利用者の Authorization ヘッダーの token は本文の i へ 移す (daemon への Authorization は serviceToken が使う)。
func NewForwarder ¶
NewForwarder returns a Forwarder for the control API at baseURL. An empty baseURL or token answers BACKUP_SERVICE_NOT_CONFIGURED.
func (*Forwarder) Configured ¶
Configured reports whether a backup service is set.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler serves admin/backup/*.
func NewHandler ¶
func NewHandler(svc *backupadmin.Service, verifier *strongauth.Verifier, modlog ModLogger) *Handler
NewHandler returns a Handler. modlog may be nil only in tests.
func (*Handler) Download ¶
Download handles POST /api/admin/backup/download, after the re-authentication.
func (*Handler) ReauthChallenge ¶
ReauthChallenge handles POST /api/admin/backup/reauth-challenge. It returns the PublicKeyCredentialRequestOptions for a passkey re-authentication.
再認証の前段なので Guard は掛けない。代わりに、再認証以外の条件 (管理者・ native token・2FA の登録) をここで見る。challenge を出すだけで、何も見せず 何も変えない。
func (*Handler) RestoreAbort ¶
RestoreAbort handles POST /api/admin/backup/restore/abort.
func (*Handler) RestoreCandidates ¶
RestoreCandidates handles POST /api/admin/backup/restore/candidates, after the re-authentication.
一覧 (admin/backup/list の listBackups) と同じく、閲覧も記録する。退避した DB には 利用者の秘密鍵などがそのまま入っており、その名前と大きさを誰がいつ見たかを追える ようにする。成立した (daemon が 200 を返した) ときだけ書く。
func (*Handler) RestoreConfirm ¶
RestoreConfirm handles POST /api/admin/backup/restore/confirm.
func (*Handler) RestorePrepare ¶
RestorePrepare handles POST /api/admin/backup/restore/prepare.
func (*Handler) RestoreStatus ¶
RestoreStatus handles POST /api/admin/backup/restore/status.
func (*Handler) ServeDownload ¶
ServeDownload handles GET /backup-download?token=..., the server-side download of a directory storage. The token comes from Download.
func (*Handler) SetForwarder ¶
SetForwarder sets the forwarder of the restore endpoints.
type ModLogger ¶
type ModLogger interface {
Log(ctx context.Context, moderatorID string, t moderationlog.LogType, info map[string]any)
}
ModLogger records moderation logs. *moderationlog.Service implements it.
type RefusalResponse ¶
type RefusalResponse struct {
Status int
Body any
// RetryAfter is the Retry-After header value, or "".
RetryAfter string
}
RefusalResponse is the HTTP response for a strongauth refusal.
func Refusal ¶
func Refusal(err error, suspended bool) RefusalResponse
Refusal returns the response for err from strongauth. suspended tells a suspended account from a missing credential.
バックアップ用のサービス (#3463 (6c)) も同じ形で返す。本体は daemon の応答を そのまま利用者へ渡すので、管理画面から見て本体と daemon の区別が付かない。