他のユーザーでXアプリケーションを実行する方法(vscode)

他のユーザーでXアプリケーションを実行する方法(vscode)

本質的に私が望むのは、私のホームディレクトリに対する読み取り権限を付与せずにvscodeを実行することです。

だから新しいユーザーを作成し、次からファイルをダウンロードしましたvscode.tar.gzhttps://code.visualstudio.com/#alt-downloads

それでは、次のようにログインしてcode実行しようとしています。vscode

~$ su - vscode -c "/home/vscode/code-stable-x64-1638855856/VSCode-linux-x64/bin/code --verbose"
Password: 
[8347:1214/125108.021461:ERROR:browser_main_loop.cc(1402)] Unable to open X display.
The futex facility returned an unexpected error code.
/dev/fd/3: No such file or directory
Server response:

私も内部で起動を試してみましたが、うまくいきましたが、ssh -Y vscode@localhost可能であればcodesshの使用を避けたいと思います。

ベストアンサー1

あなたはする必要があります

  1. 変数を正しく設定してください$DISPLAY
  2. ファイル~/.Xauthorityへのアクセス許可
  3. /tmp/.X11-unix共有ディレクトリ内のソケット

Xサーバーを他のクライアントと共有する場合、セキュリティの観点から見ると、これは基本的に自分のユーザーとしてプログラムを実行するのと同じです。クライアントはキーボードを観察し、スクリーンショットを撮り、キーストロークを合成することができますが、一部は驚くことはありません。 X11プロトコルのあまり使用されていない機能(テクスチャローディング?フォントローディング?)のいくつかは、リモートファイルリーダーとして乱用される可能性があります。しかし、私はX11プロトコルの専門家ではありません。

分離が非常に弱いため、とにかくホームディレクトリであるコンテナへのアクセスを制限する方法はあまり洗練されていません。

Linuxには名前空間があり、docker、kubernetes、snapなどの技術はすべてそれに依存します。あなたができることは、通常のユーザーとしてプロセスを開始し、そのプロセスにホームディレクトリなしでユーザーとファイルシステム環境の完全なビューを提供することです。

Podmanはこれらの技術の1つであり、Debian、IIRCで利用可能です。インストールはできるだけ簡単にする必要があります。

sudo apt install -y podman

これでコンテナを実行できます。

podman run -it --rm debian:sid
#       |   |   |    |
#       +--------------- Run subcommand: run a container
#           |   |    |
#           +----------- interactive, i.e., assign a virtual terminal, 
#               |    |   so you can see and type into an interactive session
#               |    |
#               +------- Remove the container after you're done - no data survives,
#                    |   if it's only in the container. Of course, things on 
#                    |   volumes specified using the -v source_path:destination
#                    |   persist, since they are "outside".
#                    |
#                    +-- name:tag is the way to specify what
#                        container you want to fetch in which version

グラフィックタスクを実行するには、上記のことを許可し、SELinuxに約束したタスクを実行していることを知らせる必要があります。

podman run -e DISPLAY=$DISPLAY \
            -v /tmp/.X11-unix:/tmp/.X11-unix:Z \
             -v ~/.Xauthority:/root/.Xauthority:Z \
              --security-opt label=type:container_runtime_t \
               -it --rm fedora:35
#           ||||
#           +---- -e INSIDE=OUTSIDE  set an env variable INSIDE inside the
#            |||     container to the value OUTSIDE
#            ||| 
#            +--- -v SOURCE:DEST[:permissions]
#             ||     SOURCE directory or file appears under DEST within
#             ||     container; :Z means that the podman-running users'
#             ||     permissions are translated to root permissions inside.
#             ||     Here, mount the host's X11 socket directory at the same place
#             ||
#             +-- -v SOURCE:DEST[:permissions] again
#              |     Here, mount the podman-running user's ~/.Xauthority
#              |     as /root/.Xauthority owned by root.
#              |     
#              +- --rm -it: see above     
[root@4da385540218 /]#

起動したコンテナの中で突然ルート以外の状態になったことを確認してください!

これで、このコンテナにvscodeをインストールし、コンテナと~/sourcecode同様にフォルダを共有し、/sourcecodevscodeのユーザーデータディレクトリとして使用できるようになりました。

podman run -e DISPLAY=$DISPLAY \
           -v /tmp/.X11-unix:/tmp/.X11-unix:Z \
           -v ~/.Xauthority:/root/.Xauthority:Z \
           --security-opt label=type:container_runtime_t \
           -v ~/sourcecode:/sourcecode:Z \
           -it --rm fedora:35
[root@4da385540218 /]#
 rpm --import https://packages.microsoft.com/keys/microsoft.asc
[root@4da385540218 /]#
 echo -e "[code]\nname=Visual Studio Code\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/vscode.repo
[root@4da385540218 /]#
 dnf --refresh update -y
[root@4da385540218 /]#
 dnf install -y code
[root@4da385540218 /]#
 code --user-data-dir /sourcecode/ --no-sandbox

おすすめ記事