nfsgateway.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. """
  2. Licensed to the Apache Software Foundation (ASF) under one
  3. or more contributor license agreements. See the NOTICE file
  4. distributed with this work for additional information
  5. regarding copyright ownership. The ASF licenses this file
  6. to you under the Apache License, Version 2.0 (the
  7. "License"); you may not use this file except in compliance
  8. with the License. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing, software
  11. distributed under the License is distributed on an "AS IS" BASIS,
  12. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. See the License for the specific language governing permissions and
  14. limitations under the License.
  15. """
  16. from resource_management.libraries.script import Script
  17. from resource_management.libraries.functions.check_process_status import check_process_status
  18. from resource_management.libraries.functions.security_commons import build_expectations, \
  19. cached_kinit_executor, get_params_from_filesystem, validate_security_config_properties, \
  20. FILE_TYPE_XML
  21. from hdfs_nfsgateway import nfsgateway
  22. from hdfs import hdfs
  23. from resource_management.libraries.functions import conf_select
  24. from resource_management.libraries.functions import hdp_select
  25. from resource_management.libraries.functions.version import compare_versions, format_hdp_stack_version
  26. class NFSGateway(Script):
  27. def get_stack_to_component(self):
  28. return {"HDP": "hadoop-hdfs-nfs3"}
  29. def install(self, env):
  30. import params
  31. env.set_params(params)
  32. self.install_packages(env, params.exclude_packages)
  33. def pre_rolling_restart(self, env):
  34. import params
  35. env.set_params(params)
  36. if Script.is_hdp_stack_greater_or_equal('2.3.0.0'):
  37. conf_select.select(params.stack_name, "hadoop", params.version)
  38. hdp_select.select("hadoop-hdfs-nfs3", params.version)
  39. def start(self, env, rolling_restart=False):
  40. import params
  41. env.set_params(params)
  42. self.configure(env)
  43. nfsgateway(action="start")
  44. def stop(self, env, rolling_restart=False):
  45. import params
  46. env.set_params(params)
  47. nfsgateway(action="stop")
  48. def configure(self, env):
  49. import params
  50. env.set_params(params)
  51. hdfs()
  52. nfsgateway(action="configure")
  53. def status(self, env):
  54. import status_params
  55. env.set_params(status_params)
  56. check_process_status(status_params.nfsgateway_pid_file)
  57. def security_status(self, env):
  58. import status_params
  59. env.set_params(status_params)
  60. props_value_check = {"hadoop.security.authentication": "kerberos",
  61. "hadoop.security.authorization": "true"}
  62. props_empty_check = ["hadoop.security.auth_to_local"]
  63. props_read_check = None
  64. core_site_expectations = build_expectations('core-site', props_value_check, props_empty_check,
  65. props_read_check)
  66. props_value_check = None
  67. props_empty_check = ['nfs.keytab.file',
  68. 'nfs.kerberos.principal']
  69. props_read_check = ['nfs.keytab.file']
  70. hdfs_site_expectations = build_expectations('hdfs-site', props_value_check, props_empty_check,
  71. props_read_check)
  72. hdfs_expectations = {}
  73. hdfs_expectations.update(core_site_expectations)
  74. hdfs_expectations.update(hdfs_site_expectations)
  75. security_params = get_params_from_filesystem(status_params.hadoop_conf_dir,
  76. {'core-site.xml': FILE_TYPE_XML,
  77. 'hdfs-site.xml': FILE_TYPE_XML})
  78. if 'core-site' in security_params and 'hadoop.security.authentication' in security_params['core-site'] and \
  79. security_params['core-site']['hadoop.security.authentication'].lower() == 'kerberos':
  80. result_issues = validate_security_config_properties(security_params, hdfs_expectations)
  81. if not result_issues: # If all validations passed successfully
  82. try:
  83. # Double check the dict before calling execute
  84. if ('hdfs-site' not in security_params or
  85. 'nfs.keytab.file' not in security_params['hdfs-site'] or
  86. 'nfs.kerberos.principal' not in security_params['hdfs-site']):
  87. self.put_structured_out({"securityState": "UNSECURED"})
  88. self.put_structured_out(
  89. {"securityIssuesFound": "Keytab file or principal are not set property."})
  90. return
  91. cached_kinit_executor(status_params.kinit_path_local,
  92. status_params.hdfs_user,
  93. security_params['hdfs-site']['nfs.keytab.file'],
  94. security_params['hdfs-site'][
  95. 'nfs.kerberos.principal'],
  96. status_params.hostname,
  97. status_params.tmp_dir)
  98. self.put_structured_out({"securityState": "SECURED_KERBEROS"})
  99. except Exception as e:
  100. self.put_structured_out({"securityState": "ERROR"})
  101. self.put_structured_out({"securityStateErrorInfo": str(e)})
  102. else:
  103. issues = []
  104. for cf in result_issues:
  105. issues.append("Configuration file %s did not pass the validation. Reason: %s" % (cf, result_issues[cf]))
  106. self.put_structured_out({"securityIssuesFound": ". ".join(issues)})
  107. self.put_structured_out({"securityState": "UNSECURED"})
  108. else:
  109. self.put_structured_out({"securityState": "UNSECURED"})
  110. if __name__ == "__main__":
  111. NFSGateway().execute()