Skip to content

Commit 4626feb

Browse files
author
Ludwig Cornelius
committed
check one file for syntax and rm params fixes #223
Before that all sudoers files were checked for syntax and when an application would have created a suders file with a permission/syntax error the file managed by puppet would be deleted. But the file managed by puppet would not have a syntax error. This could also occur if an application creates a file with permission 0400 instead of 0440 which is demanded by visudo. Removed delete_on_error: Now puppet will not create the file if it has a syntax error by default. Before that, syntax / permission errors in other files would also lead to deletion or error which makes no sense. Removed validate_single: Previously all files were always validated no matter which value validate_single had. This makes no sense, so remove parameter. Removed conf parameter sudo_syntax_path as the exec that used it was removed. Validation is now only via validate_cmd of the puppet file resource.
1 parent 913cb9c commit 4626feb

File tree

3 files changed

+1
-70
lines changed

3 files changed

+1
-70
lines changed

REFERENCE.md

-32
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ The following parameters are available in the `sudo` class:
6363
* [`content_string`](#-sudo--content_string)
6464
* [`secure_path`](#-sudo--secure_path)
6565
* [`ldap_enable`](#-sudo--ldap_enable)
66-
* [`delete_on_error`](#-sudo--delete_on_error)
67-
* [`validate_single`](#-sudo--validate_single)
6866
* [`config_dir_keepme`](#-sudo--config_dir_keepme)
6967
* [`use_sudoreplay`](#-sudo--use_sudoreplay)
7068
* [`wheel_config`](#-sudo--wheel_config)
@@ -263,27 +261,6 @@ Enable ldap support on the package
263261

264262
Default value: `false`
265263

266-
##### <a name="-sudo--delete_on_error"></a>`delete_on_error`
267-
268-
Data type: `Boolean`
269-
270-
True if you want that the configuration is deleted on an error
271-
during a complete visudo -c run. If false it will just return
272-
an error and will add a comment to the sudoers configuration so
273-
that the resource will be checked at the following run.
274-
275-
Default value: `true`
276-
277-
##### <a name="-sudo--validate_single"></a>`validate_single`
278-
279-
Data type: `Boolean`
280-
281-
Do a validate on the "single" file in the sudoers.d directory.
282-
If the validate fail the file will not be saved or changed
283-
if a file already exist.
284-
285-
Default value: `false`
286-
287264
##### <a name="-sudo--config_dir_keepme"></a>`config_dir_keepme`
288265

289266
Data type: `Boolean`
@@ -429,7 +406,6 @@ The following parameters are available in the `sudo::conf` defined type:
429406
* [`template`](#-sudo--conf--template)
430407
* [`sudo_config_dir`](#-sudo--conf--sudo_config_dir)
431408
* [`sudo_file_name`](#-sudo--conf--sudo_file_name)
432-
* [`sudo_syntax_path`](#-sudo--conf--sudo_syntax_path)
433409

434410
##### <a name="-sudo--conf--ensure"></a>`ensure`
435411

@@ -489,11 +465,3 @@ Set a custom file name for the snippet
489465

490466
Default value: `undef`
491467

492-
##### <a name="-sudo--conf--sudo_syntax_path"></a>`sudo_syntax_path`
493-
494-
Data type: `Any`
495-
496-
Path to use for executing the sudo syntax check
497-
498-
Default value: `'/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'`
499-

manifests/conf.pp

+1-25
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@
2626
# @param sudo_file_name
2727
# Set a custom file name for the snippet
2828
#
29-
# @param sudo_syntax_path
30-
# Path to use for executing the sudo syntax check
31-
#
3229
# @example
3330
# sudo::conf { 'admins':
3431
# source => 'puppet:///files/etc/sudoers.d/admins',
@@ -42,7 +39,6 @@
4239
$template = undef,
4340
$sudo_config_dir = undef,
4441
$sudo_file_name = undef,
45-
$sudo_syntax_path = '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
4642
) {
4743
include sudo
4844

@@ -108,22 +104,8 @@
108104
}
109105

110106
if $ensure == 'present' {
111-
if $sudo::validate_single {
112-
$validate_cmd_real = 'visudo -c -f %'
113-
} else {
114-
$validate_cmd_real = undef
115-
}
116-
if $sudo::delete_on_error {
117-
$notify_real = Exec["sudo-syntax-check for file ${cur_file}"]
118-
$delete_cmd = "( rm -f '${cur_file_real}' && exit 1)"
119-
} else {
120-
$notify_real = Exec["sudo-syntax-check for file ${cur_file}"]
121-
$errormsg = "Error on global-syntax-check with file ${cur_file_real}"
122-
$delete_cmd = "( echo '${errormsg}' && echo '#${errormsg}' >>${cur_file_real} && exit 1)"
123-
}
107+
$validate_cmd_real = 'visudo -c -f %'
124108
} else {
125-
$delete_cmd = ''
126-
$notify_real = undef
127109
$validate_cmd_real = undef
128110
}
129111

@@ -135,14 +117,8 @@
135117
mode => $sudo::params::config_file_mode,
136118
source => $source,
137119
content => $content_real,
138-
notify => $notify_real,
139120
require => File[$sudo_config_dir_real],
140121
validate_cmd => $validate_cmd_real,
141122
}
142123

143-
exec { "sudo-syntax-check for file ${cur_file}":
144-
command => "visudo -c || ${delete_cmd}",
145-
refreshonly => true,
146-
path => $sudo_syntax_path,
147-
}
148124
}

manifests/init.pp

-13
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,6 @@
8383
# @param ldap_enable
8484
# Enable ldap support on the package
8585
#
86-
# @param delete_on_error
87-
# True if you want that the configuration is deleted on an error
88-
# during a complete visudo -c run. If false it will just return
89-
# an error and will add a comment to the sudoers configuration so
90-
# that the resource will be checked at the following run.
91-
#
92-
# @param validate_single
93-
# Do a validate on the "single" file in the sudoers.d directory.
94-
# If the validate fail the file will not be saved or changed
95-
# if a file already exist.
96-
#
9786
# @param config_dir_keepme
9887
# Add a .keep-me file to the config dir
9988
#
@@ -137,8 +126,6 @@
137126
Optional[String[1]] $content_string = undef,
138127
Optional[String[1]] $secure_path = $sudo::params::secure_path,
139128
Boolean $ldap_enable = false,
140-
Boolean $delete_on_error = true,
141-
Boolean $validate_single = false,
142129
Boolean $config_dir_keepme = $sudo::params::config_dir_keepme,
143130
Boolean $use_sudoreplay = false,
144131
Enum['absent','password','nopassword'] $wheel_config = $sudo::params::wheel_config,

0 commit comments

Comments
 (0)