Skip to content

feat(cli): add 'coder upgrade' command - #7659

Closed
sreya wants to merge 6 commits into
mainfrom
jon/upgrade
Closed

sreya wants to merge 6 commits into
mainfrom
jon/upgrade

Conversation

@sreya

@sreya sreya commented May 24, 2023

Copy link
Copy Markdown
Collaborator

fixes #2744

This PR provides a command to sync a coder client with a deployment. It is mostly an alias for curl -L https://coder.com/install.sh | sh -s -- --version <version> It does not currently support Windows but I believe it should be possible to support. I'll try to get my hands on a Windows laptop tomorrow and try it out.

@sreya
sreya requested a review from mafredri May 24, 2023 06:21
@matifali

matifali commented May 24, 2023 •

Copy link
Copy Markdown
Contributor

Awesome contribution. I have a few suggestions.

  1. Thoughts on renaming coder upgrade to coder version upgrade? Because upgrade/update are synonyms, we use coder update to update the workspaces. (See https://fly.io/docs/flyctl/version-update)

  2. Would this be possible on the server too? To upgrade to the latest stable with coder upgrade? It should automatically do the service restart/daemon-reload steps too.

  3. On a client, we can run this when the user first invokes coder <sub-command> so they don't have to sync with their server version manually.

  4. On Windows, you could try using winget. It is available by default, and usually, our latest package is in the winget repo in a maximum of 1 day.

@mafredri

mafredri commented May 24, 2023 •

Copy link
Copy Markdown
Member
  1. Thoughts on renaming coder upgrade to coder version upgrade? Because upgrade/update are synonyms, we use coder update to update the workspaces. (See fly.io/docs/flyctl/version-update)

I think self-upgrade would be a pretty good name, and it's not super uncommon (this query is filtered on Go projects). It feels quite self-explanatory, distinct and is discoverable.

@mafredri mafredri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice addition!

As previously mentioned, I think self-upgrade (or self-update) would be a good naming alternative.

A few things came to my mind as I was reviewing this:

  1. We shouldn't rely on the install script, we should instead build this out with Go code (example from restic: https://github.com/restic/restic/blob/master/cmd/restic/cmd_self_update.go)
  2. We should verify the hash of the downloaded binary against our signing key

The problem with 1) is that it's a point-of-failure on at least two fronts, 1. coder.com may be down and 2. someone may replace it with an arbitrary script by attacking coder.com server or hijacking the domain.

By doing 2) (verifying the hash), and fixing 1), we ensure that only a signed binary is able to update to another signed binary, this preventing many forms of MITM. Otherwise an attacker only needs to gain enough access to modify our GitHub release and upload a malicious binary in place of the real one.

I don't think we necessarily have to fix both in this PR, and we can use the install script for a short while, but IMO it should be fairly high priority to move to a built-in updating method.

Comment thread cli/upgrade.go
Short: "Upgrade the Coder CLI to match the version of a deployment.",
Options: clibase.OptionSet{
{
Flag: "install-script-url",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: We have some other flags introduced for tests that are named test.x (i.e. test.install-script-url). This way the purpose of the flag is more clear and won't collide with non-test flags.

Comment thread cli/upgrade.go

version := semver.Canonical(serverInfo.Version)
version = strings.TrimSuffix(version, "-devel")
version = strings.TrimPrefix(version, "v")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we check that this isn't 0.0.0 in case the server was built without Makefile?

Comment thread cli/upgrade_test.go
Comment on lines +81 to +82
errC := inv.WithContext(ctx).Run()
assert.NoError(t, errC)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
errC := inv.WithContext(ctx).Run()
assert.NoError(t, errC)
err := inv.WithContext(ctx).Run()
assert.NoError(t, err)

Comment thread cli/upgrade_test.go
Comment on lines +95 to +96
errC := inv.WithContext(ctx).Run()
assert.Error(t, errC)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
errC := inv.WithContext(ctx).Run()
assert.Error(t, errC)
err := inv.WithContext(ctx).Run()
assert.Error(t, err)

Comment thread cli/upgrade.go
}

// nolint: gosec
cmd := exec.Command("sh", "-s", "--", "--version", version)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice we're not controlling where the binary will end up (path). If the idea is for the binary to update itself, it should replace itself in the same location. Otherwise we will most definitely end up placing multiple coder binaries on user filesystems which would be confusing.

This could be a flag (--binary-path) to allow the user to change it (default arg0).

This may or may not have "file is in use" ramifications on certain systems as long as the coder command is running, but probably not on Linux/macOS.

@matifali

Copy link
Copy Markdown
Contributor

@mafredri

Copy link
Copy Markdown
Member

People at fly.io seems to use the install script.

superfly/flyctl@b0911e0/internal/update/update.go#L150

Interesting. As a personal anecdote, I would be uncomfortable using that. 😄

@ammario ammario changed the title feat: add 'coder upgrade' command feat(cli): add 'coder upgrade' command Jun 3, 2023
@github-actions github-actions Bot added the stale This issue is like stale bread. label Jun 12, 2023
@github-actions github-actions Bot closed this Jun 16, 2023
@matifali

matifali commented Nov 8, 2023

Copy link
Copy Markdown
Contributor

@mafredri, @sreya, I think this can still add value to our product.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale This issue is like stale bread.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide a coder upgrade command that pulls coder directly from the server

3 participants