Repository navigation
Closed
Labels
Description
You should not be able to update an app such that its collection ID changes, but you can.
$ flatpak info com.endlessm.wiki_art.en
Ref: app/com.endlessm.wiki_art.en/x86_64/eos3
ID: com.endlessm.wiki_art.en
Arch: x86_64
Branch: eos3
Origin: eos-apps
Collection ID: com.endlessm.Dev.Apps
Date: 2018-01-26 21:32:56 +0000
Subject: Export com.endlessm.wiki_art.en
Commit: 160436e78fce0a5f4576c5baa06b0492971faebccd91839d1b67dc06ece106de
Parent: fd3d1be2bcc34d2200fbc1b47857714a47270fd741c3bc677a10e0771bd04198
Location: /var/lib/flatpak/app/com.endlessm.wiki_art.en/x86_64/eos3/160436e78fce0a5f4576c5baa06b0492971faebccd91839d1b67dc06ece106de
Installed size: 13.1 MB
Runtime: com.endlessm.apps.Platform/x86_64/3
$ cat /ostree/repo/config
[core]
repo_version=1
mode=bare
add-remotes-config-dir=false
min-free-space-percent=0
[remote "eos"]
url=https://ostree.endlessm.com/ostree/eos-amd64
branches=os/eos/amd64/eos3;
xa.disable=true
[remote "flathub"]
url=https://dl.flathub.org/repo/
xa.title=Flathub
gpg-verify=true
gpg-verify-summary=true
[remote "eos-apps"]
url=https://ostree.endlessm.com/ostree/eos-apps
xa.default-branch=eos3
gpg-verify=true
gpg-verify-summary=false
xa.title=Endless Applications
collection-id=com.endlessm.Apps
[remote "eos-runtimes"]
url=https://ostree.endlessm.com/ostree/eos-amd64
gpg-verify=true
gpg-verify-summary=false
xa.title=Endless OS and Runtimes
collection-id=com.endlessm.Os
[remote "eos-sdk"]
url=https://ostree.endlessm.com/ostree/eos-sdk
gpg-verify=true
gpg-verify-summary=false
xa.title=Endless Runtime and SDK
collection-id=com.endlessm.Sdk
Running G_MESSAGES_DEBUG=all flatpak update com.endlessm.wiki_art.en:
flatpak-update-diff-collection-try2.log
$ flatpak info com.endlessm.wiki_art.en
Ref: app/com.endlessm.wiki_art.en/x86_64/eos3
ID: com.endlessm.wiki_art.en
Arch: x86_64
Branch: eos3
Origin: eos-apps
Collection ID: com.endlessm.Apps
Date: 2018-01-26 21:32:56 +0000
Subject: Export com.endlessm.wiki_art.en
Commit: 59b85f128df8a8841257f67c38b314d4a8450a8853036c53d32427795db3cb52
Parent: d7f0c3937383db6688266bebd42adc4a2a0e76ef1d26f4aa03118a16f3ee2bdc
Location: /var/lib/flatpak/app/com.endlessm.wiki_art.en/x86_64/eos3/59b85f128df8a8841257f67c38b314d4a8450a8853036c53d32427795db3cb52
Installed size: 13.1 MB
Runtime: com.endlessm.apps.Platform/x86_64/3
Activity
mwleeds commentedon Feb 22, 2018
Steps to reproduce: (sorry these aren't really possible for people outside Endless)
eos-eos3.3-amd64-amd64.180221-070058.base.isoflatpak remote-modify --collection-id=com.endlessm.Apps eos-apps; flatpak remote-modify --collection-id=com.endlessm.Sdk eos-sdk; flatpak remote-modify --collection-id=com.endlessm.Os eos-runtimespwithnall commentedon Feb 28, 2018
To be clear, I think this is an issue because an attacker could trick you into adding a remote for some shiny new app, but that remote then also serves updates to other apps which you didn’t expect.
I guess I would be happier about the collection ID changing if
flatpakerrored out if the old and new versions of the app you’re updating are signed with different GPG keys. What currently happens in that situation?mwleeds commentedon Mar 7, 2018
I think the short answer to your question is that attack is only possible when
--useris used. When the system helper is used for deployment,handle_deploycallsflatpak_dir_pull_untrusted_localwhich callsostree_repo_verify_commit_for_remoteusing the remote of the ref being updated, so that keyring is used.When
--userwas used, flatpak relies on ostree's GPG verification during the pull. In that case (and for users of ostree other than flatpak) the attack is only possible if the sketchy remote is configured with the same collection ID as the legitimate one.OstreeRepoFinderConfigonly checks remotes with the same collection ID as the ref and that remote's keyring is then used byfind_remotes_cb(and in the pull code if it makes it that far).For the similar attack vector of advertising malicious refs over LAN or USB, the answer is similar. Since
OstreeRepoFinderMountandOstreeRepoFinderAvahiboth useostree_repo_resolve_keyring_for_collection(), the only way a ref could be verified with the "wrong" keyring is if two remotes have the same collection ID, and in that case the behavior depends on the order of the remotes.So the status quo isn't great. Some options are:
cc: @alexlarsson @cgwalters
pwithnall commentedon Mar 8, 2018
Thanks for investigating.
From the sounds of it, the status quo is pretty good. As I understand it (correct me if I’m wrong), with
--userthe sketchy remote has to have the same collection ID as the existing remote for that app in order to be able to provide upgrades for an app. Without--user, the sketchy remote can have a different collection ID, but must have the same GPG key as the existing remote.To double-check, is it the case that an app can be upgraded to a version from a repository with a different collection ID if (and only if) the other repository uses the same GPG keys as the old one?
A non-starter. Configuring two remotes to have the same collection ID is part of a valid migration path for old repository configurations to new ones (the other part of that approach being to merge the repositories on the server and redirect their URIs to the same place).
I suspect that updating a ref from a commit signed with one key to a commit signed with a different key should be an error, yes, unless explicitly allowed by the user or by the old key (for example, signing a new set of GPG keys with the old key and adding them to commit metadata).
I think flatpak has a mechanism for GPG key rotation already by adding a
xa.gpg-keyskey to theostree-metadata.We possibly should do that.
ramcq commentedon Mar 8, 2018
I believe on the way to deciding on collection IDs, we discussed and rejected the idea that GPG keys should be used as a way to identify commits, on the basis that they are non distinct and can validly change over the lifetime of a repo.
A deployed Flatpak currently stores the name of the remote it came from. A locally configured remote binds together some information, such as the URL we pull from by default, a collection ID we will permit for alternative sources (essentially: match these possible mirrors) and the GPG key which must be present when we pull from that remote.
We shouldn't be looking elsewhere. I don't think we need to look at the last commit - and nor do we want to. If we've automatically changed to a new key in the repo configuration, or the user has changed it (omg old key compromised and actively expoited by hackers) then it would be incorrect to allow a signed commit with the old key, even if we have an app installed with that old key.
As long as we always enforce the locally-configured GPG key for remote, this isn't an attack vector, I don't think. I think if --user pull allows us to pick up (even if they are validly signed for /that/ remote) commits from a different remote with the same collection ID, that's a bug which should be fixed.
(So I don't believe we need to warn about clashing collection IDs in the eg GNOME Software UI for human beings, but we might want to print a warning on the command line.)
mwleeds commentedon Dec 7, 2018
Despite this issue stagnating for a while I think there is a real problem and I have an idea for a solution. The problem is that the configured remotes aren't all trusted equally, but the P2P code (
ostree_repo_find_remotes_async/ostree_repo_pull_from_remotes_async) doesn't respect this. For example if I install an app from flathub I expect the updates for it to be signed with the GPG key on the flathub remote, regardless of if there's another remote that has its collection ID set toorg.flathub.Stable(perhaps a remote controlled by a malicious actor). This set of constraints runs counter to the wayOstreeRepoFinderConfigworks.So the solution I'm proposing is to add an option that can be passed to
ostree_repo_find_remotes_async, something likeorigin-remoteortrusted-remotethat could be set toflathubfor example. ThenOstreeRepoFinderConfigwould only return that remote, and the pull code would only use the GPG keys on that remote. As I said above, I believe this will only effectively be a change in behavior for--userpulls.I haven't written the code yet, but that makes sense right?
matthiasclasen commentedon Dec 7, 2018
Why do you need to call ostree_repo_find_remotes_async when you already know that it will return flathub ?
mwleeds commentedon Dec 7, 2018
Because it may also return USB drives or LAN peers
matthiasclasen commentedon Dec 8, 2018
wait, then .. you don't know what it'll return after all. Maybe your description of the 'trusted remote' concept was just not clear enough. This trusted remote is used for
Anything else ?
mwleeds commentedon Dec 8, 2018
Yeah I think just those two. When I install something from Flathub, I expect that when it's updated, the update will be signed with the Flathub GPG keys, regardless of whether it comes from Flathub, a USB drive, or a LAN peer. Or if it's signed with a new key, that key should be in
xa.gpg-keysin a metadata object signed with the old keys. I don't expect the flathub app to be updated from remote "sketchy-remote" that also hascollection-id=org.flathub.Stableand a different set of GPG keys (or from a USB drive with commits signed with the sketchy GPG keys).So
ostree_repo_find_remotes_asyncshould return results that meet these conditions:OstreeRepoFinderResultobject representing the configured remote, if the refs are found there (in other words if we're online)OstreeRepoFinderResultobjects for any configured mirror remotes (ones with the same collection ID and GPG key)OstreeRepoFinderResultobjects representing dynamic remotes (USB/LAN), with theOstreeRemote->keyringvalue set to the keyring of the trusted remote. If the refs provided are signed with any other keyring, this should be a non-fatal error inostree_repo_pull_from_remotes_asyncmwleeds commentedon Dec 12, 2018
I discussed this with @pwithnall over email and here's the alternative fix being considered:
Make it an error to configure a remote to have the same collection ID as an existing remote (either at the time the remote is added by the user or at the time the configuration is being updated based on metadata keys) unless the GPG keys of the two remotes also match. It would also have to be an error to update the GPG keys associated with a remote in such a way that the remotes would have matching collection IDs and differing GPG keys (in case for example the old keys are compromised, a malicious actor could switch to the compromised keys, deploy the collection ID
org.flathub.Stable, and then switch back to their own keys).I think the above fix needs to be implemented because otherwise once flatpak/ostree switch to using
refs/mirrorsmore thanrefs/remotes, you would end up with issues ifrefs/mirrors/org.flathub.Stable/ostree-metadatacould be signed with GPG Key A or GPG Key B depending on which remote it was pulled from.But even with that it might make sense to implement the
trusted-remotesupport for the purpose of layered security, and in case users of libostree other than flatpak have the same model of not all remotes being equally trustworthy.mwleeds commentedon Jan 15, 2019
I made a few attempts at fixing this today but none of them panned out. Here's what I tried:
trusted-remotesoption toostree_repo_find_remotes_asyncand implementing it infind_remotes_cb. This doesn't seem like a great solution because this problem would still exist in other places likeostree_repo_finder_resolve_async.OstreeRepoFinder2which replacesostree_repo_finder_resolve_asyncwithostree_repo_finder_resolve_with_options_async(and similarly for the related functions) so that we could have an extensible optionsGVariantthat could accepttrusted-remotesbut this breaks so much internal API that it would require a significant rewrite to avoid breaking ABI. For example one of the members ofOstreeRepoFinderResultis anOstreeRepoFinderobject so I think everything that usesOstreeRepoFinderResultwould need to be changed.flatpak_dir_modify_remoteto prevent adding or modifying a remote such that its collection ID would match an existing one but its GPG key would not. The primary problem with that is that there's not necessarily a one-to-one mapping between configured remotes and keyrings (usually it's justremote_name.trustedkeys.gpgin the repo but on Endless some keyrings are in/usr/share/keyrings/instead). So there's no way to reliably check what keyring is used by an existing remote.I'm open to ideas if anyone can think of a better solution, or perhaps I should just forge ahead with the first option. Flatpak doesn't seem to use the
ostree_repo_finder_resolve_*interfaces. Perhaps the third option is viable too since there's no way to use/usr/share/keyrings/in the normal process of adding flatpak remotes.25 remaining items
dir: Fix an edge case of resolving collection-refs
dir: Use the right keyring to verify P2P pulls
lib/repo-pull: Allow the keyring remote to be overridden
dir: Fix an edge case of resolving collection-refs
dir: Use the right keyring to verify P2P pulls
dir: Fix an edge case of resolving collection-refs
dir: Use the right keyring to verify P2P pulls
dir: Fix an edge case of resolving collection-refs
dir: Use the right keyring to verify P2P pulls
dir: Fix an edge case of resolving collection-refs
dir: Use the right keyring to verify P2P pulls
dir: Fix an edge case of resolving collection-refs
dir: Use the right keyring to verify P2P pulls
dir: Use the right keyring to verify P2P pulls