Skip to content
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

Don't add remote user to setfacl command, if it doesn't exist as an os user #2822

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions recipe/deploy/writable.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@
} elseif (commandExist('setfacl')) {
$setFaclUsers = "-m u:\"$httpUser\":rwX";
// Check if remote user exists, before adding it to setfacl
$remoteUserId = run("id -u $remoteUser &>/dev/null 2>&1 || exit 0");
if (!empty($remoteUserId)) {
$remoteUserExists = test("id -u $remoteUser &>/dev/null 2>&1 || exit 0");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also delete exit 0 and use

run('...', ['no_throw' => true]);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@antonmedv Does that mean I shall replace test() with run() again, as test() doesn't have any additional options?

If I just remove || exit 0 and use it with test(), it keeps working. I still get true if the user exists and false if it doesn't.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh, I see, sorry for misleading. Let me think a bit. Maybe test() should also have options?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@antonmedv
I am not sure if that's necessary. I tried all variants to see how it works:

If the user does exist

  1. run("id -u $remoteUser &>/dev/null 2>&1"): Returns empty string -> the deployment continues
  2. run("id -u $remoteUser &>/dev/null 2>&1", ['no_throw' => true]): Returns empty string -> the deployment continues
  3. test("id -u $remoteUser &>/dev/null 2>&1"): Returns true -> the deployment continues

If the user doesn't exist

  1. run("id -u $remoteUser &>/dev/null 2>&1"): Throws exception -> the deployment is abortet with exit code 1.
  2. run("id -u $remoteUser &>/dev/null 2>&1", ['no_throw' => true]): Returns empty string -> the deployment continues
  3. test("id -u $remoteUser &>/dev/null 2>&1"): Returns false -> the deployment continues

So i'd say test() works as expected, but I am not aware of side effects you might see.

if ($remoteUserExists === true) {
$setFaclUsers .= " -m u:$remoteUser:rwX";
}
if (empty($sudo)) {
Expand Down