【问题标题】:AWS EB + nginx: Update access.log format to obfuscate sensitive get request parametersAWS EB + nginx:更新 access.log 格式以混淆敏感的获取请求参数
【发布时间】:2019-01-21 20:15:59
【问题描述】:

我遇到了与此问题中所述相同的问题:How to not log a get request parameter in the nginx access logs?

但是,由于 nginx 是通过 AWS 配置的,所以我在部署时不确定如何修改它。我不清楚这些配置的去向。 AWS 支持无法提供帮助,因为这是 nginx 而不是 AWS 的问题。

任何能指引我正确方向的信息将不胜感激。

到目前为止,我所拥有的只是我可以在我部署到 EB 的存储库中修改 ./ebextensions/nginx.config,但其中需要设置的内容尚不清楚。

==================================

好的,所以一些有趣的更新。基本上,AWS EB 环境为其实例设置了默认的 nginx.configs。在这些配置中,它包括某个路径中的所有 *.config 文件,包括一个包含服务器指令的自动生成文件。它将所有这些注入到 nginx.config 的 http 指令中。

确实可以选择完全覆盖 nginx 配置。但是,作为一个对那里发生的一切以及这样做的潜在危险几乎一无所知的人,我认为最好不要尽可能地修改默认行为。因此,我决定找到一种方法来修改这个自动生成的 .config 文件并重新启动 nginx。

到目前为止,我的./ebextensions/01_proxy.config

files:
  "/etc/nginx/conf.d/injectObfuscation.sh":
    content: |
      # This script expects a file as input with an nginx server directive to be injected into the http directive of an nginx.config file.
      # It will make two modifications:
      # - It will create a log_format to be used when filtering the password parameter
      # - It will find the server directive and inject a location directive for the sensitive endpoint
      #   - This directive will replace the sensitive parameter with *s and use the filter log_format instead of the main log_format
      # TODO: Figure out how to do the above ^^

container_commands:
  01_update_server_directive:
    command: "./etc/nginx/conf.d/injectObfuscation.sh /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf"
  02_reload_nginx:
    command: "sudo service nginx reload"

files: 行声明我正在创建一些文件以添加到 EC2 实例。在这里,我的目标是创建一个 bash 脚本来完成我的任务。正如 cmets 中所述,我的任务是首先添加一行带有 log_format 的行。然后,找到带有server{ 的行,在它下面我需要完整地注入locations /my/sensitive/endpoint 指令。

如果对编写这个我完全不熟悉的 bash 脚本有任何帮助,我们将不胜感激。

【问题讨论】:

    标签: amazon-web-services nginx ebextensions


    【解决方案1】:

    我的尝试很愚蠢。

    我需要覆盖默认的 nginx.conf 和 00_elastic_beanstalk_proxy.conf,就像在 Node.js 特定文档中一样:https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/nodejs-platform-proxy.html

    EB上的其他平台允许你添加.ebextensions/nginx/nginx.conf来覆盖现有的nginx.conf,但是Node的启动过程好像不一样,忽略了这个文件。但是,您可以使用 .ebextension 配置在 /etc/nginx/nginx.conf 创建一个文件来替换它。

    出于我的目的,我这样做并在主 log_format 中将 $request 更改为 $temp

    对于 Node 环境,服务器指令存在于实例在启动期间自动生成的 00_elastic_beanstalk_proxy.conf 文件中。使用上面文档中的示例,我覆盖了它并添加了逻辑来混淆我需要的参数。可选地,这可以放置在此覆盖文件内的位置指令中。我可以定义一个单独的日志格式。但出于我的目的,我希望无论路径如何都不会记录此参数。

    AWS 注意,默认的 nginx.conf 和 00_elastic_beanstalk_proxy.conf 可能会根据您使用的节点环境的版本而改变,因此请始终从特定版本中提取一个。

    我做的一个尝试是只覆盖 nginx.conf。但是,set 指令只能在 location、server 和另一个我不记得的指令中使用。在 http 指令本身内设置变量是无效的。

    【讨论】:

    • 我收到一个 nginx 错误,指出名称 main 已被定义为 log_format。不过,使用 main 以外的其他名称也可以。
    猜你喜欢
    • 2018-11-01
    • 2020-06-20
    • 2015-10-01
    • 1970-01-01
    • 2017-05-28
    • 2019-03-05
    • 2016-03-04
    • 2017-01-27
    • 1970-01-01
    相关资源
    最近更新 更多