You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Set up a role on AWS on Account A, with a policy allowing sts:AssumeRole for a role on Account B.
Set up a role on AWS on Account B with a trust policy allowing the role on Account A to assume it.
Assign role from Account A to Jenkins agent.
In declarative Jenkinsfile, create withAWS block, stating name of role in Account B. Set useNode to be true to ensure that Jenkinsfile uses the role attached to the agent instead of the role attached to the master. Add an AWS command within the withAWS block to ensure that resources displayed are from Account B (i.e the assumed credentials) and not Account A.
Jenkinsfile should list ECR repositories within account B due to having assumed the IAM role from Account B.
Actual Results
Jenkinsfile assumes the role correctly, but then lists ECR repositories from Account A instead of Account B.
Setting AWS region us-west-2
Requesting assume role
Assuming role ARN is arn:aws:iam::123456789098:role/ContainerPromotionRole role arn:aws:sts::123456789098:assumed-role/ContainerPromotionRole/Jenkins-TestServices_Multibranch_Pipeline-KS-12345-D-244 with id {KEY}:Jenkins-TestServices_Multibranch_Pipeline-KS-12345-D-244
[Pipeline] {
[Pipeline] sh
Retrieving credentials from node.
+ sudo aws ecr describe-repositories --region us-west-2
(Wrong ECR repos are displayed, from Account A instead of Account B)
Anything else?
Initially I used a withAWS block without useNode. Jenkins failed to assume the role from Account B because it did not have permission. The reason was because the credentials from the Master were being used instead. As such, I added useNode to ensure that the Agent's IAM credentials would be used. After I added useNode, I successfully assumed the role from AWS Account B. However it doesn't look like it is completely working as it is still using the node/agent's credentials instead of the assumed role.
The text was updated successfully, but these errors were encountered:
Jenkins and plugins versions report
Environment
What Operating System are you using (both controller, and any agents involved in the problem)?
Master: Ubuntu 18.04.3 LTS
Agents: Ubuntu 18.04.6 LTS
Reproduction steps
Expected Results
Jenkinsfile should list ECR repositories within account B due to having assumed the IAM role from Account B.
Actual Results
Jenkinsfile assumes the role correctly, but then lists ECR repositories from Account A instead of Account B.
Anything else?
Initially I used a withAWS block without useNode. Jenkins failed to assume the role from Account B because it did not have permission. The reason was because the credentials from the Master were being used instead. As such, I added useNode to ensure that the Agent's IAM credentials would be used. After I added useNode, I successfully assumed the role from AWS Account B. However it doesn't look like it is completely working as it is still using the node/agent's credentials instead of the assumed role.
The text was updated successfully, but these errors were encountered: