使用Atlassian Bitbucket和AWS使用OIDC的错误
如帖子的结尾所述,oidc在我使用时可以使用Atlassian Pipes,但它不适用于导出和AWS CLI选项。
default:
- step:
name: Connect to AWS using OIDC
oidc: true
script:
- export AWS_REGION=$AWS_REGION
- export AWS_ROLE_ARN=arn:aws:iam::1234567890:role/MyRole
- export AWS_WEB_IDENTITY_TOKEN_FILE=$(pwd)/web-identity-token
- echo $BITBUCKET_STEP_OIDC_TOKEN > $(pwd)/web-identity-token
- printenv BITBUCKET_STEP_OIDC_TOKEN
- printenv AWS_REGION
- printenv AWS_ROLE_ARN
- aws sts assume-role-with-web-identity --role-arn arn:aws:iam::1234567890:role/MyRole --role-session-name build-session --web-identity-token "$BITBUCKET_STEP_OIDC_TOKEN" --duration-seconds 1000
printenv输出:
printenv AWS_REGION
us-east-2
printenv AWS_ROLE_ARN
arn:aws:iam::1234567890:role/MyRole
printenv BITBUCKET_STEP_OIDC_TOKEN
<nothing here>
错误:
An error occurred (AccessDenied) when calling the AssumeRoleWithWebIdentity operation: Not authorized to perform sts:AssumeRoleWithWebIdentity
但是,当我使用管道时,一切正常
- pipe: atlassian/aws-s3-deploy:1.1.0
variables:
AWS_DEFAULT_REGION: $AWS_REGION # Optional if already defined in the context or OIDC used.
AWS_OIDC_ROLE_ARN: $AWS_OIDC_ROLE_ARN # Optional by default. Required for OpenID Connect (OIDC) authentication.
S3_BUCKET: mygreat-bucket
LOCAL_PATH: 'build'
CACHE_CONTROL: 'max-age=86400'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我偶然发现了同一件事 - Bitbucket Pipes可以与AWS OIDC一起使用,但脚本却没有。如果您检查特定的管道源代码,您会发现要担任角色的额外步骤几乎需要 - https://bitbucket.org/atlassian/aws-s3-deploy/src/master/pipe/pipe/pipe.sh#lines-35
与OIDC合作的部分,您需要这样做:
I stumbled into the same thing - BitBucket pipes works with AWS OIDC out of the box but scripts does not. If you check particular pipe source code you will find there are few extra steps needed to assume the role - https://bitbucket.org/atlassian/aws-s3-deploy/src/master/pipe/pipe.sh#lines-35
So to make script section working with OIDC you need to have it like this:
我遇到了类似的情况。我想使用AWS OIDC IAM角色在脚本中运行AWS CLI命令。似乎保持
oidc:true
不足以对AWS进行身份验证。因此,作为使OIDC在脚本上工作的解决方法,我使用STS假设命令来获得临时凭据,并使用
jq
linux工具来解析响应并使用它来配置AWS CLI。不知道还有其他更轻松的解决方案,但这对我有用。
I came across a similar situation. I wanted to run aws cli commands inside a script using the AWS OIDC IAM role. Seems keeping
oidc:true
is not sufficient to authenticate to AWS.So as a workaround to make OIDC work on the scripts, I used the sts assume-role command to get the temporary credentials and using the
jq
linux tool to parse the response and use it to configure aws cli.Not sure if there are other easier solutions out there, but this worked for me.
如果我理解正确的话,导出这些ENV变量就足够了,您不需要更多的sTs假设 - with-web-nidentity命令。
只是尝试
If I understand correctly, exporting those env variables is enough and you shouldn't need further sts assume-role-with-web-identity commands.
Just try
我刚刚遇到了这个问题,并通过删除一些我认为正在干扰的旧回购变量来修复:
aws_access_key_id
和aws_secret_access_key
I just came across this issue and fixed it by removing some old repo variables that I believe were interferring:
AWS_ACCESS_KEY_ID
andAWS_SECRET_ACCESS_KEY