Interview Prep/Ansible/Security and Secrets

How do you apply least privilege to `become`?

BeginnerProductionSecurity and Secrets
Answer

Enable become only on the tasks that need it, not at play level for everything. Fact gathering, API calls delegated to localhost and reads do not need root. Use become_user for service accounts rather than root where possible, such as running application deploy steps as app.

- hosts: web
  tasks:
    - ansible.builtin.git: { repo: "{{ repo }}", dest: /srv/app }
      become: true
      become_user: app
    - ansible.builtin.systemd_service: { name: app, state: restarted }
      become: true
All Ansible questions Roadmap: Ansible

More on Security and Secrets