Начала DevOps: Opscode Chef
Day 3

Andriy Samilyak
samilyak@gmail.com
skype: samilyaka
Goals
●

New resources: file, cookbook_file

●

Berkshelf

●

DataBags

●

Deployment with Chef

●

Environments
Password protection
We need to close our site by
login/password in order to keep it private
admin/password
Password protection
HTTP Basic Authentication
<Directory <%= node['apache']['docroot_dir'] %>/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
AuthType Basic
AuthName "Restricted Files"
AuthBasicProvider file
AuthUserFile <%= node['apache']['dir'] %>/htpasswd
Require valid-user
</Directory>

Copy/paste from http://goo.gl/6sEYT5
htpasswd
We need this contents to be in
node['apache']['dir']/htpasswd
admin:$apr1$ejZO6aAi$9zUZFyNxkX7pHOfqnjs8/0

Copy/paste from http://goo.gl/6sEYT5
Google it!
'chef resource file'
Putting file to server #1
../cookbooks/webserver/recipes/default.rb

file "#{node['apache']['dir']}/htpasswd" do
owner 'root'
group node['apache']['root_group']
mode '0644'
backup false
content "admin:
$apr1$ejZO6aAi$9zUZFyNxkX7pHOfqnjs8/0"
end
Putting file to server #2
●

'content' attribute is not really scalable – what if
we need 2Kb of text inside?

●

Lets first comment out with # content attribute

●

create file
../cookbooks/webserver/files/default/htpasswd

●

and put root (not admin!) and password hash to it

●

Change resource from 'file' to 'cookbook_file'
Putting file to server #2
../cookbooks/webserver/recipes/default.rb
cookbook_file "#{node['apache']['dir']}/htpasswd" do
owner 'root'
group node['apache']['root_group']
mode '0644'
backup false
end
Welcome Berks-way!
gem install berkshelf
Test it with “berks -v”
-------------------------------------------------------------On Windows you'll need to add to chefrepo/.berkshelf/config.json:
"ssl": {
"verify": false
}
Move out community cookbooks
●

Add a line to Berksfile:
cookbook “cookbook” path: cookbooks/webserver

●

berks install ← download cookbook to local folder

●

berks upload ← upload cookbooks to Chef Server

●

remove 'apache2' folder from chef_repo
Where is cookbook now anyway?
Well done! Lets put it to git
git commit -a -m “Initial commit”
git push origin master
Berks locations
●

site:
cookbook "artifact", site:
"http://cookbooks.opscode.com/api/v1/cookbooks"
cookbook "artifact", site: :opscode

●

git:
cookbook "mysql", git: "https://github.com/opscodecookbooks/mysql.git", branch: "foodcritic"
Lets do it better now!

https://github.com/Youscribe/htpasswdcookbook
Goal: specify user/pass with cookbook
attributes
Copy/paste from http://goo.gl/6sEYT5
New cookbook in Berksfile
cookbook "htpasswd", git:
https://github.com/Youscribe/htpasswdcookbook.git
Example:
htpasswd "/etc/apache2/htpasswd" do
user node['webserver']['auth_user']
password node['webserver']['auth_pass']
end
Htpasswd - review
●

webserver/metadata.rb: add dependency

●

recipes/default.rb: add resource httpasswd

●

attributes/default.rb: add two attributes

●

berks update & berks upload
Managing users access

Site

User1/pass
User2/pass
User3/pass

Site Backend

User1/pass
User3/pass

Store Backend

User3/pass
DataBags
●

Reusable data containers

●

JSON

●

Search API
Managing user access - Plan
●

Keep user/pass with granted nodes

●

Find all users for current node

●

Generate htpasswd by adding hash for
each user
DataBags as files
chef_repo
data_bags
htpasswd
user1.json
user2.json
user3.json
user1.json
{
"id": "user1",
"pass": "password",
"nodes" : ["yournode1", "yournode2"]
}
Data bag CLI
knife data bag create htpasswd
knife data bag from file htpasswd user1.json
knife data bag from file htpasswd
data_bags/htpasswd/*
knife search htpasswd "(id:user1)"
knife search htpasswd "(nodes:yournode)"
Search API
search(:htpasswd, "nodes:#{node.name}") do |user|
#add line to file user['pass']
end
Just an example of solution...
file "#{node['apache']['dir']}/htpasswd" do
action :delete
end
search(:htpasswd, "nodes:#{node.name}") do |user|
htpasswd "#{node['apache']['dir']}/htpasswd" do
user user['id']
password user['pass']
notifies :reload, 'service[apache2]'
end
end

More Related Content

ODP
Chef training Day5
ODP
Chef training Day4
ODP
Chef training - Day2
PDF
Infrastructure = Code
PPTX
NLIT 2011: Chef & Capistrano
KEY
Cooking with Chef
PDF
Getting Started with Ansible
PPTX
Cook Infrastructure with chef -- Justeat.IN
Chef training Day5
Chef training Day4
Chef training - Day2
Infrastructure = Code
NLIT 2011: Chef & Capistrano
Cooking with Chef
Getting Started with Ansible
Cook Infrastructure with chef -- Justeat.IN

What's hot (20)

PDF
Cookbook testing with KitcenCI and Serverrspec
PDF
Docker Docker Docker Chef
PPTX
Orchestration? You Don't Need Orchestration. What You Want is Choreography.
PPTX
What Makes a Good Chef Cookbook? (May 2014 Edition)
PDF
Introduction to chef framework
PDF
Practical Chef and Capistrano for Your Rails App
PDF
Frontend JS workflow - Gulp 4 and the like
PDF
Chef infrastructure as code - paris.rb
PDF
Automating your workflow with Gulp.js
PDF
Deploying Rails Apps with Chef and Capistrano
PPTX
DevOps Hackathon: Session 3 - Test Driven Infrastructure
PDF
Ansible introduction - XX Betabeers Galicia
PPTX
Vagrant introduction for Developers
PDF
Using Test Kitchen for testing Chef cookbooks
PDF
A quick intro to Ansible
PDF
Infrastructure = code - 1 year later
PPTX
Ansible intro
PDF
Cookbook refactoring & abstracting logic to Ruby(gems)
PDF
Cloud Automation with Opscode Chef
PPTX
DevOps Hackathon - Session 1: Vagrant
Cookbook testing with KitcenCI and Serverrspec
Docker Docker Docker Chef
Orchestration? You Don't Need Orchestration. What You Want is Choreography.
What Makes a Good Chef Cookbook? (May 2014 Edition)
Introduction to chef framework
Practical Chef and Capistrano for Your Rails App
Frontend JS workflow - Gulp 4 and the like
Chef infrastructure as code - paris.rb
Automating your workflow with Gulp.js
Deploying Rails Apps with Chef and Capistrano
DevOps Hackathon: Session 3 - Test Driven Infrastructure
Ansible introduction - XX Betabeers Galicia
Vagrant introduction for Developers
Using Test Kitchen for testing Chef cookbooks
A quick intro to Ansible
Infrastructure = code - 1 year later
Ansible intro
Cookbook refactoring & abstracting logic to Ruby(gems)
Cloud Automation with Opscode Chef
DevOps Hackathon - Session 1: Vagrant
Ad

Viewers also liked (19)

PDF
Osaaminen uuden yrityksen johtajan näkökulmasta
PDF
Powerful Ways To End Emails and Blog Posts
PPT
Proxecto 6º o medio no que vivimos
PDF
NLP meetup 2016.10.05 - Szekeres Péter: Neticle
PDF
Presentation1
PPT
Универсальный энергосберегающий режущий аппарат
PDF
קורס מגיק למפתחים
PPTX
Some Notes On "Inclusion" - Pat Kane for Creative Scotland
PDF
Ux paper prototyping
PDF
Philadelphia Best Places to Work Roadshow | OpenTable
PDF
Daily Newsletter: 16th December, 2010
PDF
Chef training - Day1
PPTX
How effective is the combination of your main
PPT
производство биомелиоранта
PPTX
Nuevas tecnologías de la
PPT
Customer service communities
PPT
EVALUATION QUESTION: 05
PDF
Communitymanager
PPTX
Wykładzina vol. 14 Teatr Narodowy Opera Narodowa
Osaaminen uuden yrityksen johtajan näkökulmasta
Powerful Ways To End Emails and Blog Posts
Proxecto 6º o medio no que vivimos
NLP meetup 2016.10.05 - Szekeres Péter: Neticle
Presentation1
Универсальный энергосберегающий режущий аппарат
קורס מגיק למפתחים
Some Notes On "Inclusion" - Pat Kane for Creative Scotland
Ux paper prototyping
Philadelphia Best Places to Work Roadshow | OpenTable
Daily Newsletter: 16th December, 2010
Chef training - Day1
How effective is the combination of your main
производство биомелиоранта
Nuevas tecnologías de la
Customer service communities
EVALUATION QUESTION: 05
Communitymanager
Wykładzina vol. 14 Teatr Narodowy Opera Narodowa
Ad

Similar to Chef training - Day3 (20)

PDF
IT Automation with Chef
PDF
Chef - Administration for programmers
PDF
Chef Fundamentals Training Series Module 6: Roles, Environments, Community Co...
PDF
PPTX
London Community Summit 2016 - Fresh New Chef Stuff
PPTX
Chef introduction
PDF
Node setup, resource, and recipes - Fundamentals Webinar Series Part 2
PDF
Introduction to Cooking with Chef
PDF
MadridDevops September 2014: "From chef09 to chef11, one approach to devops"
PPTX
Chef advance
PPTX
Chef advance
KEY
Chef 0.8, Knife and Amazon EC2
PDF
Introduction to Chef - April 22 2015
PDF
Cooking Perl with Chef: Real World Tutorial with Jitterbug
PDF
Cloud Automation with Opscode Chef
PDF
Chef conf-2014
PDF
The Berkshelf Way
PPTX
Chef + AWS + CodeIgniter
PPTX
Kickstarter - Chef Opswork
PPTX
Chef Jumpstart
IT Automation with Chef
Chef - Administration for programmers
Chef Fundamentals Training Series Module 6: Roles, Environments, Community Co...
London Community Summit 2016 - Fresh New Chef Stuff
Chef introduction
Node setup, resource, and recipes - Fundamentals Webinar Series Part 2
Introduction to Cooking with Chef
MadridDevops September 2014: "From chef09 to chef11, one approach to devops"
Chef advance
Chef advance
Chef 0.8, Knife and Amazon EC2
Introduction to Chef - April 22 2015
Cooking Perl with Chef: Real World Tutorial with Jitterbug
Cloud Automation with Opscode Chef
Chef conf-2014
The Berkshelf Way
Chef + AWS + CodeIgniter
Kickstarter - Chef Opswork
Chef Jumpstart

More from Andriy Samilyak (12)

PPTX
Kaizen Magento Support - 2
ODP
Kaizen Magento support
PDF
Amazon Cognito + Lambda + S3 + IAM
PPTX
MageClinic: Affiliative program
PPTX
Magento - choosing Order Management SaaS
PPTX
TOCAT Introduction (English)
PPTX
TOCAT Introduction
ODP
Как мы играли в DevOps и как получился Magento Autoscale
ODP
Magento autoscaling
ODP
DevOps in realtime
ODP
Synthetic web performance testing with Selenium
ODP
DevOps в реальном времени
Kaizen Magento Support - 2
Kaizen Magento support
Amazon Cognito + Lambda + S3 + IAM
MageClinic: Affiliative program
Magento - choosing Order Management SaaS
TOCAT Introduction (English)
TOCAT Introduction
Как мы играли в DevOps и как получился Magento Autoscale
Magento autoscaling
DevOps in realtime
Synthetic web performance testing with Selenium
DevOps в реальном времени

Recently uploaded (20)

PPTX
Web Crawler for Trend Tracking Gen Z Insights.pptx
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PDF
Five Habits of High-Impact Board Members
PDF
August Patch Tuesday
PDF
1 - Historical Antecedents, Social Consideration.pdf
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
CloudStack 4.21: First Look Webinar slides
DOCX
search engine optimization ppt fir known well about this
PDF
DP Operators-handbook-extract for the Mautical Institute
PPT
Geologic Time for studying geology for geologist
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
Hindi spoken digit analysis for native and non-native speakers
PDF
Developing a website for English-speaking practice to English as a foreign la...
PDF
Getting started with AI Agents and Multi-Agent Systems
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PPTX
Modernising the Digital Integration Hub
Web Crawler for Trend Tracking Gen Z Insights.pptx
A contest of sentiment analysis: k-nearest neighbor versus neural network
Final SEM Unit 1 for mit wpu at pune .pptx
Five Habits of High-Impact Board Members
August Patch Tuesday
1 - Historical Antecedents, Social Consideration.pdf
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
CloudStack 4.21: First Look Webinar slides
search engine optimization ppt fir known well about this
DP Operators-handbook-extract for the Mautical Institute
Geologic Time for studying geology for geologist
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
Group 1 Presentation -Planning and Decision Making .pptx
A comparative study of natural language inference in Swahili using monolingua...
Hindi spoken digit analysis for native and non-native speakers
Developing a website for English-speaking practice to English as a foreign la...
Getting started with AI Agents and Multi-Agent Systems
Assigned Numbers - 2025 - Bluetooth® Document
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
Modernising the Digital Integration Hub

Chef training - Day3

  • 1. Начала DevOps: Opscode Chef Day 3 Andriy Samilyak [email protected] skype: samilyaka
  • 2. Goals ● New resources: file, cookbook_file ● Berkshelf ● DataBags ● Deployment with Chef ● Environments
  • 3. Password protection We need to close our site by login/password in order to keep it private admin/password
  • 4. Password protection HTTP Basic Authentication <Directory <%= node['apache']['docroot_dir'] %>/> Options Indexes FollowSymLinks MultiViews AllowOverride None AuthType Basic AuthName "Restricted Files" AuthBasicProvider file AuthUserFile <%= node['apache']['dir'] %>/htpasswd Require valid-user </Directory> Copy/paste from http://goo.gl/6sEYT5
  • 5. htpasswd We need this contents to be in node['apache']['dir']/htpasswd admin:$apr1$ejZO6aAi$9zUZFyNxkX7pHOfqnjs8/0 Copy/paste from http://goo.gl/6sEYT5
  • 7. Putting file to server #1 ../cookbooks/webserver/recipes/default.rb file "#{node['apache']['dir']}/htpasswd" do owner 'root' group node['apache']['root_group'] mode '0644' backup false content "admin: $apr1$ejZO6aAi$9zUZFyNxkX7pHOfqnjs8/0" end
  • 8. Putting file to server #2 ● 'content' attribute is not really scalable – what if we need 2Kb of text inside? ● Lets first comment out with # content attribute ● create file ../cookbooks/webserver/files/default/htpasswd ● and put root (not admin!) and password hash to it ● Change resource from 'file' to 'cookbook_file'
  • 9. Putting file to server #2 ../cookbooks/webserver/recipes/default.rb cookbook_file "#{node['apache']['dir']}/htpasswd" do owner 'root' group node['apache']['root_group'] mode '0644' backup false end
  • 10. Welcome Berks-way! gem install berkshelf Test it with “berks -v” -------------------------------------------------------------On Windows you'll need to add to chefrepo/.berkshelf/config.json: "ssl": { "verify": false }
  • 11. Move out community cookbooks ● Add a line to Berksfile: cookbook “cookbook” path: cookbooks/webserver ● berks install ← download cookbook to local folder ● berks upload ← upload cookbooks to Chef Server ● remove 'apache2' folder from chef_repo Where is cookbook now anyway?
  • 12. Well done! Lets put it to git git commit -a -m “Initial commit” git push origin master
  • 13. Berks locations ● site: cookbook "artifact", site: "http://cookbooks.opscode.com/api/v1/cookbooks" cookbook "artifact", site: :opscode ● git: cookbook "mysql", git: "https://github.com/opscodecookbooks/mysql.git", branch: "foodcritic"
  • 14. Lets do it better now! https://github.com/Youscribe/htpasswdcookbook Goal: specify user/pass with cookbook attributes Copy/paste from http://goo.gl/6sEYT5
  • 15. New cookbook in Berksfile cookbook "htpasswd", git: https://github.com/Youscribe/htpasswdcookbook.git
  • 16. Example: htpasswd "/etc/apache2/htpasswd" do user node['webserver']['auth_user'] password node['webserver']['auth_pass'] end
  • 17. Htpasswd - review ● webserver/metadata.rb: add dependency ● recipes/default.rb: add resource httpasswd ● attributes/default.rb: add two attributes ● berks update & berks upload
  • 18. Managing users access Site User1/pass User2/pass User3/pass Site Backend User1/pass User3/pass Store Backend User3/pass
  • 20. Managing user access - Plan ● Keep user/pass with granted nodes ● Find all users for current node ● Generate htpasswd by adding hash for each user
  • 23. Data bag CLI knife data bag create htpasswd knife data bag from file htpasswd user1.json knife data bag from file htpasswd data_bags/htpasswd/* knife search htpasswd "(id:user1)" knife search htpasswd "(nodes:yournode)"
  • 24. Search API search(:htpasswd, "nodes:#{node.name}") do |user| #add line to file user['pass'] end
  • 25. Just an example of solution... file "#{node['apache']['dir']}/htpasswd" do action :delete end search(:htpasswd, "nodes:#{node.name}") do |user| htpasswd "#{node['apache']['dir']}/htpasswd" do user user['id'] password user['pass'] notifies :reload, 'service[apache2]' end end