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

daemon: Add new ModifyYumRepo DBus API #1780

Closed
wants to merge 1 commit into from

Conversation

kalev
Copy link
Contributor

@kalev kalev commented Mar 8, 2019

This allows clients such as gnome-software to enable and disable
yum repositories.

Closes: #1771

(Note that this is completely untested, ran out of time today and going to be offline the whole weekend. I'll just put it up in case someone wants to have an early look. Will test it and fix things up on Monday.)

Copy link
Member

@jlebon jlebon left a comment

Choose a reason for hiding this comment

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

Looks sane at a high level! I think this is missing a new action in os_authorize_method()?

<!-- Set options in yum .repo files -->
<method name="ModifyYumRepo">
<arg type="s" name="repo_id" direction="in"/>
<arg type="a{ss}" name="repo_options" direction="in"/>
Copy link
Member

Choose a reason for hiding this comment

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

Bikeshed: maybe just options?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, I called it repo_options to avoid confusing it with options such as "dry-run" that other DBus API has. Not sure it's a huge problem :) Happy to change it if you think it's best.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

settings or parameters could work too? Just writing the polkit messages and "Authentication is required to modify repository settings" is what I have right now and "settings" seems to work well in that sentence.

Copy link
Member

Choose a reason for hiding this comment

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

Sure, settings sounds good to me!

@jlebon
Copy link
Member

jlebon commented Mar 11, 2019

bot, retest this please

@cgwalters
Copy link
Member

Thanks for working on this!

I'm a bit uncertain though long term about exposing every configuration option via DBus. An obvious 🐘 in the room here is that we don't expose a DBus API to configure the OSTree repositories either.

In the end if one can configure arbitrary yum repos it's equivalent to arbitrary code execution on the host, not going to be easy to wrap it in anything that constrains it with polkit.

For example, while it looks like systemd does have a DBus API to set unit file properties, in the end the vast majority of tooling to configure systemd just ends up writing unit files, symlinks to /dev/null to disable - because the filesystem is a well-specified API in this case. Concretely for example systemctl edit directly writes unit files rather than doing so over DBus.

I'm not saying we shouldn't do a PR like this - but let's at least consider the (IMO far simpler) alternative of just having gnome-software basically run pkexec cp /tmp/user/repos.d /etc/yum.repos.d?

@kalev
Copy link
Contributor Author

kalev commented Mar 14, 2019

I originally only wanted to add an API to enable and disable repos, I don't need to edit any of the other properties. Only did the more generic version because jlebon thought it would make sense :)

I'd be happy to change the API to EnableYumRepo with string repo_id and bool enable parameters if it seems less scary.

Sure, implementing a new dbus privilage separation daemon that can edit the .repo files for gnome-software is certainly an option if you don't want it in rpm-ostreed. It would be easier to have it in rpm-ostreed, but anything really works.

@jlebon
Copy link
Member

jlebon commented Mar 14, 2019

In the end if one can configure arbitrary yum repos it's equivalent to arbitrary code execution on the host, not going to be easy to wrap it in anything that constrains it with polkit.

That's true, though UpdateDeployment() is more or less the same way, no? E.g. "install-local-packages" + "reboot=true" is a much more direct way to gain code execution without much differentiation wrt to what's actually being installed.

Also the proposed API here is essentially the same PackageKit already offers with RepoSetData().

So focusing more on whether rpm-ostree should be in the business of editing config files. I agree we want to avoid that and not proactively add APIs that do this, though I can imagine situations where it'd be useful, esp. in scenarios where rpm-ostree is essentially part of the "host API" (an easy one that comes to mind is containers talking to rpm-ostree over D-Bus). So I guess my opinion is: ideally no, but if necessary yes? :)

but let's at least consider the (IMO far simpler) alternative of just having gnome-software basically run pkexec cp /tmp/user/repos.d /etc/yum.repos.d?

That's... pretty cool. Hadn't looked at pkexec before.

Sure, implementing a new dbus privilage separation daemon that can edit the .repo files for gnome-software is certainly an option if you don't want it in rpm-ostreed.

I think what @cgwalters is suggesting (do correct me if not!) is GNOME Software copies the yum repos to some user owned space, does whatever modifications it wants, then literally spawns pkexec cp ... to get it written back to the privileged spot. So it wouldn't have to be a separate daemon. WDYT?

@kalev
Copy link
Contributor Author

kalev commented Mar 14, 2019

Not sure I like the pkexec idea. There's no way to customize the polkit message there for starters.

@cgwalters
Copy link
Member

Sorry I'd glossed over the fact that this was originally only about enabling/disabling repos. I had thought we were scoping in adding/removing.

So focusing more on whether rpm-ostree should be in the business of editing config files. ... esp. in scenarios where rpm-ostree is essentially part of the "host API" (an easy one that comes to mind is containers talking to rpm-ostree over D-Bus). So I guess my opinion is: ideally no, but if necessary yes? :)

Talking about the machine-config-operator is a perfect example here because we have the host rootfs mounted. When we go to write systemd units it's directly via the filesystem. If we were to add an rpmRepositories entry to MachineConfig or so, I would almost certainly lean towards just writing the files to /rootfs/etc/yum.repos.d directly in the code rather than talking DBus.

(Partly because DBus in golang is...eh, but a lot just because it's simple and works)

@kalev
Copy link
Contributor Author

kalev commented Mar 14, 2019

Alright, I tested this now and seems to work fine :) Pushed a fixup with jlebon's review comments and added the missing polkit support.

The API questions are still open though: 1) should it be generic ModifyYumRepo or just EnableYumRepo?
2) If it's ModifyYumRepo should the a{ss} param be called repo_options, options, settings, or parameters?

@jlebon
Copy link
Member

jlebon commented Mar 14, 2019

Talking about the machine-config-operator is a perfect example here because we have the host rootfs mounted.

I think if a container can do this, it's clearly better. Though the MCD is basically a super-SPC (well, that's redundant, let's say mega-SPC). Not to say mounting D-Bus isn't equally dangerous if the container is also running as root.

Not sure I like the pkexec idea. There's no way to customize the polkit message there for starters.

Hmm, yeah I do see this in pkexec(1):

ACTION AND AUTHORIZATIONS
       By default, the org.freedesktop.policykit.exec action is used. To use another action,
       use the org.freedesktop.policykit.exec.path annotation on an action with the value set
       to the full path of the program. In addition to specifying the program, the
       authentication message, description, icon and defaults can be specified.

Though I think that'd mean you have to (1) ship a little helper in e.g. /usr/lib/gnome-software/..., then (2) add a policy for executing the helper? @cgwalters Is there an easier way to do this?

This is somewhat related to the discussions we've had in #1768. Unless PackageKit grows some kind of rpm-ostree backend, then it sorta falls on rpm-ostree to provide some of the same basic APIs. The alternative is e.g. GNOME Software and Discover having to learn a whole new way of asking for privileged actions.

@jlebon
Copy link
Member

jlebon commented Mar 14, 2019

should it be generic ModifyYumRepo or just EnableYumRepo?

One hybrid option is keeping as ModifyYumRepo and the method signature the same, but only accepting the enabled key for now. If another convincing use case shows up that requires broader control, then we can loosen it under a different action.

@kalev
Copy link
Contributor Author

kalev commented Mar 15, 2019

Ahh, I think that makes sense. Pushed a commit that changes it to only accept enabled for now.

Copy link
Member

@jlebon jlebon left a comment

Choose a reason for hiding this comment

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

This looks good to me, just some minor nits! Could you also just squash all your commits into one?
Will let @cgwalters take a look at the final approach here.

<!-- Set options in yum .repo files -->
<method name="ModifyYumRepo">
<arg type="s" name="repo_id" direction="in"/>
<arg type="a{ss}" name="repo_options" direction="in"/>
Copy link
Member

Choose a reason for hiding this comment

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

Sure, settings sounds good to me!

This allows clients such as gnome-software to enable and disable
yum repositories.

The API is generic, but for now we only allow changing the 'enabled'
key. If needed, it's easy to allow changing other settings in the
future. See the discussion in the PR for the reasoning.

Closes: coreos#1771
@kalev
Copy link
Contributor Author

kalev commented Mar 15, 2019

Squashed all commits and fixed the two nits! Thanks!

@cgwalters
Copy link
Member

@rh-atomic-bot r+ ae5fc1a

@rh-atomic-bot
Copy link

⌛ Testing commit ae5fc1a with merge 891f5b7...

@rh-atomic-bot
Copy link

☀️ Test successful - status-atomicjenkins
Approved by: cgwalters
Pushing 891f5b7 to master...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New DBus API to enable/disable yum repos
4 participants