DirectorySecurity AdvisoriesPricing
Sign in
Directory
crossplane-function-python logo

crossplane-function-python

packaged by Chainguard

Last changed
Request a free trial

Contact our team to test out this image for free. Please also indicate any other images you would like to evaluate.

Tags
Overview
Comparison
Provenance
Specifications
SBOM
Vulnerabilities
Advisories

Chainguard Container for crossplane-function-python

This composition function runs Python scripts written inline in a Crossplane Composition or Operation to compose resources and perform operational tasks.

Chainguard Containers are regularly-updated, secure-by-default container images.

Download this Container Image

For those with access, this container image is available on cgr.dev:

docker pull cgr.dev/ORGANIZATION/crossplane-function-python:latest

Be sure to replace the ORGANIZATION placeholder with the name used for your organization's private repository within the Chainguard Registry.

Compatibility Notes

The Chainguard crossplane-function-python container image is a drop-in replacement for the upstream function-python Crossplane package published at xpkg.upbound.io/crossplane-contrib/function-python. The image ships the function together with the Crossplane package metadata and the Script CRD in /package.yaml, so you can reference it directly in a Function resource. Like the upstream image, it installs the function into a virtual environment at /venv/fn and uses /venv/fn/bin/function as the entrypoint, so a DeploymentRuntimeConfig that overrides the container command keeps working.

The image differs from upstream in the following ways:

  • It is built on Chainguard OS instead of gcr.io/distroless/python3-debian13, which removes the operating system packages that account for most of the upstream image's vulnerabilities.
  • It runs the Chainguard OS Python, which can be a newer minor release than the one the Debian base upstream builds on provides. Upstream's pyproject.toml supports a range of minor releases that includes it, and upstream runs lint and its unit tests on the newer one, so scripts run on an interpreter upstream tests against.
  • grpcio is the PyPI wheel, as upstream ships it, which statically vendors its own copy of BoringSSL. The version is the same one upstream resolves.
  • pip is not kept in the virtual environment. The environment is managed by the package manager, and the function does not install anything at runtime.
  • It does not declare ExposedPorts. The gRPC server still listens on port 9443 by default, and Crossplane names that port on the runtime container itself.
  • It sets GRPC_DEFAULT_SSL_ROOTS_FILE_PATH to the system CA bundle, which upstream does not. Without it, a gRPC client created inside a script would trust grpcio's bundled roots.pem rather than the image's trust store.

Prerequisites

You need a Kubernetes cluster with Crossplane v2.0 or later installed. If Crossplane is not installed yet, install it with Helm:

helm repo add crossplane-stable https://charts.crossplane.io/stable
helm repo update
helm install crossplane --namespace crossplane-system --create-namespace crossplane-stable/crossplane

Getting Started

Crossplane's package manager pulls the package itself, so it needs credentials for your private repository in the namespace Crossplane runs in. Create a pull token, export its username and password as CGR_USERNAME and CGR_PASSWORD, then run:

kubectl create secret docker-registry cgr-pull-secret \
  --namespace crossplane-system \
  --docker-server=cgr.dev \
  --docker-username="$CGR_USERNAME" \
  --docker-password="$CGR_PASSWORD"

Create a Function resource that points at the Chainguard image:

cat > function.yaml <<EOF
apiVersion: pkg.crossplane.io/v1
kind: Function
metadata:
  name: function-python
spec:
  package: cgr.dev/ORGANIZATION/crossplane-function-python:latest
  packagePullSecrets:
    - name: cgr-pull-secret
EOF
kubectl apply -f function.yaml

Wait for Crossplane to install the function and report it as healthy:

kubectl wait --for=condition=Healthy function.pkg.crossplane.io/function-python --timeout=300s

Configuration

Composition steps pass Python code to the function through a Script input. The script defines a compose function that receives the RunFunctionRequest and a pre-populated RunFunctionResponse, and modifies the response. Writing to the desired composite resource is a convenient way to surface computed values in the composite resource's status.

Define the XGreeting composite resource type the script computes a status for:

cat > xrd.yaml <<EOF
apiVersion: apiextensions.crossplane.io/v1
kind: CompositeResourceDefinition
metadata:
  name: xgreetings.example.io
spec:
  group: example.io
  names:
    kind: XGreeting
    plural: xgreetings
  versions:
    - name: v1alpha1
      served: true
      referenceable: true
      schema:
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object
              properties:
                name:
                  type: string
                replicas:
                  type: integer
            status:
              type: object
              properties:
                greeting:
                  type: string
                doubled:
                  type: integer
                digest:
                  type: string
EOF
kubectl apply -f xrd.yaml

The following Composition computes the three status fields:

cat > composition.yaml <<EOF
apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
  name: python-greeting
spec:
  compositeTypeRef:
    apiVersion: example.io/v1alpha1
    kind: XGreeting
  mode: Pipeline
  pipeline:
    - step: render-status
      functionRef:
        name: function-python
      input:
        apiVersion: python.fn.crossplane.io/v1beta1
        kind: Script
        script: |
          import hashlib

          from crossplane.function.proto.v1 import run_function_pb2 as fnv1

          def compose(req: fnv1.RunFunctionRequest, rsp: fnv1.RunFunctionResponse):
              spec = req.observed.composite.resource["spec"]
              rsp.desired.composite.resource.update({
                  "status": {
                      "greeting": "Hello, " + spec["name"],
                      "doubled": int(spec["replicas"]) * 2,
                      "digest": hashlib.sha256(spec["name"].encode()).hexdigest(),
                  }
              })
EOF
kubectl apply -f composition.yaml

Create a composite resource and the function fills in its status:

cat > xr.yaml <<EOF
apiVersion: example.io/v1alpha1
kind: XGreeting
metadata:
  name: test-greeting
spec:
  name: chainguard
  replicas: 3
EOF
kubectl apply -f xr.yaml
kubectl wait --for=jsonpath='{.status.greeting}'="Hello, chainguard" xgreeting/test-greeting --timeout=120s
kubectl get xgreeting test-greeting -o jsonpath='{.status.greeting}{"\n"}{.status.doubled}{"\n"}{.status.digest}{"\n"}'
Hello, chainguard
6
9e6d67222e41669b46f524d6df8cdc5e4713449388a336a80fb678403bee0f16

Scripts have access to the function-sdk-python package as crossplane.function and to the full Python standard library. This image also ships aioboto3, which upstream includes so that scripts can call AWS APIs. Defining the function as async def compose lets the function serve other requests while the script waits on network calls.

Operations are an alpha feature, so Crossplane must run with --enable-operations (chart value args: ["--enable-operations"]). A script that defines an operate function instead of compose runs as part of a Crossplane Operation:

apiVersion: ops.crossplane.io/v1alpha1
kind: Operation
metadata:
  name: check-cert-expiry
spec:
  mode: Pipeline
  pipeline:
    - step: check-certificate
      functionRef:
        name: function-python
      input:
        apiVersion: python.fn.crossplane.io/v1beta1
        kind: Script
        script: |
          import datetime

          from crossplane.function.proto.v1 import run_function_pb2 as fnv1

          def operate(req: fnv1.RunFunctionRequest, rsp: fnv1.RunFunctionResponse):
              rsp.output["check_time"] = datetime.datetime.now().isoformat()
              rsp.output["status"] = "healthy"

A script must define exactly one of compose or operate; the function reports anything else as a fatal result.

By default the function serves gRPC over mTLS on port 9443 and reads its certificates from the directory named by TLS_SERVER_CERTS_DIR, which Crossplane sets and populates. Run it with --insecure only for local development.

Documentation and Resources

What are Chainguard Containers?

Chainguard's free tier of Starter container images are built with Wolfi, our minimal Linux undistro.

All other Chainguard Containers are built with Chainguard OS, Chainguard's minimal Linux operating system designed to produce container images that meet the requirements of a more secure software supply chain.

The main features of Chainguard Containers include:

For cases where you need container images with shells and package managers to build or debug, most Chainguard Containers come paired with a development, or -dev, variant.

In all other cases, including Chainguard Containers tagged as :latest or with a specific version number, the container images include only an open-source application and its runtime dependencies. These minimal container images typically do not contain a shell or package manager.

Although the -dev container image variants have similar security features as their more minimal versions, they include additional software that is typically not necessary in production environments. We recommend using multi-stage builds to copy artifacts from the -dev variant into a more minimal production image.

Need additional packages?

To improve security, Chainguard Containers include only essential dependencies. Need more packages? Chainguard customers can use Custom Assembly to add packages, either through the Console, chainctl, or API.

To use Custom Assembly in the Chainguard Console: navigate to the image you'd like to customize in your Organization's list of images, and click on the Customize image button at the top of the page.

Learn More

Refer to our Chainguard Containers documentation on Chainguard Academy. Chainguard also offers VMs and Libraries — contact us for access.

Trademarks

This software listing is packaged by Chainguard. The trademarks set forth in this offering are owned by their respective companies, and use of them does not imply any affiliation, sponsorship, or endorsement by such companies.

Licenses

Chainguard's container images contain software packages that are direct or transitive dependencies. The following licenses were found in the "latest" tag of this image:

    For a complete list of licenses, please refer to this Image's SBOM.

    Software license agreement

    Compliance

    Chainguard Containers are SLSA Level 3 compliant with detailed metadata and documentation about how it was built. We generate build provenance and a Software Bill of Materials (SBOM) for each release, with complete visibility into the software supply chain.

    SLSA compliance at Chainguard

    This image helps reduce time and effort in establishing PCI DSS 4.0 compliance with low-to-no CVEs.

    PCI DSS at Chainguard

    Category
    Application

    The trusted source for open source

    Talk to an expert
    PrivacyTerms

    Product

    Chainguard ContainersChainguard LibrariesChainguard VMsChainguard OS PackagesChainguard ActionsChainguard Agent SkillsIntegrationsPricing
    © 2026 Chainguard, Inc. All Rights Reserved.
    Chainguard® and the Chainguard logo are registered trademarks of Chainguard, Inc. in the United States and/or other countries.
    The other respective trademarks mentioned on this page are owned by the respective companies and use of them does not imply any affiliation or endorsement.