adminbackup

package
v0.0.0-...-9914b64 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: AGPL-3.0 Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const IDRestoreUnavailable = "515b8e48-8f90-439a-bd56-2bdd4d8870a5"

IDRestoreUnavailable is the error ID of RESTORE_UNAVAILABLE, shared by the backup service and the status forward.

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

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

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

func Reauthenticate(v *strongauth.Verifier, c *echo.Context) (bool, error)

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

func NewForwarder(baseURL, token string, client *http.Client) *Forwarder

NewForwarder returns a Forwarder for the control API at baseURL. An empty baseURL or token answers BACKUP_SERVICE_NOT_CONFIGURED.

func (*Forwarder) Configured

func (f *Forwarder) Configured() bool

Configured reports whether a backup service is set.

func (*Forwarder) Serve

func (f *Forwarder) Serve(w http.ResponseWriter, r *http.Request, op, clientIP string)

Serve relays one request for op ("prepare", ...). clientIP is the administrator's address as the server resolved it.

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) Delete

func (h *Handler) Delete(c *echo.Context) error

Delete handles POST /api/admin/backup/delete, after the re-authentication.

func (*Handler) Download

func (h *Handler) Download(c *echo.Context) error

Download handles POST /api/admin/backup/download, after the re-authentication.

func (*Handler) List

func (h *Handler) List(c *echo.Context) error

List handles POST /api/admin/backup/list, after the re-authentication.

func (*Handler) ReauthChallenge

func (h *Handler) ReauthChallenge(c *echo.Context) error

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

func (h *Handler) RestoreAbort(c *echo.Context) error

RestoreAbort handles POST /api/admin/backup/restore/abort.

func (*Handler) RestoreCandidates

func (h *Handler) RestoreCandidates(c *echo.Context) error

RestoreCandidates handles POST /api/admin/backup/restore/candidates, after the re-authentication.

一覧 (admin/backup/list の listBackups) と同じく、閲覧も記録する。退避した DB には 利用者の秘密鍵などがそのまま入っており、その名前と大きさを誰がいつ見たかを追える ようにする。成立した (daemon が 200 を返した) ときだけ書く。

func (*Handler) RestoreConfirm

func (h *Handler) RestoreConfirm(c *echo.Context) error

RestoreConfirm handles POST /api/admin/backup/restore/confirm.

func (*Handler) RestorePrepare

func (h *Handler) RestorePrepare(c *echo.Context) error

RestorePrepare handles POST /api/admin/backup/restore/prepare.

func (*Handler) RestoreStatus

func (h *Handler) RestoreStatus(c *echo.Context) error

RestoreStatus handles POST /api/admin/backup/restore/status.

func (*Handler) ServeDownload

func (h *Handler) ServeDownload(c *echo.Context) error

ServeDownload handles GET /backup-download?token=..., the server-side download of a directory storage. The token comes from Download.

func (*Handler) SetForwarder

func (h *Handler) SetForwarder(f *Forwarder)

SetForwarder sets the forwarder of the restore endpoints.

func (*Handler) Take

func (h *Handler) Take(c *echo.Context) error

Take handles POST /api/admin/backup/take, after the re-authentication.

func (*Handler) Verify

func (h *Handler) Verify(c *echo.Context) error

Verify handles POST /api/admin/backup/verify, after the re-authentication.

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 の区別が付かない。

Jump to

Keyboard shortcuts

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