-
Notifications
You must be signed in to change notification settings - Fork 8.9k
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
YARN-9708. Yarn Federation Router Support DelegationToken. #4746
Conversation
💔 -1 overall
This message was automatically generated. |
@goiri Please help to review the code, thank you very much! |
💔 -1 overall
This message was automatically generated. |
💔 -1 overall
This message was automatically generated. |
@goiri Can you help review this part of the code? Thank you very much! |
...test/java/org/apache/hadoop/yarn/server/federation/utils/TestFederationStateStoreFacade.java
Outdated
Show resolved
Hide resolved
...n/java/org/apache/hadoop/yarn/server/router/security/RouterDelegationTokenSecretManager.java
Show resolved
Hide resolved
💔 -1 overall
This message was automatically generated. |
💔 -1 overall
This message was automatically generated. |
💔 -1 overall
This message was automatically generated. |
@goiri Please help to review the code again, thank you very much! |
@@ -112,4 +115,14 @@ public YARNDelegationTokenIdentifierProto getProto() { | |||
setBuilderFields(); | |||
return builder.build(); | |||
} | |||
|
|||
@InterfaceAudience.Private |
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.
Can we import the InterfaceAudience.Private as others?
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.
I will modify the code.
|
||
// Restore the DelegationKey from the request | ||
RouterMasterKey masterKey = request.getRouterMasterKey(); | ||
ByteBuffer keyByteBuf = masterKey.getKeyBytes(); |
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.
We seem to do this a few times. Can we extract?
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.
Thanks for your suggestion, I will refactor this part of the code.
...on/src/main/java/org/apache/hadoop/yarn/server/federation/store/records/RouterMasterKey.java
Show resolved
Hide resolved
@InterfaceAudience.Private | ||
@InterfaceStability.Unstable | ||
public static RouterMasterKeyResponse newInstance(RouterMasterKey masterKey) { | ||
RouterMasterKeyResponse request = |
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.
Single line
|
||
// DTIdentifier -> renewDate | ||
private Map<RMDelegationTokenIdentifier, Long> delegationTokenState = | ||
new HashMap<RMDelegationTokenIdentifier, Long>(); |
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.
new HashMap<>();
and single line
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.
I will modify the code.
facade.storeNewToken(dtId1, renewDate1); | ||
|
||
Map<RMDelegationTokenIdentifier, Long> token1 = | ||
new HashMap<RMDelegationTokenIdentifier, Long>(); |
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.
new HashMap<>(); and single line
facade.storeNewToken(dtId1, renewDate1); | ||
|
||
Map<RMDelegationTokenIdentifier, Long> token1 = | ||
new HashMap<RMDelegationTokenIdentifier, Long>(); |
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.
Single line and shorter.
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.
I will fix it.
YarnConfiguration.RM_DELEGATION_TOKEN_RENEW_INTERVAL_DEFAULT); | ||
|
||
return new RouterDelegationTokenSecretManager(secretKeyInterval, | ||
tokenMaxLifetime, tokenRenewInterval, 3600000); |
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.
3600000 make it 10 hours: 10 * 60 * 60 * 1000
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.
Thanks for your suggestion. I will fix it.
I think hardcoding 3600000 should not be a reasonable way, the parameters should be extracted into the configuration file, because this part is consistent with RM, it will use RM-related parameter names.
It is not very reasonable to extract this parameter in this pr into the configuration file, I submitted a separate pr for extracting this parameter into the configuration file.
JIRA: YARN-11253. Add Configuration to delegationToken RemoverScanInterval.
PR: #4751
Can you help review this pr? Thank you very much!
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.
3600000 make it 10 hours: 10 * 60 * 60 * 1000
I double checked, it should be 1 hour, 60 * 60 * 1000
DelegationKey paramKey = new DelegationKey(1234, 4321, "keyBytes".getBytes()); | ||
DelegationKey responseKey = secretManager.getMasterKeyByDelegationKey(paramKey); | ||
|
||
Assert.assertNotNull(paramKey); |
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.
Import the asserts statically.
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.
I will fix it.
Assert.assertNotNull(paramKey); | ||
Assert.assertEquals(storeKey.getExpiryDate(), responseKey.getExpiryDate()); | ||
Assert.assertEquals(storeKey.getKeyId(), responseKey.getKeyId()); | ||
Assert.assertTrue(Arrays.equals(storeKey.getEncodedKey(), responseKey.getEncodedKey())); |
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.
Assert.assertArrayEquals
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.
I will fix it.
💔 -1 overall
This message was automatically generated. |
💔 -1 overall
This message was automatically generated. |
@goiri Please help to review the code again, Thank you very much! |
*/ | ||
@InterfaceAudience.Public | ||
package org.apache.hadoop.yarn.security.client.impl.pb; | ||
import org.apache.hadoop.classification.InterfaceAudience; |
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.
Import Public
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.
I will modify the code.
* @param masterKey masterKey | ||
* @return DelegationKey | ||
*/ | ||
private DelegationKey getDelegationKeyByMasterKey(RouterMasterKey masterKey) { |
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.
static?
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.
I will fix it.
💔 -1 overall
This message was automatically generated. |
💔 -1 overall
This message was automatically generated. |
@goiri Please help to review the code again, Thank you very much! |
💔 -1 overall
This message was automatically generated. |
@goiri Please help to review the code again, Thank you very much! |
💔 -1 overall
This message was automatically generated. |
💔 -1 overall
This message was automatically generated. |
@goiri Please help to review the code again, Thank you very much! |
import org.apache.hadoop.yarn.proto.YarnSecurityTokenProtos.YARNDelegationTokenIdentifierProtoOrBuilder; | ||
import org.apache.hadoop.yarn.security.client.YARNDelegationTokenIdentifier; | ||
|
||
@InterfaceAudience.Private |
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.
Import these things directly
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.
Thank you very much for your help reviewing the code, I will fix it.
💔 -1 overall
This message was automatically generated. |
@goiri Please help to review the code again, Thank you very much! |
|
||
@Private | ||
@Unstable | ||
public class YARNDelegationTokenIdentifierPBImpl extends YARNDelegationTokenIdentifier { |
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.
Do we have PBImpl tests?
It would be good to split the PR if possible.
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.
Thank you very much for your help reviewing the code, I will add PBImpl tests. This pr code is a bit too much, I will split this pr.
💔 -1 overall
This message was automatically generated. |
💔 -1 overall
This message was automatically generated. |
JIRA: YARN-9708. Yarn Router Support DelegationToken.
In the YARN non-federation mode,
RMDelegationTokenIdentifier
is generated, updated, and deleted by RM.In the YARN federation mode, the Router replaces the RM to interact with the Client, so the operation of the DelegationToken originally performed by the RM will be replaced by the Router.
In this process, it is necessary to ensure that the original generation method of DelegationToken remains unchanged.
1.RM's management of DelegationToken
RMDelegationTokenIdentifier
is managed byRMDelegationTokenSecretManager
,RMDelegationTokenSecretManager
inherits fromAbstractDelegationTokenSecretManager
.AbstractDelegationTokenSecretManager
is responsible for the generation of MasterKey and Token.RMDelegationTokenSecretManager
is responsible for storing MasterKey and Token.RMDelegationTokenSecretManager
contains 5 important methods.In the process of persisting Token, RM mainly relies on RMStateStore for storage, among which there are two key implementations, MemoryRMStateStore, ZKRMStateStore.
We can refer to the following figure
1.
AbstractDelegationTokenSecretManager
callsupdateCurrentKey
instartThread
androllMasterKey
2.
updateCurrentKey
callsstoreDelegationKey
3.
storeDelegationKey
callsstoreNewMasterKey
,4.Because
AbstractDelegationTokenSecretManager
is an abstract class, the concrete implementation will be called, andRMDelegationTokenSecretManager
will be called forstoreNewMasterKey
5.
storeNewMasterKey
call rm.getRMContext().getStateStore().storeRMDTMasterKey6.RM StateStore will send an RMStateStoreEventType.STORE_MASTERKEY event
7. We can find the following code logic in RMStateStore:
StoreRMDTMasterKeyTransition
will finally process the request ofstoreRMDTMasterKeyState
.8.1 MemoryRMStateStore#storeRMDTMasterKeyState
8.2 ZKRMStateStore#storeRMDTMasterKeyState
The calling logic of the other four methods(removeStoredMasterKey, storeNewToken, updateStoredToken, removeStoredToken) is similar to that of storeNewMasterKey.
2.Router's management of DelegationToken
The Router will replace the RM to interact with the client in the federation, and the client cannot directly connect to the RM. In order to ensure the function of RM DelegationToken, we should implement it on the Router side according to the implementation method of RM.
RMDelegationTokenSecretManager
, the Router will InheritAbstractDelegationTokenSecretManager
and implementRouterDelegationTokenSecretManager
FederationStateStore
We can refer to the following figure
1.
AbstractDelegationTokenSecretManager
callsupdateCurrentKey
instartThread
androllMasterKey
2.
updateCurrentKey
callsstoreDelegationKey
3.
storeDelegationKey
callsstoreNewMasterKey
4.Because
AbstractDelegationTokenSecretManager
is an abstract class, the concrete implementation will be called, andRouterDelegationTokenSecretManager
will be called forstoreNewMasterKey
5.
RouterDelegationTokenSecretManager
#storeNewMasterKey
callsFederationFacade
#storeNewMasterKey
6.
FederationFacade
#storeNewMasterKey
callsFederationStateStore
#storeNewMasterKey
7. For the specific implementation class of
FederationStateStore
, the implementation of related methods will be completed.