Skip to content

daemon: Use systemd to validate xdg-desktop-portal process - #242

Merged
iinuwa merged 1 commit into
mainfrom
systemd-service-lookup
Oct 12, 2026
Merged

iinuwa merged 1 commit into
mainfrom
systemd-service-lookup

Conversation

@iinuwa

@iinuwa iinuwa commented Oct 8, 2026

Copy link
Copy Markdown
Member

Adds systemd as another source of validation. Still falls back to path-based checks if systemd check fails.

Alternative to #199.

@msirringhaus msirringhaus left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Overall looking good. The new Pid-class looks overly complicated, unless I missed something.

Comment thread credentialsd/src/gateway/mod.rs
Comment thread credentialsd/src/gateway/mod.rs Outdated

struct Pid<'a> {
raw_pid: u32,
_marker: PhantomData<&'a ()>,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is this really needed? Looks like we only use it in one function anyways, or did I miss anything? Can't this just be a raw u32?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I have a plan to use this in other places (communicating with credential providers). I wanted to communicate that it's only safe to use for the lifetime of the pidfd that was used to retrieve it. But maybe we can just make that implicit or a comment instead of abstracting too soon.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yeah, I think it's usually better to add complexity only when it's really needed. If some plans don't materialize, we are left with unnecessarily complicated code.
And if it should be tied to the pidfd, maybe it would also make sense to simply give it a reference to the relevant pidfd, instead of a phantom marker? And maybe even tie the functions that use the pidfd to it?

Comment thread credentialsd/src/gateway/mod.rs Outdated

impl Pid<'_> {
fn value(&self) -> &u32 {
&self.raw_pid

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Every usage of this function immediately dereferences it. Can't we just return a plain u32 here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Probably. Do you think the reference on the Pid<'_> itself probably communicates the lifetime well enough?

I also realize that I don't need to derefence the other places, since we're just using it in format strings, where reference and u32 is represented the same way.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

As mentioned above: Depending on the future plans, it might be simpler to tie should_trust_app_id() to the new Pid-struct, which should probably not be called Pid then, but AppId or something. This could then have various functions for verifying the AppId, and internally query the Pid as well (tied to the lifetime of the pidfd, which it also owns).

Comment thread credentialsd/src/systemd.rs
Comment thread credentialsd/src/systemd.rs
Co-Authored-By: Marie Ramlow <me@nycode.dev>
@iinuwa
iinuwa force-pushed the systemd-service-lookup branch from 5e5b009 to 0597756 Compare October 12, 2026 12:49
@iinuwa

iinuwa commented Oct 12, 2026

Copy link
Copy Markdown
Member Author

Good points on the Pid struct. I dropped it and used the u32 directly. If we do more work with pidfds later, then we can work out a useful abstraction to prevent using the PID beyond the pidfd's lifetime.

@iinuwa
iinuwa requested a review from msirringhaus October 12, 2026 12:51
@iinuwa
iinuwa merged commit 57dd042 into main Oct 12, 2026
1 check passed
@iinuwa
iinuwa deleted the systemd-service-lookup branch October 12, 2026 18:16
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.

2 participants