Skip to content

feat: Add socket-activated systemd service for discovery#218

Merged
christgau merged 1 commit intochristgau:masterfrom
aleasto:systemd-socket
Jan 5, 2025
Merged

feat: Add socket-activated systemd service for discovery#218
christgau merged 1 commit intochristgau:masterfrom
aleasto:systemd-socket

Conversation

@aleasto
Copy link
Contributor

@aleasto aleasto commented Oct 9, 2024

Introduce a system-wide daemon listening on /run/wsdd.socket, which is managed by systemd.
When a client first connects to the socket the daemon is started. Multiple clients can connect and safely use the API simultaneously.

The service runs in discovery-only mode.

Uses multicast source-port 37020.

@aleasto
Copy link
Contributor Author

aleasto commented Oct 9, 2024

  • Increases the security of services like gvfs which rely discovery mode by integrating with all the security confinement features
  • Allows us to standardize one --source-port
  • Only one daemon per system
  • systemd-specific but non-intrusive

Comment on lines +7 to +11
[Service]
Type=simple
; The service is put into an empty runtime directory chroot,
; i.e. the runtime directory which usually resides under /run
ExecStart=/usr/bin/wsdd --shortlog --chroot=/run/wsdd --source-port=37020 --no-host --discovery
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we want to use the same flags from /etc/default/wsdd here?

Copy link
Owner

Choose a reason for hiding this comment

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

Might help in some minor use-cases, I think (including verbosity for debugging, e.g.), so why not. But I propose to use a different environment file.

I also propose to use a different run/chroot directory for the wsdd-discovery service in order to separate it from a regular host instance. Maybe even a different (dynamic) username might be good, although I'm not sure if dynamic users are inherently distinct (due to different namespace) even when sharing the same name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

although I'm not sure if dynamic users are inherently distinct (due to different namespace) even when sharing the same name.

They're using the same UID/GID here, so no

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How's this?
I've used the same env file but a different variable name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

--source-port 37020 could also be set in the environment file instead of hard-coded inthe systemd unit

Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice to make that configurable from the environmental file, but it is hardcoded in the firewall configuration anyway...

@aleasto
Copy link
Contributor Author

aleasto commented Oct 11, 2024

TODO: systemctl stop wsdd-discovery hangs if there are processes (gvfsd) listening on /run/wsdd.socket. We should probably close the connection.

@aleasto
Copy link
Contributor Author

aleasto commented Oct 11, 2024

TODO: systemctl stop wsdd-discovery hangs if there are processes (gvfsd) listening on /run/wsdd.socket. We should probably close the connection.

That's #219

@christgau
Copy link
Owner

@aleasto I split the UFW rules because I think enabling discovering other devices on the network should not open ports for the host itself to be discoverable. AFAIK, Windows actually has two services as well (fdPHost and FDResPub on Win11).

WDYT?

@aleasto
Copy link
Contributor Author

aleasto commented Dec 28, 2024

Yeah I think I agree.

Shouldn't you do the same for firewalld?

@christgau
Copy link
Owner

Shouldn't you do the same for firewalld?

Good point. Done

Introduce a system-wide daemon listening on /run/wsdd.socket,
which is managed by systemd.
When a client first connects to the socket the daemon is started.
Multiple clients can connect and safely use the API simultaneously.

The service runs in discovery-only mode.

Uses a fixed multicast source-port 37020, which is used by the
socket-activated discovery daemon.

Allow port 37020 in firewall profiles and split configurations for
discovery (client) and host roles.

Co-Authored-by: Steffen Christgau <mail@s14u.de>
@christgau christgau merged commit 13d2b0f into christgau:master Jan 5, 2025
2 checks passed
@aleasto
Copy link
Contributor Author

aleasto commented Apr 30, 2025

Would it be time to make a tagged release?

@marcosfrm marcosfrm mentioned this pull request May 27, 2025
gnomesysadmins pushed a commit to GNOME/gvfs that referenced this pull request Aug 13, 2025
Rather than spawning our own wsdd daemon, prefer the system service
which has:
* security confinement features
* a fixed multicast source port which can be allowlisted to enable
  wsdd discovery behind restrictive firewalls.

See: christgau/wsdd#218
Part-of: <https://gitlab.gnome.org/GNOME/gvfs/-/merge_requests/242>
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.

3 participants