このコンテンツは選択した言語では利用できません。

Chapter 20. Configure Visual Studio Code - Open Source ("Code - OSS")


Configure Visual Studio Code - Open Source ("Code - OSS") for OpenShift Dev Spaces workspaces, including multi-root project layout, trusted and default extensions, and editor settings.

20.1. Configure single and multiroot workspaces

Work with multiple project folders in the same workspace by using the multi-root workspace feature. This is useful when you are working on several related projects at once, such as product documentation and product code repositories.

By default, workspaces open in multi-root mode. After a workspace starts, the /projects/.code-workspace workspace file is generated. The workspace file contains all the projects described in the devfile.

{
	"folders": [
		{
			"name": "project-1",
			"path": "/projects/project-1"
		},
		{
			"name": "project-2",
			"path": "/projects/project-2"
		}
	]
}

If the workspace file already exists, it is updated and all missing projects are taken from the devfile. If you remove a project from the devfile, it remains in the workspace file.

You can change the default behavior and provide your own workspace file or switch to a single-root workspace.

Prerequisites

  • You have a running instance of OpenShift Dev Spaces.

Procedure

  1. Add a workspace file with the name .code-workspace to the root of your repository. After workspace creation, the Visual Studio Code - Open Source ("Code - OSS") uses the workspace file as it is.

    {
    	"folders": [
    		{
    			"name": "project-name",
    			"path": "."
    		}
    	]
    }
    Important

    Be careful when creating a workspace file. In case of errors, an empty Visual Studio Code - Open Source ("Code - OSS") opens instead. If you have several projects, the workspace file is taken from the first project. If the workspace file does not exist in the first project, a new one is created and placed in the /projects directory.

  2. Define the VSCODE_DEFAULT_WORKSPACE environment variable in your devfile with the path to an alternative workspace file.

       env:
         - name: VSCODE_DEFAULT_WORKSPACE
           value: "/projects/project-name/workspace-file"
  3. Define the VSCODE_DEFAULT_WORKSPACE environment variable and set it to / to open a workspace in single-root mode.

       env:
         - name: VSCODE_DEFAULT_WORKSPACE
           value: "/"

Verification

  • Start or restart the workspace and verify that Code - OSS opens with the expected workspace mode (single-root or multi-root).

20.2. Configure trusted extensions for Microsoft Visual Studio Code

Grant specific extensions access to OAuth authentication tokens in Microsoft Visual Studio Code by configuring the trustedExtensionAuthAccess field. This allows extensions that require access to services such as GitHub, Microsoft, or any other OAuth-enabled service to authenticate without manual intervention.

	"trustedExtensionAuthAccess": [
		"<publisher1>.<extension1>",
		"<publisher2>.<extension2>"
	]

Define the variable in the devfile or in a ConfigMap.

Warning

Use the trustedExtensionAuthAccess field with caution as it could potentially lead to security risks if misused. Give access only to trusted extensions.

Important

Since the Microsoft Visual Studio Code editor is bundled within che-code image, you can only change the product.json file when the workspace is started up.

Prerequisites

  • You have a running instance of OpenShift Dev Spaces.

Procedure

  1. Define the VSCODE_TRUSTED_EXTENSIONS environment variable in devfile.yaml:

       env:
         - name: VSCODE_TRUSTED_EXTENSIONS
           value: "<publisher1>.<extension1>,<publisher2>.<extension2>"
  2. Alternatively, mount a ConfigMap with the VSCODE_TRUSTED_EXTENSIONS environment variable. With a ConfigMap, the variable is propagated to all your workspaces and you do not need to add the variable to each devfile you are using.

    kind: ConfigMap
    apiVersion: v1
    metadata:
      name: trusted-extensions
      labels:
        controller.devfile.io/mount-to-devworkspace: 'true'
        controller.devfile.io/watch-configmap: 'true'
      annotations:
        controller.devfile.io/mount-as: env
    data:
      VSCODE_TRUSTED_EXTENSIONS: '<publisher1>.<extension1>,<publisher2>.<extension2>'

Verification

  • Start or restart the workspace and verify that the trustedExtensionAuthAccess section is added to the product.json file.

20.3. Configure default extensions

Pre-install VS Code extensions in OpenShift Dev Spaces workspaces by configuring the DEFAULT_EXTENSIONS environment variable to provide a consistent set of editor extensions on workspace startup.

After startup, the editor checks for the DEFAULT_EXTENSIONS environment variable and installs the specified extensions in the background. To specify multiple extensions, separate the paths with a semicolon.

There are three ways to embed default .vsix extensions into your workspace:

  • Add the extension binary to the source repository.
  • Use the devfile postStart event to fetch extension binaries from the network.
  • Include the extensions' .vsix binaries in the che-code image.

Prerequisites

  • You have a running OpenShift Dev Spaces instance.

Procedure

  1. Add the extension binary to the source repository.

    Adding the extension binary to the Git repository and defining the environment variable in the devfile is the easiest way to add default extensions to your workspace. If the extension.vsix file exists in the repository root, set the DEFAULT_EXTENSIONS environment variable for the tooling container in your .devfile.yaml:

    schemaVersion: 2.3.0
    metadata:
      generateName: example-project
    components:
      - name: tools
        container:
          image: quay.io/devfile/universal-developer-image:ubi8-latest
          env:
            - name: 'DEFAULT_EXTENSIONS'
              value: '/projects/example-project/extension.vsix'
  2. Use the devfile postStart event to fetch extension binaries from the network.

    Use cURL or GNU Wget to download extensions to your workspace. Specify a devfile command to download extensions and add a postStart event to run the command on workspace startup. Define the DEFAULT_EXTENSIONS environment variable in the devfile:

    schemaVersion: 2.3.0
    metadata:
      generateName: example-project
    components:
      - name: tools
        container:
          image: quay.io/devfile/universal-developer-image:ubi8-latest
          env:
            - name: DEFAULT_EXTENSIONS
              value: '/tmp/extension-1.vsix;/tmp/extension-2.vsix'
    
    commands:
      - id: add-default-extensions
        exec:
          # name of the tooling container
          component: tools
          # download several extensions using curl
          commandLine: |
            curl https://.../extension-1.vsix --location -o /tmp/extension-1.vsix
            curl https://.../extension-2.vsix --location -o /tmp/extension-2.vsix
    
    events:
      postStart:
        - add-default-extensions
    Warning

    In some cases curl may download a .gzip compressed file. This might make installing the extension impossible. To fix that, save the file as a .vsix.gz file and then decompress it with gunzip. This replaces the .vsix.gz file with an unpacked .vsix file: curl https://some-extension-url --location -o /tmp/extension.vsix.gz && gunzip /tmp/extension.vsix.gz

  3. Include the extensions .vsix binaries in the che-code image.

    Bundling extensions in the editor image and defining the DEFAULT_EXTENSIONS environment variable in a ConfigMap applies default extensions without changing the devfile.

    1. Create a directory and place your selected .vsix extensions in this directory.
    2. Create a Dockerfile with the following content:

      # inherit che-incubator/che-code:latest
      FROM quay.io/che-incubator/che-code:latest
      USER 0
      
      # copy all .vsix files to /default-extensions directory
      RUN mkdir --mode=775 /default-extensions
      COPY --chmod=755 *.vsix /default-extensions/
      
      # add instruction to the script to copy default extensions to the working container
      RUN echo "cp -r /default-extensions /checode/" >> /entrypoint-init-container.sh
    3. Build the image and then push it to a registry:

      $ docker build -t yourname/che-code:next .
      $ docker push yourname/che-code:next
    4. Add the new ConfigMap to the user’s project, define the DEFAULT_EXTENSIONS environment variable, and specify the absolute paths to the extensions. This ConfigMap sets the environment variable to all workspaces in the user’s project.

      kind: ConfigMap
      apiVersion: v1
      metadata:
        name: vscode-default-extensions
        labels:
          controller.devfile.io/mount-to-devworkspace: 'true'
          controller.devfile.io/watch-configmap: 'true'
        annotations:
          controller.devfile.io/mount-as: env
      data:
        DEFAULT_EXTENSIONS: '/checode/default-extensions/extension1.vsix;/checode/default-extensions/extension2.vsix'
    5. Open the OpenShift Dev Spaces Dashboard and navigate to the Create Workspace tab on the left side.
    6. In the Editor Selector section, expand the Use an Editor Definition dropdown and set the editor URI to yourname/che-code:next.
    7. Create a workspace by selecting a sample or entering a Git repository URL.

Verification

  • Verify that the extensions are installed in the workspace by checking the Extensions panel in the editor.

20.4. Visual Studio Code - Open Source editor configuration sections

The Visual Studio Code - Open Source ("Code - OSS") editor supports several configuration sections in a ConfigMap. Each section maps to a specific editor config file and controls a different aspect of editor behavior.

The following sections are currently supported:

settings.json
Contains various settings with which you can customize different parts of the Code - OSS editor.
extensions.json
Contains recommended extensions that are installed when a workspace is started.
product.json
Contains properties that you need to add to the editor’s product.json file. If the property already exists, its value is updated.
configurations.json

Contains properties for Code - OSS editor configuration. For example, you can use the extensions.install-from-vsix-enabled property to disable the Install from VSIX menu item in the Extensions panel.

Note

The extensions.install-from-vsix-enabled property disables only the UI action. Extensions can still be installed by using the workbench.extensions.command.installFromVSIX API command or the CLI. To block these paths as well, manage extension installation policies.

policy.json
Controls Code - OSS extension installation by using the AllowedExtensions policy and the ability to fully block extension installation.

20.5. Apply Code - OSS editor configurations with a ConfigMap

Configure the Code - OSS editor for all workspaces by defining settings, recommended extensions, and product properties in a ConfigMap. When you start a workspace, the editor reads this ConfigMap and applies the configurations to the corresponding config files.

Prerequisites

  • You have an active OpenShift Dev Spaces workspace or you are ready to start one.
  • You have an active oc session with permissions to create ConfigMaps in user projects.

Procedure

  1. Add a new ConfigMap in valid JSON format to the user’s project, define the supported sections, and specify the properties you want to add.

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: vscode-editor-configurations
      labels:
         app.kubernetes.io/part-of: che.eclipse.org
    data:
      extensions.json: |
        {
          "recommendations": [
              "dbaeumer.vscode-eslint",
              "github.vscode-pull-request-github"
          ]
        }
      settings.json: |
        {
          "window.header": "A HEADER MESSAGE",
          "window.commandCenter": false,
          "workbench.colorCustomizations": {
            "titleBar.activeBackground": "#CCA700",
            "titleBar.activeForeground": "#ffffff"
          }
        }
      product.json: |
        {
          "extensionEnabledApiProposals": {
            "ms-python.python": [
              "contribEditorContentMenu",
              "quickPickSortByLabel"
            ]
          },
          "trustedExtensionAuthAccess": [
            "<publisher1>.<extension1>",
            "<publisher2>.<extension2>"
          ]
        }
      configurations.json: |
        {
          "extensions.install-from-vsix-enabled": false
        }

    where:

    <publisher1>.<extension1>, <publisher2>.<extension2>
    The publisher and extension name pairs for extensions that are granted trusted authentication access. Use the format publisher.extensionName.
  2. Optional: To replicate the ConfigMap across all user projects while preventing user modifications, add the ConfigMap to the openshift-devspaces namespace instead of individual user projects.
  3. Start or restart your workspace.

Verification

  1. Verify that settings defined in the ConfigMap are applied using one of the following methods:

    • Use F1 Preferences: Open Remote Settings to check if the defined settings are applied.
    • Ensure that the settings from the ConfigMap are present in the /checode/remote/data/Machine/settings.json file by using the F1 File: Open File…​ command to inspect the file’s content.
  2. Verify that extensions defined in the ConfigMap are applied:

    • Go to the Extensions view (F1 View: Show Extensions) and check that the extensions are installed
    • Ensure that the extensions from the ConfigMap are present in the .code-workspace file by using the F1 File: Open File…​ command. By default, the workspace file is placed at /projects/.code-workspace.
  3. Verify that product properties defined in the ConfigMap are being added to the Visual Studio Code product.json:

    • Open a terminal, run the command cat /checode/entrypoint-logs.txt | grep -a "Node.js dir" and copy the Visual Studio Code path.
    • Press Ctrl + O, paste the copied path and open product.json file.
    • Ensure that product.json file contains all the properties defined in the ConfigMap.
  4. Verify that extensions.install-from-vsix-enabled property defined in the ConfigMap is applied to the Code - OSS editor:

    • Open the Command Palette (use F1) to check that Install from VSIX command is not present in the list of commands.
    • Use F1 Open View Extensions to open the Extensions panel, then click …​ on the view (Views and More Actions tooltip) to check that Install from VSIX action is absent in the list of actions.
    • Go to the Explorer, find a file with the vsix extension (redhat.vscode-yaml-1.17.0.vsix, for example), open menu for that file. Install from VSIX action should be absent in the menu.

20.6. Manage extension installation with a ConfigMap

Control Code - OSS extension installation by using a ConfigMap. Enforce a fine-grained allow or deny list by using the AllowedExtensions policy.

You can also block installs through the CLI, default extensions, and the workbench.extensions.command.installFromVSIX API command. The following properties are supported:

  • BlockCliExtensionsInstallation — when enabled, blocks installation of extensions through the CLI.
  • BlockDefaultExtensionsInstallation — when enabled, blocks installation of default extensions. See Section 20.3, “Configure default extensions”.
  • BlockInstallFromVSIXCommandExtensionsInstallation — when enabled, blocks installation of extensions through the workbench.extensions.command.installFromVSIX API command.
  • AllowedExtensions — provides fine-grained control over Code - OSS extension installation. When this policy is applied, already installed extensions that are not allowed are disabled and display a warning. For conceptual background, see Configure allowed extensions.

Prerequisites

  • You have administrator access to the OpenShift cluster.

Procedure

  1. Add a new ConfigMap to the openshift-devspaces namespace and specify the properties you want to add:

    kind: ConfigMap
    apiVersion: v1
    metadata:
      name: vscode-editor-configurations
      namespace: openshift-devspaces
      labels:
        app.kubernetes.io/component: workspaces-config
        app.kubernetes.io/part-of: che.eclipse.org
      annotations:
        controller.devfile.io/mount-as: subpath
        controller.devfile.io/mount-path: /checode-config
        controller.devfile.io/read-only: 'true'
    data:
      policy.json: |
        {
          "BlockCliExtensionsInstallation": true,
          "BlockDefaultExtensionsInstallation": true,
          "BlockInstallFromVSIXCommandExtensionsInstallation": true,
          "AllowedExtensions": {
              "*": true,
              "dbaeumer.vscode-eslint": false,
              "ms-python.python": false,
              "redhat": false
           }
        }
    Note

    Ensure that the ConfigMap contains data in a valid JSON format.

  2. Optional: To completely disable extension installation instead of using fine-grained control, set all extensions to disallowed:

    kind: ConfigMap
    apiVersion: v1
    metadata:
      name: vscode-editor-configurations
      namespace: openshift-devspaces
      labels:
        app.kubernetes.io/component: workspaces-config
        app.kubernetes.io/part-of: che.eclipse.org
      annotations:
        controller.devfile.io/mount-as: subpath
        controller.devfile.io/mount-path: /checode-config
        controller.devfile.io/read-only: 'true'
    data:
      policy.json: |
        {
          "AllowedExtensions": {
            "*": false
          }
        }
  3. Start or restart your workspace.
  4. Optional: Add the ConfigMap in the user’s project:

    kind: ConfigMap
    apiVersion: v1
    metadata:
      name: vscode-editor-configurations
      labels:
        controller.devfile.io/mount-to-devworkspace: 'true'
        controller.devfile.io/watch-configmap: 'true'
      annotations:
        controller.devfile.io/mount-as: subpath
        controller.devfile.io/mount-path: /checode-config
        controller.devfile.io/read-only: 'true'
    data:
      policy.json: |
        {
          "AllowedExtensions": {
              "*": false
           }
        }
    Note

    When the ConfigMap is stored in the user’s project, the user can edit its values.

Verification

  1. Verify that the BlockCliExtensionsInstallation property is applied:

    • Press F1, select Preferences: Open Settings (UI), and enter BlockCliExtensionsInstallation in search.
    • Provide a .vsix file and try CLI install. The installation fails with "Installation of extensions via CLI has been blocked by an administrator".
  2. Verify that the BlockDefaultExtensionsInstallation property is applied:

    • Check Settings for the property.
    • Configure default extensions and verify they are not installed on workspace start or restart.
  3. Verify that the BlockInstallFromVSIXCommandExtensionsInstallation property is applied:

    • Check Settings for the property.
    • The workbench.extensions.command.installFromVSIX API command is blocked.
  4. Verify that rules defined in the AllowedExtensions section are applied:

    • Check Settings extensions.allowed.
    • Disallowed extensions display a "This extension cannot be installed because it is not in the allowed list" warning.
Red Hat logoGithubredditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

Red Hat ドキュメントについて

Legal Notice

Theme

© 2026 Red Hat
トップに戻る