Function Runtime Permissions and Mounts#
kpt enforces hermetic execution for container-based KRM functions by default — no network access, no host filesystem access. Privileged capabilities (network, mounts, exec binaries) require explicit opt-in, and the available options differ between kpt fn render and kpt fn eval.
Key Types and Files#
| File | Purpose |
|---|---|
pkg/lib/runneroptions/runneroptions.go | RunnerOptions struct — top-level permission flags surfaced to CLI commands |
pkg/fn/runtime/container.go | ContainerFnPermission struct; builds the container run command |
pkg/fn/runtime/runner.go | NewRunner — wires RunnerOptions into a ContainerFn for fn render |
thirdparty/kyaml/runfn/runfn.go | defaultFnFilterProvider — wires permissions into ContainerFn for fn eval |
thirdparty/cmdconfig/commands/cmdeval/cmdeval.go | CLI flag definitions for fn eval (--network, --mount, --as-current-user) |
commands/fn/render/cmdrender.go | CLI flag definitions for fn render (--allow-network, --allow-exec) |
Permission Model#
RunnerOptions (render-level flags)#
RunnerOptions centralizes flags that both commands share:
AllowExec— permits binary executables in the pipeline (render only; eval always uses--exec).AllowNetwork— allows container functions to access the network (off by default).AllowWasm— alpha; enables Wasm function runtime.ImagePullPolicy— controls whether to pull images (always|ifNotPresent|never); defaults toIfNotPresent.
ContainerFnPermission (container-level gates)#
ContainerFnPermission has two boolean fields applied when building the docker run (or podman/nerdctl) command:
AllowNetwork— maps to--network none(default) or--network host.AllowMount— gates whetherStorageMountsare appended to therunargs .
--security-opt=no-new-privileges is always passed , and the container user defaults to nobody unless UIDGID is set .
fn render vs fn eval: Permission Differences#
fn render#
fn render is the declarative path. It executes functions declared in the Kptfile pipeline and is intentionally more restricted .
--allow-networksetsRunnerOptions.AllowNetwork→ forwarded toContainerFnPermission.AllowNetwork.- No
--mountflag exists.AllowMountis hardcoded tofalseinNewRunnerwith a comment that it may change in the future . --allow-execis required to run binary functions; omitting it blocks exec-based pipeline steps .- No
--as-current-user; containers always run asnobodyduring render.
fn eval#
fn eval is the imperative path. Since the user explicitly specifies the function, it permits more privileged access .
--network→ setsNetwork: trueonRunFns, forwarded toContainerFnPermission.AllowNetwork.--mount→ parses mount strings viatoStorageMounts()into[]runtimeutil.StorageMount, then setsStorageMountsonContainerFn;AllowMountis hardcoded totruefor eval .--as-current-user→ resolvesuid:gidviagetUIDGID()and setsUIDGIDonContainerFn, allowing the container to access host paths owned by the running user .--env/-e→ passes environment variables into the container; unavailable for exec-based functions .--mount,--as-current-user,--network, and--envare container-only — using them with--execreturns an error .
Capability Matrix#
| Capability | fn render | fn eval |
|---|---|---|
| Network access | --allow-network | --network |
| Host mounts | ❌ not supported | --mount |
| Run as current user | ❌ not supported | --as-current-user |
| Binary exec functions | --allow-exec | --exec (always permitted) |
| Inject env vars | ❌ not supported | --env / -e |
Mount Format#
--mount accepts Docker volume syntax :
--mount type=bind,src="/path/to/dir",dst=/mount-point
All volumes are read-only by default. Pass rw=true to mount read-write:
--mount type=bind,src="/path/to/dir",dst=/mount-point,rw=true
Because container functions default to running as nobody, host paths may be inaccessible without --as-current-user.
Container Runtime Selection#
The runtime binary (docker, podman, or nerdctl) is selected via the KRM_FN_RUNTIME environment variable. When unset, docker is used . Minimum supported Docker version is v20.10.0 .