sous-chefs / users

Development repository for the users cookbook
https://supermarket.chef.io/cookbooks/users
Apache License 2.0
138 stars 218 forks source link

.ssh directory owned by root when uid not specified #446

Closed evandam closed 3 years ago

evandam commented 3 years ago

:ghost: Brief Description

When creating a user without specifying a uid/gid, the user's ~/.ssh directory is owned by root since user[:uid].to_i returns 0 (since nil.to_i is 0) in https://github.com/sous-chefs/users/blob/master/resources/manage.rb#L99-L100.

:pancakes: Cookbook version

6.0.0

:woman_cook: Chef-Infra Version

15.15.1

:tophat: Platform details

Ubuntu 18.04

Steps To Reproduce

Steps to reproduce the behavior:

dev_user = {
  "id": "dev_user",
  "password": "secretpassword",
  "ssh_keys": [
    "ssh-rsa blah"
  ],
  "groups": [
    "dev"
  ],
  "shell": "/bin/bash",
  "comment": "Test user without root login",
  "root_login": false,
  "auto_remove": false
}

users_manage group do
  group_id 900
  users [dev_user]
  action :create
end
# ls -la /home/dev_user/
total 24
drwxr-xr-x 3 dev_user dev_user 4096 Mar 12 21:24 .
drwxr-xr-x 6 root     root     4096 Mar 12 17:40 ..
-rw-r--r-- 1 dev_user dev_user  220 Apr  4  2018 .bash_logout
-rw-r--r-- 1 dev_user dev_user  223 Mar 12 17:40 .bashrc
-rw-r--r-- 1 dev_user dev_user  807 Apr  4  2018 .profile
drwx------ 2 root     root     4096 Mar 12 21:24 .ssh

:heavy_plus_sign: Additional context

This runs the risk of locking folks out of their environment very easily 😅

frank-m commented 3 years ago

Fixed by merging #449