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

Improve permissions adjustment logic #27

Closed

Conversation

miclaus
Copy link

@miclaus miclaus commented Nov 27, 2024

Previously, permissions were exclusively adjusted using privilege elevation tools (sudo or doas). This causes an issue on systems where the current user is not in the sudoers file (e.g., on macOS, where the current user is a standard user, not an administrator), resulting in an error like: "User is not in the sudoers file. This incident has been reported to the administrator."

This PR fixes and improves this by first attempting to adjust permissions without elevated privileges. If that fails, it falls back to using sudo or doas (if available). If neither method succeeds, the user is informed and encouraged to try running the application, as it might still work without adjusted permissions. (In the example mentioned, the application worked correctly even though permissions adjustment failed for the standard user.)

- First, attempts permissions adjustment without elevated privileges
- Fallback to privilege elevation tools (`sudo` or `doas`) if available
- If applicable, print permissions adjustment error and guide user
@miclaus miclaus force-pushed the feature/permissions-adjustment-logic branch from c25ed54 to e23ef22 Compare November 27, 2024 23:05
@taylorotwell
Copy link
Member

I'm scared to keep tinkering with this user stuff much more unless there is a serious problem with for most developers using Sail. 😬

@miclaus
Copy link
Author

miclaus commented Dec 16, 2024

@taylorotwell I totally get the concern around "tinkering with this user stuff". That said, I believe sudo isn't always necessary here, and we can set permissions without it in most cases.

My change first tries to set permissions without sudo. If that fails, it gracefully falls back to using sudo, preserving the script's original behavior when permissions can't be set without sudo (or doas).

The current script isn't ideal because it always prompts developers for their password, even when it's unnecessary. And even if they provide it, it might not work in certain cases (as mentioned above). My version avoids the need for a password when permissions can be set without sudo, making it more developer-friendly.

Think about how many security-conscious developers have probably wondered, "Why does this script need my password? What am I giving it access to?" Some, myself included, likely had to kill the script, inspect what it was doing with elevated permissions, and then rerun it, which interrupts the workflow.

I'm confident this change will improve the developer experience, by avoiding asking developers for their password, when it's not needed. It should work smoothly across environments (macOS, Linux, WSL2), but feedback from other developers could help confirm that.

@miclaus
Copy link
Author

miclaus commented Jan 11, 2025

@taylorotwell Just had the same issue with yet another project:

bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants