-
Notifications
You must be signed in to change notification settings - Fork 586
HDDS-8164. Authorize secret key APIs #4597
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jojochuang
merged 7 commits into
apache:HDDS-7733-Symmetric-Tokens
from
duongkame:HDDS-8164
May 12, 2023
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
057c1cc
HDDS-8164. SCM: Authorize secret key APIs
duongkame acc6e99
Adapt to rebase.
duongkame 0665ebb
correct proto info.
duongkame 4b62146
fix tests
duongkame ff4a860
Update javadoc.
duongkame 9ea7d76
Correct new lines.
duongkame 875e8c7
Prevent system exit in integ test.
duongkame File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...common/src/main/java/org/apache/hadoop/hdds/security/exception/SCMSecretKeyException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /* | ||
| * 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.hdds.security.exception; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| /** | ||
| * Exception for all secret key related errors. | ||
| */ | ||
| public class SCMSecretKeyException extends IOException { | ||
| private final ErrorCode errorCode; | ||
|
|
||
| public SCMSecretKeyException(String message, ErrorCode errorCode) { | ||
| super(message); | ||
| this.errorCode = errorCode; | ||
| } | ||
|
|
||
| public ErrorCode getErrorCode() { | ||
| return errorCode; | ||
| } | ||
|
|
||
| /** | ||
| * Error codes to make it easy to decode these exceptions. | ||
| */ | ||
| public enum ErrorCode { | ||
| OK, | ||
| INTERNAL_ERROR, | ||
| SECRET_KEY_NOT_ENABLED, | ||
| SECRET_KEY_NOT_INITIALIZED | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/protocol/SecretKeyProtocol.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /** | ||
| * 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.hdds.protocol; | ||
|
|
||
| import org.apache.hadoop.hdds.annotation.InterfaceAudience; | ||
| import org.apache.hadoop.hdds.scm.ScmConfig; | ||
| import org.apache.hadoop.hdds.security.symmetric.ManagedSecretKey; | ||
| import org.apache.hadoop.security.KerberosInfo; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.List; | ||
| import java.util.UUID; | ||
|
|
||
| /** | ||
| * The protocol used to expose secret keys in SCM. | ||
| */ | ||
| @KerberosInfo( | ||
| serverPrincipal = ScmConfig.ConfigStrings.HDDS_SCM_KERBEROS_PRINCIPAL_KEY) | ||
| @InterfaceAudience.Private | ||
| public interface SecretKeyProtocol { | ||
|
|
||
| /** | ||
| * Get the current SecretKey that is used for signing tokens. | ||
| * @return ManagedSecretKey | ||
| */ | ||
| ManagedSecretKey getCurrentSecretKey() throws IOException; | ||
|
|
||
| /** | ||
| * Get a particular SecretKey by ID. | ||
| * | ||
| * @param id the id to get SecretKey. | ||
| * @return ManagedSecretKey. | ||
| */ | ||
| ManagedSecretKey getSecretKey(UUID id) throws IOException; | ||
|
|
||
| /** | ||
| * Get all the non-expired SecretKey managed by SCM. | ||
| * @return list of ManagedSecretKey. | ||
| */ | ||
| List<ManagedSecretKey> getAllSecretKeys() throws IOException; | ||
| } |
34 changes: 34 additions & 0 deletions
34
...ds/framework/src/main/java/org/apache/hadoop/hdds/protocol/SecretKeyProtocolDatanode.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /** | ||
| * 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.hdds.protocol; | ||
|
|
||
| import org.apache.hadoop.hdds.annotation.InterfaceAudience; | ||
| import org.apache.hadoop.security.KerberosInfo; | ||
|
|
||
| import static org.apache.hadoop.hdds.scm.ScmConfig.ConfigStrings.HDDS_SCM_KERBEROS_PRINCIPAL_KEY; | ||
| import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_DATANODE_KERBEROS_PRINCIPAL_KEY; | ||
|
|
||
| /** | ||
| * The client protocol to access secret key from Datanode. | ||
| */ | ||
| @KerberosInfo( | ||
| serverPrincipal = HDDS_SCM_KERBEROS_PRINCIPAL_KEY, | ||
| clientPrincipal = DFS_DATANODE_KERBEROS_PRINCIPAL_KEY | ||
| ) | ||
| @InterfaceAudience.Private | ||
| public interface SecretKeyProtocolDatanode extends SecretKeyProtocol { | ||
| } |
32 changes: 32 additions & 0 deletions
32
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/protocol/SecretKeyProtocolOm.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| /** | ||
| * 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.hdds.protocol; | ||
|
|
||
| import org.apache.hadoop.security.KerberosInfo; | ||
|
|
||
| import static org.apache.hadoop.hdds.scm.ScmConfig.ConfigStrings.HDDS_SCM_KERBEROS_PRINCIPAL_KEY; | ||
|
|
||
| /** | ||
| * The client protocol to access secret key from OM. | ||
| */ | ||
| @KerberosInfo( | ||
| serverPrincipal = HDDS_SCM_KERBEROS_PRINCIPAL_KEY, | ||
| // TODO: move OMConfigKeys.OZONE_OM_KERBEROS_PRINCIPAL_KEY to hdds-common. | ||
| clientPrincipal = "ozone.om.kerberos.principal" | ||
| ) | ||
| public interface SecretKeyProtocolOm extends SecretKeyProtocol { | ||
| } |
31 changes: 31 additions & 0 deletions
31
...op-hdds/framework/src/main/java/org/apache/hadoop/hdds/protocol/SecretKeyProtocolScm.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /** | ||
| * 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.hdds.protocol; | ||
|
|
||
| import org.apache.hadoop.security.KerberosInfo; | ||
|
|
||
| import static org.apache.hadoop.hdds.scm.ScmConfig.ConfigStrings.HDDS_SCM_KERBEROS_PRINCIPAL_KEY; | ||
|
|
||
| /** | ||
| * The client protocol to access secret key from SCM. | ||
| */ | ||
| @KerberosInfo( | ||
| serverPrincipal = HDDS_SCM_KERBEROS_PRINCIPAL_KEY, | ||
| clientPrincipal = HDDS_SCM_KERBEROS_PRINCIPAL_KEY | ||
| ) | ||
| public interface SecretKeyProtocolScm extends SecretKeyProtocol { | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error code seems to be only checked but it is not thrown... Do we still need it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like SCM never throws that error code. It can be deleted I guess, but we should do that on master.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh... I see now...
Sorry, I thought it is newly added here, but it is just a punctuation change in the line... Ok, please ignore this earlier comment for this PR.