|
@@ -36,6 +36,7 @@ import org.apache.hadoop.security.AccessControlException;
|
|
import org.apache.hadoop.security.UserGroupInformation;
|
|
import org.apache.hadoop.security.UserGroupInformation;
|
|
import org.apache.hadoop.security.token.Token;
|
|
import org.apache.hadoop.security.token.Token;
|
|
import org.apache.hadoop.security.token.SecretManager.InvalidToken;
|
|
import org.apache.hadoop.security.token.SecretManager.InvalidToken;
|
|
|
|
+import org.apache.hadoop.security.token.delegation.DelegationKey;
|
|
import org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier;
|
|
import org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier;
|
|
import org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenSecretManager;
|
|
import org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenSecretManager;
|
|
import org.apache.hadoop.util.*;
|
|
import org.apache.hadoop.util.*;
|
|
@@ -73,6 +74,8 @@ import org.apache.hadoop.io.IOUtils;
|
|
import org.apache.hadoop.io.Text;
|
|
import org.apache.hadoop.io.Text;
|
|
|
|
|
|
import java.io.BufferedWriter;
|
|
import java.io.BufferedWriter;
|
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
|
+import java.io.DataInputStream;
|
|
import java.io.File;
|
|
import java.io.File;
|
|
import java.io.FileWriter;
|
|
import java.io.FileWriter;
|
|
import java.io.FileNotFoundException;
|
|
import java.io.FileNotFoundException;
|
|
@@ -286,11 +289,16 @@ public class FSNamesystem implements FSConstants, FSNamesystemMBean, FSClusterSt
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ void activateSecretManager() throws IOException {
|
|
|
|
+ if (dtSecretManager != null) {
|
|
|
|
+ dtSecretManager.startThreads();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Activate FSNamesystem daemons.
|
|
* Activate FSNamesystem daemons.
|
|
*/
|
|
*/
|
|
void activate(Configuration conf) throws IOException {
|
|
void activate(Configuration conf) throws IOException {
|
|
- dtSecretManager.startThreads();
|
|
|
|
setBlockTotal();
|
|
setBlockTotal();
|
|
blockManager.activate();
|
|
blockManager.activate();
|
|
this.hbthread = new Daemon(new HeartbeatMonitor());
|
|
this.hbthread = new Daemon(new HeartbeatMonitor());
|
|
@@ -365,6 +373,7 @@ public class FSNamesystem implements FSConstants, FSNamesystemMBean, FSClusterSt
|
|
this.blockManager = new BlockManager(this, conf);
|
|
this.blockManager = new BlockManager(this, conf);
|
|
setConfigurationParameters(conf);
|
|
setConfigurationParameters(conf);
|
|
this.dir = new FSDirectory(fsImage, this, conf);
|
|
this.dir = new FSDirectory(fsImage, this, conf);
|
|
|
|
+ dtSecretManager = createDelegationTokenSecretManager(conf);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -4407,15 +4416,23 @@ public class FSNamesystem implements FSConstants, FSNamesystemMBean, FSClusterSt
|
|
conf.getLong(
|
|
conf.getLong(
|
|
DFSConfigKeys.DFS_NAMENODE_DELEGATION_TOKEN_RENEW_INTERVAL_KEY,
|
|
DFSConfigKeys.DFS_NAMENODE_DELEGATION_TOKEN_RENEW_INTERVAL_KEY,
|
|
DFSConfigKeys.DFS_NAMENODE_DELEGATION_TOKEN_RENEW_INTERVAL_DEFAULT),
|
|
DFSConfigKeys.DFS_NAMENODE_DELEGATION_TOKEN_RENEW_INTERVAL_DEFAULT),
|
|
- DELEGATION_TOKEN_REMOVER_SCAN_INTERVAL);
|
|
|
|
|
|
+ DELEGATION_TOKEN_REMOVER_SCAN_INTERVAL, this);
|
|
}
|
|
}
|
|
|
|
|
|
public DelegationTokenSecretManager getDelegationTokenSecretManager() {
|
|
public DelegationTokenSecretManager getDelegationTokenSecretManager() {
|
|
return dtSecretManager;
|
|
return dtSecretManager;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * @param renewer
|
|
|
|
+ * @return Token<DelegationTokenIdentifier>
|
|
|
|
+ * @throws IOException
|
|
|
|
+ */
|
|
public Token<DelegationTokenIdentifier> getDelegationToken(Text renewer)
|
|
public Token<DelegationTokenIdentifier> getDelegationToken(Text renewer)
|
|
throws IOException {
|
|
throws IOException {
|
|
|
|
+ if (isInSafeMode()) {
|
|
|
|
+ throw new SafeModeException("Cannot issue delegation token", safeMode);
|
|
|
|
+ }
|
|
UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
|
|
UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
|
|
String user = ugi.getUserName();
|
|
String user = ugi.getUserName();
|
|
Text owner = new Text(user);
|
|
Text owner = new Text(user);
|
|
@@ -4425,18 +4442,116 @@ public class FSNamesystem implements FSConstants, FSNamesystemMBean, FSClusterSt
|
|
}
|
|
}
|
|
DelegationTokenIdentifier dtId = new DelegationTokenIdentifier(owner,
|
|
DelegationTokenIdentifier dtId = new DelegationTokenIdentifier(owner,
|
|
renewer, realUser);
|
|
renewer, realUser);
|
|
- return new Token<DelegationTokenIdentifier>(dtId, dtSecretManager);
|
|
|
|
|
|
+ Token<DelegationTokenIdentifier> token = new Token<DelegationTokenIdentifier>(
|
|
|
|
+ dtId, dtSecretManager);
|
|
|
|
+ long expiryTime = dtSecretManager.getTokenExpiryTime(dtId);
|
|
|
|
+ logGetDelegationToken(dtId, expiryTime);
|
|
|
|
+ return token;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ *
|
|
|
|
+ * @param token
|
|
|
|
+ * @return New expiryTime of the token
|
|
|
|
+ * @throws InvalidToken
|
|
|
|
+ * @throws IOException
|
|
|
|
+ */
|
|
public long renewDelegationToken(Token<DelegationTokenIdentifier> token)
|
|
public long renewDelegationToken(Token<DelegationTokenIdentifier> token)
|
|
throws InvalidToken, IOException {
|
|
throws InvalidToken, IOException {
|
|
|
|
+ if (isInSafeMode()) {
|
|
|
|
+ throw new SafeModeException("Cannot renew delegation token", safeMode);
|
|
|
|
+ }
|
|
String renewer = UserGroupInformation.getCurrentUser().getShortUserName();
|
|
String renewer = UserGroupInformation.getCurrentUser().getShortUserName();
|
|
- return dtSecretManager.renewToken(token, renewer);
|
|
|
|
|
|
+ long expiryTime = dtSecretManager.renewToken(token, renewer);
|
|
|
|
+ DelegationTokenIdentifier id = new DelegationTokenIdentifier();
|
|
|
|
+ ByteArrayInputStream buf = new ByteArrayInputStream(token.getIdentifier());
|
|
|
|
+ DataInputStream in = new DataInputStream(buf);
|
|
|
|
+ id.readFields(in);
|
|
|
|
+ logRenewDelegationToken(id, expiryTime);
|
|
|
|
+ return expiryTime;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ *
|
|
|
|
+ * @param token
|
|
|
|
+ * @throws IOException
|
|
|
|
+ */
|
|
public void cancelDelegationToken(Token<DelegationTokenIdentifier> token)
|
|
public void cancelDelegationToken(Token<DelegationTokenIdentifier> token)
|
|
throws IOException {
|
|
throws IOException {
|
|
|
|
+ if (isInSafeMode()) {
|
|
|
|
+ throw new SafeModeException("Cannot cancel delegation token", safeMode);
|
|
|
|
+ }
|
|
String canceller = UserGroupInformation.getCurrentUser().getShortUserName();
|
|
String canceller = UserGroupInformation.getCurrentUser().getShortUserName();
|
|
- dtSecretManager.cancelToken(token, canceller);
|
|
|
|
|
|
+ DelegationTokenIdentifier id = dtSecretManager
|
|
|
|
+ .cancelToken(token, canceller);
|
|
|
|
+ logCancelDelegationToken(id);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @param out save state of the secret manager
|
|
|
|
+ */
|
|
|
|
+ void saveSecretManagerState(DataOutputStream out) throws IOException {
|
|
|
|
+ dtSecretManager.saveSecretManagerState(out);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @param in load the state of secret manager from input stream
|
|
|
|
+ */
|
|
|
|
+ void loadSecretManagerState(DataInputStream in) throws IOException {
|
|
|
|
+ dtSecretManager.loadSecretManagerState(in);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Log the getDelegationToken operation to edit logs
|
|
|
|
+ *
|
|
|
|
+ * @param id identifer of the new delegation token
|
|
|
|
+ * @param expiryTime when delegation token expires
|
|
|
|
+ */
|
|
|
|
+ private void logGetDelegationToken(DelegationTokenIdentifier id,
|
|
|
|
+ long expiryTime) throws IOException {
|
|
|
|
+ synchronized (this) {
|
|
|
|
+ getEditLog().logGetDelegationToken(id, expiryTime);
|
|
|
|
+ }
|
|
|
|
+ getEditLog().logSync();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Log the renewDelegationToken operation to edit logs
|
|
|
|
+ *
|
|
|
|
+ * @param id identifer of the delegation token being renewed
|
|
|
|
+ * @param expiryTime when delegation token expires
|
|
|
|
+ */
|
|
|
|
+ private void logRenewDelegationToken(DelegationTokenIdentifier id,
|
|
|
|
+ long expiryTime) throws IOException {
|
|
|
|
+ synchronized (this) {
|
|
|
|
+ getEditLog().logRenewDelegationToken(id, expiryTime);
|
|
|
|
+ }
|
|
|
|
+ getEditLog().logSync();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Log the cancelDelegationToken operation to edit logs
|
|
|
|
+ *
|
|
|
|
+ * @param id identifer of the delegation token being cancelled
|
|
|
|
+ */
|
|
|
|
+ private void logCancelDelegationToken(DelegationTokenIdentifier id)
|
|
|
|
+ throws IOException {
|
|
|
|
+ synchronized (this) {
|
|
|
|
+ getEditLog().logCancelDelegationToken(id);
|
|
|
|
+ }
|
|
|
|
+ getEditLog().logSync();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Log the updateMasterKey operation to edit logs
|
|
|
|
+ *
|
|
|
|
+ * @param key new delegation key.
|
|
|
|
+ */
|
|
|
|
+ public void logUpdateMasterKey(DelegationKey key) throws IOException {
|
|
|
|
+ synchronized (this) {
|
|
|
|
+ getEditLog().logUpdateMasterKey(key);
|
|
|
|
+ }
|
|
|
|
+ getEditLog().logSync();
|
|
}
|
|
}
|
|
}
|
|
}
|