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

Allow setting the user which we drop permissions to using suid. #370

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

alexmv
Copy link

@alexmv alexmv commented Feb 24, 2023

What do these changes do?

We may want a different user than nobody when dropping permissions -- for example, if we intend to connect to a PostgreSQL database which does ident authentication.

Are there changes in behavior for the user?

No behaviour change.

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • tox testenvs have been executed in the following environments:
    • Linux (Ubuntu 18.04, Ubuntu 20.04, Arch): {py36,py37,py38,py39}-{nocov,cov,diffcov}, qa, docs
    • Windows (7, 10): {py36,py37,py38,py39}-{nocov,cov,diffcov}
    • WSL 1.0 (Ubuntu 18.04): {py36,py37,py38,py39}-{nocov,cov,diffcov}, pypy3-{nocov,cov}, qa, docs
    • FreeBSD (12.2, 12.1, 11.4): {py36,pypy3}-{nocov,cov,diffcov}, qa
    • Cygwin: py36-{nocov,cov,diffcov}, qa, docs
  • Documentation reflects the changes
  • Add a news fragment into the NEWS.rst file

@codecov
Copy link

codecov bot commented Mar 2, 2023

Codecov Report

Merging #370 (bedda90) into master (83168cd) will not change coverage.
The diff coverage is 100.00%.

❗ Current head bedda90 differs from pull request most recent head 9182c42. Consider uploading reports for the commit 9182c42 to get more accurate results

@@            Coverage Diff            @@
##            master      #370   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            7         7           
  Lines         1706      1707    +1     
  Branches       310       310           
=========================================
+ Hits          1706      1707    +1     
Impacted Files Coverage Δ
aiosmtpd/main.py 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Collaborator

@waynew waynew left a comment

Choose a reason for hiding this comment

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

Just a small change in regards to the documentation. And another optional change.

Otherwise, I'm +1 on this. I went ahead and checked it out locally and verified that the tests fail when the code is as-is on the main branch.

I do have a slight concern that there might be a better way to have the other connections made and then drop privileges to nobody... but I don't think that's necessarily a blocker here.

(FYI I used to run test clinics for the Salt project - I'm running my own, and I went through this one at https://twitch.tv/wayneswonderarium tonight if anyone wants to catch the rerun. Also noticed a failure on mac but I don't think that was related to this PR -- was probably just a flaky issue with mac)

aiosmtpd/main.py Outdated Show resolved Hide resolved
Comment on lines 240 to 244
print(
'Cannot setuid "nobody"; try running with -n option.', file=sys.stderr
f'Cannot setuid to "{args.suid_user}"; try running with -n option.',
file=sys.stderr,
)
sys.exit(1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion (non-blocking) Since we're going ahead and exiting with status 1 we could go ahead and simply sys.exit(f"Cannot ...") -- and use the (documented) functionality of sys.exit. However one of our tests does check that the exception .value.code == 1, and it would have to equal the error message instead.

Not a big deal, but that would simplify things here just a bit.

Copy link
Author

Choose a reason for hiding this comment

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

This feels very tangential to this PR. Personally, I feel like the explicit print and exit code is more readable -- I've never seen the sys.exit("...") formulation, though it's by no means new!

So I'm not going to include this change in the PR, because I'm not entirely sold on it.

@alexmv
Copy link
Author

alexmv commented Mar 2, 2023

Thanks for the review! I've repushed with your documentation change.

I do have a slight concern that there might be a better way to have the other connections made and then drop privileges to nobody... but I don't think that's necessarily a blocker here.

I don't think there is -- neither root nor nobody can auth, so both making the connections before or after calling suid(nobody) isn't feasible.

@alexmv
Copy link
Author

alexmv commented Mar 23, 2023

Gentle nudge on this -- anything I can do to help move this forward?

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