envutil

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: AGPL-3.0 Imports: 5 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

Overview

Package envutil provides shared helpers for building process environment variable slices from os.Environ() plus a caller-supplied override map.

It depends only on the standard library so that any sub-package of internal/worker can import it without creating a cycle.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BaseEnv added in v0.3.0

func BaseEnv(p Policy) map[string]string

BaseEnv returns the portion of the daemon environment a job-supplied process may inherit. It governs only inherited variables; variables the job itself supplies are never filtered (see BuildFromBase).

func Build

func Build(overrides map[string]string) []string

Build constructs a process environment slice by starting from os.Environ() and applying overrides on top. Keys present in overrides take precedence over the inherited environment. When overrides is empty the raw os.Environ() slice is returned directly (no allocation).

The output format is "KEY=VALUE", matching exec.Cmd.Env expectations. Output order is non-deterministic (map iteration); callers must not rely on any specific ordering.

func BuildFromBase added in v0.3.0

func BuildFromBase(base, overrides map[string]string, unset map[string]bool) []string

BuildFromBase renders a process environment from an already-filtered base, applying job-supplied overrides on top and then removing every key in unset.

Filtering happens exactly once, when base is built by BaseEnv at session creation. Everything in overrides is job data — static Environment.variables, dynamic openjd_env exports, task template variables — and passes through unfiltered. Re-filtering here would drop a job's own exports, whose names no operator allowlist would contain.

func BuildWithUnset

func BuildWithUnset(overrides map[string]string, unset map[string]bool) []string

BuildWithUnset is like Build but additionally removes every key in unset from the resulting environment — including keys inherited from os.Environ() and keys supplied via overrides. This implements OpenJD's openjd_unset_env directive, where a variable must be absent from a subsequent action's environment even if it was set by the worker's own environment or by a static environment Variables entry.

Removal is applied after overrides, so a key present in both overrides and unset is removed. When unset is empty the call is equivalent to Build.

The output format is "KEY=VALUE"; output order is non-deterministic.

Types

type Policy added in v0.3.0

type Policy struct {
	// Allowlist holds variable name patterns inherited in addition to
	// minimalBase, matched with filepath.Match semantics. Matching is
	// case-insensitive on Windows, mirroring that platform's own rules.
	Allowlist []string
	// Enabled reports whether filtering applies at all.
	Enabled bool
}

Policy controls how much of the worker daemon's own environment is inherited by job-supplied processes.

When Enabled is false the entire daemon environment is inherited. When true, only minimalBase plus Allowlist survive, which stops daemon credentials (AWS keys, mount secrets, license tokens) reaching job code.

Jump to

Keyboard shortcuts

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