Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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 @@ -255,6 +255,7 @@ public static boolean isReadOnly(
case TenantListUser:
case ListSnapshot:
case EchoRPC:
case GetCurrentSecretKey:
case RangerBGSync:
// RangerBGSync is a read operation in the sense that it doesn't directly
// write to OM DB. And therefore it doesn't need a OMClientRequest.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -995,4 +995,6 @@ EchoRPCResponse echoRPCReq(byte[] payloadReq,
*/
boolean recoverLease(String volumeName, String bucketName,
String keyName) throws IOException;

void refetchSecretKey() throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.FinalizeUpgradeResponse;
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.GetAclRequest;
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.GetAclResponse;
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.GetCurrentSecretKeyRequest;
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.GetDelegationTokenResponseProto;
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.GetFileStatusRequest;
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.GetFileStatusResponse;
Expand Down Expand Up @@ -1355,6 +1356,17 @@ public S3VolumeContext getS3VolumeContext() throws IOException {
return S3VolumeContext.fromProtobuf(resp);
}

@Override
public void refetchSecretKey() throws IOException {
final GetCurrentSecretKeyRequest.Builder requestBuilder =
GetCurrentSecretKeyRequest.newBuilder();
final OMRequest omRequest = createOMRequest(Type.GetCurrentSecretKey)
.setGetCurrentSecretKeyRequest(requestBuilder)
.build();
final OMResponse omResponse = submitRequest(omRequest);
handleError(omResponse);
}

/**
* Return the proxy object underlying this protocol translator.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.RandomUtils;
import org.apache.hadoop.hdds.annotation.InterfaceAudience;
import org.apache.hadoop.hdds.cli.OzoneAdmin;
import org.apache.hadoop.hdds.conf.DefaultConfigManager;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.scm.ScmConfig;
Expand Down Expand Up @@ -55,8 +56,11 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.io.InputStream;
import java.net.InetAddress;
import java.util.Objects;
Expand Down Expand Up @@ -112,6 +116,7 @@ public final class TestBlockTokens {
public Timeout timeout = Timeout.seconds(180);

private static MiniKdc miniKdc;
private static OzoneAdmin ozoneAdmin;
private static OzoneConfiguration conf;
private static File workDir;
private static File ozoneKeytab;
Expand All @@ -121,6 +126,7 @@ public final class TestBlockTokens {
private static String host;
private static String clusterId;
private static String scmId;
private static String omServiceId;
private static MiniOzoneHAClusterImpl cluster;
private static OzoneClient client;
private static BlockInputStreamFactory blockInputStreamFactory =
Expand All @@ -137,13 +143,15 @@ public static void init() throws Exception {
GenericTestUtils.getTestDir(TestBlockTokens.class.getSimpleName());
clusterId = UUID.randomUUID().toString();
scmId = UUID.randomUUID().toString();
omServiceId = "om-service-test";

startMiniKdc();
setSecureConfig();
createCredentialsInKDC();
setSecretKeysConfig();
startCluster();
client = cluster.newClient();
ozoneAdmin = new OzoneAdmin(conf);
createTestData();
}

Expand Down Expand Up @@ -271,6 +279,22 @@ public void blockTokenFailsOnWrongPassword() throws Exception {
assertExceptionContains("Invalid token for user", ex);
}

@Test
public void testGetCurrentSecretKey() throws UnsupportedEncodingException {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PrintStream printStream = new PrintStream(outputStream, true, "UTF-8");
System.setOut(printStream);

String[] args =
new String[]{"om", "fetch-key", "--service-id=" + omServiceId};
ozoneAdmin.execute(args);

String actualOutput = outputStream.toString("UTF-8");
System.setOut(System.out);

assertTrue(actualOutput.contains("Successfully re-fetched the secret key"));
}


private UUID extractSecretKeyId(OmKeyInfo keyInfo) throws IOException {
OmKeyLocationInfo locationInfo =
Expand Down Expand Up @@ -383,6 +407,7 @@ private static void startCluster()
MiniOzoneCluster.Builder builder = MiniOzoneCluster.newHABuilder(conf)
.setClusterId(clusterId)
.setSCMServiceId("TestSecretKey")
.setOMServiceId("om-service-test")
.setScmId(scmId)
.setNumDatanodes(3)
.setNumOfStorageContainerManagers(3)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ enum Type {
TransferLeadership = 117;
SnapshotPurge = 118;
RecoverLease = 119;
GetCurrentSecretKey = 120;
}

message OMRequest {
Expand Down Expand Up @@ -252,6 +253,7 @@ message OMRequest {
optional SnapshotPurgeRequest SnapshotPurgeRequest = 118;

optional RecoverLeaseRequest RecoverLeaseRequest = 119;
optional GetCurrentSecretKeyRequest GetCurrentSecretKeyRequest = 120;
}

message OMResponse {
Expand Down Expand Up @@ -362,6 +364,7 @@ message OMResponse {
optional hdds.TransferLeadershipResponseProto TransferOmLeadershipResponse = 117;
optional SnapshotPurgeResponse SnapshotPurgeResponse = 118;
optional RecoverLeaseResponse RecoverLeaseResponse = 119;
optional GetCurrentSecretKeyResponse GetCurrentSecretKeyResponse = 120;
}

enum Status {
Expand Down Expand Up @@ -589,6 +592,14 @@ message SetVolumePropertyResponse {
optional bool response = 1;
}

message GetCurrentSecretKeyRequest {

}

message GetCurrentSecretKeyResponse {

}

/**
* Checks if the user has specified permissions for the volume
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,10 @@ private void stopSecretManager() {
}
}

public void refetchSecretKey() {
secretKeyClient.getCurrentSecretKey();
}

@VisibleForTesting
public void startSecretManager() {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.GetFileStatusResponse;
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.GetKeyInfoRequest;
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.GetKeyInfoResponse;
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.GetCurrentSecretKeyResponse;
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.InfoBucketRequest;
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.InfoBucketResponse;
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.InfoVolumeRequest;
Expand Down Expand Up @@ -310,6 +311,9 @@ public OMResponse handleReadRequest(OMRequest request) {
responseBuilder.setTransferOmLeadershipResponse(transferLeadership(
request.getTransferOmLeadershipRequest()));
break;
case GetCurrentSecretKey:
responseBuilder.setGetCurrentSecretKeyResponse(getCurrentSecretKey());
break;
default:
responseBuilder.setSuccess(false);
responseBuilder.setMessage("Unrecognized Command Type: " + cmdType);
Expand Down Expand Up @@ -944,6 +948,13 @@ private RangerBGSyncResponse triggerRangerBGSync(
return RangerBGSyncResponse.newBuilder().setRunSuccess(res).build();
}

private GetCurrentSecretKeyResponse getCurrentSecretKey() {
impl.refetchSecretKey();
GetCurrentSecretKeyResponse response =
GetCurrentSecretKeyResponse.newBuilder().build();
return response;
}

@RequestFeatureValidator(
conditions = ValidationCondition.OLDER_CLIENT_REQUESTS,
processingPhase = RequestProcessingPhase.POST_PROCESS,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.admin.om;

import java.util.concurrent.Callable;
import org.apache.hadoop.hdds.cli.HddsVersionProvider;
import org.apache.hadoop.ozone.om.protocol.OzoneManagerProtocol;
import picocli.CommandLine;

/**
* Handler of ozone admin om fetch-key command.
*/
@CommandLine.Command(
name = "fetch-key",
description = "CLI command to fetch the latest key",
mixinStandardHelpOptions = true,
versionProvider = HddsVersionProvider.class
)
public class FetchKeySubCommand implements Callable<Void> {
@CommandLine.ParentCommand
private OMAdmin parent;

@CommandLine.Option(
names = {"-id", "--service-id"},
description = "Ozone Manager Service ID",
required = true
)
private String omServiceId;

@Override
public Void call() throws Exception {
try (OzoneManagerProtocol client = parent.createOmClient(omServiceId)) {
client.refetchSecretKey();
System.out.println("Successfully re-fetched the secret key.");
}
return null;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
FinalizationStatusSubCommand.class,
DecommissionOMSubcommand.class,
UpdateRangerSubcommand.class,
TransferOmLeaderSubCommand.class
TransferOmLeaderSubCommand.class,
FetchKeySubCommand.class
})
@MetaInfServices(SubcommandWithParent.class)
public class OMAdmin extends GenericCli implements SubcommandWithParent {
Expand Down