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

feat: add support for EXTERNAL auth without uid #193

Merged
merged 6 commits into from
Jan 7, 2023

Conversation

mvn23
Copy link
Contributor

@mvn23 mvn23 commented Jan 4, 2023

As a follow-up to #188 , this PR allows EXTERNAL auth without a uid as per RFC4422. If we pass -1 as the uid, it will trigger the following auth sequence (source: https://gitlab.freedesktop.org/dbus/dbus/-/issues/195):

C: AUTH EXTERNAL            # I want to use EXTERNAL, but I do not
                            # have an initial response
S: DATA                     # Who do you claim you are?
C: DATA                     # Whoever the kernel says I am
S: OK                       # Can't argue with that!

The upside of this is that when running in a user namespace (e.g. rootless docker), we don't need to know our uid mapping outside of the namespace to connect to the system dbus on the host.

@codecov
Copy link

codecov bot commented Jan 4, 2023

Codecov Report

Base: 82.28% // Head: 82.38% // Increases project coverage by +0.09% 🎉

Coverage data is based on head (8a34008) compared to base (830183e).
Patch coverage: 83.33% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #193      +/-   ##
==========================================
+ Coverage   82.28%   82.38%   +0.09%     
==========================================
  Files          27       27              
  Lines        3162     3167       +5     
  Branches      652      654       +2     
==========================================
+ Hits         2602     2609       +7     
+ Misses        343      342       -1     
+ Partials      217      216       -1     
Impacted Files Coverage Δ
src/dbus_fast/__version__.py 0.00% <0.00%> (ø)
src/dbus_fast/auth.py 87.93% <100.00%> (+4.91%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

src/dbus_fast/auth.py Outdated Show resolved Hide resolved
src/dbus_fast/auth.py Outdated Show resolved Hide resolved
@bdraco
Copy link
Member

bdraco commented Jan 5, 2023

Can you add coverage for these lines?
Screenshot 2023-01-05 at 1 59 18 PM

@mvn23
Copy link
Contributor Author

mvn23 commented Jan 6, 2023

All done. Should we try to fall back to this method if the default method with the uid from os.getuid() fails?

@bdraco
Copy link
Member

bdraco commented Jan 6, 2023

All done. Should we try to fall back to this method if the default method with the uid from os.getuid() fails?

I think its probably fine without it os.getuid() is unlikely to fail

@bdraco bdraco changed the title Add support for EXTERNAL auth without uid feat: add support for EXTERNAL auth without uid Jan 6, 2023
@bdraco
Copy link
Member

bdraco commented Jan 6, 2023

This looks good.

Would you update the doc string below as well?

    """An authenticator class for the external auth protocol for use with the
    :class:`MessageBus <dbus_fast.message_bus.BaseMessageBus>`.
    :sealso: https://dbus.freedesktop.org/doc/dbus-specification.html#auth-protocol
    """

@mvn23
Copy link
Contributor Author

mvn23 commented Jan 6, 2023

I think its probably fine without it os.getuid() is unlikely to fail

It is currently the only reason I'm patching the Home Assistant docker image locally...
Granted, it's quite a specific scenario (running containerized in a user namespace with mapped uids), but if we only fall back to it after the initial attempt with the uid has failed, what's the harm?

@bdraco
Copy link
Member

bdraco commented Jan 6, 2023

I think its probably fine without it os.getuid() is unlikely to fail

It is currently the only reason I'm patching the Home Assistant docker image locally... Granted, it's quite a specific scenario (running containerized in a user namespace with mapped uids), but if we only fall back to it after the initial attempt with the uid has failed, what's the harm?

Isn't that silently hiding an issue, it might not be the behavior the caller wants?

@bdraco
Copy link
Member

bdraco commented Jan 7, 2023

Tested 👍

@bdraco bdraco merged commit 4939ef8 into Bluetooth-Devices:main Jan 7, 2023
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