How does a CI pipeline get credentials to deploy with Ansible without long-lived secrets?
AdvancedProductionTesting, CI/CD and Quality
Answer
Use short-lived, identity-based credentials:
- Cloud APIs: OIDC federation. GitHub Actions or GitLab exchanges its job token for a temporary AWS role; no access keys stored anywhere.
- SSH: SSH certificates signed per job by Vault or a CA with a 30 to 60 minute TTL, or SSM Session Manager so there is no SSH at all.
- Vault password / secrets: fetched at runtime from Vault or Secrets Manager using the same OIDC identity.
permissions:
id-token: write
contents: read
steps:
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::123456789012:role/ci-ansible-prod
aws-region: ap-south-1
Scope the IAM role's trust policy to the repo and the protected branch or environment, so a fork or feature branch cannot assume the prod role.
More on Testing, CI/CD and Quality
What does a testing pyramid look like for Ansible code?BeginnerHow do you roll out `ansible-lint` profiles across a team without blocking everyone?IntermediateWhen do you use `skip_list`, `warn_list` and `# noqa`?IntermediateHow do you set up pre-commit hooks for an Ansible repo?BeginnerHow is a Molecule scenario laid out, and what does `molecule test` actually run?IntermediateDocker, Podman or real VMs as the Molecule driver: how do you choose?Advanced