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

Feature #79 sudo users #125

Merged
merged 7 commits into from
Oct 31, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ This project makes use of the [Sementic Versioning](http://semver.org/)
- Backup compression using GZip
- Added ruby 2.1.3 to the ruby binary list
- test-kitchen to automatically test the cookbooks and resulting server setup
- Sysadmins recipe which allows you to provide sysadmin users in the node configuration.

### Deprecated
- Nothing
Expand All @@ -21,6 +22,8 @@ This project makes use of the [Sementic Versioning](http://semver.org/)

### Misc
- Upgraded the chef-repo ruby version to 2.1.2
- Sudo recipe configuration changed to match Ubuntu's default sudo
behaviour more closely.

## 2.1.0 - 2014-08-18

Expand Down
1 change: 1 addition & 0 deletions Cheffile
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ cookbook "packages", path: "vendor/cookbooks/packages"
cookbook "rails", path: "vendor/cookbooks/rails"
cookbook "ssh_deploy_keys", path: "vendor/cookbooks/ssh_deploy_keys"
cookbook "backups", path: "vendor/cookbooks/backups"
cookbook "sysadmins", path: "vendor/cookbooks/sysadmins"
6 changes: 6 additions & 0 deletions Cheffile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ PATH
specs:
ssh_deploy_keys (0.1.0)

PATH
remote: vendor/cookbooks/sysadmins
specs:
sysadmins (0.1.0)

DEPENDENCIES
apt (~> 2.5.2)
backups (>= 0)
Expand All @@ -104,4 +109,5 @@ DEPENDENCIES
ruby_build (~> 0.8.0)
ssh_deploy_keys (>= 0)
sudo (~> 2.7.0)
sysadmins (>= 0)

1 change: 1 addition & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
json_payload = {
"authorization" => {
"sudo" => {
"passwordless" => true,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Required, because otherwise vagrant will suddently require a password for the vagrant user, breaking the vagrant provision horribly.

"users" => ["vagrant"]
}
},
Expand Down
9 changes: 9 additions & 0 deletions nodes/sample_host.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
"server_repl_password": "<enter a random password>"
},
"packages": ["<option list of system wide packages>"],
"sysadmins": {
"<username>":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your missing a { here

"password": "<hashed password: openssl passwd -1 'plaintextpassword'>",
"ssh_keys": [
"ssh-rsa AAA123...xyz== foo",
"ssh-rsa AAA456...uvw== bar"
]
}
}
"ssh_deploy_keys": [
"<enter the contents of an id_rsa.pub here>"
],
Expand Down
23 changes: 23 additions & 0 deletions roles/sysadmins.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name "sysadmins"
description "This role configures sysadmins, users with sudo-rights on your server"
run_list(
"role[base]",
"recipe[packages]",
"recipe[sysadmins]",
"recipe[sudo]"
)
# Configure the sudo recipe so it mirrors Ubuntu's default behaviour
default_attributes(
"authorization" => {
"sudo" => {
"groups" => ["admin"],
"passwordless" => false,
"include_sudoers_d" => true,
"sudoers_default" => [
"env_reset",
"mail_badpass",
"secure_path=\"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\""
],
}
}
)
8 changes: 8 additions & 0 deletions vendor/cookbooks/sysadmins/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
sysadmins CHANGELOG
===================

This file is used to list changes made in each version of the sysadmins cookbook.

0.1.0
-----
- [Bèr Kessels] - Initial release of sysadmins
46 changes: 46 additions & 0 deletions vendor/cookbooks/sysadmins/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
sysadmins Cookbook
==================

Creates sysadmin accounts: accounts that can access the server over SSH.

Attributes
----------

#### sysadmins::default
<table>
<tr>
<th>Key</th>
<th>Type</th>
<th>Description</th>
<th>Default</th>
</tr>
<tr>
<td><tt>['sysadmins']</tt></td>
<td>Hash</td>
<td>key: username</td>
<td><tt>empty, won't create sysadmins</tt></td>
</tr>
</table>

Usage
-----

Add sysadmins to your node configuration:

```@json
{
"sysadmins": {
"bofh": {
"password": "$1$d...HgH0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it wise to specify a password for users? I suggest we only add a key with a disabled password. If someone wants to enable their password, they can do so after logging in with the given ssh key. What do you think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had a discussion about this in the old PR.

TL;DR: since we cannot really oversee what the security-implications are of all choices, lets stick to The Ubuntu Default. Which is demand a password per user.

This is also the way the often-used users::sysadmins cookbook works. (formerly known as LWRP-users).

The password is not stored plain-text, but rather the one-way hashed version. (Still: getting hold of this hashed password gives the attacker full access; it's just that he or she cannot read the actual password, this way)

"ssh_keys": [
"ssh-rsa AAA123...xyz== foo",
"ssh-rsa AAA456...uvw== bar"
]
}
}
```

* Create a hashed password with `openssl passwd -1 'plaintextpassword'`.
This password is needed for running `sudo`.
* SSH-keys should be the **public** key. You can leave them out, in
which case you have to log in with the password.
1 change: 1 addition & 0 deletions vendor/cookbooks/sysadmins/attributes/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
default["sysadmins"] = []
7 changes: 7 additions & 0 deletions vendor/cookbooks/sysadmins/metadata.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name "sysadmins"
maintainer "Bèr `berkes` Kessels"
maintainer_email "ber@berk.es"
license "MIT"
description "Creates sysadmin user accounts"
long_description IO.read(File.join(File.dirname(__FILE__), "README.md"))
version "0.1.2"
55 changes: 55 additions & 0 deletions vendor/cookbooks/sysadmins/recipes/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#
# Cookbook Name:: sysadmins
# Recipe:: default
#
# Copyright 2014, Bèr `berkes` Kessels
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

node[:sysadmins].each do |username, user|
home_dir = "/home/#{username}"
# Create a user
user username do
home home_dir
password user["password"] if user["password"]

shell "/bin/bash"
manage_home true
action :create
end

# Add ssh-keys to authorized_keys
# Always create the file and dir, even if user did not provide
# ssh-keys
directory "#{home_dir}/.ssh" do
owner username
group username
mode "0700"
end
if user["ssh_keys"]
template "#{home_dir}/.ssh/authorized_keys" do
source "authorized_keys.erb"
owner username
group username
mode "0600"
variables ssh_keys: user["ssh_keys"]
end
end

end

# Add users to the sysadmin group. This is the group used by
# the sudo cookbook to grant users sudo-access.
group "admin" do
members node[:sysadmins].keys
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Generated by Chef for <%= node["fqdn"] %>
# Local modifications will be overwritten.
# Created by sysadmins cookbook
<% Array(@ssh_keys).each do |key| %>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the type casting needed here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<% Array(@ssh_keys).each do |key| %>

This way the node.json can provide either a string: one ssh-key, an array of ssh-keys or no ssh-keys. It is taken from the often used users::sysadmin cookbook.
I could simplify it, if you wish and simply require a user to always provide an array of ssh-keys.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok! I don't feel strongly one way or the other, so pick what you feel most comfortable with :)

<%= key %>
<% end -%>