Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assume Role support improvements #20

Merged
merged 1 commit into from
Aug 3, 2017

Conversation

alexejk
Copy link
Contributor

@alexejk alexejk commented May 30, 2017

Two changes in this PR.

1. Session Token variable

To use e.g AWS CLI with AssumeRole support, an AWS_SESSION_TOKEN variable must be set, or AWS would complain that no access key is found on record. This variable is only bound if credentials returned by the credentials provider are session-based.
Fixes #19

2. Instance Profile credentials

To further support moving away from hard-set AWS Credentials and allow role switching (e.g cross-account access), this PR also adds following behavior:
If no access & secret keys are set as part of credentials, but IAM role is set - attempting to fetch credentials via instance profile.
Fixes #18 #15

Motivation for both changes is to simplify management of multi-AWS account environments and to remove useage of Access/Secret keys which should be rotated quite often according to security best-practices. Relying on instance profile and assume-role allows us to completely forget about provisioning IAM users in different accounts.

I've also added compile version of the HPI file here: https://github.com/AlexejK/aws-credentials-plugin/releases/tag/aws-credentials-1.21-pr20 (for those who need to try this out but can't build themselves)

@alexejk alexejk changed the title Session token variable set Assume Role support improvements May 30, 2017
@ghost
Copy link

ghost commented Jun 1, 2017

This pull request originates from a CloudBees employee. At CloudBees, we require that all pull requests be reviewed by other CloudBees employees before we seek to have the change accepted. If you want to learn more about our process please see this explanation.

@jglick
Copy link
Member

jglick commented Jun 1, 2017

Please delete the @ reviewbybees mention, assuming you are not in fact a CloudBees employee. See link above.

@alexejk
Copy link
Contributor Author

alexejk commented Jun 1, 2017

Sorry for that, was my assumption this was required to get this on the radar of maintainers (based on other PRs). Fixed

@alexejk
Copy link
Contributor Author

alexejk commented Jun 7, 2017

Now rebased on-top of 1.20 release of this plugin

@andresrc
Copy link
Contributor

Sorry for not including this one in the upcoming release, I'll try to get someone more appropriate than me to review it.

If no access key and secret is set, also attempting to fetch credentials via instance profile
@HontoNoRoger
Copy link

What's the ETA on this? We'd like to get this feature included as well.

@alexejk
Copy link
Contributor Author

alexejk commented Jul 12, 2017

@HontoNoRoger Even though not ideal - you may want to try using the pre-built version I've linked at the end of my PR. We've been using that version on our Jenkins servers since the creation of this PR and it has been working nicely for us.

@oleg-nenashev
Copy link
Member

@andresrc any updates?

Copy link
Member

@oleg-nenashev oleg-nenashev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change looks good to me, but I am not an expert in this API. 👍 for pushing it anyway!

@alexejk
Copy link
Contributor Author

alexejk commented Jul 24, 2017

Hey guys, would it be possible to merge this so it comes in the next release?

@farrellit
Copy link

this is really necessary for the role assumption thing to work at all. Without this change, it you can't even use the role beasue the token insn't set! I don't really understand how the role assumption thing was half implemented in the first place; apparently it wasn't tested at all.

@oleg-nenashev
Copy link
Member

@andresrc ping

@andresrc
Copy link
Contributor

andresrc commented Aug 3, 2017

I'm ok with the change, but I would like a review from @Vlatombe

@Vlatombe
Copy link
Member

Vlatombe commented Aug 3, 2017

LGTM

@andresrc andresrc merged commit 90daab3 into jenkinsci:master Aug 3, 2017
@alexejk
Copy link
Contributor Author

alexejk commented Aug 16, 2017

@andresrc thanks for merging. Would it be possible to push a release so we don't have to use my custom build?

@cpanato
Copy link

cpanato commented Aug 28, 2017

this was released?

@alexejk
Copy link
Contributor Author

alexejk commented Aug 29, 2017

Still no release. This was merged post 1.21 release so should come in 1.22 is my guess.
However I do not know if @andresrc or @oleg-nenashev can comment on the release timeline.

@oleg-nenashev
Copy link
Member

I can comment. The release happens when the maintainer does the release. Keep pinging @andresrc. You can also offer to take ownership of this plugin if @andresrc has no time for this plugin (I'd guess so)

@andresrc
Copy link
Contributor

Hi, sorry for the delay in the answer, I was out. Version 1.22 has been released.

@cpanato
Copy link

cpanato commented Aug 31, 2017

this page still show the 1.21 :( https://wiki.jenkins.io/display/JENKINS/CloudBees+AWS+Credentials+Plugin

@alexejk
Copy link
Contributor Author

alexejk commented Aug 31, 2017

@cpanato While the wiki is out of data, Jenkins servers do see the new version

@@ -113,6 +114,11 @@ public AWSCredentials getCredentials() {
if (StringUtils.isBlank(iamRoleArn)) {
return initialCredentials;
} else {
// Handle the case of delegation to instance profile
if (StringUtils.isBlank(accessKey) && StringUtils.isBlank(secretKey.getPlainText()) ) {
initialCredentials = (new InstanceProfileCredentialsProvider()).getCredentials();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this has already been merged and released, but isn't the manually-specified IAM role in the credentials entry (iamRoleArn) redundant in this case? The instance profile already contains an assigned IAM role, which is what should be used in this case, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use-case for this feature is to specifically switch to a different account's role.
Useful in cross-account integrations.

Instance Profile is needed for this (unless creds are used) to authenticate that you are allowed to do this switch, and role is needed as a target.

@kivagant-ba
Copy link

kivagant-ba commented May 13, 2019

How to use the feature in a pipeline script? Where to find the documentation?

UP: Found #15 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AWS_SESSION_TOKEN environment variable not being set EC2 Instance Profile support for AWS Credentials
10 participants