-
Notifications
You must be signed in to change notification settings - Fork 694
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
JENKINS-72643: Fixed listing regions when using ec2 ARN role with instance profile #957
base: master
Are you sure you want to change the base?
Conversation
…credentials In the case where a user specified an ARN Role in the advanced section of cloud config we need to use that information when pulling the list of regions. In my case without this ARN Role being used with credentials I would get an empty drop-down list with no errors. I added a log message with the exception to expose a bit of information in case of failures.
@@ -185,14 +185,20 @@ public FormValidation doCheckAltEC2Endpoint(@QueryParameter String value) { | |||
public ListBoxModel doFillRegionItems( | |||
@QueryParameter String altEC2Endpoint, | |||
@QueryParameter boolean useInstanceProfileForCredentials, | |||
@QueryParameter String roleArn, | |||
@QueryParameter String roleSessionName, | |||
@QueryParameter String region, | |||
@QueryParameter String credentialsId) | |||
|
|||
throws IOException, ServletException { | |||
ListBoxModel model = new ListBoxModel(); | |||
if (Jenkins.get().hasPermission(Jenkins.ADMINISTER)) { | |||
try { | |||
AWSCredentialsProvider credentialsProvider = createCredentialsProvider(useInstanceProfileForCredentials, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as far as I can tell from EC2Cloud.java my use here should be OK because there is a guard for empty roleArn and roleSessionName
if (StringUtils.isNotEmpty(roleArn) && StringUtils.isNotEmpty(roleSessionName)) {
return new STSAssumeRoleSessionCredentialsProvider.Builder(roleArn, roleSessionName)
...
@@ -201,6 +207,7 @@ public ListBoxModel doFillRegionItems( | |||
model.add(name, name); | |||
} | |||
} catch (SdkClientException ex) { | |||
LOGGER.log(Level.INFO, "AmazonEC2Cloud.doFillRegionItems() got exception: " + ex); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking I would change this message to incorporate the comment about this may happen before credentials are specified so maybe "OK".
Can we write unit tests which check for logging? The logging would have been VERY helpful to me initially when I encountered this issue.
In the case where a user specified an ARN Role in the advanced section of cloud config we need to use that information when pulling the list of regions.
In my case without this ARN Role being used with credentials I would get an empty drop-down list with no errors.
I added a log message with the exception to expose a bit of information in case of failures.
Testing done
I did test with an ARN Role in the advanced section of cloud config.
I did not (yet) test without this but will do this next. I suppose I could check if roleArn is empty/null and use a different createCredentialsProvider() signature.
I did not see an existing test involving ec2 instance profile or listing regions so did not add one.
Submitter checklist