Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.apache.hadoop.ozone.OzoneFsServerDefaults;
import org.apache.hadoop.ozone.client.protocol.ClientProtocol;
import org.apache.hadoop.ozone.om.exceptions.OMException;
import org.apache.hadoop.ozone.om.helpers.AssumeRoleResponseInfo;
import org.apache.hadoop.ozone.om.helpers.BucketLayout;
import org.apache.hadoop.ozone.om.helpers.DeleteTenantState;
import org.apache.hadoop.ozone.om.helpers.OmVolumeArgs;
Expand Down Expand Up @@ -750,6 +751,25 @@ public Iterator<OzoneSnapshotDiff> listSnapshotDiffJobs(
return new SnapshotDiffJobIterator(volumeName, bucketName, jobStatus, listAllStatus, prevSnapshotDiffJob);
}

/**
* Process the AssumeRole operation.
*
* @param roleArn The ARN of the role to assume
* @param roleSessionName The session name (should be unique) for this operation
* @param durationSeconds The duration in seconds for the token validity
* @param awsIamSessionPolicy The AWS IAM JSON session policy
* @return AssumeRoleResponseInfo The AssumeRole response information containing temporary credentials
* @throws IOException if an error occurs during the AssumeRole operation
*/
public AssumeRoleResponseInfo assumeRole(
String roleArn,
String roleSessionName,
int durationSeconds,
String awsIamSessionPolicy
) throws IOException {
return proxy.assumeRole(roleArn, roleSessionName, durationSeconds, awsIamSessionPolicy);
}

/**
* An Iterator to iterate over {@link SnapshotDiffJobIterator} list.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.apache.hadoop.ozone.client.io.OzoneOutputStream;
import org.apache.hadoop.ozone.om.OMConfigKeys;
import org.apache.hadoop.ozone.om.exceptions.OMException;
import org.apache.hadoop.ozone.om.helpers.AssumeRoleResponseInfo;
import org.apache.hadoop.ozone.om.helpers.DeleteTenantState;
import org.apache.hadoop.ozone.om.helpers.ErrorInfo;
import org.apache.hadoop.ozone.om.helpers.LeaseKeyInfo;
Expand Down Expand Up @@ -1359,4 +1360,20 @@ void putObjectTagging(String volumeName, String bucketName, String keyName,
void deleteObjectTagging(String volumeName, String bucketName, String keyName)
throws IOException;

/**
* Process the AssumeRole operation.
*
* @param roleArn The ARN of the role to assume
* @param roleSessionName The session name (should be unique) for this operation
* @param durationSeconds The duration in seconds for the token validity
* @param awsIamSessionPolicy The AWS IAM JSON session policy
* @return AssumeRoleResponseInfo The AssumeRole response information containing temporary credentials
* @throws IOException if an error occurs during the AssumeRole operation
*/
AssumeRoleResponseInfo assumeRole(
String roleArn,
String roleSessionName,
int durationSeconds,
String awsIamSessionPolicy
) throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
import org.apache.hadoop.ozone.client.protocol.ClientProtocol;
import org.apache.hadoop.ozone.om.OmConfig;
import org.apache.hadoop.ozone.om.exceptions.OMException;
import org.apache.hadoop.ozone.om.helpers.AssumeRoleResponseInfo;
import org.apache.hadoop.ozone.om.helpers.BasicOmKeyInfo;
import org.apache.hadoop.ozone.om.helpers.BucketEncryptionKeyInfo;
import org.apache.hadoop.ozone.om.helpers.BucketLayout;
Expand Down Expand Up @@ -2790,6 +2791,16 @@ public void deleteObjectTagging(String volumeName, String bucketName,
ozoneManagerClient.deleteObjectTagging(keyArgs);
}

@Override
public AssumeRoleResponseInfo assumeRole(
String roleArn,
String roleSessionName,
int durationSeconds,
String awsIamSessionPolicy
) throws IOException {
return ozoneManagerClient.assumeRole(roleArn, roleSessionName, durationSeconds, awsIamSessionPolicy);
}

private static ExecutorService createThreadPoolExecutor(
int corePoolSize, int maximumPoolSize, String threadNameFormat) {
return new ThreadPoolExecutor(corePoolSize, maximumPoolSize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ public static boolean isReadOnly(
case CompleteMultiPartUpload:
case AbortMultiPartUpload:
case GetS3Secret:
case AssumeRole:
case GetDelegationToken:
case RenewDelegationToken:
case CancelDelegationToken:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.hadoop.ozone.om.helpers;

import java.util.Objects;
import net.jcip.annotations.Immutable;
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.AssumeRoleResponse;

/**
* Utility class to handle AssumeRoleResponse protobuf message.
*/
@Immutable
public class AssumeRoleResponseInfo {

private final String accessKeyId;
private final String secretAccessKey;
private final String sessionToken;
private final long expirationEpochSeconds;
private final String assumedRoleId;

public String getAccessKeyId() {
return accessKeyId;
}

public String getSecretAccessKey() {
return secretAccessKey;
}

public String getSessionToken() {
return sessionToken;
}

public long getExpirationEpochSeconds() {
return expirationEpochSeconds;
}

public String getAssumedRoleId() {
return assumedRoleId;
}

public AssumeRoleResponseInfo(
String accessKeyId,
String secretAccessKey,
String sessionToken,
long expirationEpochSeconds,
String assumedRoleId
) {
this.accessKeyId = accessKeyId;
this.secretAccessKey = secretAccessKey;
this.sessionToken = sessionToken;
this.expirationEpochSeconds = expirationEpochSeconds;
this.assumedRoleId = assumedRoleId;
}

public static AssumeRoleResponseInfo fromProtobuf(
AssumeRoleResponse response
) {
return new AssumeRoleResponseInfo(
response.getAccessKeyId(),
response.getSecretAccessKey(),
response.getSessionToken(),
response.getExpirationEpochSeconds(),
response.getAssumedRoleId()
);
}

public AssumeRoleResponse getProtobuf() {
return AssumeRoleResponse.newBuilder()
.setAccessKeyId(accessKeyId)
.setSecretAccessKey(secretAccessKey)
.setSessionToken(sessionToken)
.setExpirationEpochSeconds(expirationEpochSeconds)
.setAssumedRoleId(assumedRoleId)
.build();
}

@Override
public String toString() {
return "AssumeRoleResponseInfo{" +
"accessKeyId='" + accessKeyId + '\'' +
", secretAccessKey='" + secretAccessKey + '\'' +
", sessionToken='" + sessionToken + '\'' +
", expirationEpochSeconds=" + expirationEpochSeconds +
", assumedRoleId='" + assumedRoleId + '\'' +
'}';
}

@Override
public boolean equals(
Object o
) {
if (this == o) {
return true;
}

if (o == null || getClass() != o.getClass()) {
return false;
}

final AssumeRoleResponseInfo that = (AssumeRoleResponseInfo) o;
return expirationEpochSeconds == that.expirationEpochSeconds &&
Objects.equals(accessKeyId, that.accessKeyId) &&
Objects.equals(secretAccessKey, that.secretAccessKey) &&
Objects.equals(sessionToken, that.sessionToken) &&
Objects.equals(assumedRoleId, that.assumedRoleId);
}

@Override
public int hashCode() {
return Objects.hash(
accessKeyId,
secretAccessKey,
sessionToken,
expirationEpochSeconds,
assumedRoleId
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.hadoop.ozone.om.IOmMetadataReader;
import org.apache.hadoop.ozone.om.OMConfigKeys;
import org.apache.hadoop.ozone.om.exceptions.OMException;
import org.apache.hadoop.ozone.om.helpers.AssumeRoleResponseInfo;
import org.apache.hadoop.ozone.om.helpers.DBUpdates;
import org.apache.hadoop.ozone.om.helpers.DeleteTenantState;
import org.apache.hadoop.ozone.om.helpers.ErrorInfo;
Expand Down Expand Up @@ -1175,4 +1176,25 @@ default void deleteObjectTagging(OmKeyArgs args) throws IOException {
* @throws IOException
*/
void startQuotaRepair(List<String> buckets) throws IOException;

/**
* Process the AssumeRole operation.
*
* @param roleArn The ARN of the role to assume
* @param roleSessionName The session name (should be unique) for this operation
* @param durationSeconds The duration in seconds for the token validity
* @param awsIamSessionPolicy The AWS IAM JSON session policy
* @return AssumeRoleResponseInfo The AssumeRole response information containing temporary credentials
* @throws IOException if an error occurs during the AssumeRole operation
*/
default AssumeRoleResponseInfo assumeRole(
String roleArn,
String roleSessionName,
int durationSeconds,
String awsIamSessionPolicy
) throws IOException {
throw new UnsupportedOperationException(
"OzoneManager does not require this to be implemented"
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.apache.hadoop.ozone.ClientVersion;
import org.apache.hadoop.ozone.OzoneAcl;
import org.apache.hadoop.ozone.om.exceptions.OMException;
import org.apache.hadoop.ozone.om.helpers.AssumeRoleResponseInfo;
import org.apache.hadoop.ozone.om.helpers.BasicOmKeyInfo;
import org.apache.hadoop.ozone.om.helpers.DBUpdates;
import org.apache.hadoop.ozone.om.helpers.DeleteTenantState;
Expand Down Expand Up @@ -2650,6 +2651,29 @@ public void deleteObjectTagging(OmKeyArgs args) throws IOException {
handleError(omResponse);
}

@Override
public AssumeRoleResponseInfo assumeRole(
String roleArn,
String roleSessionName,
int durationSeconds,
String awsIamSessionPolicy
) throws IOException {
final OzoneManagerProtocolProtos.AssumeRoleRequest.Builder request =
OzoneManagerProtocolProtos.AssumeRoleRequest.newBuilder()
.setRoleArn(roleArn)
.setRoleSessionName(roleSessionName)
.setDurationSeconds(durationSeconds)
.setAwsIamSessionPolicy(awsIamSessionPolicy != null ? awsIamSessionPolicy : "");

final OMRequest omRequest = createOMRequest(Type.AssumeRole)
.setAssumeRoleRequest(request)
.build();

return AssumeRoleResponseInfo.fromProtobuf(
handleError(submitRequest(omRequest)).getAssumeRoleResponse()
);
}

private SafeMode toProtoBuf(SafeModeAction action) {
switch (action) {
case ENTER:
Expand Down
Loading