Skip to main content

Buildah component

Build container images with Buildah. The deprecated container component forwards to this implementation; new pipelines should include buildah directly. Build and push commands use Buildah. Image execution and OCI archive export still use Podman; the shared builder image supplies both tools.

Container images built from branches receive an immutable release tag composed of the normalized branch name and full commit SHA. Protected branches and the default branch also receive a mutable normalized branch tag. For example, a protected dev pipeline publishes dev and dev.<commit-sha>. The component sanitizes unsupported characters and truncates only the branch portion when necessary, keeping the complete tag within the OCI 128-character limit. Unprotected non-default branches and merge request pipelines publish only the commit-based tag, preventing them from overwriting shared mutable tags.

For private base images and publishing credentials, follow the central registry authentication guide.

Stable SemVer tag pipelines publish latest only when their tag is the newest stable release. Retrying an older release pipeline still publishes its immutable version tag without moving latest backwards.

Usage​

In a GitLab project, create a Containerfile:

FROM alpine:3.23

Create .gitlab-ci.yml:

include:
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/common@stable
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/buildah@stable
inputs:
name: myapplication
path: .

Run the pipeline. The build:myapplication job builds and publishes the image; its configured scanner jobs check the published image.

Set the image title and description​

For a CI build, set the project name to Orders API and the project description to HTTP API for creating and tracking orders. in GitLab under Settings > General > Naming, topics, avatar. The next build uses those values for org.opencontainers.image.title and org.opencontainers.image.description. The component does not read the context README.md for labels.

For a standalone build outside GitLab CI, set the same labels in the Containerfile:

FROM alpine:3.23
LABEL org.opencontainers.image.title="Orders API" \
org.opencontainers.image.description="HTTP API for creating and tracking orders."
buildah build -t localhost/orders-api:local .
podman image inspect localhost/orders-api:local --format '{{json .Config.Labels}}'

When the component supplies a nonempty value for a label, its Buildah --label option overrides the same label in the Containerfile.

OCI label (prefix org.opencontainers.image.)Default source
createdGitLab job start time (CI_JOB_STARTED_AT)
authorsCommit author (CI_COMMIT_AUTHOR)
url, sourceProject URL (CI_PROJECT_URL)
versionNormalized Git tag, or normalized branch and full SHA; full SHA when the branch is unavailable
revisionFull commit SHA (CI_COMMIT_SHA)
vendorRoot namespace (CI_PROJECT_ROOT_NAMESPACE), falling back to CI_PROJECT_NAMESPACE
titleProject title (CI_PROJECT_TITLE), falling back to CI_PROJECT_NAME
descriptionProject description (CI_PROJECT_DESCRIPTION)

A label is not added by the component if its value is empty.

Build from another Git repository​

Use a catalog release that lists the source-repository input. Set it to a git+https:// repository URL to build sources outside the job checkout. Public repositories need no credentials. Private GitLab sources use the shared Git authentication setup and require a token with access to the source project; keep credentials in CI/CD variables or Git's credential configuration, not URLs.

include:
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/common@stable
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/buildah@stable
inputs:
name: burpbountylab
source-repository: git+https://github.com/BountySecurity/BurpBountyLab.git
path: .

The builder clones the repository's default branch and logs its resolved commit. There is no branch, tag or commit selector. path and an optional containerfile-path are relative to the clone's root; absolute paths and paths or symlinks escaping that root fail. The temporary clone is removed on success or failure. Release artifacts remain in the job checkout, and image tags, publication, signing, scanning and existing commit-image reuse remain unchanged. An empty source-repository keeps the original local-context behavior.

Pass native build secrets​

Use a catalog revision that lists secrets as an array input. Create a GitLab CI/CD variable named PACKAGE_TOKEN, either an environment variable or a file variable. Pass an object containing its name, not its value, to secrets:

include:
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/common@stable
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/buildah@stable
inputs:
name: myapplication
secrets:
- name: PACKAGE_TOKEN

Consume it as a native secret file in your Containerfile:

FROM alpine:3.23
RUN --mount=type=secret,id=PACKAGE_TOKEN,required=true \
test -s /run/secrets/PACKAGE_TOKEN

Add one {name: VARIABLE_NAME} object per source. The default is []; strings, duplicate names and unsupported object fields are refused. Each name must identify an exported variable. An existing regular-file value is passed as a file source; other values, including values with line breaks, remain environment sources. Values are not added to the build command or its log, and caller-owned source files are not removed. File paths containing commas or newlines are refused.

For Buildah, an environment source still supplies a mounted file inside RUN, not an in-container environment variable. Set target, mode and uid on the RUN --mount instruction when needed. These are Containerfile options, not builder --secret options. The array currently accepts only name; component-level target, mode, uid and automatic in-container environment destinations are not supported. Both the container and buildah components accept this array. A reused commit image does not require build-only secret sources.

Pass build arguments to the container builder​

Use the args input when your Containerfile needs build-time values. List the names of exported CI/CD variables, separated by spaces. The builder receives their values through a private build-argument file; do not put --build-arg flags in this input.

include:
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/common@stable
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/buildah@stable
inputs:
name: myapplication
path: .
args: "APP_ENV CI_COMMIT_SHA"

variables:
APP_ENV: production

Example Containerfile consuming the build arguments:

FROM registry.access.redhat.com/ubi10/ubi-minimal:10.1
ARG APP_ENV=development
ARG CI_COMMIT_SHA
LABEL org.opencontainers.image.revision=$CI_COMMIT_SHA
RUN echo "Building for ${APP_ENV}"

Use Red Hat entitlement files during a build​

Make your entitlement certificates and keys available to the CI job at /etc/pki/entitlement, for example through a read-only Kubernetes Secret mount on the runner. The container and buildah components automatically mount that directory read-only at /etc/pki/entitlement for build RUN instructions. If the source directory is absent, the build continues without an entitlement mount.

For a different source location, set the job variable:

build:myapplication:
variables:
CI_CONTAINER_ENTITLEMENT_DIR: /run/secrets/redhat-entitlement

Use this override with a component whose name is myapplication. The directory must already exist inside the CI job. This does not register a subscription or supply entitlement files.

The files are bind-mounted, not copied into the build context or committed to image layers. They are unavailable when the resulting image runs. Do not copy them elsewhere from a RUN instruction: an explicit copy would persist in the image. The component test checks both builders with synthetic entitlement data, including read-only access during the build and absence in the resulting image.

Publish to your own registry​

The component can publish to any OCI-compatible registry, including a self-managed Harbor instance and Azure Container Registry. Configure the registry through component inputs and keep its credentials in GitLab CI/CD variables.

Configure the destination hostname and repository path, then follow the central registry authentication guide for credentials. It includes Harbor and Azure Container Registry account setup.

Publish to the registry via components:

include:
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/common@stable
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/buildah@stable
inputs:
name: myapplication
path: .

This publishes myapplication below $CI_REGISTRY/$CI_REGISTRY_PROJECT_PATH. Overriding the standard registry variables keeps the same component configuration portable between GitLab.com, self-managed GitLab, and external registries.

Test the configuration​

Run the pipeline from a branch that can read the configured credentials. The build log should report the selected registry and successful login without printing the password. The component test pipeline also publishes an expiring image to ttl.sh with test-only credentials, covering the authenticated OCI client path without retaining a permanent image.

Build timeout​

Build and image publication jobs default to a one-hour timeout. Set the timeout input when a build needs a different limit:

include:
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/buildah@stable
inputs:
name: app
path: container/app
timeout: 2h

The generated build:app job uses the two-hour limit. The Runner's maximum job timeout still applies. Scanner jobs keep their separate scanning timeout.

Trust a private certificate authority during builds​

Set CI_CA_BUNDLE_PATH to the absolute path of a readable PEM-encoded CA bundle inside the CI job container. Make the file available at that path before the build starts, including any public roots needed by package repositories. The image's original certificates are not merged into this bundle. The buildah and container components automatically mount the validated input certificates read-only during each RUN. Existing native stores need no Containerfile changes or privileged image user. Minimal base images need the initial store setup described below.

include:
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/common@stable
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/buildah@stable
inputs:
name: app
path: container/app

If the runner already supplies a bundle, leave the generated job unchanged to use it. To override it for this build, set the path in the job before the component starts. The replacement file must be readable inside the job:

build:app:
before_script:
- export CI_CA_BUNDLE_PATH="$CI_PROJECT_DIR/certs/build-roots.pem"

To disable injection for the same job instead, use unset CI_CA_BUNDLE_PATH in its before_script. Other jobs retain the runner default. Keep any existing before_script steps when adding the override. The build logs one summary with the effective path, certificate count and whether injection is enabled; it does not print the PEM. Per-RUN hook messages are shown only with CI_DEBUG_TRACE=true.

In non-root jobs, CI Tools adds the supplied root certificates to a private copy of the system bundle for Podman, Buildah, curl and Git. This does not modify the system store. It is separate from the trust mounted inside each build step.

For Debian and Red Hat images with existing native trust stores, the hook populates temporary filesystems at standard OS trust paths from only your injected bundle. Each directory contains the bundle and hashed certificate links, so native tools do not need environment variable support. These temporary stores work for root and non-root image users. On RHEL, the image’s separate code-signing bundle stays available to NuGet. The injected TLS roots do not become package signers. The temporary stores are writable for package trust-update scripts; changes last only for that RUN. Each new RUN starts again from your supplied bundle. Explicit trust updates within a command can replace the temporary trust for that command.

Minimal images without a native store initially receive no native overlay. This leaves their first CA-package installation visible in the image instead of hiding its default store on a temporary filesystem. A later RUN with that store present receives the native overlay. Install the image's CA package before a command that needs native private-CA trust. The injected CA is never written to the package's permanent sources.

The hook does not set SSL_CERT_FILE, SSL_CERT_DIR, CURL_CA_BUNDLE or REQUESTS_CA_BUNDLE: OpenSSL, curl and Python must use the OS trust paths. It exports NODE_EXTRA_CA_CERTS because Node uses its own built-in roots. Node adds the injected certificates to its built-in roots for that RUN; this replaces any previous NODE_EXTRA_CA_CERTS value. It does not change the resulting image's Node trust. Applications with other private trust paths need their own configuration. The hook does not call OS trust-update scripts or write injected certificates to permanent trust sources.

When JAVA_HOME provides bin/keytool, the hook creates a new Java trust store containing only the injected certificates on a temporary filesystem. It never extends or copies the image's default Java store. It appends the temporary store settings to JAVA_TOOL_OPTIONS, preserving existing options. Import failures fail the build. An unset JAVA_HOME or unavailable keytool is reported without a Java import.

The source bundle, scripts, generated OS bundles and Java store do not enter image layers. All trust mounts disappear after each build command; the resulting image retains its underlying trust stores. Applications needing the injected certificates at runtime must receive them separately. Explicitly copying mounted certificates elsewhere in a Containerfile can still persist them; do not copy them into image paths if they must remain build-only.

Hook environment variables apply only to RUN; they do not add runtime ENV settings to the image. The hook preserves the original command, arguments, and image USER, and passes the mounted path as the CI_CA_BUNDLE_PATH build argument.

Without a CA bundle, the component leaves the image's trust stores unchanged. A configured but unreadable, empty, or invalid bundle fails before the builder starts. Base images must provide /bin/sh and standard file utilities for hook execution.

The component enforces --isolation=rootless for builds, even when the CI job runs as UID 0 or supplies a different isolation option. This mode runs OCI hooks with or without a custom CA. Pass --hooks-dir explicitly for your own hooks when running Buildah rootless. The runner must allow the nested OCI runtime to start; the build does not fall back to chroot.

When a CA is configured, the build uses a job-local runtime adapter for crun or runc. The chroot isolation does not run an OCI runtime, and Buildah does not accept the precreate stage in --hooks-dir. The adapter updates the OCI process configuration before runtime creation, then delegates all runtime arguments unchanged. An explicit --runtime choice is retained as the underlying runtime; CI_CONTAINER_CA_RUNTIME can also name one. The runner must support OCI execution; no privilege or capability is added.

Inputs​

NameDescriptionDefaultType
------------
argsArguments to pass to the builder.string
cache-enabledShould registry-backed build cache be used?falseboolean
containerfile-pathAlternate path to the Containerfile, if either Dockerfile or Containerfile in the conect directory.string
dependenciesThe dependencies that this job depends on.[]array
nameName for the pipeline jobs and the container.containerstring
needsThe jobs that this job depends on.[]array
pathPath to the directory containing Container sources / context..string
registryRegistry to store container image releases in$CI_REGISTRYstring
repository-pathRepository to store container image releases in$CI_REGISTRY_PROJECT_PATHstring
rulesThe jobs that this job depends on.[{"if":"$CI_PIPELINE_SOURCE == \"schedule\"","when":"never"},{"if":"$CI_PIPELINE_SOURCE == \"merge_request_event\"","when":"on_success"},{"when":"on_success"}]array
scannersScanners to use. none, vuln, license, secret, misconfig["vuln","secret","license","misconfig"]array
scanning-allow-failureShould the pipeline fail if scanning the built container image fails?falseboolean
scanning-enabledShould the built container image be scanned?trueboolean
scanning-ignore-unfixedExclude vulnerabilities that do not have a fix available.trueboolean
scanning-severityWhat level of severity should cause scanning of the built container to fail?CRITICALstring
scanning-timeoutHow long should the scanning process be allowed to run before timing out? Use format e.g. 5m0s30m0sstring
secretsArray of native build secret sources, each with a GitLab CI/CD variable name.[]array
signing-enabledShould the built container image be signed?trueboolean
source-repositoryOptional git+https repository to clone; path and containerfile-path are relative to its root. Empty uses the job checkout.string
stageThe pipeline stage that the jobs belongs to.buildstring
tagsThe runners that this job depends on.[]array
timeoutMaximum duration of the build and image publication job.1hstring
versionInternal version of the nested component to use.mainstring