Skip to content

function-oci-v0.3.0

Choose a tag to compare

@jonasz-lasut jonasz-lasut released this 13 Nov 17:40
b5a7187

Caution

This is a security release, and every installation of 0.2.0 should upgrade. A module's process could exhaust the pod's memory with its output, an image could do the same when its layers were unpacked, and two checks on a module's signature and repository could be stepped around. After the upgrade an image may unpack to at most eight times --module-size-limit, a policy that names a repository in a non-canonical spelling stops the runtime at startup, and every stored image is unpacked again once. Read "Before you upgrade".

function-oci 0.3.0 bounds what a module and its image can take from the runtime, closes several ways around a policy, and makes a run faster: the root filesystem is packed with zstd, and a caller gets its response before the VM is torn down. The Input, the manifest and the contract an image implements are unchanged, and an image that ran on 0.2.0 runs without a rebuild.

Before you upgrade

Check the repository names in your policies. The runtime now reads the registry part of every OCI reference into one canonical form, and refuses a policy, the operator's or a compositionPolicy, that names a Repository in another spelling. The operator policy is checked at startup, so run function validate with the new version against your policy file first. The refusal gives the name to write:

Repository::"GHCR.IO/acme/prod" is not the canonical name of that repository; write Repository::"ghcr.io/acme/prod"

The canonical form is a lowercase host with no trailing dot and no default port, and Docker Hub is index.docker.io, as before.

Check image references that depended on a spelling. A reference with user information in its registry part (user:password@registry/…) is refused. So are a shorthand IP address such as 127.1 and a non-ASCII host name. A registry is reached over plain HTTP only when its host is exactly localhost or a loopback IP address.

Check large images. What an image's layers unpack to is bounded to eight times --module-size-limit and to a million entries. A larger image is refused at load with image unpacks to more than … bytes, eight times the size limit (--module-size-limit): raise the flag or build a smaller image.

Check policies with a forbid that leaves its action unconstrained, forbid (principal, action, resource) when { … };. On 0.2.0 such a rule did nothing for composeResource, requireResource and the sandbox actions of a compositionPolicy. On 0.3.0 it applies to them, so a module whose output, reads or requirements the rule matches is refused.

Expect the first run of every image to be slow once. A stored root filesystem and its VM snapshot from 0.2.0 aren't reused: each image is unpacked, packed and snapshotted again the first time it runs.

If you run your own guest kernel, it needs squashfs with zstd built in (CONFIG_SQUASHFS_ZSTD). The kernel in the package has it. Without it no VM mounts its root filesystem, and a run ends at its deadline with the guest did not connect before the deadline.

If you watch guestfn_module_run_duration_seconds, expect it about 20 ms lower. It's now observed when the caller has its response, as the metrics page describes it, and no longer includes the VM's teardown.

Security

A process's output was buffered without a bound

The host collects what a module's process writes to stdout and stderr, to log it and to quote its last line when the process fails. It kept all of it in memory for the length of the run, outside the VM's memory limit. A process that wrote continuously could exhaust the memory of the function's pod and flood its log.

0.3.0 keeps the last 256 KiB of a run's output and says in one warning how much it dropped, and cuts a logged line at 16 KiB (OCI modules, #356).

An image was unpacked without a bound

--module-size-limit bounded the compressed bytes the runtime pulled and nothing bounded what they expand to. A layer that compresses very well, or a tar header stating a very large entry, ended the pod when the image was loaded, before any run-time limit applies.

0.3.0 bounds what the layers unpack to, as "Before you upgrade" describes, and reserves nothing from a header's stated size. It also unpacks layers as a container runtime does: whiteouts apply to the lower layers alone, an entry under a symbolic link to a directory goes where the link leads inside the image, and an entry with a .. segment, one under a file, and a hard link to a file that isn't in the image are refused (Troubleshooting, #358).

A verified signature was remembered by digest alone

The runtime verifies an image's signature once per process and remembers the verdict. It remembered it under the manifest digest, without the repository. The trustSigner rules decide per repository, so once a digest had been verified in a repository whose signer the policy trusts, the same digest referenced from another repository loaded without a check against that repository's rules.

0.3.0 remembers a verdict per repository and digest (Signatures, #357).

A registry had more than one spelling

The policies compared an image's location as it was written. GHCR.IO/acme/x, ghcr.io:443/acme/x and ghcr.io./acme/x reach the same repository as ghcr.io/acme/x, and none of them matched a rule written for it, so a Composition author could step around a requireSignature or forbid rule with such a spelling.

0.3.0 reads the registry part into one canonical form before any policy, signature check or message uses it, refuses a reference whose registry part isn't a host, and refuses a policy that names a repository in another spelling (The canonical registry, #357).

A forbid of any action didn't apply to the fences

A policy layer judges composeResource, requireResource and, in a compositionPolicy, the sandbox actions only where one of its rules specifies the action. A forbid with an unconstrained action specifies none, so the layer wasn't consulted and the rule never applied. In 0.3.0 such a rule applies to those actions without scoping them: where no other rule specifies the action, the layer refuses what the forbid matches and permits the rest (The composition layer, #360).

Smaller hardening

  • A registry's manifest is read up to 4 MiB and a token endpoint's answer up to 1 MiB (#360).
  • The metrics and health listeners give a connection five seconds to send its request (#359).
  • The VM's root filesystem, its overlay and /tmp are mounted nodev and nosuid (#362).

For operators

A run is faster

The runtime packs an image's root filesystem with zstd instead of gzip. The guest reads it faster on every run, cold or restored from a snapshot, and the stored image is the same size. For the Go example, a 37 MiB image, a cold run went from 552 to 436 ms and a restored run from 448 to 321 ms, measured on a GitHub-hosted runner under nested KVM. Packing an image at its first load is faster too, 173 ms against 1,450 ms (#382).

A caller also gets its response as soon as the function has answered. The runtime used to stop the VM first, which took about 20 ms. The VM is now stopped in the background, and the run's slot and its memory reservation stay held until it's gone, so --max-concurrent-runs and the memory pool bound what they did. A step's own limits.concurrency ends with the call, so a step can for a moment have one more VM being stopped (#382).

A loaded image's root filesystem survives the disk sweep

With --max-cache-size set, the sweep could remove the stored root filesystem of an image still loaded in memory, and every later run of that image failed until it left memory. The runtime now holds the file while the image is loaded, and the sweep skips it. The stores can therefore stay over the bound while the loaded images alone exceed it (Runtime flags, #362).

A multi-platform image keeps loading

An image referenced by its index, as a multi-platform image is, could be refused with … is an image index; reference the manifest holding the module once the runtime had loaded a few thousand modules and the image was still cached. The runtime now reads the platform's manifest in that case as it does on a first load (#384).

Other fixes

  • A failed VM snapshot removes its unfinished files, which the sweep didn't see (#362).
  • A limits.memory or limits.timeout with a fraction too long to compute is refused as not valid, where it wrapped to a wrong value (#384).
  • A new compositionPolicy no longer delays the requests that carry another policy while it's compiled (#384).
  • A grpc-timeout too large to state as a deadline is read as none (#369).

The package is signed in the run that publishes it

From this release the package's provenance names the workflow that built it at the release's tag, and the tag's commit. The signer identity is unchanged, supplychain.yml@refs/heads/main, so a cosign verify command or an ImageConfig written for 0.2.0 keeps working (Verify the package, #365).

Merged pull requests

Full changelog: function-oci-v0.2.0...function-oci-v0.3.0