我试图通过jenkins-cloudformation插件从git中存储的模板启动cloudformation堆栈,但是即使我提供了正确的access_key和secret_key,我也会收到错误消息“ Invalid Client Id”。
此外,将适当的IAM角色附加到运行jenkins的ec2实例,并且jenkins用户可以访问该实例元数据。
无论我是否在jenkins配置中传递secretKey,accessKey,都会出现此错误。
有人可以指导我哪里出问题了吗
错误
Building in workspace /apps/jenkins/.jenkins/workspace/Cloudformation_Test
> /usr/bin/git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> /usr/bin/git config remote.origin.url https://xxxx.git # timeout=10
Fetching upstream changes from https://xxxx.git
> /usr/bin/git --version # timeout=10
using GIT_ASKPASS to set credentials Gitlab user webadmdeamon to perform CICD with Jenkins
> /usr/bin/git fetch --tags --progress https://xxx.get +refs/heads/*:refs/remotes/origin/*
> /usr/bin/git rev-parse refs/remotes/origin/master^{commit} # timeout=10
> /usr/bin/git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision 827b91075eb0ae5901b641a7588b9b5769ad2ce7 (refs/remotes/origin/master)
> /usr/bin/git config core.sparsecheckout # timeout=10
> /usr/bin/git checkout -f 827b91075eb0ae5901b641a7588b9b5769ad2ce7
Commit message: "Add new file"
> /usr/bin/git rev-list --no-walk 827b91075eb0ae5901b641a7588b9b5769ad2ce7 # timeout=10
Determining to create or update Cloud Formation stack: JenkinsCloudformationTest
Stack not found: JenkinsCloudformationTest. Reason: Detailed Message: The security token included in the request is invalid. (Service: AmazonCloudFormation; Status Code: 403; Error Code: InvalidClientTokenId; Request ID: be71618c-3027-11e9-8d00-45421bf87ce0)
Status Code: 403
Error Code: InvalidClientTokenId
Creating Cloud Formation stack: JenkinsCloudformationTest
Failed to create stack: JenkinsCloudformationTest. Reason: Detailed Message: The security token included in the request is invalid. (Service: AmazonCloudFormation; Status Code: 403; Error Code: InvalidClientTokenId; Request ID: be73364d-3027-11e9-8d00-45421bf87ce0)
Status Code: 403
Error Code: InvalidClientTokenId
Finished: FAILURE
编辑---
我能够在相同的ec2实例中和同一用户下使用aws cli创建堆栈。
答案 0 :(得分:1)
日志显示您的问题与身份验证有关:
Reason: Detailed Message: The security token included in the request is invalid.
(Service: AmazonCloudFormation; Status Code: 403; Error Code: InvalidClientTokenId; Request
ID: be71618c-3027-11e9-8d00-45421bf87ce0)
Status Code: 403
Error Code: InvalidClientTokenId
问题可能是Jenkins插件中的错误,或者是(更可能是)您提供给插件的密钥问题。
与此同时,插件的源代码(code ref)似乎表明该插件始终尝试使用您提供的访问密钥。如果您将键字段留为空白,我猜它会尝试将空字符串作为键。因此,附加到实例的IAM角色可能不相关。
请注意,您收到的InvalidClientTokenId
错误已记录为here:
InvalidClientTokenId
提供的X.509证书或AWS访问密钥ID在我们的记录中不存在。
HTTP状态码:403
现在,您在更新中提到:
我能够在相同的ec2实例中和同一用户下使用aws cli创建堆栈。
因此,首先,请重试,然后在CloudTrail中查看。按EventName = CreateStack进行过滤,然后您将看到类似以下内容的
:用户和访问密钥是否真的相同?
我怀疑您会发现它不是,而解决方法将是提供正确的访问密钥。如果没有,请告诉我,我们可以考虑其他可能性。