Open cbirchinger opened 1 month ago
cc: @malmeloo
I did a little digging and what I think is happening here is aiohttp dropping the Authorization
header when it encounters a redirect. Could you post a few log lines from Apache to confirm that that's also what's going on here?
Ah, aiohttp! I think i've found the issue.
Changed in version 3.0: Added support for ~/.netrc file.
Changed in version 3.9: Added support for reading HTTP Basic Auth credentials from ~/.netrc file.
It is using a credential entry in ~/.netrc for the autentication. Because in ~/.netrc only the machine name is configured so it seems to be using it for all requests on that host regardless of the subpath.
The question now is can it be changed so the values in ~/.config/vdirsyncer/config have higher priority than the generic ~/.netrc
EDIT: As far as i understand the aiohttp documentation ~/.netrc should only be used related to proxy authentication. Does it consider a web service behind a reverse proxy such as Apache or nginx needs to be treated like a Squid web cache that requires auth?
I’ll take a patch that disables netrc support when invoking aiohttp. It isn’t a supported mechanism for Vdirsyncer.
That option should still be off by default though, so I'm not entirely convinced that's the problem here. But I will investigate a little more and see if I can repro.
I don't see an explicit option for this. It's tied to the "trust_env" option in "aiohttp.ClientSession" though
if auth is None and trust_env and self.url.host is not None:
netrc_obj = netrc_from_env()
with contextlib.suppress(LookupError):
auth = basicauth_from_netrc(netrc_obj, self.url.host)
vdirsyncer currently is using "True": https://github.com/search?q=repo%3Apimutils%2Fvdirsyncer%20trust_env&type=code
Setting it to "False" fixes the issue for me. It also does disable a users ability to set the NETRC environment to have an alternative to the hardcoded ~/.netrc
Oh the option is enabled? Right, that explains the issue then. I think disabling it would also disable support for setting proxy details using env vars though, is that desirable?
Not really, a lot more people probably use the "http_proxy" environment variables.
Knowing the root cause of the issue, I have some workarounds for the time being like running "NETRC=/dev/null vdirsyncer sync"
If that fixes it we could probably override that env var in vdirsyncer, as a workaround...
The more I learn about aiohttp, the more I'm starting to dislike it.
Yes, please. Having the env var set to something like /dev/null by default would help. vdirsyncer has it's own username and password settings. I see no benefit in using the less flexible and if present probably used for something else ~/.netrc instead.
@cbirchinger could you try #1141 to see if it fixes the issue?
@cbirchinger could you try #1141 to see if it fixes the issue?
Yes, that fixes the issue. Thank you.
After updating from 0.19.2 to 0.19.3 the server rejects the connection with 401 instead of 207 (-vdebug outputs below)
Nothing other than the update from 0.19.2 to 0.19.3 was changed. Same Python, same configuration, same server setup. Downgrading to 0.19.2 again fixes the issue and the sync works again
Server: Radicale 3.2.3 behind Apache 2.4.62 (mod_proxy) OS: Gentoo Linux (Server and Client) Python: 3.12
Hardcoded password instead of password.fetch was also tried without success.
-vdebug output of 0.19.3 (FAIL)
-vdebug output of 0.19.2 (OK)
config
Apache vhost