The Simplest Way to Make Bitbucket and IAM Roles Work Like They Should
You pair bitbucket and iam roles to run cloud tasks from your code pipelines. Your build runner trades a short token for temporary cloud permissions without saved keys. Teams use this setup to push apps, update cloud state, and run tests. When you remove static keys from repos, you reduce the risk of leaked secrets. How bitbucket and iam roles pass identity and permissions The workflow starts when a developer pushes code and triggers a pipeline run. Bitbucket generates a signed OpenID Connec
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
You pair bitbucket and iam roles to run cloud tasks from your code pipelines. Your build runner trades a short token for temporary cloud permissions without saved keys.
Teams use this setup to push apps, update cloud state, and run tests. When you remove static keys from repos, you reduce the risk of leaked secrets.
How bitbucket and iam roles pass identity and permissions
The workflow starts when a developer pushes code and triggers a pipeline run. Bitbucket generates a signed OpenID Connect token for that specific build step.
This token holds facts about the workspace, the repo, and the target branch. The pipeline runner sends this signed token to your cloud provider.
Your cloud identity system checks the token signature against the trusted issuer address. Next, the cloud provider checks the trust policy attached to the target role.
If the repo and branch match the rule, the cloud issues temporary credentials. The pipeline step uses those temporary credentials to talk to cloud APIs.
When the job ends, the temporary credentials expire on their own. You never store long-lived keys inside your repo settings or team variables.
Common failure modes and how to scope roles
Many teams still paste shared service account keys into workspace variables. Anyone with repo write rights can print those keys in the build log.
Another common mistake is writing a loose trust rule on the cloud role. If you only check the workspace ID, any repo in that workspace can assume it.
AWS IAM Policies + Lambda Execution Roles: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
A test repo could then change production servers or read sensitive data stores. Teams also grant broad admin rights to a single pipeline role for speed.
When a build script runs untrusted code, broad roles put your whole cloud at risk. You can fix this by scoping each role to one repo and branch.
Create separate roles for staging builds and production deploys. Lock the production role trust rule to your protected main branch only.
Keep the permission list small so each step only touches what it needs. Also check that your cloud logs record the repo claim from each token.
Auditing pipeline runs and database tasks
Pipelines often do more than push container images or update static files. Many release jobs also run schema changes or fix records in production databases.
Cloud roles control who can start a job or reach a network. Still, cloud roles rarely show the exact queries a script ran inside a database.
Standard build logs show the job output, not the row-level database impact. If a script reads customer emails or card numbers, you need clear audit trails.
You can add data masking to rewrite sensitive fields in query results. You should also log every command by identity and tie it to the caller.
Add runtime guardrails and masking beside your databases and APIs
Login rules, role grants, and CI checks govern who connects to your stack. Yet any allowed script, engineer, or AI agent still runs commands with the full scope of its role. For workloads on Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes, SSH, or internal HTTP services, hoop.dev sits beside the service as an open-source proxy, a sidecar for your database or API.
Before a query runs, hoop.dev guardrails check the statement against your rules. An AI Analyzer you configure can score intent or hold risky calls for human review. Next, hoop.dev data masking rewrites sensitive fields in responses, and each verdict is logged per listener. Explore the MIT-licensed project on GitHub.
Frequently asked questions
How do I stop feature branches from assuming a production role?
Add a branch condition to the trust rule on your production cloud role. Set the rule to allow tokens only when the branch claim matches your main branch.
Why does my pipeline fail to assume the cloud role?
Most failures happen when the audience string or repo ID does not match. Check that your cloud identity provider settings match the exact strings from your repo.
Should I use one cloud role for all my repos?
No, sharing one role across repos gives every project the same cloud reach. Create a dedicated role per repo and environment so each pipeline stays isolated.
Related guides
In this post