Push code to Git at regular intervals
Continuously push your Kestra flows and namespace files to a Git repository on a schedule for GitOps version control.
Find running Docker containers with no restart policy, set it in place behind an approval, then re-read it and prove the service was not interrupted.
A container started with --restart=no, which is the default, never comes back. The host reboots or dockerd restarts, then that container stays down. Nothing alerts, because the daemon did exactly what it was told. Someone notices hours later when a queue stops draining or a health check page is missing a tile.
This blueprint finds those containers while they are still up and fixes them in place. It reads the restart policy of every container carrying a label you apply yourself, keeps anything on a protect-list, caps how many change in one run, then writes the policy you chose with docker update behind a dry run and an approval. Every labelled container is inspected again afterwards. The run fails if a target is still unprotected or if the workload was disturbed.
This blueprint was created by zkasuran.
The write is a configuration rewrite, which is why this flow can act on a running service at all:
docker update does not restart anything. It rewrites HostConfig.RestartPolicy on the existing container. The process keeps running and the container keeps its id. The policy takes effect at the next stop. This is the whole reason the flow is safe to run against production containers, where a reaper or a recreate is not.State.StartedAt are captured before the change and read again after it. A target counts as hardened only when the policy is the one asked for and the id, the start time and the running state are all unchanged. A recreated container comes back with a new id, so it cannot read as untouched.label_selector, so a container without that label is never returned, let alone changed.protected_name_pattern wins over every other rule. One-shot jobs belong there, since a job meant to run once should stay with no restart policy.max_updates bounds one run, so a selector that matches more than you expected cannot rewrite a whole host in one execution.auto_remediate true, dry_run false, then an approved Pause. The shipped defaults and the disabled schedule are read-only.docker_host over the Engine API and every write goes to the same endpoint through DOCKER_HOST. The flow holds no socket path and no hostname of its own, so the daemon that runs Kestra is never a target.list_running (io.kestra.plugin.core.http.Request, read-only) asks the Docker Engine API for running containers matching label_selector. The Docker plugin has no container list task, so the inventory comes from the API. candidates keeps the ids and names.
inspect_each (io.kestra.plugin.core.flow.Loop, read-only) inspects each candidate. HostConfig.RestartPolicy, State.StartedAt and RestartCount are in the inspect payload only, not in the list.
assess gives every candidate a verdict. An empty policy name and the literal no both mean the daemon will leave the container down:
KEEP_POLICY_SET: it already has a policy;KEEP_PROTECTED: its name matches protected_name_pattern;KEEP_NOT_RUNNING: the daemon no longer reports it running;KEEP_OVER_CAP: eligible, but beyond max_updates for this run;HARDEN: running, unprotected, no policy, inside the cap.summary logs the counts, every target and its start time.
route stops with a log line when there is nothing to harden. Otherwise findings_alert posts the plan to Slack and remediate_gate checks auto_remediate and dry_run.
hold (io.kestra.plugin.core.flow.Pause) waits for approval. remediate_update (Loop, concurrencyLimit: 1) then runs one docker update --restart=<policy> <id> per target through io.kestra.plugin.scripts.shell.Commands on the docker:27-cli image, pointed at docker_host by DOCKER_HOST.
reverify_each inspects every labelled container again by name. result joins the plan with the host. verify fails the run in three cases: a target still unprotected, a hardened container that lost its id or its start time, a container the plan kept that changed.
errors alerts Slack when the flow fails, including when the verification gate fails.
--restart.A shell loop can run docker update across a host, but it cannot hold the change behind an approval, cannot keep a protect-list, cannot stop at a ceiling and cannot prove it left the running workload alone. That last part is what makes this safe to automate: the run is only green when the policy changed and the container id, the start time and the running state did not. Kestra reads the host, computes the plan, waits for a human, writes one container at a time so a failure is attributable, then reads the host again and fails the execution when the result does not match the plan. The execution history becomes the record of which host was hardened, when it happened and who approved it.
On Kestra 2.0.5 OSS against an isolated Docker 27.5.1 daemon (Docker-in-Docker on its own network), with a local HTTP sink standing in for Slack. The daemon held four running containers: app-ledger (labelled, --restart=no), app-unlabelled (no label, --restart=no), app-already (labelled, already unless-stopped), migrate-once (labelled, --restart=no, matching the protect-list).
| Run | Inputs | Result |
|---|---|---|
| 1 | defaults | 3 labelled containers read, 1 target (app-ledger). app-already kept as KEEP_POLICY_SET, migrate-once kept by the protect-list, app-unlabelled never returned by the query |
| 2 | auto_remediate: true |
Same plan, nothing changed. The dry run blocks the write even with auto_remediate on |
| 3 | run 2 plus dry_run: false, pause approved |
app-ledger went from no to unless-stopped. Same container id, same State.StartedAt, still running, RestartCount still 0. The other three untouched, confirmed with docker inspect on the daemon itself |
| 4 | same, pause resumed with approved: false |
Nothing changed |
| 5 | rerun of run 3 on the now clean host | 0 targets, the nothing_to_harden branch |
| 6 | same as run 3, but the target was recreated during the pause | The policy read back correct while the container id had changed, so verify failed the run and errors posted to Slack |
| 7 | max_updates: 1 with two eligible containers |
1 target, the other reported as KEEP_OVER_CAP |
| 8 | unreachable daemon | errors alert sent |
Proof the whole thing is worth doing: the daemon was restarted after run 3. app-ledger came back by itself, app-unlabelled stayed down.
--label kestra.restart-policy=managed to your docker run or to the service in your Compose file, then point label_selector at it.docker:27-cli container must be able to reach docker_host. Leave docker_cli_network as bridge for a daemon that resolves by DNS. Point it at the user-defined network when the daemon is itself a container.docker run -d --privileged --name dind -e DOCKER_TLS_CERTDIR= docker:27-dind --host=tcp://0.0.0.0:2375, start a few labelled containers inside it, then set docker_host to tcp://dind:2375.SLACK_WEBHOOK_URL: used by findings_alert and the errors block. In Kestra OSS, provide it as the base64-encoded environment variable SECRET_SLACK_WEBHOOK_URL.| Input | Default | Purpose |
|---|---|---|
docker_host |
tcp://docker-host:2375 |
Daemon to harden |
docker_cli_network |
bridge |
Network the docker CLI container joins |
label_selector |
kestra.restart-policy=managed |
The only containers read |
desired_policy |
unless-stopped |
Policy to write |
protected_name_pattern |
^(batch|job|migrate|oneshot|init)([-_.].*)?$ |
Names left alone |
max_updates |
25 |
Ceiling for one run |
auto_remediate |
false |
Must be true to write anything |
dry_run |
true |
Must be false to write anything |
SLACK_WEBHOOK_URL secret.docker run --label kestra.restart-policy=managed ....docker_host and label_selector, run it with the defaults and read the plan.auto_remediate: true and dry_run: false, read the plan in the paused execution, then resume it with approved: true.nightly trigger once the plans look right. Change its inputs when you want it to act.desired_policy instead of treating any policy as acceptable.on-failure:N to desired_policy for workloads that should retry a crash a fixed number of times, then split the retry count off the value before it reaches the CLI.