|
| 1 | +# |
| 2 | +# Cookbook:: fb_sssd |
| 3 | +# Recipe:: default |
| 4 | +# |
| 5 | +# Copyright (c) 2025-present, Meta Platforms, Inc. |
| 6 | +# Copyright (c) 2025-present, Phil Dibowitz |
| 7 | +# All rights reserved. |
| 8 | +# |
| 9 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 10 | +# you may not use this file except in compliance with the License. |
| 11 | +# You may obtain a copy of the License at |
| 12 | +# |
| 13 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | +# |
| 15 | +# Unless required by applicable law or agreed to in writing, software |
| 16 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 17 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 | +# See the License for the specific language governing permissions and |
| 19 | +# limitations under the License. |
| 20 | +# |
| 21 | + |
| 22 | +packages = %w{ |
| 23 | + sssd |
| 24 | + sssd-ad |
| 25 | + sssd-common |
| 26 | + sssd-dbus |
| 27 | + sssd-ipa |
| 28 | + sssd-krb5 |
| 29 | + sssd-krb5-common |
| 30 | + sssd-ldap |
| 31 | + sssd-proxy |
| 32 | + sssd-tools |
| 33 | +} |
| 34 | + |
| 35 | +extra_packages = value_for_platform_family( |
| 36 | + ['fedora', 'rhel'] => ['sssd-client'], |
| 37 | + ['debian'] => ['sssd-ad-common'], |
| 38 | +) |
| 39 | + |
| 40 | +packages += extra_packages |
| 41 | + |
| 42 | +package packages do |
| 43 | + only_if { node['fb_sssd']['enable'] && node['fb_sssd']['manage_packages'] } |
| 44 | + action :upgrade |
| 45 | +end |
| 46 | + |
| 47 | +package 'remove sssd' do |
| 48 | + not_if { node['fb_sssd']['enable'] } |
| 49 | + package_name packages |
| 50 | + action :remove |
| 51 | +end |
| 52 | + |
| 53 | +template '/etc/sssd/sssd.conf' do |
| 54 | + only_if { node['fb_sssd']['enable'] } |
| 55 | + owner 'root' |
| 56 | + group 'root' |
| 57 | + mode '0600' |
| 58 | + notifies :restart, 'service[sssd]' |
| 59 | +end |
| 60 | + |
| 61 | +file '/etc/sssd/sssd.conf' do |
| 62 | + not_if { node['fb_sssd']['enable'] } |
| 63 | + action :delete |
| 64 | +end |
| 65 | + |
| 66 | +Dir.glob('/etc/sssd/conf.d/*').each do |f| |
| 67 | + file f do |
| 68 | + only_if { node['fb_sssd']['enable'] } |
| 69 | + action :delete |
| 70 | + end |
| 71 | +end |
| 72 | + |
| 73 | +service 'sssd' do |
| 74 | + only_if { node['fb_sssd']['enable'] } |
| 75 | + action [:enable, :start] |
| 76 | + # nsswitch is before sssd (for good reasons), but that means on first |
| 77 | + # boot, we'll trigger on the nsswitch notification and try to restart |
| 78 | + # even when we can't. This could of course happen outside of firstboot |
| 79 | + # so if the binary isn't there at compile time, don't bother setting up |
| 80 | + # the notification. This is safe: if the binary isn't there, it can't |
| 81 | + # be running and therefore can't have an old config... it will then be |
| 82 | + # started by this resource |
| 83 | + if File.exist?('/usr/sbin/sssd') |
| 84 | + subscribes :restart, 'template[/etc/nsswitch.conf]', :immediately |
| 85 | + end |
| 86 | +end |
| 87 | + |
| 88 | +service 'disable sssd' do |
| 89 | + not_if { node['fb_sssd']['enable'] } |
| 90 | + # once the package is removed, this fails, sadly |
| 91 | + only_if { ::File.exist?('/lib/systemd/system/sssd.service') } |
| 92 | + service_name 'sssd' |
| 93 | + action [:stop, :disable] |
| 94 | +end |
0 commit comments