TechBuzzPro

On-Demand CI Runners: Nomad + Temporal Safety

· 7 min read · Apps & Browsers

In this article
  1. What This Architecture Actually Does
  2. Isolation and Security Boundaries
  3. Authentication and Secret Management
  4. Operational Safety and Failure Handling
  5. Comparing to Traditional CI Runners
  6. Cost and Performance Considerations
  7. Common Pitfalls and Misconceptions
  8. Frequently Asked Questions

Yes, running on-demand CI runners with HashiCorp Nomad and Temporal is safe when you implement proper isolation, authentication, and resource controls. This architecture is increasingly common for teams that want dynamic, cost-efficient CI without managing a dedicated runner fleet, but its safety depends entirely on how you configure the underlying infrastructure and workflow orchestration.

What This Architecture Actually Does

Nomad is a cluster scheduler that places and runs containerized or binary workloads across a pool of machines. Temporal is a durable workflow engine that manages long-running, fault-tolerant processes. In this setup, Temporal acts as the orchestrator: a CI job triggers a Temporal workflow, which calls Nomad’s API to start a short-lived runner container. That runner executes the build or test, then exits. The runner is destroyed, and the workflow records the outcome.

This pattern is attractive because you only pay for compute while a job is running. There is no idle pool of persistent runners. It also gives you a single control plane for retries, timeouts, and failure handling through Temporal’s built-in features.

Isolation and Security Boundaries

The primary safety concern is that CI workloads are untrusted code—they can run arbitrary commands, access network resources, and potentially exfiltrate secrets. The runner container must be treated as a hostile environment, not a trusted component.

  • Container isolation: Use a sandboxed runtime like gVisor or Kata Containers, or at minimum run with user namespaces and seccomp profiles. Standard Docker isolation is not sufficient for multi-tenant CI.
  • Network segmentation: Place runners in a dedicated network namespace with no route to internal services unless explicitly required. Use firewalls or network policies to restrict egress.
  • Ephemeral storage: Use tmpfs or a volume that is wiped on container exit. Never persist data between runs unless it is intentionally cached.
  • Resource limits: Enforce CPU, memory, and disk quotas in Nomad job specs to prevent a runaway build from exhausting host resources.

Nomad’s native docker driver supports many of these options, but you must explicitly configure them. The default settings are not hardened.

Authentication and Secret Management

Both Nomad and Temporal need to authenticate to each other, and the CI jobs need access to secrets like API keys or cloud credentials. The safe pattern is to use short-lived tokens and a dedicated secrets manager.

  • Nomad ACLs: Enable Access Control Lists and create a token with minimal permissions for Temporal to submit jobs. Do not use the management token.
  • Temporal TLS: Configure mutual TLS between Temporal clients and the server. Use a private CA and rotate certificates regularly.
  • Secrets injection: Have Temporal fetch secrets from a vault (e.g., HashiCorp Vault) and pass them to the runner via environment variables or a mounted file. Never hardcode secrets in workflow definitions or Nomad job specs.
  • Short-lived credentials: For cloud providers, use instance metadata or OIDC federation to grant the runner a temporary role that expires after the job finishes.

One common mistake is to give the runner broad IAM permissions. Instead, scope the role to exactly what the build needs—for example, read-only access to a specific S3 bucket.

Operational Safety and Failure Handling

Temporal’s strength is its ability to retry and recover from failures, but that can also cause problems if not configured carefully. A job that fails due to a transient network issue might be retried, which is fine. But if the failure is due to a bug in the build script, infinite retries will waste resources and potentially trigger alerting.

  • Set retry policies: Define maximum attempts and backoff coefficients in the Temporal workflow. Use a reasonable limit—typically 2–3 retries for infrastructure errors, 0 for deterministic failures.
  • Timeout everything: Each activity in the workflow should have a start-to-close timeout. If a runner hangs, the workflow should terminate it and report failure.
  • Handle Nomad API failures: If Nomad is down or the job placement fails, the workflow should catch that and either retry after a delay or fail gracefully with a clear error message.
  • Monitor runner lifecycle: Use Nomad’s job status and Temporal’s workflow history to audit that every runner is destroyed after completion. A leaked runner is a security and cost risk.

For example, a workflow might look like: StartRunner activity (calls Nomad API), then WaitForCompletion activity (polls runner status), then Cleanup activity (always runs, even on failure). This ensures no orphaned containers.

Comparing to Traditional CI Runners

Traditional CI systems like GitHub Actions or GitLab CI use persistent runner pools. Those are simpler to secure because the runners are long-lived and can be patched and monitored continuously. On-demand runners with Nomad and Temporal offer more flexibility and cost savings, but they shift the security burden to your infrastructure team.

The trade-off is that you get full control over the runner environment, which can be a safety advantage if you need to enforce specific compliance requirements. For example, you can ensure every runner starts from a hardened image with no cached state. But you also take on the responsibility of keeping that image up to date and scanning it for vulnerabilities.

If your team lacks experience with Nomad or Temporal, the learning curve can introduce misconfigurations that are worse than using a managed CI service. Start with a small pilot and gradually expand.

Cost and Performance Considerations

On-demand runners are cost-efficient because you pay only for what you use, but there are hidden costs. Nomad cluster nodes must be running even when there are no CI jobs—unless you use a serverless provider or auto-scaling group that can shrink to zero. That base cost can negate savings if your CI usage is sporadic.

Performance is also a factor. Starting a container on a cold node takes time. If your builds are latency-sensitive, you might need to keep a small pool of warm nodes, which reduces the cost benefit. Temporal adds a small overhead per workflow, but it’s negligible compared to the runner startup time.

To optimize, use Nomad’s bin packing and preemption features to run CI jobs on nodes that also serve other workloads, but be careful about noisy neighbors. A CPU-heavy build could degrade other services.

Common Pitfalls and Misconceptions

A frequent misconception is that “serverless” means “secure by default.” It does not. The security properties are the same as any container runtime; you must still configure isolation and network policies.

Another pitfall is using a single Nomad cluster for both CI and production workloads. That creates a blast radius: a compromised CI runner could potentially access production services if network policies are not strict. Separate clusters or at least separate namespaces with strict ACLs are safer.

Also, beware of caching. Caching dependencies can speed up builds, but if the cache is shared across teams, it can be poisoned. Use per-project cache keys and validate checksums.

Finally, don’t forget about audit logging. Enable Nomad audit logs and Temporal’s event history retention. You need to be able to answer “what ran, when, and with what permissions” after an incident.

Frequently Asked Questions

Can Nomad and Temporal run on the same cluster?

Yes, but it is not recommended for production. Temporal is a stateful service that needs stable storage and low latency. If you run it on the same Nomad cluster as CI workloads, a noisy build could affect Temporal’s performance, and a security breach in a runner could compromise the Temporal server. Use separate clusters or at least separate node pools with taints.

Is it safe to run Docker-in-Docker for CI?

Docker-in-Docker (DinD) is generally unsafe in multi-tenant environments because it requires privileged mode. A compromised container can escape to the host. Instead, use a rootless Docker daemon, or better, use a tool like Buildah or Kaniko that doesn’t require a daemon. If you must use DinD, run it in a VM or use a sandboxed runtime.

What if a runner is compromised during a build?

The blast radius depends on your isolation. If the runner is sandboxed and has no network access to sensitive resources, the attacker is contained. You should still kill the runner immediately, revoke any short-lived credentials, and investigate the workflow history to see what the runner accessed. Temporal’s audit trail helps with this.

How do I handle secrets for the CI job?

Use a secrets manager like Vault. The Temporal workflow fetches the secret and passes it to the runner via environment variables or a mounted file that is removed after the job. Avoid putting secrets in the Nomad job spec, as that is visible in the job definition and audit logs.

Is it worth the complexity for a small team?

For a small team with a handful of builds per day, the operational overhead of Nomad and Temporal might not be justified. A managed CI service with autoscaling runners is simpler and likely safer because the provider handles isolation and patching. Revisit this architecture when you need custom runner environments or have a dedicated DevOps engineer.