Chef remote_file 来自带有自签名证书的 https 站点
Chef remote_file from https site with self signed certificate
我想知道 Chef 是否可以使用来自使用自签名证书的 https 源的 remote_file
资源。好像做不到。文档未提及证书并提供禁用 SSL 检查的配置。
如果您有一个带 https 和自签名证书的站点,例如可以使用具有
的食谱进行复制
remote_file "/tmp/image.png" do
source "https://mywebsite.com/image.png"
end
你当然可以使用knife
获取目标节点上的证书,例如如下
vagrant@devops:~$ knife ssl fetch https://mywebsite.com/
WARNING: No knife configuration file found
WARNING: Certificates from mywebsite.com will be fetched and placed in your trusted_cert directory (/home/vagrant/.chef/trusted_certs).
Knife has no means to verify these are the correct certificates. You should
verify the authenticity of these certificates after downloading.
这似乎行不通 much/anything。厨师将继续显示消息
==> default: [2015-06-08T06:30:33+00:00] ERROR: remote_file[/tmp/image.png] (jenkins::remote_file_test line 1) had an error: OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
也许这是一个错误? Chef 似乎忽略了受信任的证书。
有解决办法吗?我们可以让 Chef 以某种方式信任证书吗?
更新
Tensibai 给出了正确答案。查看他的评论。
根据 tensibai 的技术(在原始问题中发表评论)我有以下安装证书的方法:
bash 'pull certificate from gitlab' do
code <<-EOH
openssl s_client -connect hqdevgit01.my.lan:443 -showcerts | openssl x509 -outform PEM > /opt/chef/embedded/ssl/certs/gitlab.pem
cat /opt/chef/embedded/ssl/certs/gitlab.pem >> /opt/chef/embedded/ssl/certs/cacert.pem
EOH
not_if { ::File.exists?('/opt/chef/embedded/ssl/certs/gitlab.pem') }
end
我下载 pem 并将其存储在一个单独的文件中,并在将来触发该存在的操作。我想我应该检查 cacert.pem,但如果证书被附加多次,似乎没有太大问题。
最终我需要为我的内部工具服务器获得一些证书 - 但组织很小,并且没有明确指示我们将在 6 个月内做什么和在哪里。对于我的短期需求(我们 100% 在防火墙后面),这个解决方案很好(不理想)。
我使用 certificate
食谱来安装我的自签名证书。所以我的解决方案就是基于此。在我的食谱中,我使用 certificate_manage
安装存储在加密数据包中的证书。
cert_resource = certificate_manage node['hostname'] do
action :create
ignore_missing false
end
然后我可以使用
之类的东西将证书添加到 cacert.pem
ruby_block 'add_self_signed_certificate_to_cacert' do
block do
cert_file_path = ::File.join(cert_resource.cert_path, 'certs', cert_resource.cert_file)
cacert = ::File.read('/opt/chef/embedded/ssl/certs/cacert.pem')
pem = ::File.read(::File.join(cert_resource.cert_path, 'certs',cert_resource.cert_file))
unless cacert.include? pem
File.open('/opt/chef/embedded/ssl/certs/cacert.pem', 'w') {|f| f.write(cacert + "\n" + pem) }
end
end
end
自 chef 12 起,放置您的 ca 证书文件的位置在 /etc/chef/trusted_certs
。将您的文件放在那里将解决此问题。
谢谢 onknows 的解决方案。
在 AWS OpsWorks 上,尝试从内部 CA 机构签名的远程 https 源下载文件时,我遇到了同样的问题。
在 Windows 机器上,解决方法如下。
- 以 Base-64 编码的 X.509 (.CER) 格式保存 CA 授权证书。
- 将证书放入cookbook/files目录
- 复制实例磁盘上的证书(例如在设置阶段使用配方)
cookbook_file 'C:\tmp\calive.cer' do
source "calive.cer"
rights :full_control, 'Everyone'
action :create_if_missing
end
- 将您的 CA 授权证书的内容添加到文件末尾:
C:\opscode\chef\embedded\ssl\certs\cacert.pem
ruby_block 'install_cert' do
block do
filemyca = File.open("c:\tmp\calive.cer").readlines
open("C:\opscode\chef\embedded\ssl\certs\cacert.pem", 'a') do |f|
f.puts ""
f.puts "My Internel CA Auth Cert"
f.puts "==========================================="
f.puts filemyca
end
end
action :run
end
- 执行远程文件复制
mypath = 'https://mysite.mydom.local/the_file'
mylocalfile = "c://mydir//the_file"
remote_file mylocalfile do
source mypath
action :create_if_missing
end
我想知道 Chef 是否可以使用来自使用自签名证书的 https 源的 remote_file
资源。好像做不到。文档未提及证书并提供禁用 SSL 检查的配置。
如果您有一个带 https 和自签名证书的站点,例如可以使用具有
的食谱进行复制remote_file "/tmp/image.png" do
source "https://mywebsite.com/image.png"
end
你当然可以使用knife
获取目标节点上的证书,例如如下
vagrant@devops:~$ knife ssl fetch https://mywebsite.com/
WARNING: No knife configuration file found
WARNING: Certificates from mywebsite.com will be fetched and placed in your trusted_cert directory (/home/vagrant/.chef/trusted_certs).
Knife has no means to verify these are the correct certificates. You should verify the authenticity of these certificates after downloading.
这似乎行不通 much/anything。厨师将继续显示消息
==> default: [2015-06-08T06:30:33+00:00] ERROR: remote_file[/tmp/image.png] (jenkins::remote_file_test line 1) had an error: OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
也许这是一个错误? Chef 似乎忽略了受信任的证书。
有解决办法吗?我们可以让 Chef 以某种方式信任证书吗?
更新 Tensibai 给出了正确答案。查看他的评论。
根据 tensibai 的技术(在原始问题中发表评论)我有以下安装证书的方法:
bash 'pull certificate from gitlab' do
code <<-EOH
openssl s_client -connect hqdevgit01.my.lan:443 -showcerts | openssl x509 -outform PEM > /opt/chef/embedded/ssl/certs/gitlab.pem
cat /opt/chef/embedded/ssl/certs/gitlab.pem >> /opt/chef/embedded/ssl/certs/cacert.pem
EOH
not_if { ::File.exists?('/opt/chef/embedded/ssl/certs/gitlab.pem') }
end
我下载 pem 并将其存储在一个单独的文件中,并在将来触发该存在的操作。我想我应该检查 cacert.pem,但如果证书被附加多次,似乎没有太大问题。
最终我需要为我的内部工具服务器获得一些证书 - 但组织很小,并且没有明确指示我们将在 6 个月内做什么和在哪里。对于我的短期需求(我们 100% 在防火墙后面),这个解决方案很好(不理想)。
我使用 certificate
食谱来安装我的自签名证书。所以我的解决方案就是基于此。在我的食谱中,我使用 certificate_manage
安装存储在加密数据包中的证书。
cert_resource = certificate_manage node['hostname'] do
action :create
ignore_missing false
end
然后我可以使用
之类的东西将证书添加到cacert.pem
ruby_block 'add_self_signed_certificate_to_cacert' do
block do
cert_file_path = ::File.join(cert_resource.cert_path, 'certs', cert_resource.cert_file)
cacert = ::File.read('/opt/chef/embedded/ssl/certs/cacert.pem')
pem = ::File.read(::File.join(cert_resource.cert_path, 'certs',cert_resource.cert_file))
unless cacert.include? pem
File.open('/opt/chef/embedded/ssl/certs/cacert.pem', 'w') {|f| f.write(cacert + "\n" + pem) }
end
end
end
自 chef 12 起,放置您的 ca 证书文件的位置在 /etc/chef/trusted_certs
。将您的文件放在那里将解决此问题。
谢谢 onknows 的解决方案。
在 AWS OpsWorks 上,尝试从内部 CA 机构签名的远程 https 源下载文件时,我遇到了同样的问题。
在 Windows 机器上,解决方法如下。
- 以 Base-64 编码的 X.509 (.CER) 格式保存 CA 授权证书。
- 将证书放入cookbook/files目录
- 复制实例磁盘上的证书(例如在设置阶段使用配方)
cookbook_file 'C:\tmp\calive.cer' do
source "calive.cer"
rights :full_control, 'Everyone'
action :create_if_missing
end
- 将您的 CA 授权证书的内容添加到文件末尾: C:\opscode\chef\embedded\ssl\certs\cacert.pem
ruby_block 'install_cert' do
block do
filemyca = File.open("c:\tmp\calive.cer").readlines
open("C:\opscode\chef\embedded\ssl\certs\cacert.pem", 'a') do |f|
f.puts ""
f.puts "My Internel CA Auth Cert"
f.puts "==========================================="
f.puts filemyca
end
end
action :run
end
- 执行远程文件复制
mypath = 'https://mysite.mydom.local/the_file'
mylocalfile = "c://mydir//the_file"
remote_file mylocalfile do
source mypath
action :create_if_missing
end