53 Commits

Author SHA1 Message Date
Philip Withnall
9758968cc4 dir: Support filtering app installs/upgrades by user’s OARS settings
Use the user’s OARS filter to prevent installation or upgrade of
apps which have more extreme content than the user is allowed to see.

This uses libmalcontent to load the user’s enforced OARS filter, which
describes the extremeness of each type of content the user is allowed to
see. If an app they are trying to install exceeds the filter value in
any OARS section, installation is disallowed and an error is returned.

libmalcontent stores the parental controls policy per-user in
accountsservice, which enforces access control on the policies.

The app filter is also allowed to prevent app installation entirely,
which overrides the OARS values. This is independent from the app-install
polkit action, which determines whether an unprivileged user may install
an app system-wide. Being stored in accountsservice, the new boolean is
also easier to set per-user without having to programmatically write a
polkit JS policy file which handles multiple users (and parse it back
again).

The parental controls checks are done at deploy time, either in the
`flatpak` process (for user repositories) or in the
`flatpak-system-helper` (for system repositories). The checks use
content rating data extracted from the app’s AppData XML and stored in
the `FlatpakDeploy` cache. The checks are passed through polkit (even
for user repositories) so that users can get an admin override to
install apps which would otherwise be too extreme. This uses the new
`org.freedesktop.Flatpak.parental-controls` polkit rule.

The checks have to be done at deploy time, as that’s when the AppData
XML for the app is parsed. The downside of this arrangement is that an
app must be entirely downloaded before the parental checks can be done.
This won’t be much of an issue on normal desktops, however, since we can
assume that gnome-software will check an app’s appropriateness before
showing it to the user in the first place.

Parental controls are not enforced for non-apps/runtimes, which includes
the ostree-metadata and appstream/* refs.

One thorny issue is that flatpak unit tests may be run in an environment
with no system D-Bus available to connect to (a Jenkins instance, for
example), which means the call to `mct_manager_get_app_filter()` in
`flatpak_dir_check_parental_controls()` fails.

So this commit skips the parental controls check if the system bus is
unavailable and the environment variable
`FLATPAK_SYSTEM_HELPER_ON_SESSION` is set, since the testlibrary already
sets that variable so that the system-helper will be started on the
session bus.

The feature can be tested using something like:
```
   $ malcontent-client set philip \
       violence-realistic=none app/org.freedesktop.Bustle/x86_64/stable
   App filter for user 1000 set
   $ flatpak run org.freedesktop.Bustle
   error: Running app/org.freedesktop.Bustle/x86_64/stable is not allowed by the policy set by your administrator
   $ flatpak --user install flathub io.github.FreeDM
   error: Failed to install io.github.FreeDM: Installing app/io.github.FreeDM/x86_64/stable is not allowed by the policy set by your administrator
```

Includes work by André Magalhães and Umang Jain.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-10-03 10:42:04 +02:00
Philip Withnall
ab5c0968e6 flatpak-run: Add parental controls support for filtering apps
Prevent the user from running a flatpak app if that app is filtered by
the parental controls applied to the user.

If flatpak is running as a system user (UID < 1000), ignore failure to
load the app filter. This could happen if a flatpak is run in the
gnome-initial-setup session, before the user’s account is created.

Includes contributions by André Magalhães.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

https://github.com/flatpak/flatpak/pull/2797
2019-10-03 10:42:04 +02:00
Philip Withnall
c16d6f9166 common: Split LIBADD onto multiple lines and sort alphabetically
Also sort CFLAGS alphabetically. This will reduce the likelihood of
merge conflicts in future. This assumes the libraries and CFLAGS are
independent of each other.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-10-03 10:42:04 +02:00
Debarshi Ray
e82efa8603 Trim unused shared library linkages from the session helper
The org.freedesktop.Flatpak user D-Bus service isn't just used by
flatpak(1) or applications running as Flatpaks. It's also used by
toolbox(1) for similar reasons:
 * To keep various configuration files inside the container
   synchronized with the host
 * To let the container request certain commands to be run on the host

The org.freedesktop.Flatpak D-Bus service itself doesn't need much in
the way of dependencies, but inherits a lot of unused shared library
linkages through the libflatpak-common.la convenience library. Removing
these unused shared libraries reduces the footprint of toolbox(1) for
those who care about such things. eg., Fedora CoreOS.

This commit brings down the number of shared libraries to 19 from 62.

Closes: #3052
Approved by: alexlarsson
2019-08-16 09:13:43 +00:00
Debarshi Ray
cde7934041 build: Link against libxml only when necessary
The libxml API is used in a relatively few places inside the 'common'
sub-directory. It's definitely not as widespread as GLib. A subsequent
commit will leverage this to prevent unused shared libraries from
being linked to the session helper.

Closes: #3052
Approved by: alexlarsson
2019-08-16 09:13:43 +00:00
Debarshi Ray
ebf5d08f47 build: Link against libarchive only when necessary
The libarchive API is used in a relatively few places inside the
'common' sub-directory. It's definitely not as widespread as GLib. A
subsequent commit will leverage this to prevent unused shared
libraries from being linked to the session helper.

Closes: #3052
Approved by: alexlarsson
2019-08-16 09:13:43 +00:00
Alexander Larsson
42e42ddc86 Pick up the right revokefs-fuse binary
In the normal case, pass the full LIBEXEC path, and in the tests,
pass the path via the env var FLATPAK_REVOKEFS_FUSE.

Closes: #2657
Approved by: alexlarsson
2019-04-09 09:18:15 +00:00
Matthias Clasen
f2303ee4c5 Export dconf data
We want to move away from using dconf inside the sandbox,
and instead use the keyfile backend for GSettings, which
has gained the capability to read defaults and locks.

This change makes the dconf database contents and locks
available in a suitable format. The files appear inside
the sandbox in the /etc/glib-2.0/settings directory.

We only export the default values for keys in the dconf
subtree whose path matches the app id, as well as prefixes
listed in paths key from the X-DConf group in metadata.

This commit adds a new dependency, since we're now linking
against libdconf.

Closes: #2295
Approved by: alexlarsson
2019-01-14 15:34:11 +00:00
Matthias Clasen
f9c6a769ef Stop linking libflatpak against listappstream-glib
We no longer use it here. flatpak itself still links
against it. This avoids problems with consumers who
might also link against libappstream.

Closes: #2580
Approved by: alexlarsson
2019-01-14 15:06:41 +00:00
Matthias Clasen
728f917418 Move appdata parsing to its own file
This is just moving some code around for now.
It is still using libappstream-glib.

Closes: #2580
Approved by: alexlarsson
2019-01-14 15:06:41 +00:00
Alexander Larsson
03732121db Make sure we dist flatpak-instance-private.h 2018-11-16 14:34:15 +01:00
Philip Withnall
4a1c11dba9 dir: Factor out code to load AppStream cache for a remote
This is currently only used in the ‘search’ built-in command, but will
need to be used in upcoming parental controls filtering changes in
Endless OS (which will go upstream eventually) too.

This introduces no functional changes.

The CFLAGS/LIBADD changes are necessary because of the new
AppStream #includes.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Closes: #2296
Approved by: matthiasclasen
2018-11-12 13:13:09 +00:00
Matthias Clasen
c672c55154 dir: Add logging
Write to the systemd journal for basic operations
that modify installations, such as pull, deploy,
uninstall.  Include some useful information as
separate fields, such as OPERATION, INSTALLATION,
REMOTE, REF, COMMIT.

We add the logging in the api layer that is used
by the system-helper as well, so that changes
from that side are logged as well.

All logs we write currently use the same message
ID, defined as FLATPAK_MESSAGE_ID in the headers,
for easy retrieval of messages.
2018-10-11 14:51:51 +02:00
Matthias Clasen
dd546ad365 Make FlatpakInstance api public
This can be of use in frontends like GNOME Software.

Closes: #2201
Approved by: alexlarsson
2018-10-08 08:36:23 +00:00
Matthias Clasen
336f887289 Add an instance api
This is made to let gnome-software enumerate all
running instances and get the same information
about them that flatpak ps provides.

For now, we keep it private. It will become library
api once we open new development
2018-09-03 11:54:19 -04:00
Owen W. Taylor
cd6a10cb66 flatpak-utils-http.c: Split HTTP functionality into a separate file
In preparation for extending the HTTP downloading function to include
caching, split HTTP related utilities into a separate file with a
separate header.

Closes: #1910
Approved by: alexlarsson
2018-08-09 12:49:35 +00:00
Matthew Leeds
516c0f40b6 common: Update flatpakinclude_HEADERS
These headers were recently added to flatpak.h, so they need to be in
flatpakinclude_HEADERS so they are installed.
2018-05-31 08:33:30 +02:00
Alexander Larsson
d2e419418b transaction: Change from installation_create_transaction() to transaction_new_for_installation()
This way is nicer because then the user can derive from FlatpakTransaction
2018-05-29 16:37:21 +02:00
Alexander Larsson
be6cea486c Transaction: Split out constructor into private header 2018-05-29 16:37:21 +02:00
Alexander Larsson
10dc876323 Transaction Move code to common/ 2018-05-29 16:37:21 +02:00
Alexander Larsson
3cf77f3aa9 GI: Include the right sources when building introspection
We forgot to include the sources. Also, we rename the valgrind header
to -private to avoid gtk-doc blowing its mind trying to parse it.

Closes: #1729
Approved by: alexlarsson
2018-05-29 07:53:48 +00:00
Alexander Larsson
e2972f49b9 tests: Disable F_ADD_SEALS when running under valgrind
As per https://bugs.kde.org/show_bug.cgi?id=361770, this is not supported
by valgrind. We just don't seal the fds when debugging, this won't
affect anything at runtime in the normal case.

Closes: #1720
Approved by: alexlarsson
2018-05-28 10:59:51 +00:00
Alexander Larsson
efb92704fe Merge lib/* into common
This moves all the files from lib into common, and it also adds all the libflatpak
sources into libflatpak-common, making libflatpak just a wrapper around the common
helper library.

This move allows the CLI to use all the code from libflatpak. We were already doing
this with a few things like flatpak-error*.[ch], and we want to do it even more
when sharing FlatpakTransaction. This also allows use to slowly move
the CLI to using the libflatpak apis for some things.

Closes: #1706
Approved by: alexlarsson
2018-05-24 11:59:52 +00:00
Alexander Larsson
c570e09ac9 common: Rename all generated files to *-dbus-generated.[ch]
Easier to spot them this way

Closes: #1706
Approved by: alexlarsson
2018-05-24 11:59:52 +00:00
Alexander Larsson
7c17e77e84 Move FlatpakTablePrinter to app/
This is only used by the CLI

Closes: #1706
Approved by: alexlarsson
2018-05-24 11:59:52 +00:00
Alexander Larsson
960d20448c common: Rename all private headers to *-private.h
This is the start of the merging of lib/* into common/*

Closes: #1706
Approved by: alexlarsson
2018-05-24 11:59:52 +00:00
Alexander Larsson
442c0be116 common: Move flatpak-portal-error.[ch] back to common code
A symbol from this (flatpak_portal_error_quark) was leaked to libflatpak
due to being marked FLATPAK_EXTERN, so to keep ABI we move it back.

Fixes https://github.com/flatpak/flatpak/issues/1613

Closes: #1616
Approved by: alexlarsson
2018-04-26 07:41:17 +00:00
Alexander Larsson
11ef9999b6 Add flatpak portal
This listens to org.freedesktop.portal.Flatpak and lets flatpak
sandboxes do flatpak specific things.

Initially this only allows access to "Spawn", which lets you start a
new copy of the current or latest version of the calling app,
optionally with sandboxing.

This allows the app to re-start itself with the latest version after
an update, and the sandboxing is useful for apps that want to manually
sandbox part of themselves.

You can also expose one or more subdirectories of
~/.var/app/$appid/sandbox/ to the app, read-write or read-only. This is
useful to communicate with the sandbox.
2018-04-04 17:25:59 +02:00
Alexander Larsson
f2a6c1db8d Remove document portal
This is now in xdg-desktop-portal. We keep a version of the document
portal dbus XML so that we avoid weird build dependencies.

Flatpak itself is technically not dependent on the document portal,
but it is very much recommended that you use it.

Closes: #1398
Approved by: alexlarsson
2018-02-09 09:23:26 +00:00
Alexander Larsson
1230ee85cc Move FlatpakExport to its own file
This is pure code motion

Closes: #1374
Approved by: alexlarsson
2018-02-05 14:31:30 +00:00
Alexander Larsson
8ef735369d Break out FlatpakBwrap to its own file
This is pure code motion

Closes: #1374
Approved by: alexlarsson
2018-02-05 14:31:30 +00:00
Alexander Larsson
447a8d0537 Extract FlatpakContext to a separate file
This is basically a code motion only, no changes to behaviour.

Closes: #1374
Approved by: alexlarsson
2018-02-05 14:31:30 +00:00
Philip Withnall
f47a696392 build: Add AM_* variables to all per-target special variables
For example, add $(AM_CFLAGS) to mumble_CFLAGS. Since $(WARN_CFLAGS) is
only added to $(AM_CFLAGS), this fixes the lack of inclusion of the
compiler warning flags in the compilation of half of flatpak.

Note that $(AM_*) variables are only used by automake if a more specific
(per-target) special variable is not defined instead. So if you define
mumble_CFLAGS, AM_CFLAGS will not be used for that target unless
explicitly included in mumble_CFLAGS.

See
https://www.gnu.org/software/automake/manual/html_node/Flag-Variables-Ordering.html.

Do the same for $(AM_LIBADD), $(AM_LDFLAGS), etc. These are not
currently defined, but it’s good practice to include them in
mumble_LIBADD (etc.) just in case they’re defined in future. Hopefully
their inclusions will be cargo-culted to any new targets which are
added, retaining full coverage of the code base.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2017-07-06 15:05:58 +01:00
Simon McVittie
8e03e7b719 build: Re-run gdbus-codegen if the Makefile changes
Changes to the Makefile could include changes to the options passed
to gdbus-codegen, which would invalidate the output.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2017-06-30 21:21:06 +02:00
Simon McVittie
f4c4abfb1e build: Only run each instance of gdbus-codegen once
A rule of the form

    foo.c foo.h: foo.in
        some-generator --output=foo foo.in

is essentially equivalent to writing the same rule once for each target:

    foo.c: foo.in
        some-generator --output=foo foo.in
    foo.h: foo.in
        some-generator --output=foo foo.in

In a parallel build, this can result in some-generator being run more
than once with the same inputs and outputs, leading to unpredictable
results if the outputs are overwritten in-place by two parallel copies
(particularly if the generator does not use the standard atomic-writing
trick of writing out a temporary file and renaming it over the top of
the intended name, which gdbus-codegen does not).

gdbus-codegen happens to write the .h file before the .c file, so
use the real build rules to generate the .c file, and consider the
.h file to be a side-effect.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2017-06-30 21:21:06 +02:00
Simon McVittie
f71167e7ec One more try at not distributing gdbus-codegen-generated sources
Signed-off-by: Simon McVittie <smcv@debian.org>
2017-06-21 16:08:37 +02:00
Matthias Clasen
75b84b4bfe Include the generated document portal code in common
Move the sources from app/ to common/. We will use this
code from common/ in subsequent commits.
2017-05-03 13:27:52 +02:00
Matthias Clasen
62b8ae2953 table printer: move to its own source files
This is a pretty standalone object, and it is nicer to
have it in its own files. All users have been updated
to include the new flatpak-table-printer.h header.
2017-05-02 14:56:04 +02:00
Alexander Larsson
ea803f1f80 OCI: Add flatpak_oci_sign_data 2017-03-29 17:14:36 +02:00
Alexander Larsson
63c1aace83 Import OCI initial support to common/* 2016-12-08 17:43:03 +01:00
Alexander Larsson
b744cd2493 Add backport of g_autoptr support for json-glib 2016-11-29 10:14:33 +01:00
Ismo Puustinen
2d26a7d0a6 Create directories before attempting to generate code into them
If flatpak is built from a separate build directory, code generation
fails because the directory structure is not in place. Create the
necessary directories before code generation.
2016-08-26 12:36:35 +03:00
Simon McVittie
c18626f11c common: don't distribute generated GDBus files in tarballs
Signed-off-by: Simon McVittie <smcv@debian.org>
2016-06-12 10:35:13 +01:00
Alexander Larsson
8abbc0186e Rename everything but the on-disk location to flatpak 2016-05-09 11:11:55 +02:00
Alexander Larsson
ba37b22d78 Rename library to libflatpak 2016-05-09 09:46:26 +02:00
Alexander Larsson
c24528d369 Rename source files to flatpak 2016-05-09 09:00:20 +02:00
Alexander Larsson
f55bb0edc9 Remove xdg-app-helper 2016-04-29 15:52:47 +02:00
Alexander Larsson
4c3bf179e2 Use bubblewrap instead of xdg-app-helper
Bubblewrap is a new tool from project atomic. Its similar to the old
xdg-app-helper, but even more minimal, and a bit more generic. Its designed
to be easy to git submodule install, but at some point we will probably
support using the system installed version too.

Using bubblewraps lets us share the load of security mainainance and
allows other people to use bubblewrap to do their own unprivileged
sandboxes.
2016-04-29 15:52:44 +02:00
Simon McVittie
73b0adfe0a Hide non-public symbols from libglnx and libxdgapp-common
This avoids exporting glnx_*, calc_sizes(), etc. However, we do want to
export xdg_app_error_quark(), so do that.

Signed-off-by: Simon McVittie <smcv@debian.org>
2016-01-28 23:43:30 +01:00
Alexander Larsson
6349b3ffc1 helper: Make user namespace support vs setuid a runtime, not build-time option
We now check at runtime if we have raised privs, and only if not so do we try
to use unprivileged user namespaces. This means you can build xdg-app however,
and then setuid/setcap the binary however you want afterwards.
2016-01-28 09:43:45 +01:00