Commit Graph

89 Commits (7f31a1acae8f9825ccd083cf450cf411e467fb68)

Author SHA1 Message Date
Alexander Larsson 1e854ddc11 Fix all clang warnings 2016-12-13 10:20:28 +01:00
Alexander Larsson d3715463f2 Don't export symlinks from the host into /usr and /app
These make no sense, we don't want to modify the runtime, and
we can't create parent directories there anyway which can cause
issues like https://github.com/flatpak/flatpak/pull/433
2016-12-07 19:50:14 +01:00
Alexander Larsson efc8458165 run: Record in the flatpak-info file if dbus is proxied 2016-12-07 11:31:45 +01:00
Alexander Larsson c5856dd4e5 run: Fix xauth support
We need to lseek the fd *after* the fclose has
flushed the output.
2016-12-07 11:18:27 +01:00
Mario Sanchez Prada 8193b9f282 Extra checks mounting /etc/{resolv.conf|localtime} without session helper
When no session helper is available (e.g. running flatpak run from a
socket-activated service unit), we need to be extra careful before
making these two files appear inside the sandbox. Otherwise, if they
are not reachable on the host system (or just symlinks to non-existent
targets), flatpak won't be able to create the sandbox, which will fail
due to a "No such file or directory error".

https://github.com/flatpak/flatpak/issues/409
2016-11-25 08:46:48 +01:00
Alexander Larsson cc36dbcbbf run: Allow --filesystem=foo to expose sockets
We already kind of support this by exposing the parent directory,
so this isn't really less secure, and you should not be able to
access it unless your user is allowed to anyway.
2016-11-22 11:39:58 +01:00
Alexander Larsson 60b8a0eb47 run: Make /var/run symlink relative
This lets it work during early setup phase when the new root is at
/newroot. This allows us to create things in /var/run with
e.g. --filesystem=/var/run/foo.
2016-11-22 11:37:45 +01:00
Alexander Larsson 2acb3f81a5 Special handling of accesible XDG_XYZ_HOME subdirs
If the app is explictitly given access to a subdirectory of
one of the xdg config/cache/data directories, with read-write
(or create) access, then also bind-mount that directory
into the corresponding .var/app/$APPID directory.

This allows apps that want it to keep re-using global directories
for storing per-app information.

For instance, if your app uses "~/.config/foo" to store configuration
data, then you can use --filesystem=xdg-config/foo, which will look
for the directory, and if it exist, let the app access it, as well
as mirror the content in ~/.var/app/$appid/config/foo.

You can also use a ":create" to enforce the directory to be created
and thus always do the mapping.
2016-11-14 18:58:44 +01:00
Alexander Larsson a07a146827 Allow filesystem options for xdg-[config,cache,data] for the regular xdg dirs
This means you can give access to e.g. ~/.config/dconf as --xdg-config/dconf
which then also respects XDG_CONFIG_DIR settings.
2016-11-14 18:58:44 +01:00
Alexander Larsson 2dd9b8627a Add support for --filesystem=XXX:create
This means the same as XXX:rw, but if the location doesn't exist
a directory is created there.
2016-11-14 18:58:44 +01:00
Alexander Larsson b19ea63526 By default, hide the user flatpak directory
This way you can't e.g. modify your or other applications
and runtimes. If you really need to to this, your
app can explicitly request access to this directory.
2016-11-14 18:58:44 +01:00
Alexander Larsson e1d1a29a6f run: Hide ~/.var/app (except your dir)
Unless you specifically set --filesystem=~/.var/app you will not
have any access to files from other apps
2016-11-14 18:58:44 +01:00
Alexander Larsson e32612f1c9 Handle bind-mounts of locations that are symlinks
If we're specifying --filesystem=/some/path, where the final element
in the path is a symlink we need to special case this. We used
to rely on bubblewrap resolving the symlink for the source and
creating a bind mount directly to that, but this does not work
if the parent directory is already visible in the sandbox, because
we can't bind-mount on top of the pre-existing symlink.

Instead we detect this the symlink early, resolve the target and
bind mount in that, then we create a real symlink in its place.
However, that doesn't work if the paren't *doesn't* exist, so
we have to check for this and not create the symlink if it is
already going to be visible in the sandbox.
2016-11-11 22:21:07 +01:00
Alexander Larsson e175774d35 flatpak_run_add_x11_args: Only use tmp_fd inside != -1 check 2016-11-11 10:59:00 +01:00
Alexander Larsson 041d3eeb39 Add generic static permissions to metadata
This allows you do do something like
  flatpak build-finish --add-policy=subsystem.key=v1 --add-policy=subsystem.key=v2

Which maps to this metadata keys:

[Policy subsystem]
key=v1;v2;

You can also --remove-policy to remove values from a key.

The policy values are parsed from the app and runtime metadata, and
are overridable by per-app overrides and on the command line, however
the values are never used by flatpak. They do end up in the flatpak-info
file for the running application though, so external agents can look
at them.

These
2016-10-19 20:39:17 +02:00
Alexander Larsson f9c1cc40bb run: Support running a runtime directly
This means you can do:
  flatpak run org.freedesktop.Sdk
to get a shell in a sandbox with that runtime, but with an
empty /app.

You can also specify a particular runtime branch and command like so:
  flatpak run --command=ls org.gnome.Platform//3.22 /
2016-10-19 17:33:00 +02:00
Alexander Larsson c23316cb5d Add FlatpakKinds flag and use instead of booleans 2016-10-14 11:20:53 +02:00
Alexander Larsson 972442a7b0 Don't assign unused variables 2016-10-06 12:31:54 +02:00
Adrian Perez de Castro 6cbf3b6c01 Support mixed (multilib/multiarch) binaries in Flatpaks
This adds a new "multiarch" feature which allows bundling e.g. 32-bit
binaries to be run in a x86_64 environment. By default, the seccomp
filter is configured to allow only the native architecture. When the
"multiarch" feature is enabled, the filter will be configured to allow
running binaries of additional architectures supported. For x86_64, this
allows x86 32-bit binaries; and for Aarch64, allows 32-bit ARM binaries.

Application bundles can use the feature e.g. in order to ship 32-bit
binaries alongside with a mostly-64-bit application. This is particularly
interesting when for applications that might launch themselves prebuilt
programs for which 64-bit versions do not exist. For example, the Steam
application is available as a 64-bit executable, but some of the games
available are 32-bit only. A Flatpak bundle for the Steam application
with "multiarch" enabled is able launch the 32-bit games -- without the
feature enabled, the seccomp filter would prevent them from running.

Multiple-architecture support is enabled by adding the "multiarch" value
for the "features" key in the metadata file for a Flatpak:

  [Context]
  features=multiarch;

The corresponding "--allow=multiarch" command line option is supported
in "flatpak build-finish" as well.
2016-10-03 09:54:05 +02:00
Alexander Larsson c9c35133c3 Add support for --device=kvm
Solves: https://github.com/flatpak/flatpak/issues/332
2016-09-30 16:46:51 +02:00
Alexander Larsson 636130db49 Merge pull request #299 from matthiasclasen/keyring
flatpak should close up access to kernel keyring
2016-09-21 07:12:30 +02:00
Alexander Larsson acc561c6fc Add versioning info to the appinfo file. 2016-09-19 16:33:48 +02:00
Matthias Clasen 2bfb1b435a Don't allow access to the kernel keyring
For now, we don't use the kernel keyring for anything, so it is
better to shut off the access to it.
2016-09-18 16:50:32 -04:00
Sebastian Rasmussen 135476e69a run: Print errno error code consistently
Commit 352e761c0e started the trend
to print the errno error code when unable to open a file, make all
occurrences where files are opened print the same kind of message.
2016-09-15 01:23:05 +08:00
Sebastian Rasmussen b21f4bf542 Prefer g_strerror() to strerror()
It handles encodins better, is thread-safe and more portable.
2016-09-15 01:22:54 +08:00
Alexander Larsson 968d9b1169 app-info: Fix saving of features to keyfile
This was accidentally using the devices bitmask instead
2016-09-12 11:11:50 +02:00
Alexander Larsson fba645a999 Remove unused local variables reported by clang 2016-09-12 11:11:35 +02:00
Alexander Larsson 96f383198d flatpak-info: Move the instance specific data to a separate group
We don't want to confuse whats in the metadata file with this
runtime instance info.
2016-09-08 14:10:18 +02:00
Alexander Larsson b53b78b2a2 run: Drop/Hide --no-desktop option
This is no longer needed, as we don't hard-require systemd --user.
We keep the opion there, but hidden in order to be backwards compatible
with old code that used this.
2016-09-08 11:40:49 +02:00
Alexander Larsson 7f01e5113b run: Make cgroup (and the systemd --user requirements) optional
We no longer hard-depend on this, so if it fails, we just run on.
2016-09-08 11:37:17 +02:00
Alexander Larsson 352e761c0e run: Run dbus proxy under bubblewrap
This has two advantages. First of all (and most important) it
lets us put a /.flatpak-info file in it, so that the dbus peers
it talks to have the right "source" app id and sandboxed status.

Secondly, it lets us run the bus with readonly access to things,
thus being somewhat more secure.
2016-09-08 11:21:00 +02:00
Alexander Larsson e5ff76fa77 run: Fail hard if we can't create the flatpak-info file
We want to base security on this, so we need it to be there.
2016-09-08 10:16:40 +02:00
Alexander Larsson 5bf37574f1 flatpak-info: Flatten the metadata to make it more easy to parse
The info file is always standalone, as it never needs to stack on top
of another context. This means we can remove all "negative" attributes
such as "shared=!network", making it easier to parse this file.
2016-09-07 14:32:10 +02:00
Alexander Larsson e1ad3a7a3c flatpak-info: Add application branch info
Note: This is only available in flatpak run, not flatpak build, where
this info is not available.
2016-09-07 12:31:56 +02:00
Alexander Larsson 0fc06022c8 flatpak-info: Add runtime path 2016-09-07 12:19:13 +02:00
Alexander Larsson 32c571ae79 Move $XDG_RUNTIME_DIR/flatpak-info to /.flatpak-info and make it read-only
The old location keeps working because we create a symlink.

The interesting part of this is that the sandbox now can't modify,
remove or replace the file, and it is in a fixed position. This means
that given a sandboxed pid, we can find this file as
"/proc/$pid/root/.flatpak-info".

This is very nice for two reasons:
 * We can use this instead of the cgroup to find out if a pid is
   sandboxed or not. This means we can drop the dependency on
   systemd --user for this.
 * We can get more information about the peer process that the
   app id. For instance, we can see what permissions the sandboxed
   app has.
2016-09-07 11:53:05 +02:00
Alexander Larsson 983b2a5db1 lib: Look for "bwrap" in PATH when launching from libflatpak
We forgot to look in the path, which made it fail when using
the system bwrap and not passing a full path.
2016-09-06 15:29:36 +02:00
Alexander Larsson aafc0f3b66 run/metadata: Add support for --allow=devel
This enables support for ptrace and perf for the app, similar
to what run -d manually gave you before. This is nice to be
able to package an app like gnome-software.
2016-09-05 21:41:14 +02:00
Alexander Larsson 4865d1edd2 common: Export flatpak_run_add_app_info_args
We want to use this from flatpak build too
2016-09-05 11:54:12 +02:00
Alexander Larsson 3ec0ecba93 common: add_app_info_args() talk GFile *app_files instead of a deploy
We don't really need the full deploy anyway.
2016-09-05 11:54:12 +02:00
Alexander Larsson 509bb33a2b Merge pull request #237 from mwleeds/add-trace-msg
utils: Print a debug message when launching subprocesses
2016-08-30 09:22:02 +02:00
Alexander Larsson 24c691f645 run: Mount /run/user/$uid/app/$appid in the sandbox
This directory is shared between all instances of the app, as well
as the host. In many ways this is similar to the ~/.var/app/$appid
directory, but the directory is guaranteed to not be persistent (/run
is on tmpfs), local to the host (not NFS), as well as nice support
for features like locks and mmap (due to being tmpfs).
2016-08-24 14:11:45 +02:00
Alexander Larsson 6578d37984 Drop libgsystem dependency 2016-08-22 16:00:33 +02:00
Alexander Larsson 65f1cf993d Create and use flatpak_file_get_path_cached
This is simpler that the one in libgs, as well as lockless. Also, it
removes one more use of libgs.
2016-08-22 10:22:42 +02:00
Alexander Larsson e0bd22bfe8 Add flatpak_mkdir_p helper and use it
This replaces all current callers of gs_file_ensure_directory with
equivalent code.

Actually, two instances were calling gs_file_ensure_directory with
FALSE, i.e. error out on EEXIST, but those cases seem fine with the
do-nothing-if-exists semantics.
2016-08-22 09:29:24 +02:00
Matthew Leeds 392c597c5f utils: Print a debug message when launching subprocesses
This commit makes flatpak print a debug message (which only appears to
the user if the -v option is used) whenever a subprocess is launched.
This should make debugging easier, both for flatpak users and
developers.
2016-08-05 14:15:19 -04:00
Matthias Clasen 75218c4a65 Fix license headers
We were referring to the nonexisting "version 2" of the
Lesser GPL. It should be "version 2.1".
2016-07-29 14:27:49 -04:00
Alexander Larsson 003ef9ee2e Revert "Set up logging to the journal" 2016-07-29 00:24:43 +02:00
Matthias Clasen 772d2ab562 Fix dbus logging
We were adding the --log option in the wrong spot of the dbus-proxy
commandline, causing it to a) not accept it and b) spew a warning.
2016-07-28 09:06:23 -04:00
Matthias Clasen d7da128818 Optionally redirect stdout and stderr to the journal
Arrange for stdout and stderr to be redirected to the systemd
journal, before exec'ing bwrap. This is under the control of
a pair of run flags. By default, we try to be smart and only
redirect if stderr is not a tty.
2016-07-25 10:36:00 -04:00