Install Chef server Lets Encrypt

Chef server Lets Encrypt

Chef server Lets Encrypt

Do not want to mention what Chef is, or what Let’s Encrypt is. This is just a short step-by-step tutorial to guide you how to install Chef server Lets Encrypt for the server SSL.

Setup Let’s Encrypt

  • First, install let’s encrypt to generate a standalone certificate before installing chef server:
    git clone https://github.com/letsencrypt/letsencrypt
    cd letsencrypt
    ./letsencrypt-auto
    ./letsencrypt-auto certonly --standalone --email [email protected] -d chefserver.DOMAIN.com
    

    . Now we will have the SSL certificate located at /etc/letsencrypt/live/chefserver.YOURDOMAIN.com/fullchain.pem and SSL key located at /etc/letsencrypt/live/chefserver.YOURDOMAIN.com/privkey.pem

Chef server with Lets Encrypt

  • Install chef server (for ubuntu 14.x. For other OS, we can easily replace the link getting from Chef’s website):
    wget https://packages.chef.io/stable/ubuntu/14.04/chef-server-core_12.6.0-1_amd64.deb
    dpkg -i chef-server-core_*.deb
    

    . At this step, do not run reconfiguring command to edit the server configuration first.

  • Edit /etc/opscode/chef-server.rb to include the SSL certificate from Let’s encrypt:
    server_name = "chefserver.YOURDOMAIN.com"
    api_fqdn server_name
    bookshelf['vip'] = server_name
    nginx['url'] = "https://#{server_name}"
    nginx['server_name'] = server_name
    nginx['ssl_certificate'] = "/etc/letsencrypt/live/chefserver.YOURDOMAIN.com/fullchain.pem"
    nginx['ssl_certificate_key'] = "/etc/letsencrypt/live/chefserver.YOURDOMAIN.com/privkey.pem"
  • Reconfiguring the chef-server to take the setting into account:
    chef-server-ctl reconfigure
  • Install Chef management console:
    chef-server-ctl install opscode-manage
    chef-server-ctl reconfigure
    opscode-manage-ctl reconfigure
  • Install Chef reporting features:
    chef-server-ctl install opscode-reporting
    chef-server-ctl reconfigure
    opscode-reporting-ctl reconfigure
  • Create an admin user:
    mkdir ~/.chef
    chef-server-ctl user-create YOUR_USERNAME YOUR_FIRST_NAME YOUR_LAST_NAME YOUR_EMAIL YOUR_PASSWORD --filename ~/.chef/YOUR_USERNAME.pem
    
  • Create a new organization:
    chef-server-ctl org-create YOUR_ORGNAME YOUR_FULL_ORGANIZATION_NAME --association_user YOUR_USERNAME --filename ~/.chef/YOUR_ORGNAME.pem
  • Trying https://chefserver.YOURDOMAIN.com :-).

Setting Up a Workstation

In my machine, I have an existing CentOS 6 VM, so I utilize it. So these instructions are for CentOS 6 instead of Ubuntu in the server, he he.

  • Install Chef DK (Chef Development Kit):
    rpm -Uvh https://packages.chef.io/stable/el/6/chefdk-0.14.25-1.el6.x86_64.rpm
  • Verify its components:
    chef verify
  • Generate the chef-repo in your home folder:
    cd ~
    chef generate repo chef-repo
    cd chef-repo
  • Copying RSA Private Keys from Chef Server:
    mkdir .chef
    scp [email protected]_SERVER_IP_ADDRESS:~/.chef/*.pem ~/chef-repo/.chef/
    ls ~/chef-repo/.chef
  • Add git for versioning:
    git init
    git config --global user.name "YOUR NAME"
    git config --global user.email [email protected]
    echo ".chef" > .gitignore
    git add .
    git commit -m "Initial commit"
    git status
  • Generate knife.rb with specific Chef server information:
    cd ~/chef-repo/.chef
    nano knife.rb
    log_level                :info
    log_location             STDOUT
    node_name                'YOUR_USERNAME'
    client_key               '~/chef-repo/.chef/YOUR_USERNAME.pem'
    validation_client_name   'YOUR_ORGNAME-validator'
    validation_key           '~/chef-repo/.chef/YOUR_ORGNAME.pem'
    chef_server_url          'https://chefserver.YOURDOMAIN.com/organizations/YOUR_ORGNAME'
    syntax_check_cache_path  '~/chef-repo/.chef/syntax_check_cache'
    cookbook_path [ '~/chef-repo/cookbooks' ]

Bootstrap a Node

  • We can add a node to client list by calling knife bootstrap as follows:
    knife bootstrap YOUR_CLIENT_SERVER_IP -x root -P YOURPASSWORD --ssh-port SSH_PORT --node-name yournodename
    • If you face an error regarding not found private key such as “ERROR: Your private key could not be loaded from /etc/chef/client.pem“, you’ll need to “cd” to the chef-repo folder where you put your .chef to in your workstation.
    • If you face an error regarding time different such as “The request failed because your clock has drifted by more than 15 minutes.“, you’ll need to login to your client node and update time to a ntp server:
      yum install ntp
      ntpdate pool.ntp.org
  • Confirm that the node is in your client list:
    knife node list

Download a Cookbook and Pushing to Chef server

There is a pre-built cookbook to help run the chef-client hourly and delete the validation.pem in the client node for security purpose. We will see how to use the workstation to download the cookbook, push it to the server and apply to the client node.

  • First, install thecron-delvalidate cookbook:
    knife cookbook site install cron-delvalidate

    . We can see the content of the default recipe at cookbooks/cron-delvalidate/recipes/default.rb

  • Next, add the recipe to the bootstrapped node:
    knife node run_list add yournodename 'recipe[cron-delvalidate::default]'
  • Then, upload the cookbook to the Chef-server:
    knife cookbook upload cron-delvalidate
  • Finally, switch to your yournodename server and run the initial chef-client command:
    chef-client
    • We can check the crontab list after that
      crontab -l

With both the server and a workstation configured, you can then bootstrap your first node, download / create a cookbook to apply to your client node. For more detail about advanced cookbook / recipe tuts, I’ll try to create another tutorial in the future (not now :lol:).

Leave a Reply