Documentation
¶
Overview ¶
Package kubeworkload defines how managed MCP workloads are secured.
It provides the restricted pod and container security contexts, the workload ServiceAccount, the operator's secret and trust-bundle access, the per-server ingress NetworkPolicy, and parsing of the cluster-admin egress CIDRs that become pod egress ipBlocks (ParseEgressCIDRs, EgressBlocks). The default route is rejected so a cluster cannot open every address by accident.
Index ¶
- Constants
- func ApplyRestrictedPodDefaults(spec *corev1.PodSpec)
- func EnsureOperatorSecretAccess(ctx context.Context, client kubernetes.Interface, namespace string) error
- func EnsureOperatorTrustBundleAccess(ctx context.Context, client kubernetes.Interface, namespace string) error
- func EnsureServiceAccount(ctx context.Context, client kubernetes.Interface, namespace string) error
- func OperatorSecretNamespaceProtected(namespace string) bool
- func ParseEgressCIDRs(raw string) ([]netip.Prefix, error)
- func RestrictedContainerSecurityContext() *corev1.SecurityContext
- func RestrictedPodSecurityContext() *corev1.PodSecurityContext
- func RestrictedReadOnlyContainerSecurityContext() *corev1.SecurityContext
- func ServerIngressPolicy(namespace, name, uid string, gateway, mtls bool, ingressNamespace string, ...) networkingv1.NetworkPolicySpec
- func ServiceAccount(namespace string) *corev1.ServiceAccount
- type EgressBlock
Constants ¶
const ( // DefaultServiceAccountName is the service account used by managed MCP workloads. DefaultServiceAccountName = "mcp-workload" // RestrictedRunAsUser is the non-root user used by managed workload pods. RestrictedRunAsUser = int64(65532) )
const ( ServerUIDLabel = "mcpruntime.org/server-uid" PlatformManagedLabel = "platform.mcpruntime.org/managed" )
const ( OperatorSecretAccessName = "mcp-runtime-operator-managed-secrets" // #nosec G101 -- ClusterRole name, not a credential // OperatorWorkloadAccessName grants Deployment, ServiceAccount and // Certificate mutation, which are indirect routes to a Secret. OperatorWorkloadAccessName = "mcp-runtime-operator-managed-workloads" OperatorServiceAccountName = "mcp-runtime-operator-controller-manager" OperatorNamespace = "github.com/mcp-runtime/mcp-runtime" OperatorTrustBundleName = "mcp-adapter-client-ca" // #nosec G101 -- object name, not a credential )
Variables ¶
This section is empty.
Functions ¶
func ApplyRestrictedPodDefaults ¶
ApplyRestrictedPodDefaults applies the shared restricted pod defaults.
func EnsureOperatorSecretAccess ¶
func EnsureOperatorSecretAccess(ctx context.Context, client kubernetes.Interface, namespace string) error
EnsureOperatorSecretAccess binds the operator's namespace-local Secret and workload roles. It is invoked only after the installer or platform has established that the namespace hosts managed MCPServers.
func EnsureOperatorTrustBundleAccess ¶
func EnsureOperatorTrustBundleAccess(ctx context.Context, client kubernetes.Interface, namespace string) error
EnsureOperatorTrustBundleAccess pre-creates the public CA bundle Secret and grants only named get/update/patch. Kubernetes cannot restrict create by resourceNames, so the operator never gets Secret create in the TLS namespace. An existing bundle is preserved; the operator refreshes it after issuance.
func EnsureServiceAccount ¶
EnsureServiceAccount creates or updates the restricted workload ServiceAccount.
func OperatorSecretNamespaceProtected ¶
OperatorSecretNamespaceProtected excludes infrastructure and prospective namespace domains from tenant Secret grants, including before migration.
func ParseEgressCIDRs ¶
ParseEgressCIDRs accepts a comma-separated list of canonical prefixes. IPv4 prefixes must be /8 or longer, and IPv6 prefixes must be /32 or longer.
func RestrictedContainerSecurityContext ¶
func RestrictedContainerSecurityContext() *corev1.SecurityContext
RestrictedContainerSecurityContext returns the shared container-level security context.
func RestrictedPodSecurityContext ¶
func RestrictedPodSecurityContext() *corev1.PodSecurityContext
RestrictedPodSecurityContext returns the shared pod-level security context.
func RestrictedReadOnlyContainerSecurityContext ¶
func RestrictedReadOnlyContainerSecurityContext() *corev1.SecurityContext
RestrictedReadOnlyContainerSecurityContext returns the shared read-only security context.
func ServerIngressPolicy ¶
func ServerIngressPolicy(namespace, name, uid string, gateway, mtls bool, ingressNamespace string, ingressLabels map[string]string) networkingv1.NetworkPolicySpec
ServerIngressPolicy describes the actual public listener, never the raw upstream behind a gateway. Named ports keep retained/candidate pod revisions correct during a serving-port change. The namespace's generic workload policy must exclude MCPServer pods: NetworkPolicy allows are additive.
func ServiceAccount ¶
func ServiceAccount(namespace string) *corev1.ServiceAccount
ServiceAccount returns the restricted workload ServiceAccount object.
Types ¶
type EgressBlock ¶
EgressBlock is one NetworkPolicy ipBlock: a destination prefix minus cluster ranges that must stay on the normal pod policy.
func EgressBlocks ¶
func EgressBlocks(allows, except []netip.Prefix) ([]EgressBlock, error)
EgressBlocks returns ipBlock entries for allows, subtracting except prefixes that fall inside each allow. A private allow with no contained exception is rejected so the cluster pod and service ranges are not opened by accident.