host

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: Apache-2.0 Imports: 52 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

Index

Constants

View Source
const AnnotationInvalidatesGrantsOnWrite = "kdex.dev/invalidates-grants-on-write"

AnnotationInvalidatesGrantsOnWrite marks a KDexFunction whose successful writes mutate membership/role state; host-manager bumps the shared grant generation on such a response so browser sessions re-resolve (#203).

Variables

PageDenialModes is every value --page-denial-mode accepts.

Functions

func GetErrorResponseWriter

func GetErrorResponseWriter(w http.ResponseWriter) *errorResponseWriter

Types

type AnalysisCache

type AnalysisCache struct {
	// contains filtered or unexported fields
}

AnalysisCache stores the results of the InferenceEngine for a short period so that the redirected user can view the report.

func NewAnalysisCache

func NewAnalysisCache() *AnalysisCache

func (*AnalysisCache) Get

func (*AnalysisCache) Store

func (ac *AnalysisCache) Store(result *sniffer.AnalysisResult) string

type CheckRequest added in v0.2.9

type CheckRequest struct {
	Checks []string `json:"checks"`
}

type CheckResponse added in v0.2.9

type CheckResponse struct {
	Passed []string `json:"passed"`
}

type FeedbackTheme

type FeedbackTheme struct {
	// CLI Colors (ANSI)
	CLIHeader  string
	CLISuccess string
	CLIWarning string
	CLIDim     string
	CLILineNum string
	CLIReset   string

	// HTML Colors (CSS)
	BgPage        string
	BgSidebar     string
	BgCard        string
	BgCode        string
	Border        string
	TextPrimary   string
	TextSecondary string
	TextAccent    string
	TextLint      string
	TextCode      string
	MethodGet     string
	MethodPost    string
	MethodPut     string
	MethodDelete  string
	BtnSuccess    string
	BtnHover      string
}

type HostHandler

type HostHandler struct {
	Mux          *http.ServeMux
	Name         string
	Namespace    string
	Pages        *page.PageStore
	Translations Translations
	// contains filtered or unexported fields
}

func NewHostHandler

func NewHostHandler(c client.Client, name string, namespace string, log logr.Logger, cacheManager cache.CacheManager) *HostHandler

func (*HostHandler) AddOrUpdateTranslation

func (hh *HostHandler) AddOrUpdateTranslation(name string, translation *kdexv1alpha1.KDexTranslationSpec)

func (*HostHandler) AddOrUpdateUtilityPage

func (hh *HostHandler) AddOrUpdateUtilityPage(ph page.PageHandler)

func (*HostHandler) BuildMenuEntries

func (hh *HostHandler) BuildMenuEntries(
	ctx context.Context,
	entry *render.PageEntry,
	l *language.Tag,
	isDefaultLanguage bool,
	parent *page.PageHandler,
)

func (*HostHandler) CheckHandler added in v0.2.9

func (hh *HostHandler) CheckHandler(w http.ResponseWriter, r *http.Request)

func (*HostHandler) Checksum added in v0.2.7

func (hh *HostHandler) Checksum() string

func (*HostHandler) DesignMiddleware

func (hh *HostHandler) DesignMiddleware(next http.Handler) http.Handler

func (*HostHandler) FootScriptToHTML

func (hh *HostHandler) FootScriptToHTML(handler page.PageHandler) string

func (*HostHandler) GeneratePageCacheKey added in v0.2.7

func (hh *HostHandler) GeneratePageCacheKey(ph page.PageHandler, l language.Tag) string

func (*HostHandler) GetCacheManager

func (hh *HostHandler) GetCacheManager() cache.CacheManager

func (*HostHandler) GetOpenAPIBuilder

func (hh *HostHandler) GetOpenAPIBuilder() *ko.Builder

func (*HostHandler) GetStatus

func (hh *HostHandler) GetStatus() HostStatus

func (*HostHandler) GetUtilityPageHandler

func (hh *HostHandler) GetUtilityPageHandler(name kdexv1alpha1.KDexUtilityPageType) page.PageHandler

func (*HostHandler) HeadScriptToHTML

func (hh *HostHandler) HeadScriptToHTML(handler page.PageHandler) string

func (*HostHandler) InspectHandler

func (hh *HostHandler) InspectHandler(w http.ResponseWriter, r *http.Request)

InspectHandler serves the feedback UI

func (*HostHandler) IsAuthEnabled added in v0.2.10

func (hh *HostHandler) IsAuthEnabled() bool

func (*HostHandler) L10nRender

func (hh *HostHandler) L10nRender(
	handler page.PageHandler,
	pageMap map[string]any,
	l language.Tag,
	extraTemplateData map[string]any,
	translations *Translations,
) (string, error)

func (*HostHandler) L10nRenderText added in v0.9.0

func (hh *HostHandler) L10nRenderText(
	ph page.PageHandler,
	lang language.Tag,
	translations *Translations,
) (string, error)

L10nRenderText renders a text-mime KDexPage's body (ph.Page.Body) through the same [[ ]]-delimited Go-template + l10n translation pipeline L10nRender uses -- same FuncMap, same MessagePrinter, built by the shared l10nRenderer -- but executes ONLY the body as the top-level template, with none of L10nRender's archetype/header/footer/navigation chrome assembled around it. TemplateData() still runs (it renders the untouched chrome fields to empty strings), which is what keeps this a thin wrapper around the same pipeline rather than a parallel one.

Unlike L10nRender, this uses render.Renderer.RenderOneText (text/template) rather than RenderOne (html/template): text-mime bodies (text/plain, json, yaml, markdown, xml) are not HTML, so an interpolated [[ l10n "key" ]] value must come through verbatim -- html/template's auto-escaping would corrupt any &, <, >, or " in a translation or template value.

func (*HostHandler) L10nRenders

func (hh *HostHandler) L10nRenders(
	handler page.PageHandler,
	pageMaps map[language.Tag]map[string]any,
	translations *Translations,
) map[string]string

func (*HostHandler) LoginGet

func (hh *HostHandler) LoginGet(w http.ResponseWriter, r *http.Request)

func (*HostHandler) LoginPost

func (hh *HostHandler) LoginPost(w http.ResponseWriter, r *http.Request)

func (*HostHandler) LogoutPost

func (hh *HostHandler) LogoutPost(w http.ResponseWriter, r *http.Request)

func (*HostHandler) MetaToString

func (hh *HostHandler) MetaToString(handler page.PageHandler, l language.Tag) string

func (*HostHandler) NavigationGet

func (hh *HostHandler) NavigationGet(w http.ResponseWriter, r *http.Request)

func (*HostHandler) OpenAPIGet

func (hh *HostHandler) OpenAPIGet(w http.ResponseWriter, r *http.Request)

func (*HostHandler) RebuildMux

func (hh *HostHandler) RebuildMux()

func (*HostHandler) RemovePage added in v0.2.19

func (hh *HostHandler) RemovePage(name string)

func (*HostHandler) RemoveTranslation

func (hh *HostHandler) RemoveTranslation(name string)

func (*HostHandler) RemoveUtilityPage

func (hh *HostHandler) RemoveUtilityPage(name string)

func (*HostHandler) RouteCollisions added in v0.9.0

func (hh *HostHandler) RouteCollisions() []RouteCollision

RouteCollisions returns the page-vs-page route collisions detected by the most recent RebuildMux. Empty when none were found. Callers (e.g. the KDexInternalHost reconciler) use this to surface a Degraded status condition -- registration itself never silently serves or drops a colliding route without recording it here.

func (*HostHandler) SchemaGet

func (hh *HostHandler) SchemaGet(w http.ResponseWriter, r *http.Request)

func (*HostHandler) SchemaListGet added in v0.2.30

func (hh *HostHandler) SchemaListGet(w http.ResponseWriter, r *http.Request)

func (*HostHandler) SecuritySchemes

func (hh *HostHandler) SecuritySchemes() *openapi.SecuritySchemes

func (*HostHandler) ServeHTTP

func (hh *HostHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*HostHandler) SetHost

func (hh *HostHandler) SetHost(
	ctx context.Context,
	host *kdexv1alpha1.KDexHostSpec,
	status *kdexv1alpha1.KDexObjectStatus,
	packageReferences []kdexv1alpha1.PackageReference,
	themeAssets []kdexv1alpha1.Asset,
	scripts []kdexv1alpha1.ScriptDef,
	importmap string,
	paths map[string]ko.PathInfo,
	functions []kdexv1alpha1.KDexFunction,
	authExchanger *auth.Exchanger,
	authConfig *auth.Config,
	scheme string,
	snif *sniffer.RequestSniffer,
	reconcileTime time.Time,
)

TODO: add individual cache configurations

func (*HostHandler) SetPageDenialMode added in v0.8.0

func (hh *HostHandler) SetPageDenialMode(m PageDenialMode) *HostHandler

SetPageDenialMode replaces the HostHandler's page-denial rendering mode. An empty or unrecognised value resolves to PageDenialDiscover.

This coercion is a SAFETY NET, not the validation. It resolves to the LESS strict mode, so an operator typo reaching here would silently buy the opposite of what was asked for -- which is why cmd/main.go refuses to start on anything that is not exactly "discover" or "forbid", and why a coercion that does happen is logged at V(0): reaching it means something bypassed that check.

func (*HostHandler) SetProxyTimeouts added in v0.2.78

func (hh *HostHandler) SetProxyTimeouts(t ProxyTimeouts) *HostHandler

SetProxyTimeouts replaces the HostHandler's proxy transport timeouts. Method-chain return makes it composable with NewHostHandler. Zero-valued fields fall back to defaults inside newProxyTransport.

func (*HostHandler) ThemeAssetsToString

func (hh *HostHandler) ThemeAssetsToString() string

func (*HostHandler) TransferGet added in v0.4.20

func (hh *HostHandler) TransferGet(w http.ResponseWriter, r *http.Request)

TransferGet redeems a /-/transfer/<handle> capability: resolve the handle, spend one budget unit, inject the stored identity, and re-dispatch the bound target through the mux (which runs the proxy identity gate + per-op security against the injected entitlements). All non-redeemable cases return an identical 410 to preserve anti-enumeration.

func (*HostHandler) TranslationGet

func (hh *HostHandler) TranslationGet(w http.ResponseWriter, r *http.Request)

type HostStatus

type HostStatus string
const (
	HostStatusInitializing HostStatus = "Initializing"
	HostStatusReady        HostStatus = "Ready"
	HostStatusDegraded     HostStatus = "Degraded"
	HostStatusProgressing  HostStatus = "Progressing"
)

type KDexFunctionHandler

type KDexFunctionHandler struct {
	Function *kdexv1alpha1.KDexFunction
	Handler  http.Handler
	// contains filtered or unexported fields
}

func (*KDexFunctionHandler) ServeHTTP

func (h *KDexFunctionHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type MintRequest added in v0.2.9

type MintRequest struct {
	// Action is the action of the tokens to mint (metadata-based revocation).
	Action string `json:"act"`
	// Audience is the audience of the tokens to mint (metadata-based revocation).
	Audience string `json:"aud"`
	// Scope is the scope of the tokens to mint (metadata-based revocation).
	Scope string `json:"scp"`
	// Sub is the subject of the tokens to mint (metadata-based revocation).
	Sub string `json:"sub"`
	// TTL is the duration for which the tokens should be valid (metadata-based revocation).
	// Default: 24h.
	TTL string `json:"ttl"`
}

type MintResponse added in v0.2.9

type MintResponse struct {
	Token string `json:"token"`
}

type MintTokenRequest added in v0.4.0

type MintTokenRequest struct {
	Entitlements []string        `json:"entitlements"`
	TTLSeconds   int             `json:"ttl_seconds,omitempty"`
	Uses         int             `json:"uses,omitempty"`
	Delivery     string          `json:"delivery,omitempty"`
	Target       *TransferTarget `json:"target,omitempty"`
}

MintTokenRequest is the argument shape of the mint_token MCP tool.

type MintTokenResult added in v0.4.0

type MintTokenResult struct {
	Token         string   `json:"token,omitempty"`
	URL           string   `json:"url,omitempty"`
	ExpiresAt     int64    `json:"expires_at"`
	Entitlements  []string `json:"entitlements"`
	UsesRemaining int      `json:"uses_remaining"`
}

MintTokenResult is the mint_token success payload.

type OAuth2Resource added in v0.3.0

type OAuth2Resource struct {
	BasePath string
	Resource string
	Scopes   []string
}

OAuth2Resource describes a KDexFunction basePath that an operation has opted into protecting with the built-in "oauth2" security scheme.

type PageDenialMode added in v0.8.0

type PageDenialMode string

PageDenialMode selects how the page gate renders FORBIDDEN to a browser. It governs the HTML rendering ONLY -- a non-HTML caller gets 403 in every mode, because the knob is about presentation, not about the contract.

const (
	// PageDenialDiscover sends a browser to the first page it can reach,
	// carrying ?denied=<path>. Preserves the behaviour that predates the
	// denial contract. Default.
	PageDenialDiscover PageDenialMode = "discover"
	// PageDenialForbid renders the 403 error page instead.
	PageDenialForbid PageDenialMode = "forbid"
)

func (PageDenialMode) IsValid added in v0.8.0

func (m PageDenialMode) IsValid() bool

IsValid reports whether m is a recognised mode. Callers that ACCEPT a mode from an operator must check this and refuse to start otherwise: SetPageDenialMode's coercion resolves an unrecognised value to the LESS strict mode, so a typo would otherwise buy the opposite of what was asked for with no diagnostic anywhere.

type ProtectedResourceMetadata added in v0.3.0

type ProtectedResourceMetadata struct {
	Resource               string   `json:"resource"`
	AuthorizationServers   []string `json:"authorization_servers"`
	ScopesSupported        []string `json:"scopes_supported,omitempty"`
	BearerMethodsSupported []string `json:"bearer_methods_supported,omitempty"`
}

ProtectedResourceMetadata is the RFC 9728 OAuth 2.0 Protected Resource Metadata document.

type ProxyTimeouts added in v0.2.78

type ProxyTimeouts struct {
	// DialTimeout caps the connection-establishment phase (TCP + TLS).
	DialTimeout time.Duration
	// ResponseHeaderTimeout caps the wait between sending the request and
	// receiving the first response byte from the backend. This is the knob
	// that matters for scale-from-zero Knative cold starts.
	ResponseHeaderTimeout time.Duration
	// IdleConnTimeout caps how long an unused keep-alive connection lingers
	// in the transport's pool before being closed.
	IdleConnTimeout time.Duration
}

ProxyTimeouts holds the http.Transport timeout knobs used when proxying to KDexFunction backends. Zero-value fields fall back to defaults at transport-construction time (see newProxyTransport in proxy.go), so callers can leave any subset unset.

type RevokeRequest added in v0.2.30

type RevokeRequest struct {
	// Action is the action of the tokens to revoke (metadata-based revocation).
	Action string `json:"act"`
	// Audience is the audience of the tokens to revoke (metadata-based revocation).
	Audience string `json:"aud"`
	// Sub is the subject of the tokens to revoke (metadata-based revocation).
	Sub string `json:"sub"`
	// TTL is the duration for which the revocation should be persisted in the cache (metadata-based revocation).
	// Default: 24h.
	TTL string `json:"ttl"`
	// Token is the full signed token to revoke.
	Token string `json:"token"`
}

RevokeRequest is the request body for the token revocation endpoint.

type RevokeResponse added in v0.2.30

type RevokeResponse struct {
	// Status is the result of the revocation request.
	Status string `json:"status"`
}

RevokeResponse is the response body for the token revocation endpoint.

type RouteCollision added in v0.9.0

type RouteCollision struct {
	// Pattern is the "METHOD /path" ServeMux pattern both pages wanted.
	Pattern string
	// WinnerName / WinnerBasePath identify the page that keeps the route.
	WinnerName     string
	WinnerBasePath string
	// LoserName / LoserBasePath identify the page whose registration for
	// Pattern was refused.
	LoserName     string
	LoserBasePath string
}

RouteCollision records a page registration refused during the most recent RebuildMux because a DIFFERENT, earlier-claimed page already owns the literal "METHOD /path" ServeMux pattern it wanted.

This is the enumerated-per-language-prefix collision class: replacing the old "/{l10n}" wildcard with one literal route per supported language means a page whose basePath equals "/<lang>" (or "/<lang>/...") produces the SAME pattern as another, independently-authored page's own language- prefixed (or bare, for text-mime pages) route. E.g. with "en" (default) and "fr" supported, the home page (basePath "/") registers "GET /fr/{$}" as its French route, and a page at basePath "/fr" wants that exact pattern for its own bare route.

The winner is whichever page registration-time ordering (basePath-sorted, see rebuildMuxSnapshot) processes first; the loser's route is refused outright rather than silently served or silently dropped -- see RouteCollisions.

type TransferTarget added in v0.4.20

type TransferTarget struct {
	Method string `json:"method"`
	Path   string `json:"path"`
}

TransferTarget is the single concrete operation a delivery:"url" capability authorizes. Download-only in this release: Method must be GET.

type Translations

type Translations struct {
	// contains filtered or unexported fields
}

func NewTranslations

func NewTranslations(defaultLanguage string, translations map[string]kdexv1alpha1.KDexTranslationSpec) (*Translations, error)

func (*Translations) Catalog

func (t *Translations) Catalog() *catalog.Builder

func (*Translations) Keys

func (t *Translations) Keys() []string

func (*Translations) Languages

func (t *Translations) Languages() []language.Tag

type VerifyRequest added in v0.2.9

type VerifyRequest struct {
	Token string `json:"token"`
}

type WhoamiResult added in v0.5.1

type WhoamiResult struct {
	Identity          string   `json:"identity"`
	Name              string   `json:"name,omitempty"`
	GivenName         string   `json:"given_name,omitempty"`
	FamilyName        string   `json:"family_name,omitempty"`
	PreferredUsername string   `json:"preferred_username,omitempty"`
	Entitlements      []string `json:"entitlements"`

	// EntitlementsWithheld reports that the credential currently presented
	// carries FEWER entitlements than the user effectively holds, so some of
	// the entitlements listed here cannot be exercised with it. Set whenever
	// the two differ — including for a deliberately attenuated capability
	// token, where it is expected rather than a misconfiguration.
	EntitlementsWithheld bool `json:"entitlements_withheld,omitempty"`

	// Hint is a short actionable explanation, present only when something is
	// actionable.
	Hint string `json:"hint,omitempty"`
}

WhoamiResult is the whoami success payload.

It describes what the USER can do. whoami is a reporting tool and hands out no authority by answering, so it reports effective entitlements rather than whatever the credential in hand happens to carry — see applyEffectiveEntitlements.

Identity and Entitlements are MANDATORY: whatever the scope, a caller must always learn who the server thinks they are and what they may do — that is the entire purpose of the tool. Identity falls back to the subject, which every credential carries, and an empty entitlement set serializes as `[]` rather than being dropped so a client can iterate without a nil check.

The profile fields ARE omitempty, and that is the privacy contract: they are scope-controlled claim families (see Signer.confineByScope), so absent means "this credential was not granted it" — which is information an empty string would not convey.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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