mirror of
https://github.com/netblue30/firejail.git
synced 2026-05-15 14:16:14 -06:00
[GH-ISSUE #1988] Profile option to access files in CLI arguments #1339
Labels
No labels
LTS merge
LTS merge
bug
bug
converted-to-discussion
doc-todo
documentation
duplicate
enhancement
file-transfer
firecfg
firejail-in-firejail
firetools
graphics
help wanted
information_old
installation
invalid
modif
moved
needinfo
networking
notabug
notourbug
old-version
overlayfs
packaging
profile-request
pull-request
question
question_old
removal
runtime-permissions
sandbox-ipc
security
stale
wiki
wiki
wontfix
wordpress
workaround
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/firejail#1339
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @nikolay-turpitko on GitHub (Jun 11, 2018).
Original GitHub issue: https://github.com/netblue30/firejail/issues/1988
Please add (or suggest if can be achieved with existing features) an option to enable in the profile config an access to the all files, listed in the command's CLI arguments. For example, i use such programs as
Midnight Commanderandmutt, which are configured to invoke certain commands to preview files (pdftotext,lynx, ...). Those commands are sandboxed and have no access to files they are invoked with. Say,lynxcan be invoked with temporary file in the/tmp, or with file in the/homedir as an argument:It's perfectly OK to give it access to any file, provided as it's command line argument. I assume, that I tell it explicit enough that I want it to be able to access this file. It's not desirable to give command access to all other files in the
/homedirectory via profile, if they are not listed on the command line. It's not desirable to whitelist this file viafirejailCLI argument, because I'll need to change config of every tool so that every tool be aware aboutfirejail. I mean, I'll need to change configs ofmc,mutt,vfmand whatever tool I may use to invoke those sandboxed programs.What I'd prefer is to put some option in my custom firejail config, to say it what I want to do with files on the command line. Something like:
cli-args: no-blacklist,read-only,cli-args: whitelist,cli-args: mkfile(copy), or other way around - add special notation forcli-argsto be added to existing options. Like:read-only: <cli-args>.@chiraag-nataraj commented on GitHub (Jun 11, 2018):
So...I know this doesn't already exist (I'll mark it as an enhancement), but here's what I currently do to get around this.
/tmp/user/1000/, this doesn't break and emacsclient is so well protected it's basically a non-issue.@nikolay-turpitko commented on GitHub (Jun 11, 2018):
@chiraag-nataraj
Thanks for your detailed replay, but I'm not sure if I can apply it to my cases.
OK, let's leave
muttaside, it works mostly with/tmpdir and I can just allow access to it for some tools likelynxandpdftotext.My other use case, which I don't know how to solve properly, is
mc(midnight commander, it's a console file manager). I am not sandboxingmc, of course, I need it have access to whatever file in the system.mchas plugable viewers, it can invoke any tool, registered for file type, when I pressF3to preview the file. For example, for pdf files it invokespdftotext, which has default firejail profile, installed with Debian package. Which is cool. And normally I don't wan'tpdftotexthas access to any other file, except one I passed to it via command line. The thing is, I may want to preview any file in any directory usingmc. For example, I may haveProjectsdir, which I especially want to protect from incident corruption, and I'm glad firejail can blacklist it for many programs. I don't want to open this dir to any tool by default. At the same time, I heavily usemcfor development and like to preview some files in theProjectsdir. In case when I hitF3on the file I want the tool have access to the file. Mostly I want a viewer has read-only access. Probably, there could be cases, when I may want to give write access, though I haven't encountered such cases yet. So, the point is,pdftotextshould not have access to theProjectsdir. It should have an access only to that one file I give it via argument. It'd be very inconvenient to invoke something likefirejail --noblacklist=/my.pdf pdftotext /my.pdfbecause settings are not in one place.mchas it's own script, where some file types are specified, some files it doesn't know it delegates toxdg-open, other file types may end up in the.mailcapetc. Moreover, I'd like those settings, specific tofirejailwere encapsulated in firejail profiles, not scattered all over other dotfiles. So that I could reuse them with or withoutfirejailinstalled, for example.So, in this case I cannot automatically copy file into known shared dir, like
/tmp(or can I?), and don't see how to use cron/systemd to whitelist file, because I cannot predict when I may need which one. Copying file may be doable, I'll check ifmchas some option for it. Though I don't much like the idea to even temporary copy my precious private files into some other dir.@chiraag-nataraj commented on GitHub (Jun 11, 2018):
So in this case, I would do option (2) from my list above. Create a handler script which invokes firejail with the appropriate arguments. This way, you can have all programs use that script and can easily toggle whether firejail is invoked without the other programs knowing anything.
For example, I have a script called
fxin~/scripts. The main reason I do this is that I dynamically generate theprivate-liblist (since the default seems to be broken?) and I want to usesystemd-runto ensure it's run as its own (transient) unit. I could setfxto be used for all web browsing stuff (includingxdg-openetc), which would mean that if I wanted to toggle using firejail, I just edit the script. This way, it's as centralized as you would like (firejail use is controlled by one script) and you can do whatever whitelisting you want within the script while keeping it completely transparent to other programs. I use my script (fx) as the URL handler inurxvt, for example.urxvthas absolutely no idea that the script is usingsystemd-runor that I'm invokingfirejail. All it knows is that it invokes the scriptfxwith the URL argument, andfxtakes care of the rest.@nikolay-turpitko commented on GitHub (Jun 11, 2018):
Hmm... Can I invoke some script from within firejail profile then? I don't want
mcbe aware even about my own script. It has a bunch of it's own scripts for many file types, supported by the community. I don't want to mangle them. They can be updated with package manager, for example. Also, there can be a lot individual commands to change. Though, I think I understood your idea, thanks. I'll see if I can do something like that. But if firejail profile allows some dynamic, it can be helpful too. And my first idea about profile option for cli arguments - please consider it too.@chiraag-nataraj commented on GitHub (Jun 11, 2018):
But whatever the defaults are, you should be able to override it in a per-user configuration, in which case the system defaults don't matter (such defaults exist for
urxvt, for example). And yes, you can invoke scripts from within firejail, but then you'd need to configuremcto be aware offirejail, which goes against the whole point!If I understood correctly, you were asking for a way to be able to set up firejail with other programs not knowing (basically, a
firejail-agnostic setup). That is certainly possble right now, either throughfirecfg(but note that you can't pass additional arguments tofirejailthat way) or through a custom script. Since you can't pass additional arguments tofirejailwhen you usefirecfg, I suggested the script approach.Looking at the
mcman page, I see that you can set up your per-user per-extension defaults in~/.config/mc/mc.ext(see the man page for more info as to the format, etc). This means you basically need to add a line of the type:(note the leading space on the second line...I think that's how this works, at least after a cursory glance at the man page). You can get the mimetype by using
file /path/to/example/file(I presume there's also something inmcthat tells you the mimetype). What you're asking for is eminently doable, at least formc, without touching global configuration (so system-wide defaults can be updated as usual and you don't have to care). Same goes forxdg-open- I believe you should be able to set stuff usingxdg-settings, but I don't really use it, so YMMV.Also, if you don't want your firejail scripts cluttering up the rest of your scripts, you can put them somewhere outside the normal path (e.g.
~/.config/firejail/scripts/), which, as a bonus, means programs running underfirejailwon't be able to access them (if you want them accessible, you should put them somewhere else...a good place might be~/.firejail/).I wonder what @netblue30 thinks of this proposal.
@nikolay-turpitko commented on GitHub (Jun 21, 2018):
@chiraag-nataraj
@netblue30
OK, I'm closing this issue. I solved my particular case by other means, but I still think, that feature I suggested in the initial post might be useful, it's up to you to decide if it worth to be implemented and in which form. I think you've got notifications, so there is no need to keep this issue opened.
For those who will face the same problem and might be interested in the solution: I think solution, suggested by chiraag-nataraj (proxy script) might work, but it's a bit more complicated to support, then I'm willing to invest into such thing (though, I may return to it later). Meantime I just whitelisted (in my custom profile) directories I'm using more frequently and will see if it's enough for me.
@chiraag-nataraj Thank you for your efforts and shared ideas. Also, you mentioned that it's possible to invoke scripts from firejail profile to dynamically adjust it (at least it was what I asked about and you answered that it's possible). Could you please point me to the documentation or source code for the feature? I'll see if I can use it in this or other use cases. Thanks.
@chiraag-nataraj commented on GitHub (Jun 25, 2018):
@nikolay-turpitko I probably misunderstood you. At this time, afaik, it's not possible to run scripts from within the firejail profile to dynamically adjust it. But, you can run a script within firejail (
firejail /path/to/script.sh) or run firejail from within a script, which is what I think I thought you meant 😜 Sorry for the confusion.