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

Is there a way to disable the terminal? #1937

Open
rdbeach opened this issue Aug 2, 2020 · 10 comments
Open

Is there a way to disable the terminal? #1937

rdbeach opened this issue Aug 2, 2020 · 10 comments
Labels
enhancement Some improvement that isn't a feature security Security related
Milestone

Comments

@rdbeach
Copy link
Contributor

rdbeach commented Aug 2, 2020

Hi. I was wondering if it was possible to disable the terminal. This would involve both removing from the UI and preventing terminal requests from being processed by the server. Or if you could direct me to the part of the code where terminal requests are handled, that would be helpful. I've been looking at the code for a few days now, but am finding the execution flow very difficult to follow. Thx.

@rdbeach rdbeach added the feature label Aug 2, 2020
@code-asher
Copy link
Member

There's no way to disable it at the moment so we'd need to add it.

The terminal requests are handled via the extension host protocol. The server-side implementation is in lib/vscode/src/vs/workbench/api/node/extHostTerminalService.ts so maybe we could just throw errors if those methods are called and terminals are disabled.

Terminals are used for debugging as well so doing this will also disable debugging.

In terms of the UI I think it might be better to leave everything in and show a message when trying to access the disabled functionality. Something like "terminals have been disabled" just to prevent anyone from thinking the missing terminals are a bug or something like that especially if they're familiar with VS Code already.

For the terminal we can write a message in lib/vscode/src/vs/workbench/contrib/terminal/browser/terminalInstance.ts by adding an xterm.write("message").

You might have already considered this but just in case you'll also probably need to disable installing new extensions (or whitelist extensions in some way) and make the extensions directory read-only (or restrict the file picker, see #1834) so users can't add an extension that just bypasses all this and gives them access to run commands on the system.

Depending on your goal it might be easier to run code-server in some kind of jail but I think we plan on doing this for collaboration eventually anyway (we'd disable all the "dangerous" stuff for the guests) so it wouldn't be bad to get a start on it.

@nhooyr nhooyr added security Security related enhancement Some improvement that isn't a feature and removed feature labels Dec 7, 2020
@dyegoaurelio
Copy link

Any updates?

@code-asher
Copy link
Member

code-asher commented Jan 19, 2021 via email

@jsjoeio jsjoeio added this to the Backlog milestone Apr 29, 2021
@Livven
Copy link

Livven commented Jun 11, 2021

Regarding the security aspect, also consider the VS Code tasks system, Git hooks, and probably a lot more. The attack surface here is extremely large.

@qqw78901
Copy link

Any updates?

@code-asher
Copy link
Member

code-asher commented Jul 12, 2021 via email

@laza6030
Copy link

Any update?

@code-asher
Copy link
Member

code-asher commented Dec 10, 2021 via email

@code-asher
Copy link
Member

If someone picks this up here are some investigation notes: #6138 (comment)

@malwareslayer
Copy link

In Linux you could use firejail to restrict specific you want, instead modifying parent functionality to be disabled. In my case i just let my code-server could run Java and minimal shell utility (no cat). For example:

include code-server.local
include globals.local

# Default Java
include allow-java.inc

noblacklist ${PATH}/javac

whitelist /usr/bin/java
whitelist /usr/bin/javac
# =======

include disable-common.inc
include disable-devel.inc
# include disable-exec.inc
include disable-interpreters.inc
include disable-programs.inc

whitelist ${HOME}/.config/fish/fish_variables
whitelist ${HOME}/.config/fish/completions
whitelist ${HOME}/.config/fish/conf.d
whitelist ${HOME}/.config/fish/functions/fish_greeting.fish
whitelist ${HOME}/.config/fish/functions/fish_right_prompt.fish

whitelist ${HOME}/.config/omf
whitelist ${HOME}/.local/share/omf

## Code Server User Directory
whitelist ${HOME}/.config/code-server
whitelist ${HOME}/.local/share/code-server

whitelist /usr/bin/code-server
## =======

## Default Shared
whitelist ${HOME}/Documents/Workspaces Shared
## =======

whitelist /usr/bin/cd
whitelist /usr/bin/clear
whitelist /usr/bin/basename
whitelist /usr/bin/bash
whitelist /usr/bin/date
whitelist /usr/bin/dirname
whitelist /usr/bin/echo
whitelist /usr/bin/env
whitelist /usr/bin/file
whitelist /usr/bin/fish
whitelist /usr/bin/git
whitelist /usr/bin/jobs
whitelist /usr/bin/kill
whitelist /usr/bin/ls
whitelist /usr/bin/mkdir
whitelist /usr/bin/readlink
whitelist /usr/bin/realpath
whitelist /usr/bin/sh
whitelist /usr/bin/shellfirm
whitelist /usr/bin/set
whitelist /usr/bin/stat
whitelist /usr/bin/stty
whitelist /usr/bin/test
whitelist /usr/bin/uname
whitelist /usr/bin/wc

noblacklist /sbin
noblacklist /usr/sbin
noblacklist /usr/bin
noblacklist /usr/lib

blacklist /boot
blacklist /var
blacklist /efi
blacklist /mnt
blacklist /opt
blacklist /root
blacklist /srv

caps.drop all
ipc-namespace
no3d
nodvd
nogroups
nonewprivs
noroot
nosound
notv
nou2f
novideo
seccomp

disable-mnt
private-dev
private-tmp

restrict-namespaces

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Some improvement that isn't a feature security Security related
Projects
None yet
Development

No branches or pull requests

9 participants