Class RegistrySecurity
java.lang.Object
org.apache.hadoop.service.AbstractService
org.apache.hadoop.registry.client.impl.zk.RegistrySecurity
- All Implemented Interfaces:
Closeable,AutoCloseable,org.apache.hadoop.service.Service
public class RegistrySecurity
extends org.apache.hadoop.service.AbstractService
Implement the registry security ... a self contained service for
testability.
This class contains:
- The registry security policy implementation, configuration reading, ACL setup and management
- Lots of static helper methods to aid security setup and debugging
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classon-demand stringifier for a list of ACLsstatic classOn demand string-ifier for UGI with extra detailsNested classes/interfaces inherited from interface org.apache.hadoop.service.Service
org.apache.hadoop.service.Service.STATE -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final org.apache.zookeeper.data.ACLAn ACL with read access for anyonestatic final org.apache.zookeeper.data.ACLAn ACL with read-write access for anyonestatic final StringError raised when the registry is tagged as secure but this process doesn't have hadoop security enabled.static final Stringthere's no default user to add with permissions, so it would be impossible to create nodes with unrestricted user accessstatic final Stringstatic final List<org.apache.zookeeper.data.ACL>An ACL list containing theALL_READWRITE_ACCESSentry. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringaclsToString(List<org.apache.zookeeper.data.ACL> acls) Stringify a list of ACLs for logging.static StringaclToString(org.apache.zookeeper.data.ACL acl) Convert an ACL to a string, with any obfuscation neededbooleanaddDigestACL(org.apache.zookeeper.data.ACL acl) Add a digest ACLvoidaddSystemACL(org.apache.zookeeper.data.ACL acl) Add another system ACLvoidapplySecurityEnvironment(org.apache.curator.framework.CuratorFrameworkFactory.Builder builder) Apply the security environment to this curator instance.static voidbindJVMtoJAASFile(File jaasFile) Bind the JVM JAS setting to the specified JAAS file.static voidbindZKToServerJAASContext(String contextName) Set the Zookeeper server propertyZookeeperConfigOptions.PROP_ZK_SERVER_SASL_CONTEXTto the SASL context.List<org.apache.zookeeper.data.ACL>Parse the IDs, adding a realm if needed, setting the permissionsBuild up low-level security diagnostics to aid debuggingstatic voidReset any system properties related to JAASstatic voidClear all the ZK SASL Client properties Important:This is JVM-wideorg.apache.zookeeper.data.ACLcreateACLForUser(org.apache.hadoop.security.UserGroupInformation ugi, int perms) Create an ACL For a user.org.apache.zookeeper.data.ACLcreateACLfromUsername(String username, int perms) Given a user name (short or long), create a SASL ACLcreateJAASEntry(String context, String principal, File keytab) Create a JAAS entry for insertionorg.apache.zookeeper.data.ACLcreateSaslACL(org.apache.hadoop.security.UserGroupInformation ugi, int perms) Given a UGI, create a SASL ACL from itorg.apache.zookeeper.data.ACLcreateSaslACLFromCurrentUser(int perms) Create a SASL ACL for the userGenerate a base-64 encoded digest of the idPasswordPair pairGenerate a base-64 encoded digest of the idPasswordPair pairstatic voidForce disable ZK SASL bindings.protected static voidTurn ZK SASL on Important:This is JVM-wideList<org.apache.zookeeper.data.ACL>Get all ACLs needed for a client to use when writing to the repo.static StringGet the default kerberos realm —returning "" if there is no realm or other problemstatic StringGet the appropriate Kerberos Auth module for JAAS entries for this JVM.Get the derived kerberos realm.List<org.apache.zookeeper.data.ACL>Get the system principalsstatic StringidToString(org.apache.zookeeper.data.Id id) Convert an ID to a string, stripping out all but the first few characters of any digest auth hash for security reasonsstatic booleanIs the system property enabling the SASL client set?booleanFlag to indicate the cluster is securebooleanCheck for an id:password tuple being valid.voidLog details about the current Hadoop user at INFO.org.apache.zookeeper.data.IdParse a string down to an ID, adding a realm if neededList<org.apache.zookeeper.data.ACL>Parse an ACL list.voidReset the digest ACL listprotected voidserviceInit(org.apache.hadoop.conf.Configuration conf) Init the service: this sets up security based on the configurationvoidsetKerberosPrincipalAndKeytab(String principal, String keytab) static voidsetZKSaslClientProperties(String username, String context) Set the client properties.splitAclPairs(String aclString, String realm) Split up a list of the formsasl:mapred@,digest:5f55d66, sasl@yarn@EXAMPLE.COMinto a list of possible ACL values, trimming as needed The supplied realm is added to entries where the string begins "sasl:" the string ends with "@" No attempt is made to validate any of the acl patterns.org.apache.zookeeper.data.IdtoDigestId(String digest) Given a digest, create an ID from itorg.apache.zookeeper.data.IdtoDigestId(String id, String password) Create a Digest ID from an id:pass pairstatic AppConfigurationEntry[]validateContext(String context) Resolve the context of an entry.Methods inherited from class org.apache.hadoop.service.AbstractService
close, getBlockers, getConfig, getFailureCause, getFailureState, getLifecycleHistory, getName, getServiceState, getStartTime, init, isInState, noteFailure, putBlocker, registerGlobalListener, registerServiceListener, removeBlocker, serviceStart, serviceStop, setConfig, start, stop, toString, unregisterGlobalListener, unregisterServiceListener, waitForServiceToStop
-
Field Details
-
E_UNKNOWN_AUTHENTICATION_MECHANISM
- See Also:
-
E_NO_USER_DETERMINED_FOR_ACLS
there's no default user to add with permissions, so it would be impossible to create nodes with unrestricted user access- See Also:
-
E_NO_KERBEROS
Error raised when the registry is tagged as secure but this process doesn't have hadoop security enabled.- See Also:
-
ALL_READWRITE_ACCESS
public static final org.apache.zookeeper.data.ACL ALL_READWRITE_ACCESSAn ACL with read-write access for anyone -
ALL_READ_ACCESS
public static final org.apache.zookeeper.data.ACL ALL_READ_ACCESSAn ACL with read access for anyone -
WorldReadWriteACL
An ACL list containing theALL_READWRITE_ACCESSentry. It is copy on write so can be shared without worry
-
-
Constructor Details
-
RegistrySecurity
Create an instance- Parameters:
name- service name
-
-
Method Details
-
serviceInit
Init the service: this sets up security based on the configuration- Overrides:
serviceInitin classorg.apache.hadoop.service.AbstractService- Parameters:
conf- configuration- Throws:
Exception
-
addSystemACL
public void addSystemACL(org.apache.zookeeper.data.ACL acl) Add another system ACL- Parameters:
acl- add ACL
-
addDigestACL
public boolean addDigestACL(org.apache.zookeeper.data.ACL acl) Add a digest ACL- Parameters:
acl- add ACL
-
resetDigestACLs
public void resetDigestACLs()Reset the digest ACL list -
isSecureRegistry
public boolean isSecureRegistry()Flag to indicate the cluster is secure- Returns:
- true if the config enabled security
-
getSystemACLs
Get the system principals- Returns:
- the system principals
-
getClientACLs
Get all ACLs needed for a client to use when writing to the repo. That is: system ACLs, its own ACL, any digest ACLs- Returns:
- the client ACLs
-
createSaslACLFromCurrentUser
Create a SASL ACL for the user- Parameters:
perms- permissions- Returns:
- an ACL for the current user or null if they aren't a kerberos user
- Throws:
IOException
-
createSaslACL
public org.apache.zookeeper.data.ACL createSaslACL(org.apache.hadoop.security.UserGroupInformation ugi, int perms) Given a UGI, create a SASL ACL from it- Parameters:
ugi- UGIperms- permissions- Returns:
- a new ACL
-
isValid
Check for an id:password tuple being valid. This test is stricter than that inDigestAuthenticationProvider, which splits the string, but doesn't check the contents of each half for being non-"".- Parameters:
idPasswordPair- id:pass pair- Returns:
- true if the pass is considered valid.
-
getKerberosRealm
Get the derived kerberos realm.- Returns:
- this is built from the JVM realm, or the configuration if it overrides it. If "", it means "don't know".
-
digest
Generate a base-64 encoded digest of the idPasswordPair pair- Parameters:
idPasswordPair- id:password- Returns:
- a string that can be used for authentication
- Throws:
IOException
-
digest
Generate a base-64 encoded digest of the idPasswordPair pair- Parameters:
id- IDpassword- pass- Returns:
- a string that can be used for authentication
- Throws:
IOException
-
toDigestId
Given a digest, create an ID from it- Parameters:
digest- digest- Returns:
- ID
-
toDigestId
Create a Digest ID from an id:pass pair- Parameters:
id- IDpassword- password- Returns:
- an ID
- Throws:
IOException
-
splitAclPairs
Split up a list of the formsasl:mapred@,digest:5f55d66, sasl@yarn@EXAMPLE.COMinto a list of possible ACL values, trimming as needed The supplied realm is added to entries where- the string begins "sasl:"
- the string ends with "@"
- Parameters:
aclString- list of 0 or more ACLsrealm- realm to add- Returns:
- a list of split and potentially patched ACL pairs.
-
parse
Parse a string down to an ID, adding a realm if needed- Parameters:
idPair- id:data tuplerealm- realm to add- Returns:
- the ID.
- Throws:
IllegalArgumentException- if the idPair is invalid
-
buildACLs
public List<org.apache.zookeeper.data.ACL> buildACLs(String principalList, String realm, int perms) throws IOException Parse the IDs, adding a realm if needed, setting the permissions- Parameters:
principalList- id stringrealm- realm to addperms- permissions- Returns:
- the relevant ACLs
- Throws:
IOException
-
parseACLs
Parse an ACL list. This includes configuration indirectionZKUtil.resolveConfIndirection(String)- Parameters:
zkAclConf- configuration string- Returns:
- an ACL list
- Throws:
IOException- on a bad ACL parse
-
getKerberosAuthModuleForJVM
Get the appropriate Kerberos Auth module for JAAS entries for this JVM.- Returns:
- a JVM-specific kerberos login module classname.
-
createJAASEntry
Create a JAAS entry for insertion- Parameters:
context- context of the entryprincipal- kerberos principalkeytab- keytab- Returns:
- a context
-
bindJVMtoJAASFile
Bind the JVM JAS setting to the specified JAAS file. Important: once a file has been loaded the JVM doesn't pick up changes- Parameters:
jaasFile- the JAAS file
-
bindZKToServerJAASContext
Set the Zookeeper server propertyZookeeperConfigOptions.PROP_ZK_SERVER_SASL_CONTEXTto the SASL context. When the ZK server starts, this is the context which it will read in- Parameters:
contextName- the name of the context
-
clearJaasSystemProperties
public static void clearJaasSystemProperties()Reset any system properties related to JAAS -
validateContext
Resolve the context of an entry. This is an effective test of JAAS setup, because it will relay detected problems up- Parameters:
context- context name- Returns:
- the entry
- Throws:
RuntimeException- if there is no context entry found
-
applySecurityEnvironment
public void applySecurityEnvironment(org.apache.curator.framework.CuratorFrameworkFactory.Builder builder) throws IOException Apply the security environment to this curator instance. This may include setting up the ZK system properties for SASL- Parameters:
builder- curator builder- Throws:
IOException- if jaas configuration can't be generated or found
-
setKerberosPrincipalAndKeytab
-
setZKSaslClientProperties
Set the client properties. This forces the ZK client into failing if it can't auth. Important:This is JVM-wide.- Parameters:
username- usernamecontext- login context- Throws:
RuntimeException- if the context cannot be found in the current JAAS context
-
clearZKSaslClientProperties
public static void clearZKSaslClientProperties()Clear all the ZK SASL Client properties Important:This is JVM-wide -
enableZookeeperClientSASL
protected static void enableZookeeperClientSASL()Turn ZK SASL on Important:This is JVM-wide -
disableZookeeperClientSASL
public static void disableZookeeperClientSASL()Force disable ZK SASL bindings. Important:This is JVM-wide -
isClientSASLEnabled
public static boolean isClientSASLEnabled()Is the system property enabling the SASL client set?- Returns:
- true if the SASL client system property is set.
-
logCurrentHadoopUser
public void logCurrentHadoopUser()Log details about the current Hadoop user at INFO. Robust against IOEs when trying to get the current user -
aclsToString
Stringify a list of ACLs for logging. Digest ACLs have their digest values stripped for security.- Parameters:
acls- ACL list- Returns:
- a string for logs, exceptions, ...
-
aclToString
Convert an ACL to a string, with any obfuscation needed- Parameters:
acl- ACL- Returns:
- ACL string value
-
idToString
Convert an ID to a string, stripping out all but the first few characters of any digest auth hash for security reasons- Parameters:
id- ID- Returns:
- a string description of a Zookeeper ID
-
buildSecurityDiagnostics
Build up low-level security diagnostics to aid debugging- Returns:
- a string to use in diagnostics
-
getDefaultRealmInJVM
Get the default kerberos realm —returning "" if there is no realm or other problem- Returns:
- the default realm of the system if it could be determined
-
createACLForUser
public org.apache.zookeeper.data.ACL createACLForUser(org.apache.hadoop.security.UserGroupInformation ugi, int perms) Create an ACL For a user.- Parameters:
ugi- User identity- Returns:
- the ACL For the specified user. Ifthe username doesn't end in "@" then the realm is added
-
createACLfromUsername
Given a user name (short or long), create a SASL ACL- Parameters:
username- user name; if it doesn't contain an "@" symbol, the service's kerberos realm is addedperms- permissions- Returns:
- an ACL for the user
-