jenkinsci / aws-credentials-plugin

CloudBees Amazon Web Services Credentials Plugin
https://plugins.jenkins.io/aws-credentials/
MIT License
27 stars 72 forks source link

Added IamRoleRegion to Credential in order to set a custom sts region for sts Client #235

Open foglia-prometeia opened 5 months ago

foglia-prometeia commented 5 months ago

Added iamRoleRegion as attribute in:

GUI Changes

Before image

After image

Testing done

We created this simple use case:

pipeline {
    agent any
    parameters {
        string(name: 'region', defaultValue: "")
        string(name: 'credential', defaultValue: "")
    }
    stages {
        stage('TEST') {
            steps {
                withCredentials([[
                    $class: 'AmazonWebServicesCredentialsBinding',
                    credentialsId: "${params.credential}",
                    accessKeyVariable: 'AWS_ACCESS_KEY_ID',
                    secretKeyVariable: 'AWS_SECRET_ACCESS_KEY'
                ]]) {
                    sh "aws sts get-caller-identity --region ${params.region}"
                }
            }
        }

    }
}

Problem found before iamRoleRegion Using the provided test over a credential:role we encountered this error "The security token included in the request is invalid" caused by the role being assumed in a different region then the target region for the aws cli operations. Thus to solve this problem iamRoleRegion has been added to the plugin Credential.

### Submitter checklist
- [x] Make sure you are opening from a **topic/feature/bugfix branch** (right side) and not your main branch!
- [x] Ensure that the pull request title represents the desired changelog entry
- [x] Please describe what you did
- [ ] Link to relevant issues in GitHub or Jira
- [ ] Link to relevant pull requests, esp. upstream and downstream changes
- [x] Ensure you have provided tests - that demonstrates feature works or fixes the issue