-
Notifications
You must be signed in to change notification settings - Fork 214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
syntax check should only check the file it needs to #223
Comments
+1 this just bit me |
arguably there is already a check on the specific files being installed with the "validate_cmd" param on the file resource in I would guess that the more desctuctive check triggered by @TJM you could disable the |
Disabling syntax checking or recovery from syntax errors are crude workarounds. An unrelated issue can cause this specific resource to fail in strange an mysterious ways. If we only check the file being deployed, it should only fail if that specific file has a syntax issue. If the other file has permissions that are non-compliant, then let that "unmanaged" rule fail. ~tommy |
@TJM I'm sorry I've used words that were misleading (I'm re-reading myself now). that parameter that I mentioned, I do agree though that something is not right in that exec that checks syntax errors for all files (and does it for all |
Looking at the whole visudo check, this looks more complicated than it should or I'm missing something. The change has been introduced in 650321e As far as I can see, if Shouldn't it be enough to change the default of |
I thought the same thing, way overcomplicated. To me, it is invalid logic (bad assumption) to add a new file, check all the files, and if any of them fail, remove the new file. It only makes sense to check the new file itself, and if it fails, remove it. In my opinion, validate_single should be true by default. However, validate_single would not disable the logic of checking all files and removing the new one. For that you would also have to set delete_on_error to false, but then it tries to modify the file, appending the error as a comment? Checking the syntax of ALL the files and issuing a failure message can still be an option, but it shouldn't cause a removal of the newly added file unless that file was the one that was bad. I suggest making validate_single true by default, and defanging the other "sudo syntax check" (exec). Either remove that logic entirely, or possibly make it an option to syntax check all unmanaged files too? Only makes sense without purge probably, and then you would have to do some trickery with exec like:
... that would effectively run What do you think? |
Generally speaking, prefer the current behavior. That said, I haven't looked at the code. Perhaps that could use some ❤️ |
I am not sure if it makes sense to have a problem (even just file permissions) in another file prevent adding a new one. |
Hello, I had the same problem, a sudoer file with wrong permissions, created out of puppet, deleted all my sudoers :-O! I upgraded the module today, we had an old version, but I was forced to roll back. |
Any movement on this? I'm in agreement that the behaviour seems wrong. We should only be checking validity on the files controlled by Puppet. i.e.
But I can also see a use-case for checking the entire sudoers config as a whole. Maybe we can run |
Hello, I had the same problem - some application created a sudoers file with permission 0400. But visudo expects 0440 and returns 1 / error. Then new sudoers files cannot be created by saz-sudo. This is independent from the setting validate_single. No matter if it's true or false saz-sudo will always check all sudoers files. The problem is at the end of conf.pp:
Here all files will be checked unconditionally. Best wishes |
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.
I have made a pull request which is basically the same as the one by jamesps-ebi, but I also removed the parameters delete_on_error, validate_single and sudo_syntax_path which don't make sense anymore. Puppet will not create an invalid sudo file because the file resource uses the validate_cmd:
Made some tests on RHEL 8. |
@tdlc Thanks for picking this topic up again. I now understand your comment in your PR. I'd rather keep the parameters, as this makes (or keeps) the module flexible, and maybe add another one:
At first, this makes things more complicated, but there's a history to how things are. See #125 for an example of a valid case, when a full config check will be good and prevent you from running into an issue. |
Ok I get the point of #125 that a full syntax check of all files can be desirable in some situations.
All this problems led me to the conclusion that I want to keep it simple and I removed the parameters. |
I have quickly hacked some code not thoroughly tested. Take a look at this branch if you like. |
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.
To make validate_single to really only validate single files the implementation was changed. If validate_single is true visudo will be called with -f <file>. In case validate_single is false all files will be validated. This makes sense because a single file could break the whole sudoers config, see issue saz#125. Before this commit all files would always be validated no matter which value validate_single had. This might be unwanted if an application installs some file with wrong rights 0440, see issue saz#223. Removed parameter delete_on_error because now an invalid file is never kept. When param was false it could also lead to infinite error messages in the invalid sudoers file. Removed parameter sudo_syntax_path as it is unused now. It cannot be used in puppet file's validate_cmd.
I have made up my mind on this issue again and will add a new mr:
This is completely untested code - beware. I can test this on RHEL 7 8 9 if you are interested. Are you interested? |
The syntax check
visudo -c || ( rm -f '/etc/sudoers.d/01_sensu' && exit 1)
will prevent any new sudo rules from being added in if someone "else" has created a file in /etc/sudoers.d with the wrong permissions (i.e. not setting mode at all). This results in an error that looks like:Where the file that it complains about (/etc/sudoers.d/10_oes_sudoers) is not the file it is checking/removing (/etc/sudoers.d/01_sensu).
I have had a chat with the people that created the bogus file (they obviously had seen the filename format that saz-sudo uses, given the name they picked). I changed their code to use "sudo::conf" instead of "file" and everything was fine, but the fact remains that we should probably add the
-f FILE
option to our visudo command.Suggested Fix:
use
visudo -c -f 'FILENAME' || ( rm -f 'FILENAME' && exit 1)
The text was updated successfully, but these errors were encountered: