Package org.apache.hadoop.security.token.delegation
Class AbstractDelegationTokenSecretManager<TokenIdent extends AbstractDelegationTokenIdentifier>
java.lang.Object
org.apache.hadoop.security.token.SecretManager<TokenIdent>
org.apache.hadoop.security.token.delegation.AbstractDelegationTokenSecretManager<TokenIdent>
@Public
@Evolving
public abstract class AbstractDelegationTokenSecretManager<TokenIdent extends AbstractDelegationTokenIdentifier>
extends SecretManager<TokenIdent>
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classorg.apache.hadoop.security.token.delegation.AbstractDelegationTokenSecretManager.DelegationTokenInformationClass to encapsulate a token's renew date and password.Nested classes/interfaces inherited from class org.apache.hadoop.security.token.SecretManager
org.apache.hadoop.security.token.SecretManager.InvalidToken -
Field Summary
FieldsModifier and TypeFieldDescriptionAccess to allKeys is protected by this object lockprotected intAccess to currentId is protected by this object lock.protected Map<TokenIdent,org.apache.hadoop.security.token.delegation.AbstractDelegationTokenSecretManager.DelegationTokenInformation> Cache of currently valid tokens, mapping from DelegationTokenIdentifier to DelegationTokenInformation.protected intSequence number to create DelegationTokenIdentifier.protected ObjectIf the delegation token update thread holds this lock, it will not get interrupted.protected booleanprotected booleanWhether to store a token's tracking ID in its TokenInformation.Map of token real owners to its token count. -
Constructor Summary
ConstructorsConstructorDescriptionAbstractDelegationTokenSecretManager(long delegationKeyUpdateInterval, long delegationTokenMaxLifetime, long delegationTokenRenewInterval, long delegationTokenRemoverScanInterval) Create a secret manager -
Method Summary
Modifier and TypeMethodDescriptionvoidaddKey(org.apache.hadoop.security.token.delegation.DelegationKey key) Add a previously used master key to cache (when NN restarts), should be called before activate().voidaddPersistedDelegationToken(TokenIdent identifier, long renewDate) This method is intended to be used for recovering persisted delegation tokens.protected voidAdd token stats to the owner to token count mapping.cancelToken(Token<TokenIdent> token, String canceller) Cancel a token by removing it from cache.protected org.apache.hadoop.security.token.delegation.AbstractDelegationTokenSecretManager.DelegationTokenInformationcheckToken(TokenIdent identifier) Find the DelegationTokenInformation for the given token id, and verify that if the token is expired.protected byte[]createPassword(TokenIdent identifier) Create the password for the given identifier.static SecretKeycreateSecretKey(byte[] key) Convert the byte[] to a secret keydecodeTokenIdentifier(Token<TokenIdent> token) Decode the token identifier.org.apache.hadoop.security.token.delegation.DelegationKey[]protected Map<TokenIdent,org.apache.hadoop.security.token.delegation.AbstractDelegationTokenSecretManager.DelegationTokenInformation> protected intFor subclasses externalizing the storage, for example Zookeeper based implementations.longTotal count of active delegation tokens.protected org.apache.hadoop.security.token.delegation.DelegationKeygetDelegationKey(int keyId) For subclasses externalizing the storage, for example Zookeeper based implementations.protected intFor subclasses externalizing the storage, for example Zookeeper based implementations.protected org.apache.hadoop.security.token.delegation.AbstractDelegationTokenSecretManager.DelegationTokenSecretManagerMetricsprotected org.apache.hadoop.security.token.delegation.AbstractDelegationTokenSecretManager.DelegationTokenInformationgetTokenInfo(TokenIdent ident) For subclasses externalizing the storage, for example Zookeeper based implementationsprotected longInterval for tokens to be renewed.getTokenTrackingId(TokenIdent identifier) List<org.apache.hadoop.metrics2.util.Metrics2Util.NameValuePair>getTopTokenRealOwners(int n) Return top token real owners list as well as the tokens count.protected StringgetTrackingIdIfEnabled(TokenIdent ident) protected intFor subclasses externalizing the storage, for example Zookeeper based implementations.protected intFor subclasses externalizing the storage, for example Zookeeper based implementations.booleanis secretMgr runningprotected voidlogExpireToken(TokenIdent ident) protected voidlogExpireTokens(Collection<TokenIdent> expiredTokens) protected voidlogUpdateMasterKey(org.apache.hadoop.security.token.delegation.DelegationKey key) protected voidprotected voidremoveStoredMasterKey(org.apache.hadoop.security.token.delegation.DelegationKey key) protected voidremoveStoredToken(TokenIdent ident) longrenewToken(Token<TokenIdent> token, String renewer) Renew a delegation token.voidreset()Reset all data structures and mutable state.byte[]retrievePassword(TokenIdent identifier) Retrieve the password for the given token identifier.protected voidUpdate the current master key for generating delegation tokens It should be called only by tokenRemoverThread.protected voidsetCurrentKeyId(int keyId) For subclasses externalizing the storage, for example Zookeeper based implementations.protected voidsetDelegationTokenSeqNum(int seqNum) For subclasses externalizing the storage, for example Zookeeper based implementations.voidshould be called before this object is used.voidprotected voidstoreDelegationKey(org.apache.hadoop.security.token.delegation.DelegationKey key) For subclasses externalizing the storage, for example Zookeeper based implementations.protected voidstoreNewMasterKey(org.apache.hadoop.security.token.delegation.DelegationKey key) protected voidstoreNewToken(TokenIdent ident, long renewDate) protected voidstoreToken(TokenIdent ident, org.apache.hadoop.security.token.delegation.AbstractDelegationTokenSecretManager.DelegationTokenInformation tokenInfo) For subclasses externalizing the storage, for example Zookeeper based implementations.protected voidThis method syncs token information from currentTokens to tokenOwnerStats.protected voidupdateDelegationKey(org.apache.hadoop.security.token.delegation.DelegationKey key) For subclasses externalizing the storage, for example Zookeeper based implementations.protected voidupdateStoredToken(TokenIdent ident, long renewDate) protected voidupdateToken(TokenIdent ident, org.apache.hadoop.security.token.delegation.AbstractDelegationTokenSecretManager.DelegationTokenInformation tokenInfo) For subclasses externalizing the storage, for example Zookeeper based implementations.voidverifyToken(TokenIdent identifier, byte[] password) Verifies that the given identifier and password are valid and match.Methods inherited from class org.apache.hadoop.security.token.SecretManager
checkAvailableForRead, createIdentifier, createPassword, generateSecret, retriableRetrievePassword, update, validateSecretKeyLength
-
Field Details
-
currentTokens
protected Map<TokenIdent extends AbstractDelegationTokenIdentifier,org.apache.hadoop.security.token.delegation.AbstractDelegationTokenSecretManager.DelegationTokenInformation> currentTokensCache of currently valid tokens, mapping from DelegationTokenIdentifier to DelegationTokenInformation. Protected by this object lock. -
tokenOwnerStats
Map of token real owners to its token count. This is used to generate metrics of top users by owned tokens. -
delegationTokenSequenceNumber
protected int delegationTokenSequenceNumberSequence number to create DelegationTokenIdentifier. Protected by this object lock. -
allKeys
Access to allKeys is protected by this object lock -
currentId
protected int currentIdAccess to currentId is protected by this object lock. -
storeTokenTrackingId
protected boolean storeTokenTrackingIdWhether to store a token's tracking ID in its TokenInformation. Can be overridden by a subclass. -
running
protected volatile boolean running -
noInterruptsLock
If the delegation token update thread holds this lock, it will not get interrupted.
-
-
Constructor Details
-
AbstractDelegationTokenSecretManager
public AbstractDelegationTokenSecretManager(long delegationKeyUpdateInterval, long delegationTokenMaxLifetime, long delegationTokenRenewInterval, long delegationTokenRemoverScanInterval) Create a secret manager- Parameters:
delegationKeyUpdateInterval- the number of milliseconds for rolling new secret keys.delegationTokenMaxLifetime- the maximum lifetime of the delegation tokens in millisecondsdelegationTokenRenewInterval- how often the tokens must be renewed in millisecondsdelegationTokenRemoverScanInterval- how often the tokens are scanned for expired tokens in milliseconds
-
-
Method Details
-
startThreads
should be called before this object is used.- Throws:
IOException- raised on errors performing I/O.
-
reset
public void reset()Reset all data structures and mutable state. -
getCurrentTokensSize
public long getCurrentTokensSize()Total count of active delegation tokens.- Returns:
- currentTokens.size.
-
getTokenRenewInterval
protected long getTokenRenewInterval()Interval for tokens to be renewed.- Returns:
- Renew interval in milliseconds.
-
addKey
public void addKey(org.apache.hadoop.security.token.delegation.DelegationKey key) throws IOException Add a previously used master key to cache (when NN restarts), should be called before activate().- Parameters:
key- delegation key.- Throws:
IOException- raised on errors performing I/O.
-
getAllKeys
public org.apache.hadoop.security.token.delegation.DelegationKey[] getAllKeys() -
logUpdateMasterKey
protected void logUpdateMasterKey(org.apache.hadoop.security.token.delegation.DelegationKey key) throws IOException - Throws:
IOException
-
logExpireToken
- Throws:
IOException
-
storeNewMasterKey
protected void storeNewMasterKey(org.apache.hadoop.security.token.delegation.DelegationKey key) throws IOException - Throws:
IOException
-
removeStoredMasterKey
protected void removeStoredMasterKey(org.apache.hadoop.security.token.delegation.DelegationKey key) -
storeNewToken
- Throws:
IOException
-
removeStoredToken
- Throws:
IOException
-
updateStoredToken
- Throws:
IOException
-
getCurrentKeyId
protected int getCurrentKeyId()For subclasses externalizing the storage, for example Zookeeper based implementations.- Returns:
- currentId.
-
incrementCurrentKeyId
protected int incrementCurrentKeyId()For subclasses externalizing the storage, for example Zookeeper based implementations.- Returns:
- currentId.
-
setCurrentKeyId
protected void setCurrentKeyId(int keyId) For subclasses externalizing the storage, for example Zookeeper based implementations.- Parameters:
keyId- keyId.
-
getDelegationTokenSeqNum
protected int getDelegationTokenSeqNum()For subclasses externalizing the storage, for example Zookeeper based implementations.- Returns:
- delegationTokenSequenceNumber.
-
incrementDelegationTokenSeqNum
protected int incrementDelegationTokenSeqNum()For subclasses externalizing the storage, for example Zookeeper based implementations.- Returns:
- delegationTokenSequenceNumber.
-
setDelegationTokenSeqNum
protected void setDelegationTokenSeqNum(int seqNum) For subclasses externalizing the storage, for example Zookeeper based implementations.- Parameters:
seqNum- seqNum.
-
getDelegationKey
protected org.apache.hadoop.security.token.delegation.DelegationKey getDelegationKey(int keyId) For subclasses externalizing the storage, for example Zookeeper based implementations.- Parameters:
keyId- keyId.- Returns:
- DelegationKey.
-
storeDelegationKey
protected void storeDelegationKey(org.apache.hadoop.security.token.delegation.DelegationKey key) throws IOException For subclasses externalizing the storage, for example Zookeeper based implementations.- Parameters:
key- DelegationKey.- Throws:
IOException- raised on errors performing I/O.
-
updateDelegationKey
protected void updateDelegationKey(org.apache.hadoop.security.token.delegation.DelegationKey key) throws IOException For subclasses externalizing the storage, for example Zookeeper based implementations.- Parameters:
key- DelegationKey.- Throws:
IOException- raised on errors performing I/O.
-
getTokenInfo
protected org.apache.hadoop.security.token.delegation.AbstractDelegationTokenSecretManager.DelegationTokenInformation getTokenInfo(TokenIdent ident) For subclasses externalizing the storage, for example Zookeeper based implementations- Parameters:
ident- ident.- Returns:
- DelegationTokenInformation.
-
storeToken
protected void storeToken(TokenIdent ident, org.apache.hadoop.security.token.delegation.AbstractDelegationTokenSecretManager.DelegationTokenInformation tokenInfo) throws IOException For subclasses externalizing the storage, for example Zookeeper based implementations.- Parameters:
ident- ident.tokenInfo- tokenInfo.- Throws:
IOException- raised on errors performing I/O.
-
updateToken
protected void updateToken(TokenIdent ident, org.apache.hadoop.security.token.delegation.AbstractDelegationTokenSecretManager.DelegationTokenInformation tokenInfo) throws IOException For subclasses externalizing the storage, for example Zookeeper based implementations.- Parameters:
ident- ident.tokenInfo- tokenInfo.- Throws:
IOException- raised on errors performing I/O.
-
addPersistedDelegationToken
This method is intended to be used for recovering persisted delegation tokens. Tokens that have an unknownDelegationKeyare marked as expired and automatically cleaned up. This method must be called before this secret manager is activated (before startThreads() is called)- Parameters:
identifier- identifier read from persistent storagerenewDate- token renew time- Throws:
IOException- raised on errors performing I/O.
-
rollMasterKey
Update the current master key for generating delegation tokens It should be called only by tokenRemoverThread.- Throws:
IOException- raised on errors performing I/O.
-
createPassword
Description copied from class:SecretManagerCreate the password for the given identifier. identifier may be modified inside this method.- Specified by:
createPasswordin classSecretManager<TokenIdent extends AbstractDelegationTokenIdentifier>- Parameters:
identifier- the identifier to use- Returns:
- the new password
-
checkToken
protected org.apache.hadoop.security.token.delegation.AbstractDelegationTokenSecretManager.DelegationTokenInformation checkToken(TokenIdent identifier) throws org.apache.hadoop.security.token.SecretManager.InvalidToken Find the DelegationTokenInformation for the given token id, and verify that if the token is expired. Note that this method should be called with acquiring the secret manager's monitor.- Parameters:
identifier- identifier.- Returns:
- DelegationTokenInformation.
- Throws:
org.apache.hadoop.security.token.SecretManager.InvalidToken- invalid token exception.
-
retrievePassword
public byte[] retrievePassword(TokenIdent identifier) throws org.apache.hadoop.security.token.SecretManager.InvalidToken Description copied from class:SecretManagerRetrieve the password for the given token identifier. Should check the date or registry to make sure the token hasn't expired or been revoked. Returns the relevant password.- Specified by:
retrievePasswordin classSecretManager<TokenIdent extends AbstractDelegationTokenIdentifier>- Parameters:
identifier- the identifier to validate- Returns:
- the password to use
- Throws:
org.apache.hadoop.security.token.SecretManager.InvalidToken- the token was invalid
-
getTrackingIdIfEnabled
-
getTokenTrackingId
-
verifyToken
public void verifyToken(TokenIdent identifier, byte[] password) throws org.apache.hadoop.security.token.SecretManager.InvalidToken Verifies that the given identifier and password are valid and match.- Parameters:
identifier- Token identifier.password- Password in the token.- Throws:
org.apache.hadoop.security.token.SecretManager.InvalidToken- InvalidToken.
-
renewToken
public long renewToken(Token<TokenIdent> token, String renewer) throws org.apache.hadoop.security.token.SecretManager.InvalidToken, IOException Renew a delegation token.- Parameters:
token- the token to renewrenewer- the full principal name of the user doing the renewal- Returns:
- the new expiration time
- Throws:
org.apache.hadoop.security.token.SecretManager.InvalidToken- if the token is invalidAccessControlException- if the user can't renew tokenIOException
-
cancelToken
Cancel a token by removing it from cache.- Parameters:
token- token.canceller- canceller.- Returns:
- Identifier of the canceled token
- Throws:
org.apache.hadoop.security.token.SecretManager.InvalidToken- for invalid tokenAccessControlException- if the user isn't allowed to cancelIOException
-
createSecretKey
Convert the byte[] to a secret key- Parameters:
key- the byte[] to create the secret key from- Returns:
- the secret key
-
getCandidateTokensForCleanup
protected Map<TokenIdent,org.apache.hadoop.security.token.delegation.AbstractDelegationTokenSecretManager.DelegationTokenInformation> getCandidateTokensForCleanup() -
logExpireTokens
- Throws:
IOException
-
removeExpiredStoredToken
- Throws:
IOException
-
stopThreads
public void stopThreads() -
isRunning
public boolean isRunning()is secretMgr running- Returns:
- true if secret mgr is running
-
decodeTokenIdentifier
Decode the token identifier. The subclass can customize the way to decode the token identifier.- Parameters:
token- the token where to extract the identifier- Returns:
- the delegation token identifier
- Throws:
IOException- raised on errors performing I/O.
-
getTopTokenRealOwners
public List<org.apache.hadoop.metrics2.util.Metrics2Util.NameValuePair> getTopTokenRealOwners(int n) Return top token real owners list as well as the tokens count.- Parameters:
n- top number of users- Returns:
- map of owners to counts
-
addTokenForOwnerStats
Add token stats to the owner to token count mapping.- Parameters:
id- token id.
-
syncTokenOwnerStats
protected void syncTokenOwnerStats()This method syncs token information from currentTokens to tokenOwnerStats. It is used when the currentTokens is initialized or refreshed. This is called from a single thread thus no synchronization is needed. -
getMetrics
protected org.apache.hadoop.security.token.delegation.AbstractDelegationTokenSecretManager.DelegationTokenSecretManagerMetrics getMetrics()
-