admin

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package admin implements the platform-admin surface mounted at /api/admin/* and surfaced in the portal's gated /bonkers area. It lets a platform admin see all users / organizations / providers / root identities. It is read-only: provider provisioning (workspace + ServiceAccount + kubeconfig) is driven declaratively by the Provider CR reconciler (pkg/hub/providers/provider_controller.go), not by an admin HTTP action.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Middleware

func Middleware(resolver UserResolver, checker AdminChecker) func(http.Handler) http.Handler

Middleware gates a subrouter so only platform admins reach it: 401 when no identity resolves, 403 when the caller is authenticated but not an admin.

Types

type AdminChecker

type AdminChecker interface {
	IsAdmin(ctx context.Context, userName string) bool
}

AdminChecker decides whether a resolved caller is a platform admin. The hub supplies an implementation that matches the User CR's name / email / rbacIdentity against the --admin-users allowlist.

type AdminCheckerFunc

type AdminCheckerFunc func(ctx context.Context, userName string) bool

AdminCheckerFunc adapts a function to AdminChecker.

func (AdminCheckerFunc) IsAdmin

func (f AdminCheckerFunc) IsAdmin(ctx context.Context, userName string) bool

IsAdmin implements AdminChecker.

type Handler

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

Handler serves the /api/admin/* endpoints.

func NewHandler

func NewHandler(svc *Service, userClient *farosclient.Client, registry *providers.Registry) *Handler

NewHandler builds an admin Handler.

func (*Handler) Register

func (h *Handler) Register(r *mux.Router)

Register mounts the admin routes on r (already gated by the admin Middleware).

type OnboardedWorkspace

type OnboardedWorkspace struct {
	Name    string
	Cluster string
	Phase   string
}

OnboardedWorkspace mirrors providers.OnboardedWorkspace for the admin API.

type OrgWorkspace

type OrgWorkspace struct {
	UUID                string     `json:"uuid"`
	DisplayName         string     `json:"displayName"`
	ClusterName         string     `json:"clusterName"`
	Providers           []string   `json:"providers"`
	DeletionRequestedAt *time.Time `json:"deletionRequestedAt,omitempty"`
}

OrgWorkspace is a child Workspace of an organization together with the provider names enabled in it (derived from the workspace's provider APIBindings).

type RootIdentity

type RootIdentity struct {
	Group        string `json:"group"`
	Resource     string `json:"resource"`
	IdentityHash string `json:"identityHash"`
	Export       string `json:"export"`
	Path         string `json:"path"`
}

RootIdentity is one (group, resource) served by a first-party APIExport, together with the identityHash kcp minted for it. The admin copies the hash a provider needs (e.g. edges.faros.sh for kuery) into that provider's Helm values so its `init` can stamp it onto the APIExport's permissionClaim.

type Service

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

Service performs read-only admin queries against kcp.

func NewService

func NewService(kcpConfig *rest.Config, _, _ string) *Service

NewService returns an admin Service. hubExternalURL/providerInternalURL are accepted for call-site compatibility but no longer used now that provider provisioning (which baked a server URL into minted kubeconfigs) moved to the Provider CR reconciler.

func (*Service) CreateProvider

func (s *Service) CreateProvider(ctx context.Context, name, displayName string) error

CreateProvider create-or-updates a Provider object in root:faros:system:providers. name drives the provisioned sub-workspace (root:faros:providers:<name>); displayName is informational. Idempotent.

func (*Service) DeleteProvider

func (s *Service) DeleteProvider(ctx context.Context, name string) error

DeleteProvider removes a Provider object from root:faros:system:providers. The reconciler's finalizer then tears down the sub-workspace. Idempotent.

func (*Service) GetProviderKubeconfig

func (s *Service) GetProviderKubeconfig(ctx context.Context, name string) ([]byte, error)

GetProviderKubeconfig returns the minted kubeconfig the Provider controller wrote into a Secret in root:faros:system:providers. It reads the Provider's status.secretRef to locate the Secret (falling back to the "<name>-kubeconfig" / "default" / "kubeconfig" conventions). Returns a nil slice + nil error when the Provider exists but hasn't been provisioned yet (no Secret), so callers can surface "not ready".

func (*Service) ListOnboardedWorkspaces

func (s *Service) ListOnboardedWorkspaces(ctx context.Context) ([]OnboardedWorkspace, error)

ListOnboardedWorkspaces returns the provider sub-workspaces created by onboarding, so the admin UI can show providers that have been onboarded but whose Helm chart (and CatalogEntry) is not yet installed.

func (*Service) ListOrgWorkspaces

func (s *Service) ListOrgWorkspaces(ctx context.Context, orgUUID string) ([]OrgWorkspace, error)

ListOrgWorkspaces returns every child Workspace under the org at root:faros:tenants:{orgUUID}, enriched with display name, cluster name, soft-delete timestamp and the set of enabled provider names. Reads run with kcp-admin credentials, so the admin surface sees all workspaces regardless of per-user RBAC. Per-workspace lookups are best-effort: a workspace that hasn't reached Ready (no cluster) or whose provider listing fails still appears with whatever fields resolved.

func (*Service) ListRootIdentities

func (s *Service) ListRootIdentities(ctx context.Context) ([]RootIdentity, error)

ListRootIdentities returns the (group, resource → identityHash) tuples served by the APIExports in the providers parent workspace. An empty identityHash means kcp has not minted the export's identity yet.

type UserResolver

type UserResolver interface {
	ResolveUser(r *http.Request) (string, error)
}

UserResolver maps an inbound request to the caller's User CR name, or returns an error if no identity can be resolved. Mirrors tenant.UserResolver so the hub can reuse the same OIDC IdentifyUser plumbing.

type UserResolverFunc

type UserResolverFunc func(r *http.Request) (string, error)

UserResolverFunc adapts a function to UserResolver.

func (UserResolverFunc) ResolveUser

func (f UserResolverFunc) ResolveUser(r *http.Request) (string, error)

ResolveUser implements UserResolver.

Jump to

Keyboard shortcuts

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