【问题标题】:Disable ssl on Chef-server?在 Chef-server 上禁用 ssl?
【发布时间】:2015-05-22 21:16:23
【问题描述】:

我在/etc/opscode/chef-server.rb 文件中设置了nginx['enable_non_ssl']=true 并运行chef-server-ctl reconfigure,但是当我尝试为厨师卷曲http 端口时,我仍然得到重定向,这违背了此设置的目的。请参阅下面的错误。

我的chef-server.rb 文件:

cat /etc/opscode/chef-server.rb

nginx['enable_non_ssl']=true
nginx['non_ssl_port']=80

运行重新配置:

chef-server-ctl 重新配置

Starting Chef Client, version 12.0.3
resolving cookbooks for run list: ["private-chef::default"]
[2015-05-25T13:12:26+00:00] WARN: Cookbook 'local-mode-cache' is empty or entirely chefignored at /opt/opscode/embedded/cookbooks/local-mode-cache
[2015-05-25T13:12:26+00:00] WARN: Cookbook 'local-mode-cache' is empty or entirely chefignored at /opt/opscode/embedded/cookbooks/local-mode-cache
[2015-05-25T13:12:26+00:00] WARN: Cookbook 'local-mode-cache' is empty or entirely chefignored at /opt/opscode/embedded/cookbooks/local-mode-cache
....

Curl 命令显示我仍然被重定向:

卷曲http://chef-xxx.xxxxxx.com

<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>openresty/1.7.10.1</center>
</body>
</html>

我如何启动一个工作的厨师服务器?

【问题讨论】:

标签: chef-infra chef-recipe


【解决方案1】:

我遇到了同样的问题并解决了它

我在最近安装 Chef Server (chef-manage v2.4.4) 时遇到了同样的问题

您可以通过阅读已部署 Chef 服务器的更改日志来查看您的 Chef Manage 版本:http(s)://your-chef-server.com/changelog

我们想要什么

在专用服务器上安装我的 Chef 服务器实例后,它确实可以正常使用 SSL。

但我们的生产服务器部署在专用 VLAN 中的专用主机上,用户通过作为反向代理运行的 nginx Web 服务器访问服务或 Web 应用程序。

因此,要将 Chef 服务器置于生产模式,我必须配置我的反向代理来代理请求:

这里是正确的请求/响应路由模式:

请求:

client    443 >> 443 chef.company.com (DNS: rev-proxy)
rev-proxy  80 >> 80  chef.vlan

回复:

rev-proxy  80 << 80  chef.vlan
client    443 << 443 chef.company.com

正常问题

但是,像您一样,厨师服务器默认配置强制 SSL 重定向从反向代理到 vlan 中的厨师主机。 它会导致无限重定向循环:

client     443 >> 443 rev-proxy
proxy       80 >> 80  chef.vlan
client      80 << 80  chef.company.com (redirect to https://$host$request_uri)
client     443 >> 443 rev-proxy
proxy       80 >> 80  chef.vlan
client      80 << 80  chef.company.com (redirect to https://$host$request_uri)
...
client     443 >> 443 rev-proxy
proxy       80 >> 80  chef.vlan
client      80 << 80  chef.company.com (redirect to https://$host$request_uri)
...

正常修复

所以我们必须禁用 SSL chef.vlan 端。

常规方法是通过插入以下指令来编辑文件/opt/obscode.chef-server.rb(如果不存在则创建它):

nginx['enable_non_ssl']=true

以及可选(因为这已经是默认值)以下一个:

nginx['non_ssl_port']=80

因此我们将不得不重新配置厨师服务器:

# chef-server-ctl reconfigure

但是 chef-server 有一个 bug

但是在用于生成 nginx 配置文件的 chef 模板配方中有一个错误。因此,当我们重新配置厨师服务器时,前面的指令将被忽略。

所以无限循环停留在那里。

Bug 票:https://tickets.opscode.com/browse/CHEF-3999

此外,您还可以查看以下其他资源:

https://github.com/chef/omnibus-chef/pull/57

https://docs.chef.io/config_rb_server.html

https://github.com/chef/chef-server/issues/973

解决问题

为了解决这种情况,我不得不从 bug 票中调整建议的解决方案。

在 chef 主机上找到 nginx 配置文件

root@chef-srv:~# find / -name nginx.conf
/opt/chef-manage/embedded/service/gem/ruby/2.2.0/gems/unicorn-4.9.0/examples/nginx.conf
/opt/opscode/embedded/service/gem/ruby/2.2.0/gems/unicorn-5.1.0/examples/nginx.conf
/opt/opscode/embedded/conf/nginx.conf
/var/opt/opscode/nginx/etc/nginx.conf

最后一个是嵌入的nginx conf文件。它包含以下块代码,问题的来源:

# We support three options: serve nothing on non_ssl_port (80),
# redirect to https, or actually serve the API.
      server {
        listen 80;
        access_log /var/log/opscode/nginx/rewrite-port-80.log;
        return 301 https://$host$request_uri;
      }

查找获取嵌入式 nginx 配置的 nginx 配置配方

root@chef-srv:~# find / -name nginx.rb
/opt/chef-manage/embedded/cookbooks/omnibus-chef-manage/recipes/nginx.rb
/opt/chef-manage/embedded/cookbooks/cache/cookbooks/omnibus-chef-manage/recipes/nginx.rb
/opt/opscode/embedded/cookbooks/private-chef/recipes/nginx.rb
/var/opt/opscode/local-mode-cache/cookbooks/private-chef/recipes/nginx.rb

第三个是生成嵌入式nginx配置的模板:

/opt/opscode/embedded/cookbooks/private-chef/recipes/nginx.rb
  === > /var/opt/opscode/nginx/etc/nginx.conf

修正配方

我们必须通过以下几行来修复它:

node.default['private_chef']['nginx']['enable_non_ssl']=true

我们应该将它附加到以下块:

# Save node attributes back for use in config template generation
node.default['private_chef']['nginx']['ssl_certificate'] ||= ssl_crtfile
node.default['private_chef']['nginx']['ssl_certificate_key'] ||= ssl_keyfile
node.default['private_chef']['nginx']['ssl_dhparam'] ||= ssl_dhparam

所以最终的代码块看起来像:

# nano /opt/opscode/embedded/cookbooks/private-chef/recipes/nginx.rb

# Save node attributes back for use in config template generation
node.default['private_chef']['nginx']['ssl_certificate'] ||= ssl_crtfile
node.default['private_chef']['nginx']['ssl_certificate_key'] ||= ssl_keyfile
node.default['private_chef']['nginx']['ssl_dhparam'] ||= ssl_dhparam
node.default['private_chef']['nginx']['enable_non_ssl']=true

应用更改

最后我们必须通过重新配置厨师服务器从配方模板重新生成 nginx 配置文件:

# chef-server-ctl reconfigure

然后路由模式按预期工作。

享受吧!

【讨论】:

    【解决方案2】:

    Relevant settings from Chef:

    注意 chef-server.rb 文件默认不存在。要修改 Chef 服务器的设置,请在 /etc/opscode/ 目录中创建一个名为 chef-server.rb 的文件。

    注意 此文件在以前版本的 Enterprise Chef 中被命名为 private-chef.rb。从 Enterprise Chef 升级到 Chef server 12 后,private-chef.rb 文件符号链接到 chef-server.rb。从 Chef 服务器 12 开始,不推荐使用 private-chef.rb 文件。

    nginx['enable_non_ssl']
    

    用于允许端口 80 重定向到端口 443。当此值设置为 false 时,允许前端硬件上的负载平衡器对 WebUI 和 API 进行 SSL 终止。默认值:假。

    nginx['non_ssl_port']   
    

    WebUI 和 API 绑定到非 SSL 连接的端口。默认值:80。使用 nginx['enable_non_ssl'] 在此端口号上启用或禁用 SSL 重定向。设置为 false 以禁用非 SSL 连接。

    所以根据上面我相信你需要在/etc/opscode/目录下编辑/创建chef-server.rb文件,然后运行chef-server-ctl reconfigure

    【讨论】:

    • 不,我仍然收到重定向,请参阅上面的更新问题。我已经完成了所有这些步骤,我只是使用 /etc/chef-server/chef-server.rb 而不是 /etc/opscode/chef-server.rb。但是,移动文件并不能解决任何问题。
    • @UsmanIsmail 您运行的是社区版还是企业版?如果您正在运行社区,我将启动一个 AWS EC2 系统进行测试。如果是企业,我建议提交工单。
    • @UsmanIsmail 只是为了快速检查您是否在运行 ubuntu/red hat/centos?
    • 我认为是红帽变体的 AWS AMI
    • 这有什么更新吗?我在 Chef Server 11.1.0-1 上看到了同样的问题...尝试在 Chef 节点上禁用 SSL,以便能够在外部 F5 上管理 SSL 终止。
    【解决方案3】:

    chef-server.rb 文件中的更改使 url 成为 http 但是当我再次登录时提示 https 登录方式;用户登录两次,一次在 http 中,一次在 https 中。

    如果您有机会尝试此操作以及配置为 HTTP 实例是否成功,请告诉我提前致谢。

    【讨论】:

      【解决方案4】:

      所以,我调查了这个问题并发现了下一个:

      除了 Nginx,WebUI chef-manage 使用 Unicorn web-server,并且应用程序具有属性 config.force_ssl=true,除非 ENV['NO_SSL']。

      因此,要禁用 SSL,您需要传递环境变量 export NO_SSL=true 来运行 WebUI 的命令或运行脚本。

      【讨论】:

        猜你喜欢
        • 2015-03-29
        • 1970-01-01
        • 1970-01-01
        • 2011-01-29
        • 1970-01-01
        • 2021-10-13
        • 1970-01-01
        • 1970-01-01
        • 2018-10-09
        相关资源
        最近更新 更多