Skip to content

Commit 8a79f51

Browse files
authored
Merge pull request #1 from fmorg-git/HDDS-13724-base-classes
[HDDS-13724] Create initial classes for storing temporary secrets
2 parents ed13a05 + 243266e commit 8a79f51

21 files changed

Lines changed: 667 additions & 162 deletions

File tree

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,6 @@ public S3SecretValue getS3Secret(String kerberosID, boolean createIfNotExist)
204204
return proxy.getS3Secret(kerberosID, createIfNotExist);
205205
}
206206

207-
public String getS3StsToken(String accessId) throws IOException {
208-
return proxy.getS3StsToken(accessId);
209-
}
210207
/**
211208
* Set secretKey for accessId.
212209
* @param accessId

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -750,13 +750,6 @@ S3SecretValue setS3Secret(String accessId, String secretKey)
750750
*/
751751
void revokeS3Secret(String kerberosID) throws IOException;
752752

753-
/**
754-
* Get STS token for given accessId and secret.
755-
* @param accessID
756-
* @throws IOException
757-
*/
758-
String getS3StsToken(String accessID) throws IOException;
759-
760753
/**
761754
* Create a tenant.
762755
* @param tenantId tenant name.

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -847,18 +847,6 @@ public void revokeS3Secret(String kerberosID) throws IOException {
847847
ozoneManagerClient.revokeS3Secret(kerberosID);
848848
}
849849

850-
/**
851-
* {@inheritDoc}
852-
*/
853-
@Override
854-
public String getS3StsToken(String accessID)
855-
throws IOException {
856-
Preconditions.checkArgument(StringUtils.isNotBlank(accessID),
857-
"accessID cannot be null or empty.");
858-
System.out.println("RpcClient received getS3StsToken request.");
859-
return ozoneManagerClient.getS3StsToken(accessID);
860-
}
861-
862850
/**
863851
* {@inheritDoc}
864852
*/
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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.om;
19+
20+
import java.io.IOException;
21+
import org.apache.hadoop.ozone.om.helpers.S3TemporarySecretValue;
22+
23+
/**
24+
* Batcher for write and read operations for temporary s3 secrets. Depend on provide batch operator.
25+
*/
26+
public interface S3TemporarySecretBatcher {
27+
/**
28+
* Add with provided batch.
29+
* @param batchOperator instance of batch operator.
30+
* @param id entity id.
31+
* @param s3TemporarySecretValue s3 temporary secret value.
32+
* @throws IOException in case when batch operation failed.
33+
*/
34+
void addWithBatch(AutoCloseable batchOperator,
35+
String id,
36+
S3TemporarySecretValue s3TemporarySecretValue)
37+
throws IOException;
38+
39+
/**
40+
* Delete with provided batch.
41+
* @param batchOperator instance of batch operator.
42+
* @param id entity id.
43+
* @throws IOException in case when batch operation failed.
44+
*/
45+
void deleteWithBatch(AutoCloseable batchOperator, String id)
46+
throws IOException;
47+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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.om;
19+
20+
import java.util.List;
21+
import org.apache.hadoop.ozone.om.helpers.S3TemporarySecretValue;
22+
23+
/**
24+
* Cache layer of S3 temporary secrets.
25+
*/
26+
public interface S3TemporarySecretCache {
27+
/**
28+
* Put temporary secret value to cache.
29+
* @param accessKeyId temporary secret value identifier.
30+
* @param temporarySecretValue temporary secret value.
31+
*/
32+
void put(String accessKeyId, S3TemporarySecretValue temporarySecretValue);
33+
34+
/**
35+
* Invalidate temporary secret value with provided secret identifier.
36+
* @param accessKeyId temporary secret identifier.
37+
*/
38+
void invalidate(String accessKeyId);
39+
40+
/**
41+
* Clears the cache, removing all entries, this is called when the
42+
* doubleBuffer is flushed to the DB.
43+
*/
44+
void clearCache(List<Long> transactionIds);
45+
46+
/**
47+
* Get value from cache.
48+
* @param accessKeyId temporary secret value identifier.
49+
* @return Temporary Secret value or {@code null} if value doesn't exist.
50+
*/
51+
S3TemporarySecretValue get(String accessKeyId);
52+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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.om;
19+
20+
import java.io.IOException;
21+
22+
/**
23+
* Functional interface for s3 temporary secret locked actions.
24+
* @param <T>
25+
*/
26+
public interface S3TemporarySecretFunction<T> {
27+
28+
T accept(S3TemporarySecretManager s3TemporarySecretManager) throws IOException;
29+
}
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
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.om;
19+
20+
import java.io.IOException;
21+
import java.util.List;
22+
import org.apache.hadoop.ozone.om.helpers.S3TemporarySecretValue;
23+
import org.slf4j.Logger;
24+
import org.slf4j.LoggerFactory;
25+
26+
/**
27+
* Interface to manage s3 temporary secrets.
28+
*/
29+
public interface S3TemporarySecretManager {
30+
Logger LOG = LoggerFactory.getLogger(S3TemporarySecretManager.class);
31+
32+
/**
33+
* API to get s3 temporary secret value for given access key id.
34+
* @param accessKeyId s3 access key id.
35+
* @return associated s3 temporary secret or null if secret doesn't exist.
36+
* @throws IOException if error occurs while retrieving the secret
37+
*/
38+
S3TemporarySecretValue getTemporarySecret(String accessKeyId) throws IOException;
39+
40+
/**
41+
* API to get s3 temporary secret for given accessKeyId.
42+
* @param accessKeyId s3 access key id.
43+
* @return associated s3 temporary secret or null if secret doesn't exist.
44+
* @throws IOException if error occurs while retrieving the secret
45+
*/
46+
String getTemporarySecretString(String accessKeyId) throws IOException;
47+
48+
/**
49+
* Store provided s3 temporary secret and associate it with access key id.
50+
* @param accessKeyId s3 access key id.
51+
* @param temporarySecretValue s3 temporary secret value.
52+
* @throws IOException if error occurs while storing the temporary secret.
53+
*/
54+
void storeTemporarySecret(String accessKeyId, S3TemporarySecretValue temporarySecretValue)
55+
throws IOException;
56+
57+
/**
58+
* Revoke s3 temporary secret which associated with provided access key id.
59+
* @param accessKeyId s3 access key id.
60+
* @throws IOException if error occurs while revoking the temporary secret.
61+
*/
62+
void revokeTemporarySecret(String accessKeyId) throws IOException;
63+
64+
/**
65+
* Clear s3 temporary secret cache when double buffer is flushed to the DB.
66+
*/
67+
void clearS3TemporaryCache(List<Long> epochs);
68+
69+
/**
70+
* Apply provided action under write lock.
71+
* @param lockId lock identifier.
72+
* @param action custom action.
73+
* @param <T> type of action result.
74+
* @return action result.
75+
* @throws IOException in case the action failed.
76+
*/
77+
<T> T doUnderLock(String lockId, S3TemporarySecretFunction<T> action)
78+
throws IOException;
79+
80+
/**
81+
* Default implementation of secret check method.
82+
* @param accessKeyId s3 access key id.
83+
* @return true if an associated s3 temporary secret exists for given {@code accessKeyId},
84+
* false if not.
85+
*/
86+
default boolean hasS3TemporarySecret(String accessKeyId) throws IOException {
87+
return getTemporarySecret(accessKeyId) != null;
88+
}
89+
90+
S3TemporarySecretBatcher batcher();
91+
92+
default boolean isBatchSupported() {
93+
return batcher() != null;
94+
}
95+
96+
/**
97+
* Direct temporary secret cache accessor.
98+
* @return s3 temporary secret cache.
99+
*/
100+
S3TemporarySecretCache cache();
101+
102+
default void updateCache(String accessKeyId, S3TemporarySecretValue temporarySecretValue) {
103+
final S3TemporarySecretCache cache = cache();
104+
if (cache != null) {
105+
LOG.info("Updating temporary secret cache for accessKeyId: {}.", accessKeyId);
106+
cache.put(accessKeyId, temporarySecretValue);
107+
}
108+
}
109+
110+
default void invalidateCacheEntry(String id) {
111+
final S3TemporarySecretCache cache = cache();
112+
if (cache != null) {
113+
cache.invalidate(id);
114+
}
115+
}
116+
117+
default void clearCache(List<Long> flushedTransactionIds) {
118+
final S3TemporarySecretCache cache = cache();
119+
if (cache != null) {
120+
cache.clearCache(flushedTransactionIds);
121+
}
122+
}
123+
124+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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.om;
19+
20+
import java.io.IOException;
21+
import org.apache.hadoop.ozone.om.helpers.S3TemporarySecretValue;
22+
23+
/**
24+
* S3 temporary secret store interface.
25+
*/
26+
public interface S3TemporarySecretStore {
27+
28+
/**
29+
* Store provided s3 temporary secret with associated access key id.
30+
* @param accessKeyId access key id.
31+
* @param temporarySecret s3 temporary secret.
32+
* @throws IOException if error occurs while storing the temporary secret.
33+
*/
34+
void storeTemporarySecret(String accessKeyId, S3TemporarySecretValue temporarySecret)
35+
throws IOException;
36+
37+
/**
38+
* Get s3 temporary secret associated with provided access key id.
39+
* @param accessKeyId access key id.
40+
* @return s3 temporary secret value or null if s3 temporary secret not founded.
41+
* @throws IOException if error occurs while getting the temporary secret.
42+
*/
43+
S3TemporarySecretValue getTemporarySecret(String accessKeyId) throws IOException;
44+
45+
/**
46+
* Revoke s3 temporary secret associated with provided access key id.
47+
* @param accessKeyId access key id.
48+
* @throws IOException if error occurs while revoking the temporary secret.
49+
*/
50+
void revokeTemporarySecret(String accessKeyId) throws IOException;
51+
52+
/**
53+
* @return s3 temporary batcher instance, null if batch operation isn't supported.
54+
*/
55+
S3TemporarySecretBatcher batcher();
56+
}

0 commit comments

Comments
 (0)