You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by ta...@apache.org on 2018/09/26 06:09:33 UTC

[03/11] impala git commit: IMPALA-7456: Deprecate file-based authorization

IMPALA-7456: Deprecate file-based authorization

This patch simply adds a warning message to the log when the
authorization_policy_file run-time flag is used.  Sentry has
deprecated the use of policy files and they do not support
user level privileges which are required for object ownership.
Here is the Jira where it will be removed. SENTRY-1922

Test:
- Added custom cluster test to validate logs
- Ran all custom cluster tests

Change-Id: Ibbb13f3ef1c3a00812c180ecef022ea638c2ebc7
Reviewed-on: http://gerrit.cloudera.org:8080/11502
Reviewed-by: Fredy Wijaya <fw...@cloudera.com>
Tested-by: Impala Public Jenkins <im...@cloudera.com>


Project: http://git-wip-us.apache.org/repos/asf/impala/repo
Commit: http://git-wip-us.apache.org/repos/asf/impala/commit/48640b5d
Tree: http://git-wip-us.apache.org/repos/asf/impala/tree/48640b5d
Diff: http://git-wip-us.apache.org/repos/asf/impala/diff/48640b5d

Branch: refs/heads/master
Commit: 48640b5dfa131ca0c7ae9e541e376d11ac6e6d33
Parents: c5dc6de
Author: Adam Holley <gi...@holleyism.com>
Authored: Fri Sep 21 10:15:40 2018 -0500
Committer: Impala Public Jenkins <im...@cloudera.com>
Committed: Tue Sep 25 23:03:27 2018 +0000

----------------------------------------------------------------------
 .../apache/impala/service/BackendConfig.java    |  4 ++
 .../org/apache/impala/service/JniFrontend.java  |  4 ++
 tests/authorization/test_authorization.py       | 24 ++++++++
 tests/common/custom_cluster_test_suite.py       | 14 ++++-
 tests/common/file_utils.py                      | 47 +++++++++++++-
 tests/custom_cluster/test_redaction.py          | 65 +++++---------------
 6 files changed, 103 insertions(+), 55 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/impala/blob/48640b5d/fe/src/main/java/org/apache/impala/service/BackendConfig.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/service/BackendConfig.java b/fe/src/main/java/org/apache/impala/service/BackendConfig.java
index 34d8b8f..acf768b 100644
--- a/fe/src/main/java/org/apache/impala/service/BackendConfig.java
+++ b/fe/src/main/java/org/apache/impala/service/BackendConfig.java
@@ -87,6 +87,10 @@ public class BackendConfig {
     return !Strings.isNullOrEmpty(backendCfg_.authorized_proxy_group_config);
   }
 
+  public boolean isAuthorizationFileSet() {
+    return !Strings.isNullOrEmpty(backendCfg_.authorization_policy_file);
+  }
+
   public boolean disableCatalogDataOpsDebugOnly() {
     return backendCfg_.disable_catalog_data_ops_debug_only;
   }

http://git-wip-us.apache.org/repos/asf/impala/blob/48640b5d/fe/src/main/java/org/apache/impala/service/JniFrontend.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/service/JniFrontend.java b/fe/src/main/java/org/apache/impala/service/JniFrontend.java
index 2781865..9f21b03 100644
--- a/fe/src/main/java/org/apache/impala/service/JniFrontend.java
+++ b/fe/src/main/java/org/apache/impala/service/JniFrontend.java
@@ -696,6 +696,10 @@ public class JniFrontend {
     if (BackendConfig.INSTANCE.isAuthorizedProxyGroupEnabled()) {
       output.append(checkGroupsMappingProvider(CONF));
     }
+    if (BackendConfig.INSTANCE.isAuthorizationFileSet()) {
+      LOG.warn("authorization_policy_file flag is deprecated. Object Ownership feature" +
+          " is not supported with authorization_policy_file.");
+    }
     return output.toString();
   }
 

http://git-wip-us.apache.org/repos/asf/impala/blob/48640b5d/tests/authorization/test_authorization.py
----------------------------------------------------------------------
diff --git a/tests/authorization/test_authorization.py b/tests/authorization/test_authorization.py
index 3e6c56e..75c0997 100644
--- a/tests/authorization/test_authorization.py
+++ b/tests/authorization/test_authorization.py
@@ -31,10 +31,15 @@ from thrift.transport.TSocket import TSocket
 from thrift.transport.TTransport import TBufferedTransport
 from thrift.protocol import TBinaryProtocol
 from tests.common.custom_cluster_test_suite import CustomClusterTestSuite
+from tests.common.file_utils import assert_file_in_dir_contains,\
+    assert_no_files_in_dir_contain
 from tests.hs2.hs2_test_suite import operation_id_to_query_id
 from tests.util.filesystem_utils import WAREHOUSE
 
 AUTH_POLICY_FILE = "%s/authz-policy.ini" % WAREHOUSE
+SENTRY_CONFIG_DIR = os.getenv('IMPALA_HOME') + '/fe/src/test/resources/'
+SENTRY_CONFIG_FILE = SENTRY_CONFIG_DIR + 'sentry-site.xml'
+
 
 class TestAuthorization(CustomClusterTestSuite):
   AUDIT_LOG_DIR = tempfile.mkdtemp(dir=os.getenv('LOG_DIR'))
@@ -357,3 +362,22 @@ class TestAuthorization(CustomClusterTestSuite):
     else:
       assert "User %s is not authorized to access the runtime profile or "\
           "execution summary." % (getuser()) in str(exec_summary_resp)
+
+  @pytest.mark.execute_serially
+  @CustomClusterTestSuite.with_args(
+      impalad_args="--server_name=server1 --sentry_config=" + SENTRY_CONFIG_FILE,
+      catalogd_args="--sentry_config=" + SENTRY_CONFIG_FILE,
+      log_dir=tempfile.mkdtemp(prefix="test_deprecated_none_", dir=os.getenv("LOG_DIR")))
+  def test_deprecated_flag_doesnt_show(self):
+    assert_no_files_in_dir_contain(self.impala_log_dir, "authorization_policy_file " +
+        "flag is deprecated. Object Ownership feature is not supported")
+
+  @pytest.mark.execute_serially
+  @CustomClusterTestSuite.with_args("--server_name=server1\
+      --authorization_policy_file=%s\
+      --authorization_policy_provider_class=%s" % (AUTH_POLICY_FILE,
+       "org.apache.sentry.provider.file.LocalGroupResourceAuthorizationProvider"),
+      log_dir=tempfile.mkdtemp(prefix="test_deprecated_", dir=os.getenv("LOG_DIR")))
+  def test_deprecated_flags(self):
+    assert_file_in_dir_contains(self.impala_log_dir, "authorization_policy_file flag" +
+        " is deprecated. Object Ownership feature is not supported")

http://git-wip-us.apache.org/repos/asf/impala/blob/48640b5d/tests/common/custom_cluster_test_suite.py
----------------------------------------------------------------------
diff --git a/tests/common/custom_cluster_test_suite.py b/tests/common/custom_cluster_test_suite.py
index ed3d671..7e3c0b0 100644
--- a/tests/common/custom_cluster_test_suite.py
+++ b/tests/common/custom_cluster_test_suite.py
@@ -45,6 +45,7 @@ SENTRY_CONFIG = 'sentry_config'
 # Default query options passed to the impala daemon command line. Handled separately from
 # other impala daemon arguments to allow merging multiple defaults into a single list.
 DEFAULT_QUERY_OPTIONS = 'default_query_options'
+LOG_DIR = 'log_dir'
 
 # Run with fast topic updates by default to reduce time to first query running.
 DEFAULT_STATESTORE_ARGS = '--statestore_update_frequency_ms=50 \
@@ -95,7 +96,7 @@ class CustomClusterTestSuite(ImpalaTestSuite):
 
   @staticmethod
   def with_args(impalad_args=None, statestored_args=None, catalogd_args=None,
-                start_args=None, sentry_config=None, default_query_options=None):
+      start_args=None, sentry_config=None, default_query_options=None, log_dir=None):
     """Records arguments to be passed to a cluster by adding them to the decorated
     method's func_dict"""
     def decorate(func):
@@ -114,6 +115,8 @@ class CustomClusterTestSuite(ImpalaTestSuite):
         func.func_dict[SENTRY_CONFIG] = sentry_config
       if default_query_options is not None:
         func.func_dict[DEFAULT_QUERY_OPTIONS] = default_query_options
+      if log_dir is not None:
+        func.func_dict[LOG_DIR] = log_dir
       return func
     return decorate
 
@@ -128,8 +131,13 @@ class CustomClusterTestSuite(ImpalaTestSuite):
     if SENTRY_CONFIG in method.func_dict:
       self._start_sentry_service(method.func_dict[SENTRY_CONFIG])
     # Start a clean new cluster before each test
-    self._start_impala_cluster(
-        cluster_args, default_query_options=method.func_dict.get(DEFAULT_QUERY_OPTIONS))
+    if LOG_DIR in method.func_dict:
+      self._start_impala_cluster(cluster_args,
+          default_query_options=method.func_dict.get(DEFAULT_QUERY_OPTIONS),
+          log_dir=method.func_dict[LOG_DIR])
+    else:
+      self._start_impala_cluster(cluster_args,
+          default_query_options=method.func_dict.get(DEFAULT_QUERY_OPTIONS))
     super(CustomClusterTestSuite, self).setup_class()
 
   def teardown_method(self, method):

http://git-wip-us.apache.org/repos/asf/impala/blob/48640b5d/tests/common/file_utils.py
----------------------------------------------------------------------
diff --git a/tests/common/file_utils.py b/tests/common/file_utils.py
index d3fa61c..cf7e7c0 100644
--- a/tests/common/file_utils.py
+++ b/tests/common/file_utils.py
@@ -15,7 +15,9 @@
 # specific language governing permissions and limitations
 # under the License.
 
-# This module contains utility functions for testing Parquet files
+# This module contains utility functions for testing Parquet files,
+# and other functions used for checking for strings in files and
+# directories.
 
 import os
 from subprocess import check_call
@@ -56,3 +58,46 @@ def create_table_and_copy_files(impala_client, create_stmt, unique_database, tab
     qualified_table_name = '{0}.{1}'.format(unique_database, table_name)
     impala_client.execute('load data inpath "{0}" into table {1}'.format(
       hdfs_file, qualified_table_name))
+
+
+def grep_dir(dir, search):
+  '''Recursively search for files that contain 'search' and return a list of matched
+     lines grouped by file.
+  '''
+  matching_files = dict()
+  for dir_name, _, file_names in os.walk(dir):
+    for file_name in file_names:
+      file_path = os.path.join(dir_name, file_name)
+      if os.path.islink(file_path):
+        continue
+      with open(file_path) as file:
+        matching_lines = grep_file(file, search)
+        if matching_lines:
+          matching_files[file_name] = matching_lines
+  return matching_files
+
+
+def grep_file(file, search):
+  '''Return lines in 'file' that contain the 'search' term. 'file' must already be
+     opened.
+  '''
+  matching_lines = list()
+  for line in file:
+    if search in line:
+      matching_lines.append(line)
+  return matching_lines
+
+
+def assert_file_in_dir_contains(dir, search):
+  '''Asserts that at least one file in the 'dir' contains the 'search' term.'''
+  results = grep_dir(dir, search)
+  assert results, "%s should have a file containing '%s' but no file was found" \
+      % (dir, search)
+
+
+def assert_no_files_in_dir_contain(dir, search):
+  '''Asserts that no files in the 'dir' contains the 'search' term.'''
+  results = grep_dir(dir, search)
+  assert not results, \
+      "%s should not have any file containing '%s' but a file was found" \
+      % (dir, search)

http://git-wip-us.apache.org/repos/asf/impala/blob/48640b5d/tests/custom_cluster/test_redaction.py
----------------------------------------------------------------------
diff --git a/tests/custom_cluster/test_redaction.py b/tests/custom_cluster/test_redaction.py
index cb0e8fa..9cdb71d 100644
--- a/tests/custom_cluster/test_redaction.py
+++ b/tests/custom_cluster/test_redaction.py
@@ -27,6 +27,8 @@ from tempfile import mkdtemp
 from time import sleep
 
 from tests.common.custom_cluster_test_suite import CustomClusterTestSuite
+from tests.common.file_utils import grep_file, assert_file_in_dir_contains,\
+    assert_no_files_in_dir_contain
 
 LOG = logging.getLogger(__name__)
 
@@ -121,20 +123,20 @@ class TestRedaction(CustomClusterTestSuite, unittest.TestCase):
       if self.cluster.impalads:
         raise Exception("No impalads should have started")
     with open(os.path.join(self.log_dir, 'impalad-error.log')) as file:
-      result = self.grep_file(file, expected_error_message)
+      result = grep_file(file, expected_error_message)
     assert result, 'The expected error message was not found'
 
   def assert_log_redaction(self, unredacted_value, redacted_value, expect_audit=True):
     '''Asserts that the 'unredacted_value' is not present but the 'redacted_value' is.'''
     # Logs should not contain the unredacted value.
-    self.assert_no_files_in_dir_contain(self.log_dir, unredacted_value)
-    self.assert_no_files_in_dir_contain(self.audit_dir, unredacted_value)
-    self.assert_no_files_in_dir_contain(self.profile_dir, unredacted_value)
+    assert_no_files_in_dir_contain(self.log_dir, unredacted_value)
+    assert_no_files_in_dir_contain(self.audit_dir, unredacted_value)
+    assert_no_files_in_dir_contain(self.profile_dir, unredacted_value)
     # But the redacted value should be there except for the profile since that is
     # encoded.
-    self.assert_file_in_dir_contains(self.log_dir, redacted_value)
+    assert_file_in_dir_contains(self.log_dir, redacted_value)
     if expect_audit:
-      self.assert_file_in_dir_contains(self.audit_dir, redacted_value)
+      assert_file_in_dir_contains(self.audit_dir, redacted_value)
 
   def assert_web_ui_redaction(self, query_id, unredacted_value, redacted_value):
     '''Asserts that the 'unredacted_value' is not present but the 'redacted_value' is.'''
@@ -145,7 +147,7 @@ class TestRedaction(CustomClusterTestSuite, unittest.TestCase):
       for response_format in ('html', 'json'):
         # The 'html' param is actually ignored by the server.
         url = page + '?query_id=' + query_id + "&" + response_format
-        results = self.grep_file(impala_service.open_debug_webpage(url), unredacted_value)
+        results = grep_file(impala_service.open_debug_webpage(url), unredacted_value)
         assert not results, "Web page %s should not contain '%s' but does" \
             % (url, unredacted_value)
     # But the redacted value should be shown.
@@ -157,7 +159,7 @@ class TestRedaction(CustomClusterTestSuite, unittest.TestCase):
     impala_service = self.create_impala_service()
     for page in ('queries', 'query_stmt', 'query_plan_text', 'query_profile'):
       url = '%s?query_id=%s' % (page, query_id)
-      results = self.grep_file(impala_service.open_debug_webpage(url), search)
+      results = grep_file(impala_service.open_debug_webpage(url), search)
       assert results, "Web page %s should contain '%s' but does not" \
           % (url, search)
 
@@ -165,49 +167,10 @@ class TestRedaction(CustomClusterTestSuite, unittest.TestCase):
     ''' Asserts that the query profile for 'query_id' contains 'search' string'''
     impala_service = self.create_impala_service()
     url = 'query_profile?query_id=%s' % query_id
-    results = self.grep_file(impala_service.open_debug_webpage(url), search)
+    results = grep_file(impala_service.open_debug_webpage(url), search)
     assert results, "Query profile %s should contain '%s' but does not" \
         % (url, search)
 
-  def assert_file_in_dir_contains(self, dir, search):
-    '''Asserts that at least one file in the 'dir' contains the 'search' term.'''
-    results = self.grep_dir(dir,search)
-    assert results, "%s should have a file containing '%s' but no file was found" \
-        % (dir, search)
-
-  def assert_no_files_in_dir_contain(self, dir, search):
-    '''Asserts that no files in the 'dir' contains the 'search' term.'''
-    results = self.grep_dir(dir,search)
-    assert not results, \
-        "%s should not have any file containing '%s' but a file was found" \
-        % (dir, search)
-
-  def grep_dir(self, dir, search):
-    '''Recursively search for files that contain 'search' and return a list of matched
-       lines grouped by file.
-    '''
-    matching_files = dict()
-    for dir_name, _, file_names in os.walk(dir):
-      for file_name in file_names:
-        file_path = os.path.join(dir_name, file_name)
-        if os.path.islink(file_path):
-          continue
-        with open(file_path) as file:
-          matching_lines = self.grep_file(file, search)
-          if matching_lines:
-            matching_files[file_name] = matching_lines
-    return matching_files
-
-  def grep_file(self, file, search):
-    '''Return lines in 'file' that contain the 'search' term. 'file' must already be
-       opened.
-    '''
-    matching_lines = list()
-    for line in file:
-      if search in line:
-        matching_lines.append(line)
-    return matching_lines
-
   @pytest.mark.execute_serially
   def test_bad_rules(self):
     '''Check that the server fails to start if the redaction rules are bad.'''
@@ -266,10 +229,10 @@ class TestRedaction(CustomClusterTestSuite, unittest.TestCase):
     # only a second is needed.
     sleep(5)
     # The query should show up in both the audit and non-audit logs
-    self.assert_file_in_dir_contains(self.log_dir, email)
-    self.assert_file_in_dir_contains(self.audit_dir, email)
+    assert_file_in_dir_contains(self.log_dir, email)
+    assert_file_in_dir_contains(self.audit_dir, email)
     # The profile is encoded so the email won't be found.
-    self.assert_no_files_in_dir_contain(self.profile_dir, email)
+    assert_no_files_in_dir_contain(self.profile_dir, email)
 
     # Since all the tests passed, the log dir shouldn't be of interest and can be
     # deleted.