Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在我的网站';安全的管理面板?_Php_Graphite_Grafana - Fatal编程技术网

Php 如何在我的网站';安全的管理面板?

Php 如何在我的网站';安全的管理面板?,php,graphite,grafana,Php,Graphite,Grafana,我在格拉法纳创造了一些不错的情节。我想直接在我的网站的管理面板中显示其中的一些,而不是强迫用户进入grafana仪表盘并强迫他们进行双重身份验证(一次用于我的网站,一次用于grafana) 一个选项是创建并使用grafana中每个图形都可以使用的共享/嵌入iframe选项。虽然它工作得很好,但如果任何知道适当URL的人都能看到grafana数据,这似乎是一个巨大的漏洞 然后我看到grafana有一个,但是我看不出有可能在那里显示一个特定的图形 我已经尝试了一个解决方案,如果用户在我的网站上得到正

我在格拉法纳创造了一些不错的情节。我想直接在我的网站的管理面板中显示其中的一些,而不是强迫用户进入grafana仪表盘并强迫他们进行双重身份验证(一次用于我的网站,一次用于grafana)

一个选项是创建并使用grafana中每个图形都可以使用的共享/嵌入iframe选项。虽然它工作得很好,但如果任何知道适当URL的人都能看到grafana数据,这似乎是一个巨大的漏洞

然后我看到grafana有一个,但是我看不出有可能在那里显示一个特定的图形

我已经尝试了一个解决方案,如果用户在我的网站上得到正确的身份验证,它将添加授权头并连接到grafana嵌入URL。但是,它不起作用,配置它是一场噩梦

最后一个选项是在服务器端从grafana获取图形的PNG,并仅为我的网站中经过身份验证的管理员提供这些PNG。然而,在这种情况下,我失去了grafana提供的所有很酷的OOTB功能,比如扩展/折叠时间范围、自动刷新等。

基于,我能够将grafana dashboard嵌入到我的页面中

将您的
iframe

<iframe id="dashboard"></iframe>
您必须做的最后一件事是提供nginx.conf文件:

events {
    worker_connections  1024;
}

http {
#
# Acts as a nginx HTTPS proxy server
# enabling CORS only to domains matched by regex
# /https?://.*\.mckinsey\.com(:[0-9]+)?)/
#
# Based on:
# * http://blog.themillhousegroup.com/2013/05/nginx-as-cors-enabled-https-proxy.html
# * http://enable-cors.org/server_nginx.html
#
server {
  listen 80;

  location / {
    #if ($http_origin ~* (https?://.*\.tarunlalwani\.com(:[0-9]+)?$)) {
    #   set $cors "1";
    #}
    set $cors "1";

    # OPTIONS indicates a CORS pre-flight request
    if ($request_method = 'OPTIONS') {
       set $cors "${cors}o";
    }

    # Append CORS headers to any request from
    # allowed CORS domain, except OPTIONS
    if ($cors = "1") {
       add_header Access-Control-Allow-Origin $http_origin always;
       add_header Access-Control-Allow-Credentials  true always;
       proxy_pass      http://grafana:3000;
    }

    # OPTIONS (pre-flight) request from allowed
    # CORS domain. return response directly
    if ($cors = "1o") {
       add_header 'Access-Control-Allow-Origin' '$http_origin' always;
       add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE' always;
       add_header 'Access-Control-Allow-Credentials' 'true' always;
       add_header 'Access-Control-Allow-Headers' 'Origin,Content-Type,Accept,Authorization' always;
       add_header Content-Length 0;
       add_header Content-Type text/plain;
       return 204;
    }

    # Requests from non-allowed CORS domains
       proxy_pass      http://grafana:3000;
  }
}

}
此文件基于提供的,但重要的区别是

add_header 'Access-Control-Allow-Headers' 'Origin,Content-Type,Accept,Authorization' always; 始终添加_标题“访问控制允许标题”“来源、内容类型、接受、授权”;
这表示您允许设置
授权
标题。

您在这方面取得了任何进展吗?我放弃了直接嵌入grafana图表。相反,在我的应用程序中,我公开了。它们返回json格式的度量数据。在应用程序的管理面板中,我将该数据呈现为图形。有点乏味,因为grafana已经使用相同的Graphite API做了相同的事情,但是我发现没有办法在适当的限制下重用它。谢谢。我希望绕过这个问题……将凭证放入页面的源代码是一个非常糟糕的想法,这不是问题的关键。我没有告诉您,此代码已准备好推送到您的存储库。
events {
    worker_connections  1024;
}

http {
#
# Acts as a nginx HTTPS proxy server
# enabling CORS only to domains matched by regex
# /https?://.*\.mckinsey\.com(:[0-9]+)?)/
#
# Based on:
# * http://blog.themillhousegroup.com/2013/05/nginx-as-cors-enabled-https-proxy.html
# * http://enable-cors.org/server_nginx.html
#
server {
  listen 80;

  location / {
    #if ($http_origin ~* (https?://.*\.tarunlalwani\.com(:[0-9]+)?$)) {
    #   set $cors "1";
    #}
    set $cors "1";

    # OPTIONS indicates a CORS pre-flight request
    if ($request_method = 'OPTIONS') {
       set $cors "${cors}o";
    }

    # Append CORS headers to any request from
    # allowed CORS domain, except OPTIONS
    if ($cors = "1") {
       add_header Access-Control-Allow-Origin $http_origin always;
       add_header Access-Control-Allow-Credentials  true always;
       proxy_pass      http://grafana:3000;
    }

    # OPTIONS (pre-flight) request from allowed
    # CORS domain. return response directly
    if ($cors = "1o") {
       add_header 'Access-Control-Allow-Origin' '$http_origin' always;
       add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE' always;
       add_header 'Access-Control-Allow-Credentials' 'true' always;
       add_header 'Access-Control-Allow-Headers' 'Origin,Content-Type,Accept,Authorization' always;
       add_header Content-Length 0;
       add_header Content-Type text/plain;
       return 204;
    }

    # Requests from non-allowed CORS domains
       proxy_pass      http://grafana:3000;
  }
}

}
add_header 'Access-Control-Allow-Headers' 'Origin,Content-Type,Accept,Authorization' always;