Skip to content

Commit 91bec1f

Browse files
committed
Container improvements
- The SSL certificate will be named 'chef-server.crt' by default - Disabled non SSH traffic (HTTP requests to SSL port will fail) - Moved all the Chef configuration commands out of 'run.sh'
1 parent 3f52f78 commit 91bec1f

3 files changed

Lines changed: 35 additions & 18 deletions

File tree

README.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This is a fork of: [base/chef-server](https://registry.hub.docker.com/u/base/che
88
## Environment
99
Chef is running over HTTPS/443 by default. You can however change that to another port by updating the `CHEF_PORT` variable and the expose port `-p`.
1010

11-
## Usage
11+
## Start the container
1212
*Launch the container:*
1313

1414
```
@@ -21,10 +21,16 @@ $ docker run --privileged -e CHEF_PORT=443 --name chef-server -d -p 443:443 cbui
2121
$ docker run --privileged -e CHEF_PORT=443 --name chef-server -d -v ~/chef-logs:/var/log -v ~/install-chef-out:/root -p 443:443 cbuisson/chef-server
2222
```
2323

24+
**Note:** By default `chef-server-ctl reconfigure` will create SSL certificates based on the container's FQDN (i.e "103d6875c1c5" which is its "CONTAINER ID"), I have changed that behiavior to always have a SSL certificate file named "chef-server.crt". You can change the certificate name by adding `-e CONTAINER_NAME=new_name` to the `docker run` command. Remember to reflect that change in config.rb!
25+
26+
'chef-server' or $CONTAINER_NAME **need to be resolvable by hostname!**
27+
28+
## Setup knife
29+
2430
Once Chef Server 12 is configured, you can download the Knife admin keys here:
2531

2632
```
27-
$ curl -Ok https://CONTAINER_ID:CHEF_PORT/knife_admin_key.tar.gz
33+
curl -Ok https://chef-server:$CHEF_PORT/knife_admin_key.tar.gz
2834
```
2935

3036
Then un-tar that archive and point your config.rb to the `admin.pem` and `admin-validator.pem` files.
@@ -39,28 +45,28 @@ node_name 'admin'
3945
client_key '/home/cbuisson/.chef/admin.pem'
4046
validation_client_name 'admin-validator'
4147
validation_key '/home/cbuisson/.chef/admin-validator.pem'
42-
chef_server_url 'https://CONTAINER_ID:CHEF_PORT/organizations/my_org'
48+
chef_server_url 'https://chef-server:$CHEF_PORT/organizations/my_org'
4349
```
44-
Note: CONTAINER_ID **needs** to be resolvable by hostname!
4550

46-
When the config.rb file is ready, you will need to get the SSL certificate files from the container to access Chef Server:
51+
When the config.rb file is ready, you will need to get the SSL certificate file from the container to access Chef Server:
4752

4853
```bash
4954
cbuisson@t530:~/.chef# knife ssl fetch
50-
WARNING: Certificates from 512ab20b1e0d will be fetched and placed in your trusted_cert
55+
WARNING: Certificates from chef-server will be fetched and placed in your trusted_cert
5156
directory (/home/cbuisson/.chef/trusted_certs).
5257

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

56-
Adding certificate for 512ab20b1e0d in /home/cbuisson/.chef/trusted_certs/512ab20b1e0d.crt
61+
Adding certificate for chef-server in /home/cbuisson/.chef/trusted_certs/chef-server.crt
5762
```
5863
5964
You should now be able to use the knife command!
6065
```bash
6166
cbuisson@t530:~# knife user list
6267
admin
6368
```
69+
**Done!**
6470
6571
##### Known issue
6672
`chef-manage-ctl reconfigure` needs to run in order to access the Chef webui. When this command is executed within the container, it blocks here:
@@ -71,4 +77,4 @@ Therefore the Chef Server 12 webui isn't available at the moment, however this i
7177
7278
##### Tags
7379
v1.0: Chef Server 11
74-
v2.0: Chef Server 12
80+
v2.X: Chef Server 12

configure_chef.sh

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
#/bin/bash -x
22

3+
cat > /etc/opscode/chef-server.rb << EOL
4+
nginx['enable_non_ssl']=false
5+
nginx['ssl_port']=$CHEF_PORT
6+
EOL
7+
if [[ ! -z $CONTAINER_NAME ]]; then
8+
echo "nginx['server_name']=\"$CONTAINER_NAME\"" >> /etc/opscode/chef-server.rb
9+
else
10+
echo "nginx['server_name']=\"chef-server\"" >> /etc/opscode/chef-server.rb
11+
fi
12+
313
chef-server-ctl reconfigure |tee /root/out.txt
414

515
URL="http://127.0.0.1:8000/_status"
@@ -32,8 +42,8 @@ if [[ -z "$return" ]]; then
3242
echo "$URL is not available after $SECONDS seconds...stopping the script!" |tee -a /root/out.txt
3343
exit 1
3444
fi
35-
3645
done;
46+
3747
echo -e "\n\n$URL is available!\n" |tee -a /root/out.txt
3848
echo -e "\nSetting up admin user and default organization" |tee -a /root/out.txt
3949
chef-server-ctl user-create admin Admin User admin@myorg.com "passwd" --filename /etc/chef/admin.pem |tee -a /root/out.txt
@@ -42,4 +52,14 @@ if [[ -z "$return" ]]; then
4252
chef-server-ctl install chef-manage |tee -a /root/out.txt
4353
echo -e "\nRunning: chef-server-ctl reconfigure" |tee -a /root/out.txt
4454
chef-server-ctl reconfigure |tee -a /root/out.txt
55+
echo "{ \"error\": \"Please use https:// instead of http:// !\" }" > /var/opt/opscode/nginx/html/500.json
56+
sed -i "s,/503.json;,/503.json;\n error_page 497 =503 /500.json;,g" /var/opt/opscode/nginx/etc/chef_https_lb.conf
57+
sed -i '$i\ location /knife_admin_key.tar.gz {\n default_type application/zip;\n alias /etc/chef/knife_admin_key.tar.gz;\n }' /var/opt/opscode/nginx/etc/chef_https_lb.conf
58+
echo -e "\nCreating tar file with the Knife keys" |tee -a /root/out.txt
59+
cd /etc/chef/ && tar -cvzf knife_admin_key.tar.gz admin.pem admin-validator.pem
60+
echo -e "\nRestart Nginx..." |tee -a /root/out.txt
61+
chef-server-ctl restart nginx
62+
chef-server-ctl status |tee -a /root/out.txt
63+
touch /root/chef_configured
64+
echo -e "\n\nDone!\n" |tee -a /root/out.txt
4565
fi

run.sh

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,5 @@ if [ -f "/root/chef_configured" ]
77
chef-server-ctl status |tee -a /root/out.txt
88
else
99
/usr/local/bin/configure_chef.sh
10-
sed -i "s, listen 443;, listen $CHEF_PORT;,g" /var/opt/opscode/nginx/etc/chef_https_lb.conf
11-
sed -i '$i\ location /knife_admin_key.tar.gz {\n default_type application/zip;\n alias /etc/chef/knife_admin_key.tar.gz;\n }' /var/opt/opscode/nginx/etc/chef_https_lb.conf
12-
echo -e "\nCreating tar file with the Knife keys" |tee -a /root/out.txt
13-
cd /etc/chef/ && tar -cvzf knife_admin_key.tar.gz admin.pem admin-validator.pem
14-
echo -e "\nRestart Nginx..." |tee -a /root/out.txt
15-
chef-server-ctl restart nginx
16-
chef-server-ctl status |tee -a /root/out.txt
17-
touch /root/chef_configured
18-
echo -e "\n\nDone!\n" |tee -a /root/out.txt
1910
fi
2011
tail -F /opt/opscode/embedded/service/*/log/current

0 commit comments

Comments
 (0)