예제 #1
0
파일: kms.py 프로젝트: xiaomatech/dataops
def check_ranger_service():
    import params

    policymgr_mgr_url = params.policymgr_mgr_url
    if policymgr_mgr_url.endswith('/'):
        policymgr_mgr_url = policymgr_mgr_url.rstrip('/')
    ranger_adm_obj = Rangeradmin(url=policymgr_mgr_url)
    ambari_username_password_for_ranger = format(
        "{ambari_ranger_admin}:{ambari_ranger_password}")
    response_code = ranger_adm_obj.check_ranger_login_urllib2(
        policymgr_mgr_url)

    if response_code is not None and response_code == 200:
        user_resp_code = ranger_adm_obj.create_ambari_admin_user(
            params.ambari_ranger_admin, params.ambari_ranger_password,
            params.admin_uname_password)
        if user_resp_code is not None and user_resp_code == 200:
            get_repo_flag = get_repo(policymgr_mgr_url, params.repo_name,
                                     ambari_username_password_for_ranger)
            if not get_repo_flag:
                return create_repo(policymgr_mgr_url,
                                   json.dumps(params.kms_ranger_plugin_repo),
                                   ambari_username_password_for_ranger)
            else:
                return True
        else:
            return False
    else:
        Logger.error('Ranger service is not reachable')
        return False
예제 #2
0
def check_ranger_service():
  import params

  ranger_adm_obj = Rangeradmin(url=params.policymgr_mgr_url)
  ambari_username_password_for_ranger = format("{ambari_ranger_admin}:{ambari_ranger_password}")
  response_code = ranger_adm_obj.check_ranger_login_urllib2(params.policymgr_mgr_url)

  if response_code is not None and response_code == 200:
    user_resp_code = ranger_adm_obj.create_ambari_admin_user(params.ambari_ranger_admin, params.ambari_ranger_password, params.admin_uname_password)
    if user_resp_code is not None and user_resp_code == 200:
      get_repo_flag = get_repo(params.policymgr_mgr_url, params.repo_name, ambari_username_password_for_ranger)
      if not get_repo_flag:
        create_repo_flag = create_repo(params.policymgr_mgr_url, json.dumps(params.kms_ranger_plugin_repo), ambari_username_password_for_ranger)
        if create_repo_flag:
          return True
        else:
          return False
      else:
        return True
    else:
      Logger.error('Ambari admin user creation failed')
      return False
  else:
    Logger.error('Ranger service is not reachable host')
    return False
예제 #3
0
def setup_ranger_hbase():
  import params
  
  if params.has_ranger_admin:
    File(params.downloaded_custom_connector,
         content = DownloadSource(params.driver_curl_source)
    )

    if not os.path.isfile(params.driver_curl_target):
      Execute(('cp', '--remove-destination', params.downloaded_custom_connector, params.driver_curl_target),
              path=["/bin", "/usr/bin/"],
              sudo=True)

    try:
      command = 'hdp-select status hbase-client'
      return_code, hdp_output = shell.call(command, timeout=20)
    except Exception, e:
      Logger.error(str(e))
      raise Fail('Unable to execute hdp-select command to retrieve the version.')

    if return_code != 0:
      raise Fail('Unable to determine the current version because of a non-zero return code of {0}'.format(str(return_code)))

    hdp_version = re.sub('hbase-client - ', '', hdp_output).strip()
    match = re.match('[0-9]+.[0-9]+.[0-9]+.[0-9]+-[0-9]+', hdp_version)

    if match is None:
      raise Fail('Failed to get extracted version')

    file_path = '/usr/hdp/'+ hdp_version +'/ranger-hbase-plugin/install.properties'
    if not os.path.isfile(file_path):
      raise Fail('Ranger HBase plugin install.properties file does not exist at {0}'.format(file_path))
    
    ranger_hbase_dict = ranger_hbase_properties()
    hbase_repo_data = hbase_repo_properties()

    write_properties_to_file(file_path, ranger_hbase_dict)

    if params.enable_ranger_hbase:
      cmd = format('cd /usr/hdp/{hdp_version}/ranger-hbase-plugin/ && sh enable-hbase-plugin.sh')
      ranger_adm_obj = Rangeradmin(url=ranger_hbase_dict['POLICY_MGR_URL'])
      response_code, response_recieved = ranger_adm_obj.check_ranger_login_urllib2(ranger_hbase_dict['POLICY_MGR_URL'] + '/login.jsp', 'test:test')

      if response_code is not None and response_code == 200:
        ambari_ranger_admin, ambari_ranger_password = ranger_adm_obj.create_ambari_admin_user(params.ambari_ranger_admin, params.ambari_ranger_password, params.admin_uname_password)
        ambari_username_password_for_ranger = ambari_ranger_admin + ':' + ambari_ranger_password
        if ambari_ranger_admin != '' and ambari_ranger_password != '':
          repo = ranger_adm_obj.get_repository_by_name_urllib2(ranger_hbase_dict['REPOSITORY_NAME'], 'hbase', 'true', ambari_username_password_for_ranger)
          if repo and repo['name'] == ranger_hbase_dict['REPOSITORY_NAME']:
            Logger.info('Hbase Repository exist')
          else:
            response = ranger_adm_obj.create_repository_urllib2(hbase_repo_data, ambari_username_password_for_ranger, params.policy_user)
            if response is not None:
              Logger.info('Hbase Repository created in Ranger admin')
            else:
              Logger.info('Hbase Repository creation failed in Ranger admin')
        else:
          Logger.info('Ambari admin username and password are blank ')
      else:
          Logger.info('Ranger service is not started on given host')
    else:
      cmd = format('cd /usr/hdp/{hdp_version}/ranger-hbase-plugin/ && sh disable-hbase-plugin.sh')

    Execute(cmd, environment={'JAVA_HOME': params.java64_home}, logoutput=True)                    
예제 #4
0
파일: kms.py 프로젝트: zouzhberk/ambaridemo
def enable_kms_plugin():

  import params

  if params.has_ranger_admin:

    ranger_adm_obj = Rangeradmin(url=params.policymgr_mgr_url)
    response_code, response_recieved = ranger_adm_obj.check_ranger_login_urllib2(params.policymgr_mgr_url + '/login.jsp', 'test:test')
    if response_code is not None and response_code == 200:
      ambari_ranger_admin, ambari_ranger_password = ranger_adm_obj.create_ambari_admin_user(params.ambari_ranger_admin, params.ambari_ranger_password, params.admin_uname_password)
      ambari_username_password_for_ranger = ambari_ranger_admin + ':' + ambari_ranger_password
    else:
      raise Fail('Ranger service is not started on given host')   

    if ambari_ranger_admin != '' and ambari_ranger_password != '':
      get_repo_flag = get_repo(params.policymgr_mgr_url, params.repo_name, ambari_username_password_for_ranger)
      if not get_repo_flag:
        create_repo(params.policymgr_mgr_url, json.dumps(params.kms_ranger_plugin_repo), ambari_username_password_for_ranger)
    else:
      raise Fail('Ambari admin username and password not available')

    current_datetime = datetime.now()

    File(format('{kms_conf_dir}/ranger-security.xml'),
      owner = params.kms_user,
      group = params.kms_group,
      mode = 0644,
      content = InlineTemplate(format('<ranger>\n<enabled>{current_datetime}</enabled>\n</ranger>'))
    )

    Directory([os.path.join('/etc', 'ranger', params.repo_name), os.path.join('/etc', 'ranger', params.repo_name, 'policycache')],
      owner = params.kms_user,
      group = params.kms_group,
      mode=0775,
      recursive = True
    )
    
    File(os.path.join('/etc', 'ranger', params.repo_name, 'policycache',format('kms_{repo_name}.json')),
      owner = params.kms_user,
      group = params.kms_group,
      mode = 0644        
    )

    XmlConfig("ranger-kms-audit.xml",
      conf_dir=params.kms_conf_dir,
      configurations=params.config['configurations']['ranger-kms-audit'],
      configuration_attributes=params.config['configuration_attributes']['ranger-kms-audit'],
      owner=params.kms_user,
      group=params.kms_group,
      mode=0744)

    XmlConfig("ranger-kms-security.xml",
      conf_dir=params.kms_conf_dir,
      configurations=params.config['configurations']['ranger-kms-security'],
      configuration_attributes=params.config['configuration_attributes']['ranger-kms-security'],
      owner=params.kms_user,
      group=params.kms_group,
      mode=0744)

    XmlConfig("ranger-policymgr-ssl.xml",
      conf_dir=params.kms_conf_dir,
      configurations=params.config['configurations']['ranger-kms-policymgr-ssl'],
      configuration_attributes=params.config['configuration_attributes']['ranger-kms-policymgr-ssl'],
      owner=params.kms_user,
      group=params.kms_group,
      mode=0744)

    if params.xa_audit_db_is_enabled:
      cred_setup = params.cred_setup_prefix + ('-f', params.credential_file, '-k', 'auditDBCred', '-v', PasswordString(params.xa_audit_db_password), '-c', '1')
      Execute(cred_setup, environment={'JAVA_HOME': params.java_home}, logoutput=True, sudo=True)

    cred_setup = params.cred_setup_prefix + ('-f', params.credential_file, '-k', 'sslKeyStore', '-v', PasswordString(params.ssl_keystore_password), '-c', '1')
    Execute(cred_setup, environment={'JAVA_HOME': params.java_home}, logoutput=True, sudo=True)

    cred_setup = params.cred_setup_prefix + ('-f', params.credential_file, '-k', 'sslTrustStore', '-v', PasswordString(params.ssl_truststore_password), '-c', '1')
    Execute(cred_setup, environment={'JAVA_HOME': params.java_home}, logoutput=True, sudo=True)

    File(params.credential_file,
      owner = params.kms_user,
      group = params.kms_group,
      mode = 0640
      )
예제 #5
0
파일: kms.py 프로젝트: rdoppalapudi/ambari
def enable_kms_plugin():

    import params

    if params.has_ranger_admin:

        ranger_adm_obj = Rangeradmin(url=params.policymgr_mgr_url)
        response_code, response_recieved = ranger_adm_obj.check_ranger_login_urllib2(
            params.policymgr_mgr_url + '/login.jsp', 'test:test')
        if response_code is not None and response_code == 200:
            ambari_ranger_admin, ambari_ranger_password = ranger_adm_obj.create_ambari_admin_user(
                params.ambari_ranger_admin, params.ambari_ranger_password,
                params.admin_uname_password)
            ambari_username_password_for_ranger = ambari_ranger_admin + ':' + ambari_ranger_password
        else:
            raise Fail('Ranger service is not started on given host')

        if ambari_ranger_admin != '' and ambari_ranger_password != '':
            get_repo_flag = get_repo(params.policymgr_mgr_url,
                                     params.repo_name,
                                     ambari_username_password_for_ranger)
            if not get_repo_flag:
                create_repo(params.policymgr_mgr_url,
                            json.dumps(params.kms_ranger_plugin_repo),
                            ambari_username_password_for_ranger)
        else:
            raise Fail('Ambari admin username and password not available')

        current_datetime = datetime.now()

        File(
            format('{kms_conf_dir}/ranger-security.xml'),
            owner=params.kms_user,
            group=params.kms_group,
            mode=0644,
            content=InlineTemplate(
                format(
                    '<ranger>\n<enabled>{current_datetime}</enabled>\n</ranger>'
                )))

        Directory([
            os.path.join('/etc', 'ranger', params.repo_name),
            os.path.join('/etc', 'ranger', params.repo_name, 'policycache')
        ],
                  owner=params.kms_user,
                  group=params.kms_group,
                  mode=0775,
                  recursive=True)

        File(os.path.join('/etc', 'ranger', params.repo_name, 'policycache',
                          format('kms_{repo_name}.json')),
             owner=params.kms_user,
             group=params.kms_group,
             mode=0644)

        XmlConfig(
            "ranger-kms-audit.xml",
            conf_dir=params.kms_conf_dir,
            configurations=params.config['configurations']['ranger-kms-audit'],
            configuration_attributes=params.config['configuration_attributes']
            ['ranger-kms-audit'],
            owner=params.kms_user,
            group=params.kms_group,
            mode=0744)

        XmlConfig(
            "ranger-kms-security.xml",
            conf_dir=params.kms_conf_dir,
            configurations=params.config['configurations']
            ['ranger-kms-security'],
            configuration_attributes=params.config['configuration_attributes']
            ['ranger-kms-security'],
            owner=params.kms_user,
            group=params.kms_group,
            mode=0744)

        XmlConfig(
            "ranger-policymgr-ssl.xml",
            conf_dir=params.kms_conf_dir,
            configurations=params.config['configurations']
            ['ranger-kms-policymgr-ssl'],
            configuration_attributes=params.config['configuration_attributes']
            ['ranger-kms-policymgr-ssl'],
            owner=params.kms_user,
            group=params.kms_group,
            mode=0744)

        if params.xa_audit_db_is_enabled:
            cred_setup = params.cred_setup_prefix + (
                '-f', params.credential_file, '-k', 'auditDBCred', '-v',
                PasswordString(params.xa_audit_db_password), '-c', '1')
            Execute(cred_setup,
                    environment={'JAVA_HOME': params.java_home},
                    logoutput=True,
                    sudo=True)

        cred_setup = params.cred_setup_prefix + (
            '-f', params.credential_file, '-k', 'sslKeyStore', '-v',
            PasswordString(params.ssl_keystore_password), '-c', '1')
        Execute(cred_setup,
                environment={'JAVA_HOME': params.java_home},
                logoutput=True,
                sudo=True)

        cred_setup = params.cred_setup_prefix + (
            '-f', params.credential_file, '-k', 'sslTrustStore', '-v',
            PasswordString(params.ssl_truststore_password), '-c', '1')
        Execute(cred_setup,
                environment={'JAVA_HOME': params.java_home},
                logoutput=True,
                sudo=True)

        File(params.credential_file,
             owner=params.kms_user,
             group=params.kms_group,
             mode=0640)
예제 #6
0
def setup_ranger_hive():
    import params

    if params.has_ranger_admin:
        File(
            params.ranger_downloaded_custom_connector,
            content=DownloadSource(params.ranger_driver_curl_source),
        )

        if not os.path.isfile(params.ranger_driver_curl_target):
            Execute(('cp', '--remove-destination',
                     params.ranger_downloaded_custom_connector,
                     params.ranger_driver_curl_target),
                    path=["/bin", "/usr/bin/"],
                    sudo=True)

        try:
            command = 'hdp-select status hive-server2'
            return_code, hdp_output = shell.call(command, timeout=20)
        except Exception, e:
            Logger.error(str(e))
            raise Fail(
                'Unable to execute hdp-select command to retrieve the version.'
            )

        if return_code != 0:
            raise Fail(
                'Unable to determine the current version because of a non-zero return code of {0}'
                .format(str(return_code)))

        hdp_version = re.sub('hive-server2 - ', '', hdp_output).strip()
        match = re.match('[0-9]+.[0-9]+.[0-9]+.[0-9]+-[0-9]+', hdp_version)

        if match is None:
            raise Fail('Failed to get extracted version')

        file_path = '/usr/hdp/' + hdp_version + '/ranger-hive-plugin/install.properties'
        if not os.path.isfile(file_path):
            raise Fail(
                'Ranger Hive plugin install.properties file does not exist at {0}'
                .format(file_path))

        ranger_hive_dict = ranger_hive_properties()
        hive_repo_data = hive_repo_properties()

        write_properties_to_file(file_path, ranger_hive_dict)

        if params.enable_ranger_hive:
            cmd = format(
                'cd /usr/hdp/{hdp_version}/ranger-hive-plugin/ && sh enable-hive-plugin.sh'
            )
            ranger_adm_obj = Rangeradmin(
                url=ranger_hive_dict['POLICY_MGR_URL'])
            response_code, response_recieved = ranger_adm_obj.check_ranger_login_urllib2(
                ranger_hive_dict['POLICY_MGR_URL'] + '/login.jsp', 'test:test')

            if response_code is not None and response_code == 200:
                ambari_ranger_admin, ambari_ranger_password = ranger_adm_obj.create_ambari_admin_user(
                    params.ambari_ranger_admin, params.ambari_ranger_password,
                    params.admin_uname_password)
                ambari_username_password_for_ranger = ambari_ranger_admin + ':' + ambari_ranger_password
                if ambari_ranger_admin != '' and ambari_ranger_password != '':
                    repo = ranger_adm_obj.get_repository_by_name_urllib2(
                        ranger_hive_dict['REPOSITORY_NAME'], 'hive', 'true',
                        ambari_username_password_for_ranger)

                    if repo and repo['name'] == ranger_hive_dict[
                            'REPOSITORY_NAME']:
                        Logger.info('Hive Repository exist')
                    else:
                        response = ranger_adm_obj.create_repository_urllib2(
                            hive_repo_data,
                            ambari_username_password_for_ranger,
                            params.policy_user)
                        if response is not None:
                            Logger.info(
                                'Hive Repository created in Ranger Admin')
                        else:
                            Logger.info(
                                'Hive Repository creation failed in Ranger Admin'
                            )
                else:
                    Logger.info(
                        'Ambari admin username and password are blank ')
            else:
                Logger.info('Ranger service is not started on given host')
        else:
            cmd = format(
                'cd /usr/hdp/{hdp_version}/ranger-hive-plugin/ && sh disable-hive-plugin.sh'
            )

        Execute(cmd,
                environment={'JAVA_HOME': params.java64_home},
                logoutput=True)
예제 #7
0
파일: kms.py 프로젝트: soener/ambari
def kms():
  import params

  if params.has_ranger_admin:

    File(params.downloaded_custom_connector,
      content = DownloadSource(params.driver_curl_source)
    )

    Directory(params.java_share_dir,
      mode=0755
    )

    if not os.path.isfile(params.driver_curl_target):
      Execute(('cp', '--remove-destination', params.downloaded_custom_connector, params.driver_curl_target),
              path=["/bin", "/usr/bin/"],
              sudo=True)

    XmlConfig("kms-acls.xml",
      conf_dir=params.kms_config_dir,
      configurations=params.config['configurations']['kms-acls'],
      configuration_attributes=params.config['configuration_attributes']['kms-acls'],
      owner=params.kms_user,
      group=params.kms_group
    )

    XmlConfig("kms-site.xml",
      conf_dir=params.kms_config_dir,
      configurations=params.config['configurations']['kms-site'],
      configuration_attributes=params.config['configuration_attributes']['kms-site'],
      owner=params.kms_user,
      group=params.kms_group
    )

    File(os.path.join(params.kms_config_dir, "kms-log4j.properties"),
      owner=params.kms_user,
      group=params.kms_group,
      content=params.kms_log4j
    )

    repo_data = kms_repo_properties()

    ranger_adm_obj = Rangeradmin(url=params.policymgr_mgr_url)
    response_code, response_recieved = ranger_adm_obj.check_ranger_login_urllib2(params.policymgr_mgr_url + '/login.jsp', 'test:test')
    if response_code is not None and response_code == 200:
      ambari_ranger_admin, ambari_ranger_password = ranger_adm_obj.create_ambari_admin_user(params.ambari_ranger_admin, params.ambari_ranger_password, params.admin_uname_password)
      ambari_username_password_for_ranger = ambari_ranger_admin + ':' + ambari_ranger_password
    else:
      raise Fail('Ranger service is not started on given host')      

    if ambari_ranger_admin != '' and ambari_ranger_password != '':  
      get_repo_flag = get_repo(params.policymgr_mgr_url, params.repo_name, ambari_username_password_for_ranger)
      if not get_repo_flag:
        create_repo(params.policymgr_mgr_url, repo_data, ambari_username_password_for_ranger)
    else:
      raise Fail('Ambari admin username and password not available')

    file_path = format('{kms_home}/install.properties')
    ranger_kms_dict = ranger_kms_properties()
    write_properties_to_file(file_path, ranger_kms_dict)

    env_dict = {'JAVA_HOME': params.java_home, 'RANGER_HOME': params.kms_home}
    setup_sh = format("cd {kms_home} && ") + as_sudo([format('{kms_home}/setup.sh')])
    Execute(setup_sh, environment=env_dict, logoutput=True)