]> git.openstreetmap.org Git - chef.git/blob - cookbooks/accounts/recipes/default.rb
Revert "systemd: fix property limit_cpu type"
[chef.git] / cookbooks / accounts / recipes / default.rb
1 #
2 # Cookbook Name:: accounts
3 # Recipe:: default
4 #
5 # Copyright 2010, OpenStreetMap Foundation
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 #     https://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 #
19
20 package "zsh"
21
22 administrators = []
23
24 search(:accounts, "*:*").each do |account|
25   name = account["id"]
26   details = node[:accounts][:users][name] || {}
27
28   if details[:status]
29     group_members = details[:members] || account["members"] || []
30     user_home = details[:home] || account["home"] || "#{node[:accounts][:home]}/#{name}"
31     manage_user_home = details.fetch(:manage_home, account.fetch("manage_home", node[:accounts][:manage_home]))
32
33     group_members = group_members.collect(&:to_s).sort
34
35     case details[:status]
36     when "role"
37       user_shell = "/usr/sbin/nologin"
38     when "user", "administrator"
39       user_shell = details[:shell] || account["shell"] || node[:accounts][:shell]
40     end
41
42     group name.to_s do
43       gid account["uid"].to_i
44       members group_members & node[:etc][:passwd].keys
45     end
46
47     user name.to_s do
48       uid account["uid"].to_i
49       gid account["uid"].to_i
50       comment account["comment"] if account["comment"]
51       home user_home
52       shell user_shell
53       manage_home manage_user_home
54     end
55
56     remote_directory "/home/#{name}" do
57       path user_home
58       source name.to_s
59       owner name.to_s
60       group name.to_s
61       mode 0o755
62       files_owner name.to_s
63       files_group name.to_s
64       files_mode 0o644
65       only_if do
66         begin
67           cookbook = run_context.cookbook_collection[cookbook_name]
68           files = cookbook.relative_filenames_in_preferred_directory(node, :files, name.to_s)
69           !files.empty?
70         rescue Chef::Exceptions::FileNotFound
71           false
72         end
73       end
74     end
75
76     administrators.push(name.to_s) if details[:status] == "administrator"
77   else
78     user name.to_s do
79       action :remove
80     end
81
82     group name.to_s do
83       action :remove
84     end
85   end
86 end
87
88 node[:accounts][:groups].each do |name, details|
89   group name do
90     action :modify
91     members details[:members]
92     append true
93   end
94 end
95
96 group "sudo" do
97   action :manage
98   members administrators.sort
99 end
100
101 group "admin" do
102   action :manage
103   members administrators.sort
104 end
105
106 group "adm" do
107   action :modify
108   members administrators.sort
109 end