如何以编程方式更改Ambari管理员密码

时间:2016-11-30 10:31:02

标签: ambari

我正致力于自动化群集的安装和配置,包括安装Ambari和通过API使用蓝图。这一切都运行正常,但我还有一件事我遇到了麻烦,那就是在整个配置过程中更改Ambari密码(我指的是我的流程,而不是Ambari群集创建流程)。我不想要的是保留新配置的Ambari安装程序,并使用默认的“admin / admin”凭据,我也无法让人类每次都进行更改。

我已经尝试过REST API,但即使调用似乎正确执行(例如,没有返回错误),新密码也不会生效。

我考虑过通过ssh使用ambari-admin-password-reset命令,但我的Ambari安装(使用2.1.0)似乎没有该命令。我已经仔细检查了代理程序是否正在运行,并且我已经尝试过它作为root用户,并且在每种情况下都会产生“找不到命令”错误。

我还考虑过使用JDBC,直接连接到Postgres,并直接修改密码,但我不确定Ambari使用哪种哈希算法,和/或它存储盐的位置(如果使用的话)。

如果有人可以就如何使这些方法中的任何一种或所有方法提供任何建议,我们将不胜感激。现在我准备撕掉我的最后一根头发。

编辑:FWIW,这就是我对REST API的调用,它似乎无声地失败。

public static void main( String[] args )
{


    // make REST call to Ambari to change password
    try (CloseableHttpClient httpClient = HttpClientBuilder.create().build()) 
    {
        HttpHost target = new HttpHost("admin.test-cluster-6.example.com", 8080, "http");

        String authorizationEncoded = Base64.encodeBase64String( "admin:admin".getBytes() );

        // specify the put request
        HttpPut putRequest = new HttpPut( "/api/v1/users/admin" );

        StringEntity jsonEntity = new StringEntity( "{\"Users/password\":\"newpassword\"}" );

        putRequest.setEntity( jsonEntity );
        putRequest.setHeader( "X-Requested-By:", "ambari");
        putRequest.setHeader("Authorization", "Basic " + authorizationEncoded);

        System.out.println("executing request to " + target);

        HttpResponse httpResponse = httpClient.execute(target, putRequest);
        HttpEntity entity = httpResponse.getEntity();
        System.out.println( "status: " + httpResponse.getStatusLine());
        InputStream is = entity.getContent();
        String responseBody = streamToString( is );

        System.out.println( "response: " +  responseBody );

    } 
    catch (IOException e) 
    {
        e.printStackTrace();

    }

    System.out.println( "done" );
}

这样做会产生输出

status: HTTP/1.1 200 OK

哪会使人相信操作成功。但没有骰子。

这也是Ambari 2.1.0,无论您尝试更改哪个用户的密码,都会出现相同的行为。

1 个答案:

答案 0 :(得分:1)

您拥有正确的网址,但您发送的json不正确。它应该是以下形式:

{
  "Users": {
    "user_name": "myusername",
    "old_password": "myoldpassword",
    "password": "mynewpassword"
  }

}

详情请参阅ambari wiki中的page

相关问题