Browse Source

HUE-9522 [useradmin] fix user home folder creation to use umask

Mahesh Balakrishnan 5 years ago
parent
commit
419fd43791

+ 10 - 4
apps/useradmin/src/useradmin/conf.py

@@ -27,6 +27,12 @@ HOME_DIR_PERMISSIONS = Config(
     type=str,
     default="0755")
 
+USE_HOME_DIR_PERMISSIONS = Config(
+    key="use_home_dir_permissions",
+    help=_("Disable to use umask from hdfs else new user home directory would be created with the permissions from home_dir_permissions"),
+    type=coerce_bool,
+    default=True)
+
 DEFAULT_USER_GROUP = Config(
     key="default_user_group",
     help=_("The name of a default group for users at creation time, or at first login "
@@ -38,13 +44,13 @@ PASSWORD_POLICY = ConfigSection(
   key="password_policy",
   help=_("Configuration options for user password policy"),
   members=dict(
-    IS_ENABLED = Config(
+    IS_ENABLED=Config(
       key="is_enabled",
       help=_("Enable user password policy."),
       type=coerce_bool,
       default=False),
 
-    PWD_RULE = Config(
+    PWD_RULE=Config(
       key="pwd_regex",
       help=_("The regular expression of password rule. The default rule requires that "
              "a password  must be at least 8 characters long, and must contain both "
@@ -53,7 +59,7 @@ PASSWORD_POLICY = ConfigSection(
       type=str,
       default="^(?=.*?[A-Z])(?=(.*[a-z]){1,})(?=(.*[\d]){1,})(?=(.*[\W_]){1,}).{8,}$"),
 
-    PWD_HINT = Config(
+    PWD_HINT=Config(
       key="pwd_hint",
       help=_("Message about the password rule defined in pwd_regex"),
       type=str,
@@ -61,7 +67,7 @@ PASSWORD_POLICY = ConfigSection(
               "uppercase and lowercase letters, at least one number, and at least " + \
               "one special character."),
 
-    PWD_ERROR_MESSAGE = Config(
+    PWD_ERROR_MESSAGE=Config(
       key="pwd_error_message",
       help=_("The error message displayed if the provided password does not "
              "meet the enhanced password rule"),

+ 3 - 0
desktop/conf.dist/hue.ini

@@ -1708,6 +1708,9 @@
   # Default home directory permissions
   ## home_dir_permissions=0755
 
+  # Disable to use umask from hdfs else new user home directory would be created with the permissions from home_dir_permissions
+  ## use_home_dir_permissions=true
+
   # The name of the default user group that users will be a member of
   ## default_user_group=default
 

+ 3 - 0
desktop/conf/pseudo-distributed.ini.tmpl

@@ -1694,6 +1694,9 @@
   # Default home directory permissions
   ## home_dir_permissions=0755
 
+  # Disable to use umask from hdfs else new user home directory would be created with the permissions from home_dir_permissions
+  ## use_home_dir_permissions=true
+
   # The name of the default user group that users will be a member of
   ## default_user_group=default
 

+ 5 - 4
desktop/libs/hadoop/src/hadoop/fs/hadoopfs.py

@@ -179,8 +179,9 @@ class Hdfs(object):
     if home_path is None:
       home_path = self.get_home_dir()
 
-    from useradmin.conf import HOME_DIR_PERMISSIONS
-    mode = int(HOME_DIR_PERMISSIONS.get(), 8)
+    from hadoop.hdfs_site import get_umask_mode
+    from useradmin.conf import HOME_DIR_PERMISSIONS, USE_HOME_DIR_PERMISSIONS
+    mode = int(HOME_DIR_PERMISSIONS.get(), 8) if USE_HOME_DIR_PERMISSIONS.get() else (0o777 & (0o1777 ^ get_umask_mode()))
     if not self.exists(home_path):
       user = self.user
       try:
@@ -546,7 +547,7 @@ class BlockCache(object):
     # We could do a more efficient merge here since both lists
     # are already sorted, but these data structures are small, so let's
     # do the easy thing.
-    blocks_dict = dict( (b.blockId, b) for b in self.blocks )
+    blocks_dict = dict((b.blockId, b) for b in self.blocks)
 
     # Merge in new data to dictionary
     for nb in new_blocks:
@@ -554,7 +555,7 @@ class BlockCache(object):
 
     # Convert back to sorted list
     block_list = list(blocks_dict.values())
-    block_list.sort(cmp=lambda a,b: cmp(a.startOffset, b.startOffset))
+    block_list.sort(cmp=lambda a, b: cmp(a.startOffset, b.startOffset))
 
     # Update cache with new data
     self.blocks = block_list