Skip to content

Commit 8f7ec10

Browse files
authored
HDDS-14066. [STS] Database updates for revoked STS tokens (#9420)
1 parent 3685237 commit 8f7ec10

4 files changed

Lines changed: 63 additions & 8 deletions

File tree

hadoop-ozone/interface-storage/src/main/java/org/apache/hadoop/ozone/om/OMMetadataManager.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,14 @@ String getMultipartKeyFSO(String volume, String bucket, String key, String
484484
*/
485485
Table<String, String> getMetaTable();
486486

487+
/**
488+
* Gets the S3RevokedStsTokenTable.
489+
*
490+
* @return Table.
491+
*/
492+
Table<String, String> getS3RevokedStsTokenTable();
493+
494+
487495
/**
488496
* Returns number of rows in a table. This should not be used for very
489497
* large tables.

hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataManagerImpl.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ public class OmMetadataManagerImpl implements OMMetadataManager,
181181
private TypedTable<String, String> snapshotRenamedTable;
182182
private TypedTable<String, CompactionLogEntry> compactionLogTable;
183183

184+
private TypedTable<String, String> s3RevokedStsTokenTable;
185+
184186
private OzoneManager ozoneManager;
185187

186188
// Epoch is used to generate the objectIDs. The most significant 2 bits of
@@ -486,6 +488,9 @@ protected void initializeOmTables(CacheType cacheType,
486488
// TODO: [SNAPSHOT] Initialize table lock for snapshotRenamedTable.
487489

488490
compactionLogTable = initializer.get(OMDBDefinition.COMPACTION_LOG_TABLE_DEF);
491+
492+
// temporaryAccessKeyId -> sessionToken
493+
s3RevokedStsTokenTable = initializer.get(OMDBDefinition.S3_REVOKED_STS_TOKEN_TABLE_DEF);
489494
}
490495

491496
/**
@@ -1683,6 +1688,11 @@ public Table<String, CompactionLogEntry> getCompactionLogTable() {
16831688
return compactionLogTable;
16841689
}
16851690

1691+
@Override
1692+
public Table<String, String> getS3RevokedStsTokenTable() {
1693+
return s3RevokedStsTokenTable;
1694+
}
1695+
16861696
/**
16871697
* Get Snapshot Chain Manager.
16881698
*

hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/codec/OMDBDefinition.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,14 @@
4949
* OM database definitions.
5050
* <pre>
5151
* {@code
52-
* User, Token and Secret Tables:
52+
* User, Token, Secret and Revoked STS Token Tables:
5353
* |------------------------------------------------------------------------|
54-
* | Column Family | Mapping |
54+
* | Column Family | Mapping |
5555
* |------------------------------------------------------------------------|
56-
* | userTable | /user :- UserVolumeInfo |
57-
* | dTokenTable | OzoneTokenID :- renew_time |
58-
* | s3SecretTable | s3g_access_key_id :- s3Secret |
56+
* | userTable | /user :- UserVolumeInfo |
57+
* | dTokenTable | OzoneTokenID :- renew_time |
58+
* | s3SecretTable | s3g_access_key_id :- s3Secret |
59+
* | s3RevokedStsTokenTable | sts_access_key_id :- sessionToken |
5960
* |------------------------------------------------------------------------|
6061
* }
6162
* </pre>
@@ -139,7 +140,7 @@
139140
public final class OMDBDefinition extends DBDefinition.WithMap {
140141

141142
//---------------------------------------------------------------------------
142-
// User, Token and Secret Tables:
143+
// User, Token, Secret and Revoked STS Token Tables:
143144
public static final String USER_TABLE = "userTable";
144145
/** userTable: /user :- UserVolumeInfo. */
145146
public static final DBColumnFamilyDefinition<String, PersistedUserVolumeInfo> USER_TABLE_DEF
@@ -161,6 +162,13 @@ public final class OMDBDefinition extends DBDefinition.WithMap {
161162
StringCodec.get(),
162163
S3SecretValue.getCodec());
163164

165+
public static final String S3_REVOKED_STS_TOKEN_TABLE = "s3RevokedStsTokenTable";
166+
/** s3RevokedStsTokenTable: sts_access_key_id :- sessionToken.*/
167+
public static final DBColumnFamilyDefinition<String, String> S3_REVOKED_STS_TOKEN_TABLE_DEF
168+
= new DBColumnFamilyDefinition<>(S3_REVOKED_STS_TOKEN_TABLE,
169+
StringCodec.get(),
170+
StringCodec.get());
171+
164172
//---------------------------------------------------------------------------
165173
// Volume, Bucket, Prefix and Transaction Tables:
166174
public static final String VOLUME_TABLE = "volumeTable";
@@ -339,7 +347,8 @@ public final class OMDBDefinition extends DBDefinition.WithMap {
339347
TENANT_STATE_TABLE_DEF,
340348
TRANSACTION_INFO_TABLE_DEF,
341349
USER_TABLE_DEF,
342-
VOLUME_TABLE_DEF);
350+
VOLUME_TABLE_DEF,
351+
S3_REVOKED_STS_TOKEN_TABLE_DEF);
343352

344353
private static final OMDBDefinition INSTANCE = new OMDBDefinition();
345354

hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/TestOmMetadataManager.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import static org.apache.hadoop.ozone.om.codec.OMDBDefinition.OPEN_KEY_TABLE;
3939
import static org.apache.hadoop.ozone.om.codec.OMDBDefinition.PREFIX_TABLE;
4040
import static org.apache.hadoop.ozone.om.codec.OMDBDefinition.PRINCIPAL_TO_ACCESS_IDS_TABLE;
41+
import static org.apache.hadoop.ozone.om.codec.OMDBDefinition.S3_REVOKED_STS_TOKEN_TABLE;
4142
import static org.apache.hadoop.ozone.om.codec.OMDBDefinition.S3_SECRET_TABLE;
4243
import static org.apache.hadoop.ozone.om.codec.OMDBDefinition.SNAPSHOT_INFO_TABLE;
4344
import static org.apache.hadoop.ozone.om.codec.OMDBDefinition.SNAPSHOT_RENAMED_TABLE;
@@ -52,6 +53,7 @@
5253
import static org.junit.jupiter.api.Assertions.assertEquals;
5354
import static org.junit.jupiter.api.Assertions.assertFalse;
5455
import static org.junit.jupiter.api.Assertions.assertNotEquals;
56+
import static org.junit.jupiter.api.Assertions.assertNotNull;
5557
import static org.junit.jupiter.api.Assertions.assertNull;
5658
import static org.junit.jupiter.api.Assertions.assertThrows;
5759
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -137,7 +139,8 @@ public class TestOmMetadataManager {
137139
TENANT_STATE_TABLE,
138140
SNAPSHOT_INFO_TABLE,
139141
SNAPSHOT_RENAMED_TABLE,
140-
COMPACTION_LOG_TABLE
142+
COMPACTION_LOG_TABLE,
143+
S3_REVOKED_STS_TOKEN_TABLE
141144
};
142145

143146
private OMMetadataManager omMetadataManager;
@@ -1289,4 +1292,29 @@ public void testGetMultipartUploadKeys() throws Exception {
12891292

12901293
assertEquals(25, noPagination.size());
12911294
}
1295+
1296+
@Test
1297+
public void testS3RevokedStsTokenTablePutAndGet() throws Exception {
1298+
// Ensure the table is initialized
1299+
assertNotNull(omMetadataManager.getS3RevokedStsTokenTable(), "s3RevokedStsTokenTable should be initialized");
1300+
1301+
final String tempAccessKeyId1 = "ASIA7VUS1EOBCW8RRJVR";
1302+
final String sessionToken1 = "test-session-token-1";
1303+
final String tempAccessKeyId2 = "ASIA904E65QIGL9ON305";
1304+
final String sessionToken2 = "test-session-token-2";
1305+
1306+
omMetadataManager.getS3RevokedStsTokenTable()
1307+
.put(tempAccessKeyId1, sessionToken1);
1308+
omMetadataManager.getS3RevokedStsTokenTable()
1309+
.put(tempAccessKeyId2, sessionToken2);
1310+
1311+
// Verify get and getIfExist return the stored value
1312+
assertEquals(sessionToken1, omMetadataManager.getS3RevokedStsTokenTable().get(tempAccessKeyId1));
1313+
assertEquals(sessionToken1, omMetadataManager.getS3RevokedStsTokenTable().getIfExist(tempAccessKeyId1));
1314+
assertEquals(sessionToken2, omMetadataManager.getS3RevokedStsTokenTable().get(tempAccessKeyId2));
1315+
assertEquals(sessionToken2, omMetadataManager.getS3RevokedStsTokenTable().getIfExist(tempAccessKeyId2));
1316+
1317+
// Unknown key should return null for getIfExist
1318+
assertNull(omMetadataManager.getS3RevokedStsTokenTable().getIfExist("ASIA_UNKNOWN_ACCESS_KEY"));
1319+
}
12921320
}

0 commit comments

Comments
 (0)