Skip to content
This repository has been archived by the owner on Nov 23, 2017. It is now read-only.

Commit

Permalink
[COOK-517,CHEF-1699] force group refresh using Etc.endgrent.
Browse files Browse the repository at this point in the history
  • Loading branch information
schisamo committed Apr 24, 2011
1 parent 1aaf6d6 commit a0ce93b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 12 deletions.
26 changes: 19 additions & 7 deletions users/README.rdoc → users/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
= DESCRIPTION:
Description
===========

Creates users with +authorized_keys+.
Creates users from a databag search.

= REQUIREMENTS:
Requirements
============

Platform
--------

* Debian, Ubuntu
* CentOS, Red Hat, Fedora
* FreeBSD

Data bag named "users" must exist. See USAGE.

= USAGE:
Usage
=====

This cookbook is specific for setting up sysadmin group and users for now.

Expand All @@ -21,7 +31,7 @@ Create a user.
knife data bag users bofh
{
"id": "bofh",
"ssh_keys": "",
"ssh_keys": "ssh-rsa AAAAB3Nz...yhCw== bofh",
"groups": "sysadmin",
"uid": 2001,
"shell": "\/bin\/bash",
Expand All @@ -46,11 +56,13 @@ The sysadmin group will be created with GID 2300. This may become an attribute a

The Apache cookbook can set up authentication using OpenIDs, which is set up using the openid key here. See the Opscode 'apache2' cookbook for more information about this.

= LICENSE and AUTHOR:
License and Author
==================

Author:: Joshua Timberman (<joshua@opscode.com>)
Author:: Seth Chisamore (<schisamo@opscode.com>)

Copyright:: 2009, Opscode, Inc
Copyright:: 2009-2011, Opscode, Inc

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
10 changes: 8 additions & 2 deletions users/metadata.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
{
"name": "users",
"description": "Creates users from a databag search",
"long_description": "= DESCRIPTION:\n\nCreates users with +authorized_keys+.\n\n= REQUIREMENTS:\n\nData bag named \"users\" must exist. See USAGE.\n\n= USAGE:\n\nThis cookbook is specific for setting up sysadmin group and users for now.\n\n include_recipe \"users::sysadmins\"\n\nUse knife to create a data bag for users.\n\n knife data bag create users\n\nCreate a user.\n\n knife data bag users bofh\n {\n \"id\": \"bofh\",\n \"ssh_keys\": \"\",\n \"groups\": \"sysadmin\",\n \"uid\": 2001,\n \"shell\": \"\\/bin\\/bash\",\n \"comment\": \"BOFH\",\n \"nagios\": {\n \"pager\": \"8005551212@txt.att.net\",\n \"email\": \"bofh@example.com\"\n },\n \"openid\": \"bofh.myopenid.com\"\n }\n\nThe latest version of knife supports reading data bags from a file and automatically looks in a directory called +data_bags+ in the current directory. The \"bag\" should be a directory with JSON files of each item. For the above:\n\n mkdir data_bags/users\n $EDITOR data_bags/users/bofh.json\n\nPaste the user's public SSH key into the ssh_keys value. Also make sure the uid is unique, and if you're not using bash, that the shell is installed. Group must be sysadmin.\n\nThe recipe will also create the sysadmin group. If you're using the opscode sudo cookbook, they'll have sudo access in the default site-cookbooks template. They won't have passwords though, so the sudo cookbook's template needs to be adjusted so the sysadmin group has NOPASSWD.\n\nThe sysadmin group will be created with GID 2300. This may become an attribute at a later date.\n\nThe Apache cookbook can set up authentication using OpenIDs, which is set up using the openid key here. See the Opscode 'apache2' cookbook for more information about this.\n\n= LICENSE and AUTHOR:\n\nAuthor:: Joshua Timberman (<joshua@opscode.com>)\n\nCopyright:: 2009, Opscode, Inc\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n",
"long_description": "Description\n===========\n\nCreates users from a databag search.\n\nRequirements\n============\n\nPlatform\n--------\n\n* Debian, Ubuntu\n* CentOS, Red Hat, Fedora\n* FreeBSD\n\nData bag named \"users\" must exist. See USAGE.\n\nUsage\n=====\n\nThis cookbook is specific for setting up sysadmin group and users for now.\n\n include_recipe \"users::sysadmins\"\n\nUse knife to create a data bag for users.\n\n knife data bag create users\n\nCreate a user.\n\n knife data bag users bofh\n {\n \"id\": \"bofh\",\n \"ssh_keys\": \"ssh-rsa AAAAB3Nz...yhCw== bofh\",\n \"groups\": \"sysadmin\",\n \"uid\": 2001,\n \"shell\": \"\\/bin\\/bash\",\n \"comment\": \"BOFH\",\n \"nagios\": {\n \"pager\": \"8005551212@txt.att.net\",\n \"email\": \"bofh@example.com\"\n },\n \"openid\": \"bofh.myopenid.com\"\n }\n\nThe latest version of knife supports reading data bags from a file and automatically looks in a directory called +data_bags+ in the current directory. The \"bag\" should be a directory with JSON files of each item. For the above:\n\n mkdir data_bags/users\n $EDITOR data_bags/users/bofh.json\n\nPaste the user's public SSH key into the ssh_keys value. Also make sure the uid is unique, and if you're not using bash, that the shell is installed. Group must be sysadmin.\n\nThe recipe will also create the sysadmin group. If you're using the opscode sudo cookbook, they'll have sudo access in the default site-cookbooks template. They won't have passwords though, so the sudo cookbook's template needs to be adjusted so the sysadmin group has NOPASSWD.\n\nThe sysadmin group will be created with GID 2300. This may become an attribute at a later date.\n\nThe Apache cookbook can set up authentication using OpenIDs, which is set up using the openid key here. See the Opscode 'apache2' cookbook for more information about this.\n\nLicense and Author\n==================\n\nAuthor:: Joshua Timberman (<joshua@opscode.com>)\nAuthor:: Seth Chisamore (<schisamo@opscode.com>)\n\nCopyright:: 2009-2011, Opscode, Inc\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n",
"maintainer": "Opscode, Inc.",
"maintainer_email": "cookbooks@opscode.com",
"license": "Apache 2.0",
"platforms": {
"ubuntu": ">= 0.0.0",
"debian": ">= 0.0.0",
"redhat": ">= 0.0.0",
"centos": ">= 0.0.0",
"fedora": ">= 0.0.0",
"freebsd": ">= 0.0.0"
},
"dependencies": {
},
Expand All @@ -26,5 +32,5 @@
"recipes": {
"users::sysadmin": "searches users data bag for sysadmins and creates users"
},
"version": "0.3.1"
"version": "1.0.0"
}
8 changes: 6 additions & 2 deletions users/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
maintainer_email "cookbooks@opscode.com"
license "Apache 2.0"
description "Creates users from a databag search"
long_description IO.read(File.join(File.dirname(__FILE__), 'README.rdoc'))
version "0.3.1"
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version "1.0.0"
recipe "users::sysadmin", "searches users data bag for sysadmins and creates users"

%w{ ubuntu debian redhat centos fedora freebsd}.each do |os|
supports os
end
12 changes: 11 additions & 1 deletion users/recipes/sysadmins.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Cookbook Name:: users
# Recipe:: sysadmins
#
# Copyright 2009, Opscode, Inc.
# Copyright 2009-2011, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -16,6 +16,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#

sysadmin_group = Array.new

search(:users, 'groups:sysadmin') do |u|
Expand All @@ -29,13 +30,22 @@

home_dir = "/home/#{u['id']}"

# fixes CHEF-1699
ruby_block "reset group list" do
block do
Etc.endgrent
end
action :nothing
end

user u['id'] do
uid u['uid']
gid u['gid']
shell u['shell']
comment u['comment']
supports :manage_home => true
home home_dir
notifies :create, "ruby_block[reset group list]", :immediately
end

directory "#{home_dir}/.ssh" do
Expand Down

0 comments on commit a0ce93b

Please sign in to comment.