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
NetRCInfo.netrc_info() doesn't work when run in a systemd service with DynamicUser=true #2532
Comments
Okay, so we've got two outstanding I've taken a review over our netrc handling and I believe we ought to be making a behavioural change here...
We currently have it built-in, because we're following My suggestion is this... We should drop the netrc authentication that's baked into the client instance, and instead provide a
@djmattyg007 - That'd be neat, yup. If you're up for that I can provide review, and help us to land this. Here's what I think is needed...
Implementing |
Sorry for any potential confusion - my offer to raise a PR was for a much more simplistic solution to directly address the two problems highlighted in my summary, within the existing architecture. I simply don't have the time to make more comprehensive changes than that. |
@djmattyg007 Ah no worries, yup. 😅 I've opened a proposal #2535, which would remove the issue you're seeing since If that doesn't look like it's going to land anytime soon, then we could consider making the minor change that you've proposed, so that you're not hitting issues in the meantime. |
Hi, would it be possible to reconsider this behavioral change? I think many people could be relying on netrc files to add a minimum authentication layer when they don't have much control over open source projects. Could we consider adding an environment variable like Thank you! 🙇 |
Discussed in #2526
Originally posted by djmattyg007 January 1, 2023
The function in question,
netrc_info()
, iterates over three paths. Two of these paths refer to the home directory of the current process' user, by prefixing the paths with~/
. These paths are run throughpathlib.Path.expanduser()
, which raises an exception if the home directory can't be determined.When the code is running in a systemd service with
DynamicUser=true
, there is no home directory. This meansexpanduser()
will always raise an exception.Fortunately, there's a potential override: set the
NETRC
environment variable to something. As long as it points to a file that exists, and doesn't need to know the current user's home directory, this is an acceptable workaround.Unfortunately, there's an
is_file()
check performed on thePath
object before attempting to use it. This means I can't just setNETRC=/dev/null
as a simple way of working around this problem, even thoughnetrc.netrc()
will happily accept/dev/null
.Why does any of this matter? Because I'm not using
httpx
directly. I'm using the librarypython-telegram-bot
, and have no control over how it useshttpx
internally.To summarise, there are two problems:
pathlib.Path.expanduser()
can raise an exception that isn't currently being caughtNETRC=/dev/null
doesn't work as expected, despite it being a perfectly suitable file to use in this contextI'm happy to raise an issue for this, and also to implement a PR to resolve this.
The text was updated successfully, but these errors were encountered: