Skip to content

Commit 2439e27

Browse files
authored
Merge pull request #17538 from iterate-ch/feature/GH-17437-tags
Add option to define tags when assuming role.
2 parents a8c060e + 752cbfe commit 2439e27

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

core/src/main/java/ch/cyberduck/core/Profile.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public class Profile implements Protocol {
6969
* A constant key used to define the Amazon Resource Name (ARN) for AWS Security Token Service (STS)
7070
*/
7171
public static final String STS_ROLE_ARN_PROPERTY_KEY = "role_arn";
72+
public static final String STS_TAGS_PROPERTY_KEY = "tags";
7273
public static final String STS_ROLE_SESSION_NAME_PROPERTY_KEY = "role_session_name";
7374
public static final String STS_DURATION_SECONDS_PROPERTY_KEY = "duration_seconds";
7475
/**

s3/src/main/java/ch/cyberduck/core/sts/STSAssumeRoleRequestInterceptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public STSAssumeRoleRequestInterceptor(final Host host, final X509TrustManager t
5252
public TemporaryAccessTokens refresh(final Credentials credentials) throws BackgroundException {
5353
lock.lock();
5454
try {
55-
if(StringUtils.isNotBlank(new ProxyPreferencesReader(host, credentials).getProperty(Profile.STS_ROLE_ARN_PROPERTY_KEY, "s3.assumerole.rolearn"))) {
55+
if(StringUtils.isNotBlank(new ProxyPreferencesReader(credentials, host).getProperty(Profile.STS_ROLE_ARN_PROPERTY_KEY, "s3.assumerole.rolearn"))) {
5656
log.debug("Retrieve temporary credentials with {}", credentials);
5757
// AssumeRoleRequest
5858
return tokens = this.assumeRole(credentials);

s3/src/main/java/ch/cyberduck/core/sts/STSAuthorizationService.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
import org.apache.logging.log4j.LogManager;
4242
import org.apache.logging.log4j.Logger;
4343

44+
import java.util.stream.Collectors;
45+
4446
import com.amazonaws.auth.AWSStaticCredentialsProvider;
4547
import com.amazonaws.auth.AnonymousAWSCredentials;
4648
import com.amazonaws.client.builder.AwsClientBuilder;
@@ -57,6 +59,7 @@
5759
import com.amazonaws.services.securitytoken.model.GetCallerIdentityResult;
5860
import com.amazonaws.services.securitytoken.model.GetSessionTokenRequest;
5961
import com.amazonaws.services.securitytoken.model.GetSessionTokenResult;
62+
import com.amazonaws.services.securitytoken.model.Tag;
6063
import com.auth0.jwt.JWT;
6164
import com.auth0.jwt.exceptions.JWTDecodeException;
6265

@@ -100,7 +103,7 @@ public String validate(final Credentials credentials) throws BackgroundException
100103
}
101104

102105
public TemporaryAccessTokens getSessionToken(final Credentials credentials) throws BackgroundException {
103-
final PreferencesReader settings = new ProxyPreferencesReader(bookmark, credentials);
106+
final PreferencesReader settings = new ProxyPreferencesReader(credentials, bookmark);
104107
// The purpose of the sts:GetSessionToken operation is to authenticate the user using MFA.
105108
final GetSessionTokenRequest request = new GetSessionTokenRequest()
106109
.withRequestCredentialsProvider(S3CredentialsStrategy.toCredentialsProvider(credentials));
@@ -170,12 +173,15 @@ public TemporaryAccessTokens getSessionToken(final Credentials credentials) thro
170173
* @see Profile#STS_MFA_ARN_PROPERTY_KEY
171174
*/
172175
public TemporaryAccessTokens assumeRole(final Credentials credentials) throws BackgroundException {
173-
final PreferencesReader settings = new ProxyPreferencesReader(bookmark, credentials);
176+
final PreferencesReader settings = new ProxyPreferencesReader(credentials, bookmark);
174177
final AssumeRoleRequest request = new AssumeRoleRequest()
175178
.withRequestCredentialsProvider(S3CredentialsStrategy.toCredentialsProvider(credentials));
176179
if(StringUtils.isNotBlank(settings.getProperty("s3.assumerole.durationseconds", Profile.STS_DURATION_SECONDS_PROPERTY_KEY))) {
177180
request.setDurationSeconds(PreferencesReader.toInteger(settings.getProperty("s3.assumerole.durationseconds", Profile.STS_DURATION_SECONDS_PROPERTY_KEY)));
178181
}
182+
request.setTags(settings.getMap(Profile.STS_TAGS_PROPERTY_KEY).entrySet().stream().map(
183+
entry -> new Tag().withKey(entry.getKey()).withValue(entry.getValue())).collect(Collectors.toList())
184+
);
179185
final String roleArn = settings.getProperty(Profile.STS_ROLE_ARN_PROPERTY_KEY, "s3.assumerole.rolearn");
180186
if(StringUtils.isNotBlank(roleArn)) {
181187
log.debug("Found Role ARN {} for {}", roleArn, bookmark);
@@ -257,7 +263,7 @@ public TemporaryAccessTokens assumeRole(final Credentials credentials) throws Ba
257263
}
258264

259265
public TemporaryAccessTokens assumeRoleWithSAML(final Credentials credentials) throws BackgroundException {
260-
final PreferencesReader settings = new ProxyPreferencesReader(bookmark, credentials);
266+
final PreferencesReader settings = new ProxyPreferencesReader(credentials, bookmark);
261267
final AssumeRoleWithSAMLRequest request = new AssumeRoleWithSAMLRequest().withSAMLAssertion(credentials.getToken());
262268
if(StringUtils.isNotBlank(settings.getProperty("s3.assumerole.durationseconds", Profile.STS_DURATION_SECONDS_PROPERTY_KEY))) {
263269
request.setDurationSeconds(PreferencesReader.toInteger(settings.getProperty("s3.assumerole.durationseconds", Profile.STS_DURATION_SECONDS_PROPERTY_KEY)));
@@ -288,7 +294,7 @@ public TemporaryAccessTokens assumeRoleWithSAML(final Credentials credentials) t
288294
* @return Temporary access tokens for the assumed role
289295
*/
290296
public TemporaryAccessTokens assumeRoleWithWebIdentity(final Credentials credentials) throws BackgroundException {
291-
final PreferencesReader settings = new ProxyPreferencesReader(bookmark, credentials);
297+
final PreferencesReader settings = new ProxyPreferencesReader(credentials, bookmark);
292298
final AssumeRoleWithWebIdentityRequest request = new AssumeRoleWithWebIdentityRequest();
293299
log.debug("Assume role with OIDC Id token for {}", bookmark);
294300
final String webIdentityToken = this.getWebIdentityToken(credentials.getOauth());

s3/src/main/java/ch/cyberduck/core/sts/STSGetSessionTokenRequestInterceptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public STSGetSessionTokenRequestInterceptor(final Host host, final X509TrustMana
5252
public TemporaryAccessTokens refresh(final Credentials credentials) throws BackgroundException {
5353
lock.lock();
5454
try {
55-
if(StringUtils.isNotBlank(new ProxyPreferencesReader(host, credentials).getProperty(Profile.STS_MFA_ARN_PROPERTY_KEY))) {
55+
if(StringUtils.isNotBlank(new ProxyPreferencesReader(credentials, host).getProperty(Profile.STS_MFA_ARN_PROPERTY_KEY))) {
5656
log.debug("Retrieve temporary credentials with {}", credentials);
5757
// GetSessionToken
5858
return tokens = this.getSessionToken(credentials);

0 commit comments

Comments
 (0)