Lesson 12 of 13 · 22m
Running Ansible Without Handing It the Keys
Why delegate_to and lookup('pipe') execute on your control node, ansible.cfg auto-loading, no_log, fact caches, and pinning the Galaxy supply chain.
The control node is the crown jewel, and Ansible will happily run code on it. That's the sentence to hold onto. A playbook is not a declarative manifest that only touches remote hosts — it's an executable that happens to default to SSH. Three mechanisms reach your machine directly: delegate_to: localhost, local_action, and the raw/command/shell family pointed at localhost. Plus one more people forget: lookup('pipe', '...') runs a local command on the control node at template-evaluation time, before a single task ships anywhere.
So "I'll just review this community playbook and run it" is the same threat model as "I'll just run this install.sh." Before you run a playbook you didn't write, grep -nE 'delegate_to: (localhost|127)|local_action|lookup\(.pipe|raw:|script:' — every hit is code executing where your SSH keys, your vault passwords, and your ~/.aws live.
ansible.cfg auto-loads, and that was the attack
Config discovery order: $ANSIBLE_CONFIG, then ./ansible.cfg, then ~/.ansible.cfg, then /etc/ansible/ansible.cfg. The ./ansible.cfg rung is the dangerous one — cd into a cloned repo and run ansible-playbook and that repo's config file is now steering your run: vault_password_file can point at an executable script (yes, the file may be a program Ansible runs to fetch the password), stdout_callback can load a plugin, library can shadow module paths. Ansible skips configs in world-writable directories — /tmp is safe — but a cloned repo in your home dir is not world-writable, so it loads.
The control that's actually verifiable: ANSIBLE_CONFIG=/etc/ansible/ansible.cfg pinned in CI, and awareness that checkout-then-run inherits whatever the author shipped.
Secrets: where they leak that isn't vault
Vault covers at-rest. The leaks are elsewhere:
no_log: trueon every task that touches a decrypted value — otherwise-vprints the cleartext and CI archives it forever. This includesdebug:tasks you added at 2 a.m. and left in.- Fact caches are plaintext.
fact_caching = jsonfilewrites every host's fullansible_facts— NICs, mounts, users, environment — tofact_caching_connectionas world-readable JSON unless you set the directory's mode. Redis and memcached caches need their own auth; the convenience has an exposure profile. - Callback plugins record everything. ARA and
community.general.log_playspersist every task result — registered results included — into a database. Excellent for audit; it is also a copy of everythingno_logwas trying not to say. --ask-vault-passvs a password file: the file must be0600, outside the repo, and never committed — a vault password in git history is the oldest self-own in the ecosystem.unsafe_writesand filemode:oncopy/template/lineinfile— a rendered config landing0644that should be0600is a real, silent, findings-shaped bug.
SSH posture is Ansible posture
Agentless means OpenSSH is the perimeter — both directions. host_key_checking off (a common Stack Overflow "fix") makes every first-connect a MITM invitation; ProxyJump via ansible_ssh_common_args is the correct alternative to ForwardAgent — -A hands a compromised node your agent, and the node can then authenticate as you anywhere else. become with a dedicated ansible user and per-task escalation produces an auth.log/sudo trail that means something; an ansible user that is just root with extra steps produces noise.
The supply chain you pin or get pinned by
ansible-galaxy collection install pulls tarballs of arbitrary modules — code that executes on your nodes — keyed by a namespace on a public registry. That registry has already demonstrated the failure mode twice: a 2021 normalization bug granted access to other users' namespaces (evgeni's die-welt.net writeup), and the October 2023 Galaxy NG migration transferred role namespaces to unrelated GitHub users — installing elan.opencast_user briefly fetched a different person's code entirely. Red Hat's longer-term answer is GPG signatures: ansible-galaxy collection install ns.coll --keyring ~/.ansible/pubring.kbx --signature https://.../detached.asc --required-valid-signature-count 1. Almost nothing on public Galaxy is signed, so in practice the controls are the boring ones: requirements.yml with exact versions, vendored/checked-in collections for sensitive trees, and a review of any role that configures a security boundary before it ever runs.
Field notes
no_logon a task withlooplogs nothing per item — apply it at the task level, not inside item output.delegate_to/local_action/raw/pipeare also legitimate tools — the grep is a review gate, not a blocklist.- The dangerous playbook needn't be malicious: a well-meaning role that
local_actions a cleanuprm -rfhas your home directory's full filesystem view.
Was this lesson helpful?
Keep reading
Related articles from the SudoSecurity blog.
Self-Hosting Prometheus and Grafana: Infrastructure Monitoring That Actually Works
Build a production-grade monitoring stack with Prometheus and Grafana from scratch. Covers architecture, Docker Compose deployment, Node Exporter, alerting with Alertmanager, PromQL from basics to advanced, pre-built dashboards, and everything SudoSecurity uses to monitor its own infrastructure.
Zero Trust Everything: The Complete Guide to Self-Hosting Teleport for Secure Infrastructure Access
SudoSecurity runs Teleport internally for everything — admin panel access, secure database connections, Kubernetes, and zero-trust philosophy across our entire team. This is the complete technical guide to installing, configuring, and running your own self-hosted Teleport cluster from scratch.
PostgreSQL 19 Is Out. REPACK Kept My Writes Running. The Docker Upgrade Will Stop Your App.
PostgreSQL 19 shipped on November 19 with REPACK (CONCURRENTLY), which removes table bloat without blocking writes. I measured it against VACUUM FULL, ran the upgrade from 18, and checked what breaks for self-hosters: Docker tags that refuse to start, a config setting that stops the server, and...
AWS Emulator Puts AWS on Your Laptop. Keep Your IAM Tests Off It.
AWS released AWS Emulator on November 11, a free local server that answers AWS API calls on 127.0.0.1 with per-run keys and fresh certificates.