Documentation
¶
Index ¶
- Constants
- func NewControllerProxy(options ProxyOptions) (*httputil.ReverseProxy, error)
- func WriteReject(w http.ResponseWriter, action Action)
- type Action
- type Authenticator
- func (a Authenticator) AuthenticateForm(password string) bool
- func (a Authenticator) Authorized(r *http.Request) bool
- func (a Authenticator) ClearSessionCookie(w http.ResponseWriter)
- func (a Authenticator) RejectsControllerSecretAsPassword() bool
- func (a Authenticator) SetSessionCookie(w http.ResponseWriter)
- type Mutator
- type Options
- type PanelSource
- type ProxyOptions
- type Server
Constants ¶
const ( // CookieName is the HttpOnly session cookie for the Web gateway. CookieName = "mihari_web_auth" // AuthPath is the login endpoint reserved under a mihari prefix to avoid panel SPA clashes. AuthPath = "/__mihari/auth" )
Variables ¶
This section is empty.
Functions ¶
func NewControllerProxy ¶
func NewControllerProxy(options ProxyOptions) (*httputil.ReverseProxy, error)
NewControllerProxy builds a reverse proxy that strips client Authorization and injects the controller secret.
func WriteReject ¶
func WriteReject(w http.ResponseWriter, action Action)
WriteReject writes a JSON error for a classified reject action without contacting mihomo.
Types ¶
type Action ¶
type Action int
Action is the gateway disposition for a browser API request.
const ( // ActionProxyRead forwards a safe read to the mihomo controller with injected secret. ActionProxyRead Action = iota // ActionProxyWS upgrades and proxies a streaming endpoint. ActionProxyWS // ActionProxyStorage forwards a /storage/{key} read or write (GET/HEAD/PUT/DELETE) to // the mihomo controller. Storage is a generic KV store isolated from mihari-managed // config, so writes pass through rather than routing through the coordinator. ActionProxyStorage // ActionMutateSelectProxy submits group selection through the coordinator. ActionMutateSelectProxy // ActionMutateClose closes one or all connections through the coordinator. ActionMutateClose // ActionMutateDelayTest runs a delay test through the coordinator. ActionMutateDelayTest // ActionMutateRestart restarts the supervised core through the coordinator. ActionMutateRestart // ActionMutateConfigs applies allowlisted config field patches through the coordinator. ActionMutateConfigs // ActionRejectUpgrade rejects core upgrade attempts owned by mihari. ActionRejectUpgrade // ActionRejectManaged rejects writes to mihari-managed controller/port/UI fields. ActionRejectManaged // ActionRejectUnknown is the default-deny for unrecognized write methods/paths. ActionRejectUnknown // ActionNotAPI marks non-API traffic (static/auth) that the classifier does not handle. ActionNotAPI )
func Classify ¶
Classify decides how the Web gateway handles a method+path pair. Unknown writes never fall through to the controller.
func ClassifyUpgrade ¶
ClassifyUpgrade distinguishes REST GET /connections from WebSocket upgrade.
type Authenticator ¶
type Authenticator struct {
// WebCredential is the daemon-owned browser access token (not the controller secret).
WebCredential string
// ControllerSecret is retained only to reject mistaken use as a Web password in tests/docs;
// authentication never succeeds by matching the controller secret alone when it differs.
ControllerSecret string
// CookieSecure sets the Secure flag (false for local http://127.0.0.1).
CookieSecure bool
// SessionTTL bounds cookie Max-Age.
SessionTTL time.Duration
}
Authenticator validates browser access using the dedicated Web credential. The controller secret is never accepted as a Web password.
func (Authenticator) AuthenticateForm ¶
func (a Authenticator) AuthenticateForm(password string) bool
AuthenticateForm validates a posted password field against the Web credential only.
func (Authenticator) Authorized ¶
func (a Authenticator) Authorized(r *http.Request) bool
Authorized reports whether the request carries a valid Web session cookie or Bearer token.
func (Authenticator) ClearSessionCookie ¶
func (a Authenticator) ClearSessionCookie(w http.ResponseWriter)
ClearSessionCookie expires the Web session cookie.
func (Authenticator) RejectsControllerSecretAsPassword ¶
func (a Authenticator) RejectsControllerSecretAsPassword() bool
RejectsControllerSecretAsPassword documents that using only the controller secret fails when it is not equal to the Web credential.
func (Authenticator) SetSessionCookie ¶
func (a Authenticator) SetSessionCookie(w http.ResponseWriter)
SetSessionCookie writes the Web session cookie.
type Mutator ¶
type Mutator interface {
SelectProxy(ctx context.Context, group, name string) error
CloseConnection(ctx context.Context, id string) error
CloseAllConnections(ctx context.Context) error
// ApplyConfigPatch applies allowlisted config mutations (currently TUN only).
ApplyConfigPatch(ctx context.Context, patch map[string]any) error
}
Mutator handles allowlisted browser writes through the daemon coordinator. When nil, allowlisted mutations are rejected as unsupported.
type Options ¶
type Options struct {
Reporter diagnostics.Reporter
Addr string
Auth Authenticator
ControllerURL string
ControllerSecret string
Panel PanelSource
Mutator Mutator
Transport http.RoundTripper
}
Options configures a Web gateway server.
type PanelSource ¶
type PanelSource interface {
ActiveDir() (string, error)
SetupPath(gatewayHost string) string
// PanelDir returns the static file root for an installed panel, or empty when missing.
PanelDir(panelID string) (string, error)
// SetupPathFor returns the same-origin setup deep-link for a specific panel.
SetupPathFor(panelID, gatewayHost string) string
}
PanelSource provides panel static trees and setup deep-links. Multiple installed panels may be served concurrently under /__mihari/panels/{panelID}/; ActiveDir/SetupPath describe the default panel for root "/".
type ProxyOptions ¶
type ProxyOptions struct {
Reporter diagnostics.Reporter
// ControllerURL is the loopback controller base, e.g. http://127.0.0.1:9090.
ControllerURL string
// ControllerSecret is injected as Bearer; never returned to the browser.
ControllerSecret string
// Transport is optional for tests.
Transport http.RoundTripper
}
ProxyOptions configures the secret-injecting reverse proxy to the mihomo controller.
type Server ¶
type Server struct {
Reporter diagnostics.Reporter
Addr string
Auth Authenticator
Proxy *httputil.ReverseProxy
ControllerURL string
ControllerSecret string
Panel PanelSource
Mutator Mutator
HTTPClient *http.Client
// contains filtered or unexported fields
}
Server is the loopback Web gateway: auth, static panel hosting, and API proxy.
func (*Server) ListenAddr ¶
ListenAddr returns the bound address after Serve starts, or the configured Addr.
func (*Server) SessionCount ¶
SessionCount approximates concurrent authenticated request handlers.