Skip to content

Allow user setttings to persist on server (and/or browser local storage) #6546

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

Closed
bilogic opened this issue Nov 23, 2023 · 28 comments
Closed
Assignees
Labels
enhancement Some improvement that isn't a feature

Comments

@bilogic
Copy link
Contributor

bilogic commented Nov 23, 2023

Continued from #3061 (comment)

This involves whether to remove the patch where user settings are persisted on the server

Use case

  1. Our developers store their individualized user settings on the server, and this gives the same settings even on new machines
  2. Then, there are "company" defaults stored in Machine.json, e.g. debugger ports, allocated by the "company" and these can vary between developers and not supposed to be modified in any way (I have a script that overwrites them regularly)
  3. I use workspace to store project settings, they contain minimal settings, mainly folder paths settings
  4. So, what is broken now for me is 1, where developers have to "memorize" their changes, and redo them when faced with a new machine

Proposed behavior A

  1. Load settings from browser
    • can be individualized, use case: developer personal preferences, can't sync across machines
  2. Overwrite with user settings on server
    • can be individualized, use case: developer personal preferences, sync across machines
  3. Overwrite with machine settings on server
    • can be individualized, use case: developer devops settings
  4. Overwrite with workspace settings on server
    • can't be individualized as it is commited to git
  5. Overwrite with folder settings on server
    • can't be individualized as it is commited to git
@bilogic bilogic added the enhancement Some improvement that isn't a feature label Nov 23, 2023
@bilogic
Copy link
Contributor Author

bilogic commented Nov 23, 2023

In response to the comments after #3061 (comment)

  1. Why do we need code-server if it is going to work the same as vscode.dev/Codespaces?
    • Because code-server upgrades the VSCode from microsoft, e.g. providing a login screen etc
  2. A laptop/browser is also not the best place to be storing data, it is not ideal for business continuity (backup/device loss etc)
  3. I have been telling colleagues/friends about how I can lose my laptop and still continue from where I was in minutes
  4. vscode.dev have to persist to browser because the user does not have to login, otherwise their servers would have to store unattributable data indefinitely
  5. That said, I know we can still persist to the server, but it is now all lumped together user + machine, which breaks permission controls etc
  6. I think proposal A works as a way forward, alternatively, I can think of proposal B, an idea stemming from the login screen
  7. Proposal B: we can add an entry in config.yaml to define where user settings should persist: local/server

What do you guys think?

@bilogic bilogic changed the title Allow user setttings to persist on server (and browser local storage) Allow user setttings to persist on server (and/or browser local storage) Nov 23, 2023
@benz0li
Copy link
Contributor

benz0li commented Nov 23, 2023

@spkane Regarding

/home/user/.local/share/code-server/User which contains various settings, including things like:

{
  "security.workspace.trust.enabled": false
}

which I am pretty confident are not allowed to be set by any settings layer besides the User one.

Correct. The 'Workspace Trust' feature can only be disabled in 'User Settings' – the same applies to telemetry settings.
👉 Instead, use option --disable-workspace-trust when starting code-server.

What are the reasons for disabling such a security feature by default? (Should the 'local storage' patch be removed, I might do so as well; I run code-server isolated in a container).


code-server --help
Usage: code-server [options] [path]
    - Opening a directory: code-server ./path/to/your/project
    - Opening a saved workspace: code-server ./path/to/your/project.code-workspace

Options
      --auth                             The type of authentication to use. [password, none]
      --password                         The password for password authentication (can only be passed in via $PASSWORD or the config file).
      --hashed-password                  The password hashed with argon2 for password authentication (can only be passed in via $HASHED_PASSWORD or the config file).
                                         Takes precedence over 'password'.
      --cert                             Path to certificate. A self signed certificate is generated if none is provided.
      --cert-host                        Hostname to use when generating a self signed certificate.
      --cert-key                         Path to certificate key when using non-generated cert.
      --disable-telemetry                Disable telemetry.
      --disable-update-check             Disable update check. Without this flag, code-server checks every 6 hours against the latest github release and
                                         then notifies you once every week that a new release is available.
      --disable-file-downloads           Disable file downloads from Code. This can also be set with CS_DISABLE_FILE_DOWNLOADS set to 'true' or '1'.
      --disable-workspace-trust          Disable Workspace Trust feature. This switch only affects the current session.
      --disable-getting-started-override Disable the coder/coder override in the Help: Getting Started page.
      --disable-proxy                    Disable domain and path proxy routes.
   -h --help                             Show this output.
      --locale                           Set vscode display language and language to show on the login page, more info see
                                         https://en.wikipedia.org/wiki/IETF_language_tag
      --open                             Open in browser on startup. Does not work remotely.
      --bind-addr                        Address to bind to in host:port. You can also use $PORT to override the port.
      --config                           Path to yaml config file. Every flag maps directly to a key in the config file.
      --socket                           Path to a socket (bind-addr will be ignored).
      --socket-mode                      File mode of the socket.
      --trusted-origins                  Disables authenticate origin check for trusted origin. Useful if not able to access reverse proxy configuration.
   -v --version                          Display version information.
      --user-data-dir                    Path to the user data directory.
      --extensions-dir                   Path to the extensions directory.
      --list-extensions                  List installed VS Code extensions.
      --force                            Avoid prompts when installing VS Code extensions.
      --install-extension                Install or update a VS Code extension by id or vsix. The identifier of an extension is `${publisher}.${name}`.
                                         To install a specific version provide `@${version}`. For example: '[email protected]'.
      --enable-proposed-api              Enable proposed API features for extensions. Can receive one or more extension IDs to enable individually.
      --uninstall-extension              Uninstall a VS Code extension by id.
      --show-versions                    Show VS Code extension versions.
      --github-auth                      GitHub authentication token (can only be passed in via $GITHUB_TOKEN or the config file).
      --proxy-domain                     Domain used for proxying ports.
   -e --ignore-last-opened               Ignore the last opened directory or workspace in favor of an empty window.
   -n --new-window                       Force to open a new window.
   -r --reuse-window                     Force to open a file or folder in an already opened window.
 -vvv --verbose                          Enable verbose logging.
  -an --app-name                         The name to use in branding. Will be shown in titlebar and welcome message
   -w --welcome-text                     Text to show on login page

@benz0li
Copy link
Contributor

benz0li commented Nov 23, 2023

@bilogic My feedback about your use case:

  1. Then, there are "company" defaults stored in Machine.json [...] not supposed to be modified in any way (I have a script that overwrites them regularly)

Frankly, this [a script that overwrites them regularly] is bad practise.

@benz0li
Copy link
Contributor

benz0li commented Nov 23, 2023

@bilogic About your proposed behavior A:

  1. Overwrite with user settings on server

    • can be individualized, use case: developer personal preferences, sync across machines

My response:

IMHO not going to happen; Reverted by 09dd5fe
👉 Same behaviour as Codespaces now. Use 'Remote settings' (Machine settings) instead.

#3061 (comment)

@benz0li
Copy link
Contributor

benz0li commented Nov 23, 2023

@bilogic What do I think?

  1. That said, I know we can still persist to the server, but it is now all lumped together user + machine, which breaks permission controls etc

Permission controls? ~/.local/share/code-server/Machine/settings.json (Remote Settings) is located in the user's realm (home directory) and is therefore under their control - and not anyone else's.

IMHO there is only one exception: If a user deletes a setting1 (or the whole file), e.g. by accident, it may be reinstated.
👉 If a user changes a setting, it can be assumed that this was done on purpose – even if that breaks functionality.

  1. I think proposal A works as a way forward, alternatively, I can think of proposal B, an idea stemming from the login screen
  2. Proposal B: we can add an entry in config.yaml to define where user settings should persist: local/server

What locations exactly do local and server refer to?

Footnotes

  1. non-default; pre-populated

@bilogic
Copy link
Contributor Author

bilogic commented Nov 23, 2023

@benz0li

  1. I agree overwriting is bad practice, I'm progressively relying on permissions to do the work, but as they are not highly sensitive data, e.g. debugging ports allocated to each developer, it has taken a backseat in my todo. The idea here is to manage the new developers so that they don't have to know a ton of architecture info in order to start coding, i.e. the debugger just works

  2. local refers to the browser's local storage, server refers to the machine that code-server is running on. In layman terms, when the developer loses his MacBook and is given a Windows machine, he can load the URL link to code-server and continue as-is without having to redo any configuration

  3. To my understanding, you prefer to have 1 local (user) and 1 server (machine). For me, I don't mind the new 1 local (user) , I still need 2 server (user + machine)

I think we come from very different angles, mine mainly being business continuity. But I see a way to fulfil everyone's needs and I'm hoping we can move in that direction.

@benz0li
Copy link
Contributor

benz0li commented Nov 23, 2023

  1. Proposal B: we can add an entry in config.yaml to define where user settings should persist: local/server

What locations exactly do local and server refer to?

If

  1. local = Browser (on client)
  2. server = ~/.local/share/code-server/User/settings.json (on server)

then @bilogic

  1. Name of the CLI option for code-server?
    • Option in ~/.config/code-server/config.yaml is named correspondingly?
  2. Default setting of the newly introduced option?

@code-asher Does a new option to switch between the two behaviours (current: server, i.e. 'local storage' patch enabled; new: local, i.e. 'local storage' patch disabled) seem reasonable? (My opinion: 👍 for proposal B)
ℹ️ With the current behaviour as default, this would not even be a breaking change.

@bilogic
Copy link
Contributor Author

bilogic commented Nov 23, 2023

I can't seem to find the docs for config.yaml, but in my copy, there is user-data-dir, I would be able to name the new option better if there is a full overview of the options.

@benz0li
Copy link
Contributor

benz0li commented Nov 23, 2023

I can't seem to find the docs for config.yaml, but in my copy, there is user-data-dir, I would be able to name the new option better if there is a full overview of the options.

https://coder.com/docs/code-server/latest/FAQ#how-does-the-config-file-work

Each key in the file maps directly to a code-server flag (run code-server --help to see a listing of all the flags). Any flags passed to code-server will take priority over the config file.

See #6546 (comment)

@benz0li
Copy link
Contributor

benz0li commented Nov 23, 2023

@code-asher Regarding

Thank you for the input! So right now I think we are leaning toward keeping the patch removed and doing a major bump.

Minor bump would be fine, too.

I have a few hours left before the holidays so I might have to pick this back up on Monday, but I am going to just see if I can quickly get the old behavior working while still resolving this bug, just so we know what the alternative looks like. Maybe it will not be so bad...

👍

@bilogic
Copy link
Contributor Author

bilogic commented Nov 23, 2023

--user-data-storage                storage location of user data. [directory, browser]
--user-data-dir                    Path to the user data directory, ignored if user-data set to browser.

This would be my proposal, the description should use the first option as the default, and default ought to be chosen by the maintainers to minimize support questions from new users to them or based on considerations to ease maintainence.

@benz0li
Copy link
Contributor

benz0li commented Nov 23, 2023

--user-data                        storage location of user data [directory, browser]
--user-data-dir                    Path to the user data directory, ignored if user-data set to browser

@bilogic user-data-dir is ~/.local/share/code-server by default and there is more than just settings stored there.
ℹ️ The 'User Settings' being currently stored within this path at <user-data-dir>/User/settings.json.

@benz0li
Copy link
Contributor

benz0li commented Nov 23, 2023

My proposal:

  1. Name of the CLI option for code-server?

    • Option in ~/.config/code-server/config.yaml is named correspondingly?

--user-settings-store Storage location of the user settings [disk, browser]

  1. Default setting of the newly introduced option?

disk browser

@code-asher A new option to switch between the two behaviours (current: disk (server), i.e. 'local storage' patch enabled; new: browser (local), i.e. 'local storage' patch disabled, default)

@benz0li
Copy link
Contributor

benz0li commented Nov 23, 2023

@spkane Are there other settings you suspect not allowed to be set by any settings layer besides the User one?

You may test at https://coder.jupyter.b-data.ch

@bilogic
Copy link
Contributor Author

bilogic commented Nov 23, 2023

@benz0li thanks!

I agree --user-settings-store sounds better

@benz0li
Copy link
Contributor

benz0li commented Nov 23, 2023

Final thought:

On second thought, a default setting of browser (the new behaviour) for user-settings-store seems more appropriate1.
ℹ️ Most projects do it this way: Stating the breaking change and documenting how to revert to the old behaviour – using an option/flag or environment variable.

Footnotes

  1. I.e. behaving the same way as Codespaces.

@bilogic
Copy link
Contributor Author

bilogic commented Nov 23, 2023

Sure we can follow other projects, but I feel that the main consideration should always be the amount of support/follow-up, aka impact, that decision incurs. Maintainers probably know their user base best.

@spkane
Copy link

spkane commented Nov 23, 2023

I'm probably not going to be able to test this until sometime late next week. As long as there is a way to pass in any user settings during startup, our use case should be handled, assuming that adding the patch back doesn't break the workspace file loading (which was the issue that I think initially led to removing this patch).

Basically, we use code-server to run tech training classes, and we need to set things up in a certain way for optimal student experience.

As long as we have some reasonable method to set the default for any setting and the UI refresh error that was occurring with workspace file loading is fixed, then I think we should be good to go.

@benz0li
Copy link
Contributor

benz0li commented Nov 27, 2023

I have a few hours left before the holidays so I might have to pick this back up on Monday, but I am going to just see if I can quickly get the old behavior working while still resolving this bug, just so we know what the alternative looks like. Maybe it will not be so bad...

@code-asher Getting "the old behavior working while still resolving #3061", #6500 and #6153 would be ideal, of course.

@code-asher code-asher self-assigned this Nov 27, 2023
@code-asher
Copy link
Member

code-asher commented Nov 27, 2023

I think if we manage to get the old behavior working there is probably no need to also add an option because most (all?) folks will want it on the server. Having it in browser storage is really quite inconvenient. But, if folks do want an option we can consider that as a feature request.

That depends on first getting the old behavior working without bringing back the bug though...I was not able to figure it out last week.

@bilogic
Copy link
Contributor Author

bilogic commented Nov 28, 2023

@code-asher

  1. I know the issue appeared after 4.13.0 [Bug]: Source control UI is unresponsive starting from version 4.10+ #6153 (comment)
  2. @spkane said he will be stuck on 4.16.1, I suppose that narrows it to after that Open Workspace while another Workspace is open doesn't work. #3061 (comment), but best to confirm directly with him
  3. If pt 2 is correct, the bug started after 4.16.1

@spkane
Copy link

spkane commented Nov 28, 2023 via email

@code-asher
Copy link
Member

I think I tracked it down, I will put up an RC after CI completes!

code-asher added a commit that referenced this issue Nov 28, 2023
And fix the workspace bug.  It is caused by an issue with how some
global variables are being used asynchronously and is exacerbated by the
delay reading settings from the remote introduces.

1. The workspace is created and is marked as not initialized.
2. The configuration's change handler is triggered, and now
   initialization is complete.
3. The handler tries to set the global workspace variable to initialized
   but the workspace has not been set yet so we get an undefined error.
4. The workspace global is now set, but it is set to the old value with
   initialized still set to false.
5. Workspace is never marked as initialized until something else
   triggers the on change handler again.

Fixes #3061, and closes #6546.

My guess is this logic changed in one of the VS Code updates,
introducing this async bug but never getting caught probably because for
them the settings are always local thus minimal delay.
@bilogic
Copy link
Contributor Author

bilogic commented Nov 28, 2023

https://github.com/coder/code-server/actions/runs/7014210927 looks like it is cleared, can't wait! :)

@code-asher
Copy link
Member

https://github.com/coder/code-server/releases/tag/v4.19.1-rc.2

@benz0li
Copy link
Contributor

benz0li commented Nov 28, 2023

https://github.com/coder/code-server/releases/tag/v4.19.1-rc.2

code-server-4.19.1-rc.2-linux-amd64.tar.gz with Code 1.84.2 is deployed at https://coder.jupyter.b-data.ch; Image R (base:test-devtools-docker).

Resolved issued:

@code-asher Thank you for fixing these issues.


Functionality [modified by patches] tested and found to work:

  • base-path
  • cli-window-open
  • local-storage
  • marketplace
  • proxy-url
  • service-worker
  • webview

Jupyter Notebooks also work fine:

@code-asher
Copy link
Member

Since we got a few positive reports, I will go ahead and release 4.19.1. Thanks everyone!

@spkane
Copy link

spkane commented Dec 28, 2023

Now that I have had time to get back to this, I just wanted to confirm that both issues appear to be working fine for me:

  • Multiple browser sessions, etc, can open up the workspace just fine, and refreshes don't lock up the explorer.
  • and User settings can still be passed in a stored via the filesystem.

yiliang114 pushed a commit to yiliang114/code-server that referenced this issue Jan 23, 2025
And fix the workspace bug.  It is caused by an issue with how some
global variables are being used asynchronously and is exacerbated by the
delay reading settings from the remote introduces.

1. The workspace is created and is marked as not initialized.
2. The configuration's change handler is triggered, and now
   initialization is complete.
3. The handler tries to set the global workspace variable to initialized
   but the workspace has not been set yet so we get an undefined error.
4. The workspace global is now set, but it is set to the old value with
   initialized still set to false.
5. Workspace is never marked as initialized until something else
   triggers the on change handler again.

Fixes coder#3061, and closes coder#6546.

My guess is this logic changed in one of the VS Code updates,
introducing this async bug but never getting caught probably because for
them the settings are always local thus minimal delay.
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
Projects
None yet
Development

No branches or pull requests

4 participants