Skip to content

Commit 60de919

Browse files
committed
Get basepath for token exchange from bookmark.
1 parent 8b9970b commit 60de919

File tree

6 files changed

+12
-22
lines changed

6 files changed

+12
-22
lines changed

hub/src/main/java/cloud/katta/protocols/hub/serializer/HubConfigDtoDeserializer.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import com.dd.plist.NSDictionary;
1414

1515
import static ch.cyberduck.core.Profile.*;
16-
import static cloud.katta.protocols.s3.S3AssumeRoleProtocol.OAUTH_TOKENEXCHANGE_CLIENT_ID;
1716

1817
public class HubConfigDtoDeserializer extends ProxyDeserializer<NSDictionary> {
1918

@@ -33,9 +32,6 @@ public <L> List<L> listForKey(final String key) {
3332
switch(key) {
3433
case PROPERTIES_KEY:
3534
final List<String> properties = new ArrayList<>(super.listForKey(key));
36-
if(dto.getKeycloakClientIdCryptomatorVaults() != null) {
37-
properties.add(String.format("%s=%s", OAUTH_TOKENEXCHANGE_CLIENT_ID, dto.getKeycloakClientIdCryptomatorVaults()));
38-
}
3935
return (List<L>) properties;
4036
case SCOPES_KEY:
4137
return (List<L>) Collections.singletonList("openid");

hub/src/main/java/cloud/katta/protocols/hub/serializer/StorageProfileDtoWrapperDeserializer.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ public <L> List<L> listForKey(final String key) {
5656
if(dto.getStsDurationSeconds() != null) {
5757
properties.add(String.format("%s=%s", S3AssumeRoleProtocol.S3_ASSUMEROLE_DURATIONSECONDS, dto.getStsDurationSeconds().toString()));
5858
}
59-
properties.add(String.format("%s=%s", S3AssumeRoleProtocol.OAUTH_TOKENEXCHANGE_CLIENT_SECRET, ""));
6059
}
6160
log.debug("Return properties {} from {}", properties, dto);
6261
return (List<L>) properties;

hub/src/main/java/cloud/katta/protocols/s3/S3AssumeRoleProtocol.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ public class S3AssumeRoleProtocol extends S3Protocol {
1515

1616
// Token exchange
1717
public static final String OAUTH_TOKENEXCHANGE = "oauth.tokenexchange";
18-
public static final String OAUTH_TOKENEXCHANGE_CLIENT_ID = "oauth.tokenexchange.client_id";
19-
public static final String OAUTH_TOKENEXCHANGE_CLIENT_SECRET = "oauth.tokenexchange.audience.client_secret";
20-
public static final String OAUTH_TOKENEXCHANGE_ADDITIONAL_SCOPES = "oauth.tokenexchange.additional_scopes";
18+
public static final String OAUTH_TOKENEXCHANGE_VAULT = "oauth.tokenexchange.vault";
19+
public static final String OAUTH_TOKENEXCHANGE_BASEPATH = "oauth.tokenexchange.basepath";
2120

2221
// STS assume role with web identity from Cyberduck core (AWS + MinIO)
2322
public static final String S3_ASSUMEROLE_ROLEARN = "s3.assumerole.rolearn";

hub/src/main/java/cloud/katta/protocols/s3/STSChainedAssumeRoleRequestInterceptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public void refresh() {
114114
if(StringUtils.isNotBlank(preferences.getProperty("s3.assumerole.tag"))) {
115115
request.setTags(Collections.singletonList(new Tag()
116116
.withKey(preferences.getProperty("s3.assumerole.tag"))
117-
.withValue(preferences.getProperty(S3AssumeRoleProtocol.OAUTH_TOKENEXCHANGE_ADDITIONAL_SCOPES))));
117+
.withValue(preferences.getProperty(S3AssumeRoleProtocol.OAUTH_TOKENEXCHANGE_VAULT))));
118118
}
119119
try {
120120
log.debug("Use request {}", request);

hub/src/main/java/cloud/katta/protocols/s3/TokenExchangeRequestInterceptor.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import ch.cyberduck.core.preferences.HostPreferences;
1616
import ch.cyberduck.core.preferences.PreferencesReader;
1717

18+
import static cloud.katta.protocols.s3.S3AssumeRoleProtocol.OAUTH_TOKENEXCHANGE_BASEPATH;
19+
1820
import org.apache.commons.lang3.StringUtils;
1921
import org.apache.http.client.HttpClient;
2022
import org.apache.logging.log4j.LogManager;
@@ -70,19 +72,19 @@ public OAuthTokens refresh(final OAuthTokens previous) throws BackgroundExceptio
7072
*
7173
* @param previous Input tokens retrieved to exchange at the token endpoint
7274
* @return New tokens
73-
* @see S3AssumeRoleProtocol#OAUTH_TOKENEXCHANGE_CLIENT_ID
74-
* @see S3AssumeRoleProtocol#OAUTH_TOKENEXCHANGE_ADDITIONAL_SCOPES
75+
* @see S3AssumeRoleProtocol#OAUTH_TOKENEXCHANGE_VAULT
76+
* @see S3AssumeRoleProtocol#OAUTH_TOKENEXCHANGE_BASEPATH
7577
*/
7678
public OAuthTokens exchange(final OAuthTokens previous) throws BackgroundException {
7779
log.info("Exchange tokens {} for {}", previous, bookmark);
7880
final PreferencesReader preferences = new HostPreferences(bookmark);
7981
final ApiClient apiClient = new ApiClient(Collections.singletonMap("bearer", new HttpBearerAuth("bearer")));
8082
apiClient.addDefaultHeader("Authorization",String.format("Bearer %s", previous.getAccessToken()));
81-
apiClient.setBasePath("http://localhost:8280/");
83+
apiClient.setBasePath(preferences.getProperty(OAUTH_TOKENEXCHANGE_BASEPATH));
8284

8385
final StorageResourceApi api = new StorageResourceApi(apiClient);
8486
try {
85-
AccessTokenResponse tokenExchangeResponse = api.apiStorageS3TokenPost(preferences.getProperty(S3AssumeRoleProtocol.OAUTH_TOKENEXCHANGE_ADDITIONAL_SCOPES));
87+
AccessTokenResponse tokenExchangeResponse = api.apiStorageS3TokenPost(preferences.getProperty(S3AssumeRoleProtocol.OAUTH_TOKENEXCHANGE_VAULT));
8688
// N.B. token exchange with Id token does not work!
8789
final OAuthTokens tokens = new OAuthTokens(tokenExchangeResponse.getAccessToken(),
8890
tokenExchangeResponse.getRefreshToken(),
@@ -100,12 +102,6 @@ public Credentials validate() throws BackgroundException {
100102
final Credentials credentials = super.validate();
101103
final OAuthTokens tokens = credentials.getOauth();
102104
final String accessToken = tokens.getAccessToken();
103-
final PreferencesReader preferences = new HostPreferences(bookmark);
104-
final String tokenExchangeClientId = preferences.getProperty(S3AssumeRoleProtocol.OAUTH_TOKENEXCHANGE_CLIENT_ID);
105-
if(StringUtils.isEmpty(tokenExchangeClientId)) {
106-
log.warn("Found {} empty, although {} is set to {} - misconfiguration?", S3AssumeRoleProtocol.OAUTH_TOKENEXCHANGE_CLIENT_ID, OAUTH_TOKENEXCHANGE, preferences.getBoolean(OAUTH_TOKENEXCHANGE));
107-
return credentials;
108-
}
109105
try {
110106
final DecodedJWT jwt = JWT.decode(accessToken);
111107

hub/src/main/java/cloud/katta/workflows/VaultServiceImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@
3838
import com.nimbusds.jose.jwk.OctetSequenceKey;
3939

4040
import static cloud.katta.crypto.uvf.UvfMetadataPayload.UniversalVaultFormatJWKS.memberKeyFromRawKey;
41-
import static cloud.katta.protocols.s3.S3AssumeRoleProtocol.OAUTH_TOKENEXCHANGE_ADDITIONAL_SCOPES;
42-
import static cloud.katta.protocols.s3.S3AssumeRoleProtocol.S3_ASSUMEROLE_ROLEARN;
41+
import static cloud.katta.protocols.s3.S3AssumeRoleProtocol.*;
4342

4443
public class VaultServiceImpl implements VaultService {
4544
private static final Logger log = LogManager.getLogger(VaultServiceImpl.class);
@@ -123,7 +122,8 @@ public Host getStorageBackend(final ProtocolFactory protocols, final ConfigDto c
123122
credentials.setPassword(vaultMetadata.getPassword());
124123
}
125124
if(protocol.getProperties().get(S3_ASSUMEROLE_ROLEARN) != null) {
126-
bookmark.setProperty(OAUTH_TOKENEXCHANGE_ADDITIONAL_SCOPES, vaultId.toString());
125+
bookmark.setProperty(OAUTH_TOKENEXCHANGE_VAULT, vaultId.toString());
126+
bookmark.setProperty(OAUTH_TOKENEXCHANGE_BASEPATH, this.vaultResource.getApiClient().getBasePath());
127127
}
128128
// region as chosen by user upon vault creation (STS) or as retrieved from bucket (permanent)
129129
bookmark.setRegion(vaultMetadata.getRegion());

0 commit comments

Comments
 (0)