Skip to content

Commit 7ec6aff

Browse files
author
Fabian Morgan
committed
plumbing and cli utility to revoke STS token
1 parent 8f7ec10 commit 7ec6aff

16 files changed

Lines changed: 682 additions & 1 deletion

File tree

hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/OzoneConsts.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ public final class OzoneConsts {
301301
public static final String S3_GETSECRET_USER = "S3GetSecretUser";
302302
public static final String S3_SETSECRET_USER = "S3SetSecretUser";
303303
public static final String S3_REVOKESECRET_USER = "S3RevokeSecretUser";
304+
public static final String S3_REVOKESTSTOKEN_USER = "S3RevokeSTSTokenUser";
304305
public static final String RENAMED_KEYS_MAP = "renamedKeysMap";
305306
public static final String UNRENAMED_KEYS_MAP = "unRenamedKeysMap";
306307
public static final String MULTIPART_UPLOAD_PART_NUMBER = "partNumber";
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.hadoop.ozone.shell.s3;
19+
20+
import java.io.IOException;
21+
import java.io.InputStreamReader;
22+
import java.nio.charset.StandardCharsets;
23+
import java.util.Scanner;
24+
import org.apache.hadoop.ozone.client.OzoneClient;
25+
import org.apache.hadoop.ozone.shell.OzoneAddress;
26+
import picocli.CommandLine.Command;
27+
import picocli.CommandLine.Option;
28+
29+
/**
30+
* Executes revocation of STS tokens.
31+
*
32+
* <p>This command marks the specified STS temporary access key id as revoked
33+
* by adding it to the OM's revoked STS token table. Subsequent S3 requests
34+
* using the same temporary access key id will be rejected once the revocation
35+
* state has propagated.</p>
36+
*/
37+
@Command(name = "revokeststoken",
38+
description = "Revoke S3 STS token for the given access key id")
39+
public class RevokeSTSTokenHandler extends S3Handler {
40+
41+
@Option(names = "-k",
42+
required = true,
43+
description = "STS temporary access key id (for example, ASIA...)")
44+
private String accessKeyId;
45+
46+
@Option(names = "-t",
47+
required = true,
48+
description = "STS session token")
49+
private String sessionToken;
50+
51+
@Option(names = "-y",
52+
description = "Continue without interactive user confirmation")
53+
private boolean yes;
54+
55+
@Override
56+
protected boolean isApplicable() {
57+
return securityEnabled();
58+
}
59+
60+
@Override
61+
protected void execute(OzoneClient client, OzoneAddress address)
62+
throws IOException {
63+
64+
if (!yes) {
65+
out().print("Enter 'y' to confirm STS token revocation for accessKeyId '" +
66+
accessKeyId + "': ");
67+
out().flush();
68+
final Scanner scanner = new Scanner(new InputStreamReader(System.in, StandardCharsets.UTF_8));
69+
final String confirmation = scanner.next().trim().toLowerCase();
70+
if (!"y".equals(confirmation)) {
71+
out().println("Revoke STS token operation cancelled.");
72+
return;
73+
}
74+
}
75+
76+
client.getObjectStore().revokeSTSToken(accessKeyId, sessionToken);
77+
out().println("STS token revoked for accessKeyId '" + accessKeyId + "'.");
78+
}
79+
}

hadoop-ozone/cli-shell/src/main/java/org/apache/hadoop/ozone/shell/s3/S3Shell.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
subcommands = {
2929
GetS3SecretHandler.class,
3030
SetS3SecretHandler.class,
31-
RevokeS3SecretHandler.class
31+
RevokeS3SecretHandler.class,
32+
RevokeSTSTokenHandler.class
3233
})
3334
public class S3Shell extends Shell {
3435

hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/ObjectStore.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,16 @@ public AssumeRoleResponseInfo assumeRole(String roleArn, String roleSessionName,
766766
return proxy.assumeRole(roleArn, roleSessionName, durationSeconds, awsIamSessionPolicy);
767767
}
768768

769+
/**
770+
* Revokes an STS token.
771+
* @param accessKeyId The STS accessKeyId (starting with ASIA...)
772+
* @param sessionToken The STS session token
773+
* @throws IOException if an error occurs while revoking the STS token
774+
*/
775+
public void revokeSTSToken(String accessKeyId, String sessionToken) throws IOException {
776+
proxy.revokeSTSToken(accessKeyId, sessionToken);
777+
}
778+
769779
/**
770780
* An Iterator to iterate over {@link SnapshotDiffJobIterator} list.
771781
*/

hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/protocol/ClientProtocol.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,4 +1372,12 @@ void deleteObjectTagging(String volumeName, String bucketName, String keyName)
13721372
*/
13731373
AssumeRoleResponseInfo assumeRole(String roleArn, String roleSessionName, int durationSeconds,
13741374
String awsIamSessionPolicy) throws IOException;
1375+
1376+
/**
1377+
* Revokes an STS token.
1378+
* @param accessKeyId The STS accessKeyId (starting with ASIA...)
1379+
* @param sessionToken The STS session token
1380+
* @throws IOException if an error occurs while revoking the STS token
1381+
*/
1382+
void revokeSTSToken(String accessKeyId, String sessionToken) throws IOException;
13751383
}

hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rpc/RpcClient.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2797,6 +2797,11 @@ public AssumeRoleResponseInfo assumeRole(String roleArn, String roleSessionName,
27972797
return ozoneManagerClient.assumeRole(roleArn, roleSessionName, durationSeconds, awsIamSessionPolicy);
27982798
}
27992799

2800+
@Override
2801+
public void revokeSTSToken(String accessKeyId, String sessionToken) throws IOException {
2802+
ozoneManagerClient.revokeSTSToken(accessKeyId, sessionToken);
2803+
}
2804+
28002805
private static ExecutorService createThreadPoolExecutor(
28012806
int corePoolSize, int maximumPoolSize, String threadNameFormat) {
28022807
return new ThreadPoolExecutor(corePoolSize, maximumPoolSize,

hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/OmUtils.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ public static boolean isReadOnly(
321321
case DeleteOpenKeys:
322322
case SetS3Secret:
323323
case RevokeS3Secret:
324+
case RevokeSTSToken:
324325
case PurgeDirectories:
325326
case PurgePaths:
326327
case CreateTenant:

hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocol/OzoneManagerProtocol.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,4 +1191,14 @@ default AssumeRoleResponseInfo assumeRole(String roleArn, String roleSessionName
11911191
String awsIamSessionPolicy) throws IOException {
11921192
throw new UnsupportedOperationException("OzoneManager does not require this to be implemented");
11931193
}
1194+
1195+
/**
1196+
* Revokes an STS token.
1197+
* @param accessKeyId The STS accessKeyId (starting with ASIA...)
1198+
* @param sessionToken The STS session token
1199+
* @throws IOException if an error occurs while revoking the STS token
1200+
*/
1201+
default void revokeSTSToken(String accessKeyId, String sessionToken) throws IOException {
1202+
throw new UnsupportedOperationException("OzoneManager does not require this to be implemented");
1203+
}
11941204
}

hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocolPB/OzoneManagerProtocolClientSideTranslatorPB.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2675,6 +2675,21 @@ public AssumeRoleResponseInfo assumeRole(String roleArn, String roleSessionName,
26752675
handleError(submitRequest(omRequest)).getAssumeRoleResponse());
26762676
}
26772677

2678+
@Override
2679+
public void revokeSTSToken(String accessKeyId, String sessionToken) throws IOException {
2680+
final OzoneManagerProtocolProtos.RevokeSTSTokenRequest request =
2681+
OzoneManagerProtocolProtos.RevokeSTSTokenRequest.newBuilder()
2682+
.setAccessKeyId(accessKeyId)
2683+
.setSessionToken(sessionToken)
2684+
.build();
2685+
2686+
final OMRequest omRequest = createOMRequest(Type.RevokeSTSToken)
2687+
.setRevokeSTSTokenRequest(request)
2688+
.build();
2689+
2690+
handleError(submitRequest(omRequest));
2691+
}
2692+
26782693
private SafeMode toProtoBuf(SafeModeAction action) {
26792694
switch (action) {
26802695
case ENTER:

hadoop-ozone/interface-client/src/main/proto/OmClientProtocol.proto

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ enum Type {
157157
GetObjectTagging = 141;
158158
DeleteObjectTagging = 142;
159159
AssumeRole = 143;
160+
RevokeSTSToken = 144;
160161
}
161162

162163
enum SafeMode {
@@ -306,6 +307,7 @@ message OMRequest {
306307
optional DeleteObjectTaggingRequest deleteObjectTaggingRequest = 142;
307308
repeated SetSnapshotPropertyRequest SetSnapshotPropertyRequests = 143;
308309
optional AssumeRoleRequest assumeRoleRequest = 144;
310+
optional RevokeSTSTokenRequest revokeSTSTokenRequest = 145;
309311
}
310312

311313
message OMResponse {
@@ -440,6 +442,7 @@ message OMResponse {
440442
optional PutObjectTaggingResponse putObjectTaggingResponse = 141;
441443
optional DeleteObjectTaggingResponse deleteObjectTaggingResponse = 142;
442444
optional AssumeRoleResponse assumeRoleResponse = 143;
445+
optional RevokeSTSTokenResponse revokeSTSTokenResponse = 144;
443446
}
444447

445448
enum Status {
@@ -2381,6 +2384,14 @@ message AssumeRoleResponse {
23812384
required string assumedRoleId = 5;
23822385
}
23832386

2387+
message RevokeSTSTokenRequest {
2388+
required string accessKeyId = 1;
2389+
required string sessionToken = 2;
2390+
}
2391+
2392+
message RevokeSTSTokenResponse {
2393+
}
2394+
23842395
/**
23852396
The OM service that takes care of Ozone namespace.
23862397
*/

0 commit comments

Comments
 (0)