How to Run Your Own Building Block Runner
This guide explains what building block runners are, why you might want to self-host one, and the high-level steps to get one running.
What is a Building Block Runner?
A building block runner is a small service that connects meshStack to your CI/CD platform. When an application team adds a building block to their workspace or project, meshStack queues a building block run and routes it to the runner assigned to that building block definition. The runner picks up the queued run, triggers the corresponding automation (e.g. an OpenTofu/Terraform script, a GitHub Actions workflow, a GitLab pipeline, or an Azure DevOps pipeline), and reports progress and status back to meshStack.
meshStack ships with hosted runners that run every implementation type: OpenTofu/Terraform, Manual, GitHub Actions, GitLab CI/CD, and Azure DevOps Pipelines. For most use cases, you don't need to run your own.
Should You Run Your Own Runner?
You need a self-hosted runner when:
- You need to reach a private network (private cloud or on-premise Git servers) that isn't reachable from meshStack's infrastructure
- You want dedicated isolation — a private runner only picks up runs assigned to it, with no cross-workspace interference
- Your organization's security policies require that pipeline credentials never leave your network
How Runners Work
The runner polls meshStack every few seconds for pending building block runs. When a run is available, the runner executes an OpenTofu/Terraform or manual run itself or triggers your pipeline, and reports status back.
Depending on the execution mode on the building block definition, the runner either polls the automation pipeline for completion (synchronous) or hands off and waits for the automation pipeline to report back (asynchronous). The runner executes an OpenTofu/Terraform run itself. In asynchronous mode, it hands the run over after the apply, and an external pipeline reports the final status. An asynchronous pipeline must send a status update at least once every 3 hours and a final status at the end, otherwise the run fails. It must retry each status update, above all the final one, when meshStack answers with 423, 502, 503 or 504 or the connection fails. The MESHSTACK_RUN_TOKEN is valid for 6 hours, so a pipeline that runs longer needs its own API key for later updates. See Timeout Detection and Warning Messages.
Secret inputs are encrypted with the runner's RSA public key — only the runner, using the matching private key, can decrypt them at runtime.
A self-hosted runner runs in a single container, or as a run-controller in Kubernetes. Isolating Runs explains which one to choose. The runner is open source on GitHub, so you can run it on your own infrastructure, customize it for your needs, or simply use meshStack's hosted runners.
If you replace the key pair after building blocks have stored encrypted inputs, those inputs can no longer be decrypted. Static inputs need a new definition version; user inputs need to be re-submitted by workspace users. Plan key rotation carefully.
Isolating Runs
A runner executes code that the owners of its building block definitions control. For example, an OpenTofu/Terraform run executes the modules and providers of its definition, and they can run any command. So anyone who can edit a definition that uses your runner can run code with the rights of your runner, and a runner that several teams use must keep their runs apart. How well it does that depends on how you deploy it:
- Single container: every run is a process in the runner's container, under the same user. A run can read the runner's private key, which decrypts the sensitive inputs of every run on this runner. It can also read the runner's API key and the files of other runs that run at the same time.
- Kubernetes: the run-controller starts each run as its own Kubernetes Job. The Job gets only its own run token and its own decrypted inputs. The private key and the runner's API key stay in the run-controller's pod.
A single container suits one team that runs its own building block definitions. If many teams share a runner, for example a public runner, use the Kubernetes setup.
A runner of all types is the easy default. A team that needs no OpenTofu/Terraform runs can register a runner of one type instead and so keep OpenTofu/Terraform code out of the runner. For example, a runner for GitHub workflows, GitLab pipelines or Azure DevOps pipelines only triggers the external pipeline, and its image does not contain the OpenTofu/Terraform executor.
Setting Up a Self-Hosted Runner
The easiest way to set up a runner is through the Platform Builder or Admin Area UI in meshStack — the interface walks you through each field and generates the configuration for you. The high-level steps are:
- Generate an RSA key pair. meshStack encrypts sensitive building block inputs with the runner's public key. Only your runner, with the private key, can decrypt them.
- Register the runner in meshStack. Create a Building Block Runner in the Platform Builder/Admin Area (or via the meshObject API), providing your public key and All types as the implementation type, or a single type if the runner should run only that type. meshStack assigns the runner a UUID. If your runs use Workload Identity Federation, also declare the identity your runner presents - see Declaring the Runner's Own Identity.
- Create an API key for the runner. The runner needs an API key to poll meshStack for work. Once the runner is registered, provision one from the runner's detail page in meshStack — see Runner Visibility and API Key Permissions below for the exact permissions required.
- Deploy the runner. Run the
building-block-runnerimage in a single container, or therun-controllerin Kubernetes, with the runner UUID, meshStack URL, API credentials, and private key as configuration. Keep the API client secret in a vault and pass it to the container as a file: write it asmeshstack.apiKey.clientSecretinto the mountedrunner-config.yml. The runner's detail page in meshStack shows the setup for both. The runner starts polling immediately. - Verify and assign. Confirm the runner shows as Active in meshStack, then select it on the Implementation tab of your building block definition.
meshStack marks a runner Active if it has polled within the last 5 minutes, Pending right after registration, and Error if it goes silent. You can see the last known runner version in the runner details view.
Declaring the Runner's Own Identity
If your runs authenticate to a cloud provider with Workload Identity Federation instead of long-lived credentials, tell meshStack which identity your runner presents. You do that with the optional spec.workloadIdentityFederation section when you register or update the runner.
The tokens can come from wherever your runner gets them: the cluster it runs in, HashiCorp Vault, a SPIFFE workload API, your own identity provider, or your CI system's OIDC provider. meshStack never mints them and never checks who does. What the cloud provider sees is an issuer, a subject and an audience, and that is exactly what you declare:
issuer— the OIDC issuer URL of whoever signs the tokenssubjectTemplate— the subject claim your tokens carrygcp,awsandazure— the audience and the file path each token is written to
The self-hosted runner does not mint or write these tokens itself. Provide them from your own source at the file paths you declare, for example with a projected service account token in your Kubernetes Job template. A future version of the runner may do this for you.
Writing the Subject Template
Most runners mint one identity per building block definition so the trust you set up in a cloud provider stays scoped to a single definition. Write subjectTemplate with the two placeholders that stand for the definition a run belongs to:
| Placeholder | Stands for |
|---|---|
{{ workspaceIdentifier }} | The identifier of the workspace that owns the building block definition |
{{ buildingBlockDefinitionUuid }} | The UUID of the building block definition |
Whitespace inside the braces is optional, so {{workspaceIdentifier}} works too. No other name is accepted, and a template that names one is rejected when you register the runner.
A template like this one:
system:serviceaccount:my-runners:workspace.{{ workspaceIdentifier }}.buildingblockdefinition.{{ buildingBlockDefinitionUuid }}
resolves per definition to:
system:serviceaccount:my-runners:workspace.my-team.buildingblockdefinition.3f2a1c9e-7b40-4d8e-9c11-2e5a6d0f8b31
If your runner's token issuer cannot put the definition into the subject claim, for example a single-pod runner or a CI system whose subject is fixed by repository or pipeline, register a template without placeholders. Every building block definition on that runner then shares one identity, so everyone who can use the runner can use whatever you trust it with.
meshStack resolves the template for each version of a building block definition and publishes the result. Platform builders see it under Implementation → Workload Identity Setup on the definition, and the meshObject API returns it as status.versions[].workloadIdentityFederation. Use those values in your cloud provider's trust policy rather than assembling the subject yourself. Everyone who can read the definition can read these values; they are not secrets, because the cloud provider only trusts a token that the declared issuer has signed. Building blocks stay on the version they were created with, and a version with another runner can differ in issuer, audience and subject. So the trust must cover the values of every version that building blocks still run on. See WIF Configuration Values.
Runner Visibility and API Key Permissions
Every runner is owned by a workspace and has a restriction that determines where it can be used:
- Private runners (default) are restricted to the workspace that owns them. Only that workspace can select a private runner for its building block definitions. This is the only option available when registering a runner from a workspace's Platform Builder.
- Public (shared) runners are owned by the admin workspace and available to every workspace in meshStack — they can execute runs for building block definitions owned by any workspace. Only admins can create public runners, from the Admin Area. meshStack's built-in hosted runners are public runners. Deploy a public runner on Kubernetes, as Isolating Runs explains.
The API key that authenticates your runner belongs to the workspace that owns the runner, for a private and a public runner alike. It needs two permissions:
- Write Runs — claim runs and receive their inputs
- Write Run Sources — report run status, logs, and outputs
They cover the runs of every building block definition that uses one of the workspace's runners, including definitions of other workspaces on a public runner. The runner never lists runs, so the key needs no permission to read runs.
Use the Provision API Key action on the runner's detail page to have meshStack create the key for you with these two permissions. You don't need to pick permissions manually.
The API key must belong to the same workspace that owns the runner. For a private runner, that workspace must also own the building block definitions the runner should execute — for example, if workspace A owns a building block definition and a private runner assigned to it, a building block instantiated from that definition in workspace B is still executed using the runner (and API key) in workspace A. Public runners don't have this restriction, since they can execute definitions from any workspace.
When a Building Block Definition Moves to Another Workspace
Admins can transfer the ownership of a building block definition to another workspace. The transfer doesn't change the runners of its versions. If a version uses a private runner of the previous owner, its runs still execute on that runner, with the API key of the previous owner's workspace. The previous owner's team keeps operating these runs, and the runner keeps decrypting the sensitive inputs.
The new owner can keep this runner on new versions. They can't select it again once they switch a version to another runner, because it's not their runner. To move the runs completely, select one of the new owner's runners or a public runner in a new version and release it. Existing building blocks keep running on the version they use until they're upgraded.
For workload identity federation, this is a runner change. The runs of the new version can present another issuer, audience and subject than the runs of the older versions. Keep the trust for the old runner until every building block is upgraded. Changing the Runner describes the steps.
The workspace identifier in a subject template is always the one of the current owner. If the template contains {{ workspaceIdentifier }}, the definition gets a new subject after a transfer, so update the trust relationships in your cloud provider before the next run. A template without this placeholder keeps its subject.
Runner Images
The runner images are published at ghcr.io/meshcloud/<image> and on Docker Hub at docker.io/meshcloud/<image>. They all run the same binary and read their configuration from /app/runner-config.yml, or from the path in RUNNER_CONFIG_FILE. No image contains a configuration, so mount yours into the container. meshStack generates it for you when you register the runner in the UI.
| Image | Use it for |
|---|---|
building-block-runner | A runner in a single container. It runs every implementation type, each run in its own process. |
run-controller | A runner in Kubernetes. It starts each run as a Kubernetes Job on the building-block-runner image in its own version, unless your Job template sets another image. |
A run-controller for OpenTofu/Terraform only (dispatcher.forTypes: [TERRAFORM]) also starts its Jobs on the building-block-runner image. The images tf-block-runner, manual-block-runner, github-block-runner, gitlab-block-runner and azure-devops-block-runner still exist for a runner of one type.
Every image serves /healthz and Prometheus metrics on port 2112, for liveness probes and monitoring.
Trusting Another SSH Host
An OpenTofu/Terraform run that clones its Git repository over SSH accepts the known host of its building block definition and the hosts in the image's /app/known_hosts: GitHub, GitLab, Azure DevOps and Bitbucket. To trust another host for every definition on the runner, such as your own Git server, add its host key in one of these ways:
- Mount your own
known_hostsfile over/app/known_hosts. - Mount the file at another path and set the environment variable
SSH_KNOWN_HOSTSto that path.
As a last resort, tf.insecureHostKeys: true in runner-config.yml turns the host key check off for every run of the runner.