-
Notifications
You must be signed in to change notification settings - Fork 82
Feature #79 sudo users #125
Changes from all commits
00513ac
6d74e30
22ff006
cc4ee37
7cf3146
2e201c5
ff39445
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,15 @@ | |
"server_repl_password": "<enter a random password>" | ||
}, | ||
"packages": ["<option list of system wide packages>"], | ||
"sysadmins": { | ||
"<username>": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your missing a |
||
"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>" | ||
], | ||
|
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\"" | ||
], | ||
} | ||
} | ||
) |
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 |
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", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
default["sysadmins"] = [] |
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" |
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| %> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is the type casting needed here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 -%> |
There was a problem hiding this comment.
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 thevagrant provision
horribly.