fbpx

Chef 12の新機能: knife ssl check/fetch #opschef_ja #getchef_ja

この記事は1年以上前に投稿されました。情報が古い可能性がありますので、ご注意ください。

既報の通り、Chef 12ではChef ClientからChef Serverに対するすべてのリクエストでSSL証明書の検証をデフォルトで有効になりました。検証に失敗した場合、リクエストは中止されます。

そのため、WorkstationやNodeからChef Serverに通信する前に、SSL証明書の準備をしなければいけません。本稿では、そのためにChef 12で新設された機能について実例を挙げながら見ていきます(参考: [和訳] Chef 12: 「信頼できない自己署名証明書」エラーの修正)。

検証環境

Chef Server、Workstation、Node用にそれぞれ1台ずつUbuntu 14.04 LTSを準備します。
Chef Serverはバージョン12.0.0をインストールしておきます。
WorkstationにはChef-DKではなくChef Client 12.0.3をインストールし、Chef ServerからChef Starter Kitをダウンロードしてchef-repoを作っておきます(参考: Chef Starter Kitの活用)。
Nodeには特に操作を行いません。

事前確認

knife client listでClient一覧を取得してみましょう。


ubuntu@ws:~/chef-repo$ knife client list
ERROR: SSL Validation failure connecting to host: chef-server.example.jp - SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
ERROR: Could not establish a secure connection to the server.
Use `knife ssl check` to troubleshoot your SSL configuration.
If your Chef Server uses a self-signed certificate, you can use
`knife ssl fetch` to make knife trust the server's certificates.


Original Exception: OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
ubuntu@ws:~/chef-repo$

このように、SSL証明書の検証エラーとなりました。

knife bootstrapでNodeをChef Serverに登録してみましょう。


ubuntu@ws:~/chef-repo$ knife bootstrap node.example.jp -x ubuntu --sudo
Connecting to node.example.jp
Failed to authenticate ubuntu - trying password auth
Enter your password:
node.example.jp knife sudo password:
node.example.jp
node.example.jp Installing Chef Client...
:
:
:
node.example.jp Thank you for installing Chef!
node.example.jp Starting first Chef Client run...
node.example.jp Starting Chef Client, version 12.0.3
node.example.jp Creating a new client identity for node.example.jp using the validator key.
node.example.jp [2014-12-17T16:30:42+09:00] ERROR: SSL Validation failure connecting to host: chef-server.example.jp - SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
node.example.jp
node.example.jp ================================================================================
node.example.jp Chef encountered an error attempting to create the client "node.example.jp"
node.example.jp ================================================================================
node.example.jp
node.example.jp [2014-12-17T16:30:42+09:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
node.example.jp Chef Client failed. 0 resources updated in 1.168508524 seconds
node.example.jp [2014-12-17T16:30:42+09:00] ERROR: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
node.example.jp [2014-12-17T16:30:42+09:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
ubuntu@ws:~/chef-repo$

Chef Clientパッケージのダウンロードとインストールまでは成功したものの、実際にNodeをChef Serverに登録する時点でSSL証明書の検証エラーとなりました。

先程knife client listを実行した際のエラーメッセージにどう対処するか書いてありました。その前にknife ssl checkで状況をより詳しく確認してみましょう。


ubuntu@ws:~/chef-repo$ knife ssl check
Connecting to host chef-server.example.jp:443
ERROR: The SSL certificate of chef-server.example.jp could not be verified
Certificate issuer data: /C=US/ST=WA/L=Seattle/O=YouCorp/OU=Operations/CN=chef-server.example.jp/emailAddress=you@example.com

Configuration Info:

OpenSSL Configuration:
* Version: OpenSSL 1.0.1j 15 Oct 2014
* Certificate file: /opt/chef/embedded/ssl/cert.pem
* Certificate directory: /opt/chef/embedded/ssl/certs
Chef SSL Configuration:
* ssl_ca_path: nil
* ssl_ca_file: nil
* trusted_certs_dir: "/home/ubuntu/chef-repo/.chef/trusted_certs"

TO FIX THIS ERROR:

If the server you are connecting to uses a self-signed certificate, you must
configure chef to trust that server's certificate.

By default, the certificate is stored in the following location on the host
where your chef-server runs:

/var/opt/chef-server/nginx/ca/SERVER_HOSTNAME.crt

Copy that file to your trusted_certs_dir (currently: /home/ubuntu/chef-repo/.chef/trusted_certs)
using SSH/SCP or some other secure method, then re-run this command to confirm
that the server's certificate is now trusted.


ubuntu@ws:~/chef-repo$

ここでは手動での対処方法が出ています。すなわち、Chef Serverの/var/opt/opscode/nginx/caディレクトリに自動生成されているSSL証明書を、何らかのセキュアな手段を用いてWorkstationの.chef/trusted_certs/ディレクトリ以下に設置せよ、ということです。なおメッセージ中のChef Serverのディレクトリはバグで間違っています(参考: `knife ssh check` points to incorrect chef server file location for Chef Server 12)。

Chef ServerのSSL証明書ディレクトリを確認してみましょう。


ubuntu@chef-server:~$ sudo ls -l /var/opt/opscode/nginx/ca
[sudo] password for ubuntu:
合計 12
-rw-r--r-- 1 root root 361 12月 17 15:54 chef-server.example.jp-ssl.conf
-rw-r--r-- 1 root root 1326 12月 17 15:54 chef-server.example.jp.crt
-rw-r--r-- 1 root root 1679 12月 17 15:54 chef-server.example.jp.key
ubuntu@chef-server:~$

後で必要になるので、SSL証明書のSHA256チェックサムを調べておきます。


ubuntu@chef-server:~$ sudo sha256sum /var/opt/opscode/nginx/ca/chef-server.example.jp.crt
d76dbd162d075a94a64918301970a9f19799c9c4fbf5cc204b25144ebe14b8ec /var/opt/opscode/nginx/ca/chef-server.example.jp.crt
ubuntu@chef-server:~$

SSL証明書の取得

では、knife ssl fetchコマンドを用いてChef ServerからSSL証明書を取得してみましょう。


ubuntu@ws:~/chef-repo$ knife ssl fetch
WARNING: Certificates from chef-server.example.jp will be fetched and placed in your trusted_cert
directory (/home/ubuntu/chef-repo/.chef/trusted_certs).

Knife has no means to verify these are the correct certificates. You should
verify the authenticity of these certificates after downloading.


Adding certificate for chef-server.example.jp in /home/ubuntu/chef-repo/.chef/trusted_certs/chef-server_example_jp.crt
ubuntu@ws:~/chef-repo$

取得できました。.chef/trusted_certs/ディレクトリを確認してみます。


ubuntu@ws:~/chef-repo$ ls -l .chef/trusted_certs/
合計 4
-rw-r--r-- 1 ubuntu ubuntu 1326 12月 17 16:34 chef-server_example_jp.crt
ubuntu@ws:~/chef-repo$

メッセージにある通り、本当に正しいSSL証明書を取得したのかどうかを調べる術をknifeは持っていません。なので、先程Chef Server上で確認したSSL証明書のSHA256チェックサムと突き合わせを行います。


ubuntu@ws:~/chef-repo$ sha256sum .chef/trusted_certs/chef-server_example_jp.crt
d76dbd162d075a94a64918301970a9f19799c9c4fbf5cc204b25144ebe14b8ec .chef/trusted_certs/chef-server_example_jp.crt
ubuntu@ws:~/chef-repo$

SHA256チェックサムが等しいので、正しくSSL証明書を取得できたことが確認できました。

では、通信ができるか確認してみましょう。まずknife ssl checkコマンドです。


ubuntu@ws:~/chef-repo$ knife ssl check
Connecting to host chef-server.example.jp:443
Successfully verified certificates from `chef-server.example.jp'
ubuntu@ws:~/chef-repo$

SSL証明書の検証に成功しました。次にknife client listコマンドです。


ubuntu@ws:~/chef-repo$ knife client list
testorg-validator
ubuntu@ws:~/chef-repo$

問題なくClient一覧が取得できました。そしてknife bootstrapコマンドです。


ubuntu@ws:~/chef-repo$ knife bootstrap node.example.jp -x ubuntu --sudo
Connecting to node.example.jp
Failed to authenticate ubuntu - trying password auth
Enter your password:
node.example.jp knife sudo password:
node.example.jp
node.example.jp Starting first Chef Client run...
node.example.jp Starting Chef Client, version 12.0.3
node.example.jp Creating a new client identity for node.example.jp using the validator key.
node.example.jp resolving cookbooks for run list: []
node.example.jp Synchronizing Cookbooks:
node.example.jp Compiling Cookbooks...
node.example.jp [2014-12-17T16:36:56+09:00] WARN: Node node.example.jp has an empty run list.
node.example.jp Converging 0 resources
node.example.jp
node.example.jp Running handlers:
node.example.jp Running handlers complete
node.example.jp Chef Client finished, 0/0 resources updated in 1.812147235 seconds
ubuntu@ws:~/chef-repo$


ubuntu@ws:~/chef-repo$ knife node list
node.example.jp
ubuntu@ws:~/chef-repo$

NodeをChef Serverに登録できました。

なお、bootstrap時にSSL証明書がWorkstationからNodeに転送され、/etc/chef/trusted_certs/ディレクトリ以下に保存されています。

次は、WorkstationでSSL証明書を取得しておらず、Chef Serverへの登録に失敗した際のNodeの/etc/chef/ディレクトリの状態です。


ubuntu@node:~$ ls -la /etc/chef/
合計 20
drwxr-xr-x 2 root root 4096 12月 17 16:39 .
drwxr-xr-x 90 root root 4096 12月 17 16:39 ..
-rw-r--r-- 1 root root 173 12月 17 16:39 client.rb
-rw-r--r-- 1 root root 16 12月 17 16:39 first-boot.json
-rw------- 1 root root 1679 12月 17 16:39 validation.pem
ubuntu@node:~$

次は、WorkstationでSSL証明書を取得しており、Chef Serverへの登録に成功した際のNodeの/etc/chef/ディレクトリの状態です。/etc/chef/trusted_certs/ディレクトリ以下にSSL証明書が設置されています。


ubuntu@node:~$ ls -la /etc/chef/
合計 28
drwxr-xr-x 3 root root 4096 12月 17 16:40 .
drwxr-xr-x 90 root root 4096 12月 17 16:39 ..
-rw------- 1 root root 1675 12月 17 16:40 client.pem
-rw-r--r-- 1 root root 217 12月 17 16:40 client.rb
-rw-r--r-- 1 root root 16 12月 17 16:40 first-boot.json
drwxr-xr-x 2 root root 4096 12月 17 16:40 trusted_certs
-rw------- 1 root root 1679 12月 17 16:40 validation.pem
ubuntu@node:~$ ls -la /etc/chef/trusted_certs/
合計 12
drwxr-xr-x 2 root root 4096 12月 17 16:40 .
drwxr-xr-x 3 root root 4096 12月 17 16:40 ..
-rw-r--r-- 1 root root 1327 12月 17 16:40 chef-server_example_jp.crt
ubuntu@node:~$

このSSL証明書のSHA256チェックサムを確認してみましょう。無駄な改行が末尾に入っていたためheadコマンドで末尾をカットしていますが、SHA256チェックサムが等しいことがわかります。


ubuntu@node:~$ head -n -1 /etc/chef/trusted_certs/chef-server_example_jp.crt | sha256sum
d76dbd162d075a94a64918301970a9f19799c9c4fbf5cc204b25144ebe14b8ec -
ubuntu@node:~$

knife bootstrapの新オプション

SSL証明書の検証の挙動変更により、knife bootstrapコマンドに--[no-]node-verify-api-certオプションと--node-ssl-verify-mode PEER_OR_NONEオプションが追加されています。これらを用いると、SSL証明書を取得していない状態でもNodeにbootstrapを行ってChef Serverに登録することができます。

まず先に両オプションのデフォルト値と挙動を表にまとめます。

x デフォルト値 組み合わせ1 組み合わせ2 組み合わせ3
--node-ssl-verify-mode peer peer none none
--node-verify-api-cert false true false true
Chef Server API接続以外 検証する 検証する 検証しない 検証しない
Chef Server API接続のみ 検証する(※1) 検証する 検証しない 検証する(※2)

--node-ssl-verify-modeオプションは、Chef Serverを含むすべてのSSL証明書の検証を行う(peer)か行わない(none)かを指定します。

--node-verify-api-certオプションはChef ServerのみのSSL証明書の検証を行うという意味を持ちます。--node-ssl-verify-modenoneならば、Chef ServerのSSL証明書のみを検証し、それ以外のSSL証明書の検証は行いません(※2)。

--no-node-verify-api-certオプションは--node-ssl-verify-modeの指定に依存します。peerの場合はこのオプションに関わらず、Chef ServerのSSL証明書の検証も行います(※1)。

デフォルト

Chef Server APIのSSL証明書を検証するため、Nodeの登録ができません。


ubuntu@ws:~/chef-repo$ knife bootstrap node.example.jp -x ubuntu --sudo --node-ssl-verify-mode peer --no-node-verify-api-cert
Connecting to node.example.jp
Failed to authenticate ubuntu - trying password auth
Enter your password:
node.example.jp knife sudo password:
node.example.jp
node.example.jp Starting first Chef Client run...
node.example.jp Starting Chef Client, version 12.0.3
node.example.jp [2014-12-18T10:26:35+09:00] ERROR: SSL Validation failure connecting to host: chef-server.example.jp - SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
node.example.jp
node.example.jp ================================================================================
node.example.jp Chef encountered an error attempting to load the node data for "node.example.jp"
node.example.jp ================================================================================
node.example.jp
node.example.jp Unexpected Error:
node.example.jp -----------------
node.example.jp OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
node.example.jp
node.example.jp [2014-12-18T10:26:35+09:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
node.example.jp Chef Client failed. 0 resources updated in 1.868196441 seconds
node.example.jp [2014-12-18T10:26:35+09:00] ERROR: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
node.example.jp [2014-12-18T10:26:35+09:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
ubuntu@ws:~/chef-repo$

組み合わせ1

Chef Server APIのSSL証明書を検証するため、Nodeの登録ができません。


ubuntu@ws:~/chef-repo$ knife bootstrap node.example.jp -x ubuntu --sudo --node-ssl-verify-mode peer --node-verify-api-cert
Connecting to node.example.jp
Failed to authenticate ubuntu - trying password auth
Enter your password:
node.example.jp knife sudo password:
node.example.jp
node.example.jp Starting first Chef Client run...
node.example.jp Starting Chef Client, version 12.0.3
node.example.jp [2014-12-18T10:27:16+09:00] ERROR: SSL Validation failure connecting to host: chef-server.example.jp - SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
node.example.jp
node.example.jp ================================================================================
node.example.jp Chef encountered an error attempting to load the node data for "node.example.jp"
node.example.jp ================================================================================
node.example.jp
node.example.jp Unexpected Error:
node.example.jp -----------------
node.example.jp OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
node.example.jp
node.example.jp [2014-12-18T10:27:16+09:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
node.example.jp Chef Client failed. 0 resources updated in 0.928070223 seconds
node.example.jp [2014-12-18T10:27:16+09:00] ERROR: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
node.example.jp [2014-12-18T10:27:16+09:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
ubuntu@ws:~/chef-repo$

組み合わせ2

Chef Server APIのSSL証明書を検証しないので、その旨を示す警告とともにNodeが登録できました。


ubuntu@ws:~/chef-repo$ knife bootstrap node.example.jp -x ubuntu --sudo --node-ssl-verify-mode none --no-node-verify-api-cert
Connecting to node.example.jp
Failed to authenticate ubuntu - trying password auth
Enter your password:
node.example.jp knife sudo password:
node.example.jp
node.example.jp Starting first Chef Client run...
node.example.jp [2014-12-18T10:28:53+09:00] WARN:
node.example.jp * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
node.example.jp SSL validation of HTTPS requests is disabled. HTTPS connections are still
node.example.jp encrypted, but chef is not able to detect forged replies or man in the middle
node.example.jp attacks.
node.example.jp
node.example.jp To fix this issue add an entry like this to your configuration file:
node.example.jp
node.example.jp ```
node.example.jp # Verify all HTTPS connections (recommended)
node.example.jp ssl_verify_mode :verify_peer
node.example.jp
node.example.jp # OR, Verify only connections to chef-server
node.example.jp verify_api_cert true
node.example.jp ```
node.example.jp
node.example.jp To check your SSL configuration, or troubleshoot errors, you can use the
node.example.jp `knife ssl check` command like so:
node.example.jp
node.example.jp ```
node.example.jp knife ssl check -c /etc/chef/client.rb
node.example.jp ```
node.example.jp
node.example.jp * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
node.example.jp
node.example.jp Starting Chef Client, version 12.0.3
node.example.jp Creating a new client identity for node.example.jp using the validator key.
node.example.jp resolving cookbooks for run list: []
node.example.jp Synchronizing Cookbooks:
node.example.jp Compiling Cookbooks...
node.example.jp [2014-12-18T10:28:55+09:00] WARN: Node node.example.jp has an empty run list.
node.example.jp Converging 0 resources
node.example.jp
node.example.jp Running handlers:
node.example.jp Running handlers complete
node.example.jp Chef Client finished, 0/0 resources updated in 2.03396257 seconds
ubuntu@ws:~/chef-repo$

なお、この設定でbootstrapしたNodeではすべてのSSL証明書を検証しないので、例えばremote_file ResourceでもSSL証明書の検証を行いません。


ubuntu@node:~$ chef-shell -c /etc/chef/client.rb
loading configuration: /etc/chef/client.rb
Session type: standalone
Loading..done.

This is the chef-shell.
Chef Version: 12.0.3
http://www.opscode.com/chef
http://docs.opscode.com/

run `help' for help, `exit' or ^D to quit.


Ohai2u ubuntu@node.example.jp!
chef > recipe_mode
chef:recipe > remote_file "/tmp/index.html" do ; source "https://192.168.122.101/" ; end
=> <remote_file[ tmp="" index.html]="" @name:="" "="" index.html"="" @noop:="" nil="" @before:="" @params:="" {}="" @provider:="" chef::provider::remotefile="" @allowed_actions:="" [:nothing,="" :create,="" :delete,="" :touch,="" :create_if_missing]="" @action:="" "create"="" @updated:="" false="" @updated_by_last_action:="" @supports:="" @ignore_failure:="" @retries:="" 0="" @retry_delay:="" 2="" @source_line:="" "(irb#1):1:in="" `irb_binding'"="" @guard_interpreter:="" @default_guard_interpreter:="" :default="" @elapsed_time:="" @sensitive:="" @resource_name:="" :remote_file="" @path:="" @backup:="" 5="" @atomic_update:="" true="" @force_unlink:="" @manage_symlink_source:="" @diff:="" @source:="" ["https:="" 192.168.122.101="" "]="" @use_etag:="" @use_last_modified:="" @ftp_active_mode:="" @headers:="" @declared_type:="" @cookbook_name:="" @recipe_name:="">
chef:recipe > run_chef
[2014-12-18T10:45:21+09:00] INFO: Processing remote_file[/tmp/index.html] action create ((irb#1) line 1)
[2014-12-18T10:45:21+09:00] DEBUG: remote_file[/tmp/index.html] checksumming file at /tmp/index.html.
[2014-12-18T10:45:21+09:00] DEBUG: remote_file[/tmp/index.html] checking for changes
[2014-12-18T10:45:21+09:00] INFO: Unable to access cache at /var/chef. Switching cache to /home/ubuntu/.chef
[2014-12-18T10:45:21+09:00] DEBUG: Cache control headers: {"if-modified-since"=>"Thu, 18 Dec 2014 01:43:24 GMT", "if-none-match"=>"\"2cf6-50a732a46409e-gzip\""}
[2014-12-18T10:45:21+09:00] DEBUG: Chef::HTTP calling Chef::HTTP::Decompressor#handle_request
[2014-12-18T10:45:21+09:00] DEBUG: Chef::HTTP calling Chef::HTTP::CookieManager#handle_request
[2014-12-18T10:45:21+09:00] DEBUG: Chef::HTTP calling Chef::HTTP::ValidateContentLength#handle_request
[2014-12-18T10:45:21+09:00] DEBUG: Initiating GET to https://192.168.122.101/
[2014-12-18T10:45:21+09:00] DEBUG: ---- HTTP Request Header Data: ----
[2014-12-18T10:45:21+09:00] DEBUG: if-modified-since: Thu, 18 Dec 2014 01:43:24 GMT
[2014-12-18T10:45:21+09:00] DEBUG: if-none-match: "2cf6-50a732a46409e-gzip"
[2014-12-18T10:45:21+09:00] DEBUG: Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
[2014-12-18T10:45:21+09:00] DEBUG: ---- End HTTP Request Header Data ----
[2014-12-18T10:45:21+09:00] DEBUG: ---- HTTP Status and Header Data: ----
[2014-12-18T10:45:21+09:00] DEBUG: HTTP 1.1 200 OK
[2014-12-18T10:45:21+09:00] DEBUG: date: Thu, 18 Dec 2014 01:45:21 GMT
[2014-12-18T10:45:21+09:00] DEBUG: server: Apache/2.4.7 (Ubuntu)
[2014-12-18T10:45:21+09:00] DEBUG: last-modified: Thu, 18 Dec 2014 01:03:50 GMT
[2014-12-18T10:45:21+09:00] DEBUG: etag: "2cf6-50a732a46409e-gzip"
[2014-12-18T10:45:21+09:00] DEBUG: accept-ranges: bytes
[2014-12-18T10:45:21+09:00] DEBUG: vary: Accept-Encoding
[2014-12-18T10:45:21+09:00] DEBUG: content-encoding: gzip
[2014-12-18T10:45:21+09:00] DEBUG: content-length: 3256
[2014-12-18T10:45:21+09:00] DEBUG: connection: close
[2014-12-18T10:45:21+09:00] DEBUG: content-type: text/html
[2014-12-18T10:45:21+09:00] DEBUG: ---- End HTTP Status/Header Data ----
[2014-12-18T10:45:21+09:00] DEBUG: Streaming download from https://192.168.122.101/ to tempfile /tmp/chef-rest20141218-3903-j66u2
[2014-12-18T10:45:21+09:00] DEBUG: Initializing gzip stream deflator
[2014-12-18T10:45:21+09:00] DEBUG: Chef::HTTP::StreamHandler calling Chef::HTTP::ValidateContentLength::ContentLengthCounter#handle_chunk
[2014-12-18T10:45:21+09:00] DEBUG: Chef::HTTP::StreamHandler calling Chef::HTTP::Decompressor::GzipInflater#handle_chunk
[2014-12-18T10:45:21+09:00] DEBUG: Chef::HTTP::StreamHandler calling Chef::HTTP::ValidateContentLength::ContentLengthCounter#handle_chunk
[2014-12-18T10:45:21+09:00] DEBUG: Chef::HTTP::StreamHandler calling Chef::HTTP::Decompressor::GzipInflater#handle_chunk
[2014-12-18T10:45:21+09:00] DEBUG: Chef::HTTP::StreamHandler calling Chef::HTTP::ValidateContentLength::ContentLengthCounter#handle_chunk
[2014-12-18T10:45:21+09:00] DEBUG: Chef::HTTP::StreamHandler calling Chef::HTTP::Decompressor::GzipInflater#handle_chunk
[2014-12-18T10:45:21+09:00] DEBUG: Chef::HTTP::StreamHandler calling Chef::HTTP::ValidateContentLength::ContentLengthCounter#handle_chunk
[2014-12-18T10:45:21+09:00] DEBUG: Chef::HTTP::StreamHandler calling Chef::HTTP::Decompressor::GzipInflater#handle_chunk
[2014-12-18T10:45:21+09:00] DEBUG: Chef::HTTP calling Chef::HTTP::ValidateContentLength#handle_stream_complete
[2014-12-18T10:45:21+09:00] DEBUG: Content-Length validated correctly.
[2014-12-18T10:45:21+09:00] DEBUG: Chef::HTTP calling Chef::HTTP::CookieManager#handle_stream_complete
[2014-12-18T10:45:21+09:00] DEBUG: Chef::HTTP calling Chef::HTTP::Decompressor#handle_stream_complete
[2014-12-18T10:45:21+09:00] INFO: Unable to access cache at /var/chef. Switching cache to /home/ubuntu/.chef
[2014-12-18T10:45:21+09:00] DEBUG: calculating checksum of /tmp/chef-rest20141218-3903-j66u2 to compare with 538f31569367cebb992643e46213f223fc20113e63a2e814a1dcb64a858ffb2e
[2014-12-18T10:45:21+09:00] DEBUG: found target_mode == nil, so no mode was specified on resource, not managing mode
[2014-12-18T10:45:21+09:00] DEBUG: found target_uid == nil, so no owner was specified on resource, not managing owner
[2014-12-18T10:45:21+09:00] DEBUG: found target_gid == nil, so no group was specified on resource, not managing group
=> true
chef:recipe > exit
=> :recipe
chef > exit
ubuntu@node:~$ ls -l /tmp/index.html
-rw-rw-r-- 1 ubuntu ubuntu 11510 12月 18 10:43 /tmp/index.html
ubuntu@node:~$
</remote_file[>

組み合わせ3

Chef Server APIのSSL証明書を検証するため、Nodeの登録ができません。


ubuntu@ws:~/chef-repo$ knife bootstrap node.example.jp -x ubuntu --sudo --node-ssl-verify-mode none --node-verify-api-cert
Connecting to node.example.jp
Failed to authenticate ubuntu - trying password auth
Enter your password:
node.example.jp knife sudo password:
node.example.jp
node.example.jp Starting first Chef Client run...
node.example.jp Starting Chef Client, version 12.0.3
node.example.jp Creating a new client identity for node.example.jp using the validator key.
node.example.jp [2014-12-18T10:31:27+09:00] ERROR: SSL Validation failure connecting to host: chef-server.example.jp - SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
node.example.jp
node.example.jp ================================================================================
node.example.jp Chef encountered an error attempting to create the client "node.example.jp"
node.example.jp ================================================================================
node.example.jp
node.example.jp [2014-12-18T10:31:27+09:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
node.example.jp Chef Client failed. 0 resources updated in 1.158192561 seconds
node.example.jp [2014-12-18T10:31:27+09:00] ERROR: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
node.example.jp [2014-12-18T10:31:27+09:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
ubuntu@ws:~/chef-repo$

これらの設定はknife.rbファイルやclient.rbファイルのssl_verify_modeオプションやverify_api_certオプションでも制御されています。Nodeの登録を行った後からでもSSL証明書の検証の挙動を変更できます。

まとめ

SSL証明書の検証がデフォルトで有効になったことで、Chefが行う通信の安全性が高められることになりました。またこれによって増えた設定作業も極力手間がかからないように工夫されています。是非活用してください。

Author

Chef・Docker・Mirantis製品などの技術要素に加えて、会議の進め方・文章の書き方などの業務改善にも取り組んでいます。「Chef活用ガイド」共著のほか、Debian Official Developerもやっています。

Daisuke Higuchiの記事一覧

新規CTA