How to resolve CSRF protection error while adding service through Ambari api
2021-06-08 08:03
标签:use this etc min clu inf sage ice conf Adding service through ambari gives error as shown below - You need to disable CSRF protection as mentioned below - 1.Login to ambari server using cli [superuser credentials] 2. Add below line at the bottom of the file 3. Restart ambari server 4. Try executing POST command again to add service and it should work Thanks. How to resolve CSRF protection error while adding service through Ambari api 标签:use this etc min clu inf sage ice conf 原文地址:https://www.cnblogs.com/felixzh/p/10702008.htmlShort Description:
This article will describe on how to disable CSRF protection in Ambari.Article
[root@sandbox ~]# curl -u admin:admin -i -X POST -d ‘{"ServiceInfo":{"service_name":"STORM"}}‘ http://192.168.123.129:8080/api/v1/clusters/Sandbox/services
HTTP/1.1 400 Bad Request
Set-Cookie: AMBARISESSIONID=qraouzksi4vktobhob5heqml;Path=/
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Content-Type: text/plain
Content-Length: 107
Server: Jetty(7.6.7.v20120910)
{
"status" : 400,
"message" : "CSRF protection is turned on. X-Requested-By HTTP header is required."
vi /etc/ambari-server/conf/ambari.properties
api.csrfPrevention.enabled=false
ambari-server restart
[root@sandbox ~]# curl -u admin:admin -i -X POST -d ‘{"ServiceInfo":{"service_name":"STORM"}}‘ http://192.168.123.129:8080/api/v1/clusters/Sandbox/services
HTTP/1.1 201 Created
Set-Cookie: AMBARISESSIONID=1t4c7yfbu64nw1nenrgplco7sd;Path=/
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Content-Type: text/plain
Content-Length: 0
Server: Jetty(7.6.7.v20120910)
文章标题:How to resolve CSRF protection error while adding service through Ambari api
文章链接:http://soscw.com/index.php/essay/92121.html