Skip to content

[ws-manager-mk2] Support public SSH keys #16413

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

Merged
merged 1 commit into from
Mar 13, 2023
Merged

[ws-manager-mk2] Support public SSH keys #16413

merged 1 commit into from
Mar 13, 2023

Conversation

Furisto
Copy link
Member

@Furisto Furisto commented Feb 15, 2023

Description

Support public ssh keys

Related Issue(s)

n.a.

How to test

  • Create ssh keys with ssh-keygen -t ed25519
  • Add the ssh key in user settings
  • Start workspace
  • Check that the workspace CR sshPublicKeys property is set
  • Check that the gitpod.io/sshPublicKeys annotation is set on the workspace pod
  • Create second ssh key
  • Add the ssh key in user settings
  • Check that workspace CR and workspace pod have been updated

Release Notes

None

Documentation

Build Options:

  • /werft with-github-actions
    Experimental feature to run the build with GitHub Actions (and not in Werft).
  • leeway-no-cache
    leeway-target=components:all
  • /werft no-test
    Run Leeway with --dont-test
Publish Options
  • /werft publish-to-npm
  • /werft publish-to-jb-marketplace
Installer Options
  • with-ee-license
  • with-slow-database
  • with-dedicated-emulation
  • with-ws-manager-mk2
  • workspace-feature-flags
    Add desired feature flags to the end of the line above, space separated

Preview Environment Options:

  • /werft with-local-preview
    If enabled this will build install/preview
  • /werft with-preview
  • /werft with-large-vm
  • /werft with-gce-vm
    If enabled this will create the environment on GCE infra
  • /werft with-integration-tests=all
    Valid options are all, workspace, webapp, ide, jetbrains, vscode, ssh

@werft-gitpod-dev-com
Copy link

started the job as gitpod-build-fo-adv-3.2 because the annotations in the pull request description changed
(with .werft/ from main)

@Furisto
Copy link
Member Author

Furisto commented Feb 15, 2023

/werft run with-preview with-wsman-mk2 with-large-vm with-gce-vm

👍 started the job as gitpod-build-fo-adv-3.5
(with .werft/ from main)

@Furisto Furisto marked this pull request as ready for review February 15, 2023 12:47
@Furisto Furisto requested a review from a team February 15, 2023 12:47
Copy link
Member

@WVerlaek WVerlaek left a comment

Choose a reason for hiding this comment

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

testing in a preview env, but can't connect with VSCode Desktop, keep getting prompted for a password like this: https://www.gitpod.io/blog/vscode-desktop-ssh-updates#ssh-gateway-access-using-the-owner-token

The workspace spec and pod annotations do contain the public ssh key, is there anything else I need to set before I can connect with ssh?

Comment on lines 245 to 251
case workspace.Spec.SshPublicKeys != pod.Annotations[kubernetes.WorkspaceSSHPublicKeys]:
pod.Annotations[kubernetes.WorkspaceSSHPublicKeys] = workspace.Spec.SshPublicKeys
err := r.Client.Update(ctx, pod)
if err != nil {
return ctrl.Result{Requeue: true}, err
}

Copy link
Member

Choose a reason for hiding this comment

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

could you add a test for this in workspace_controller_test?

@Furisto
Copy link
Member Author

Furisto commented Feb 17, 2023

testing in a preview env, but can't connect with VSCode Desktop, keep getting prompted for a password like this: https://www.gitpod.io/blog/vscode-desktop-ssh-updates#ssh-gateway-access-using-the-owner-token

The workspace spec and pod annotations do contain the public ssh key, is there anything else I need to set before I can connect with ssh?

Good question, maybe @iQQBot knows the answer?

@iQQBot
Copy link
Contributor

iQQBot commented Feb 17, 2023

/werft run

👍 started the job as gitpod-build-fo-adv-3.6
(with .werft/ from main)

@@ -653,6 +695,21 @@ func setEnvironment(envs []*wsmanapi.EnvironmentVariable) []corev1.EnvVar {
return envVars
}

func setSshPublicKeys(keys []string) (string, error) {
if len(keys) != 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

keep the same name SSH everywhere?

@iQQBot
Copy link
Contributor

iQQBot commented Feb 17, 2023

@Furisto Could you rebase to main? because the build is failed and I can't access the preview environment

@Furisto
Copy link
Member Author

Furisto commented Feb 17, 2023

/werft run with-preview with-wsman-mk2 with-large-vm with-gce-vm

👍 started the job as gitpod-build-fo-adv-3.8
(with .werft/ from main)

@Furisto
Copy link
Member Author

Furisto commented Feb 17, 2023

/werft run with-preview with-wsman-mk2 with-large-vm with-gce-vm recreate-vm

👍 started the job as gitpod-build-fo-adv-3.9
(with .werft/ from main)

@iQQBot
Copy link
Contributor

iQQBot commented Feb 17, 2023

/werft run with-preview with-wsman-mk2 with-large-vm with-gce-vm recreate-vm

👍 started the job as gitpod-build-fo-adv-3.10
(with .werft/ from main)

@iQQBot
Copy link
Contributor

iQQBot commented Feb 20, 2023

Good question, maybe @iQQBot knows the answer?

This implementation looks wrong. In mk2, we use CRD directly to store the public keys and we don't need to set it on annotation at all

we should put public keys in here

wsinfo := &WorkspaceInfo{
WorkspaceID: ws.Spec.Ownership.WorkspaceID,
InstanceID: ws.Name,
URL: ws.Status.URL,
IDEImage: ws.Spec.Image.IDE.Web,
SupervisorImage: ws.Spec.Image.IDE.Supervisor,
IDEPublicPort: getPortStr(ws.Status.URL),
IPAddress: podIP,
Ports: ports,
Auth: &wsapi.WorkspaceAuthentication{Admission: admission, OwnerToken: ws.Status.OwnerToken},
StartedAt: ws.CreationTimestamp.Time,
}

@@ -45,6 +45,8 @@ type WorkspaceSpec struct {

// +kubebuilder:validation:MinItems=0
Ports []PortSpec `json:"ports"`

SshPublicKeys string `json:"sshPublicKey,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

why using string? it can by array, we don't need base64 for it, we using base64 because annotation only support string.

@werft-gitpod-dev-com
Copy link

started the job as gitpod-build-fo-adv-3.12 because the annotations in the pull request description changed
(with .werft/ from main)

@Furisto
Copy link
Member Author

Furisto commented Feb 21, 2023

/werft run with-preview with-wsman-mk2 with-large-vm with-gce-vm recreate-vm

👍 started the job as gitpod-build-fo-adv-3.13
(with .werft/ from main)

@Furisto
Copy link
Member Author

Furisto commented Feb 21, 2023

/werft run with-preview with-wsman-mk2 with-large-vm with-gce-vm recreate-vm

👍 started the job as gitpod-build-fo-adv-3.14
(with .werft/ from main)

@Furisto
Copy link
Member Author

Furisto commented Feb 21, 2023

/werft run with-preview with-wsman-mk2 with-large-vm

👍 started the job as gitpod-build-fo-adv-3.15
(with .werft/ from main)

@Furisto
Copy link
Member Author

Furisto commented Feb 21, 2023

/werft run with-preview with-wsman-mk2 with-large-vm with-gce-vm recreate-vm

👍 started the job as gitpod-build-fo-adv-3.16
(with .werft/ from main)

Comment on lines 154 to 156
sshPublicKey:
format: byte
type: string
Copy link
Member

Choose a reason for hiding this comment

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

looks like this needs to be regenerated, with the type being an array now

@@ -45,6 +45,8 @@ type WorkspaceSpec struct {

// +kubebuilder:validation:MinItems=0
Ports []PortSpec `json:"ports"`

SshPublicKeys []byte `json:"sshPublicKeys,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

why use []byte here? is it possible to directly use api.SSHPublicKeys or []string, in CRDs we should keep it readable... these things are not secret

@kylos101
Copy link
Contributor

kylos101 commented Mar 6, 2023

@Furisto is this PR stalled? Should it flip back to draft?

@WVerlaek
Copy link
Member

WVerlaek commented Mar 13, 2023

/werft run -a with-preview=true -a with-wsman-mk2=true -a with-gce-vm=true

👍 started the job as gitpod-build-fo-adv-3.18
(with .werft/ from main)

Copy link
Member

@WVerlaek WVerlaek left a comment

Choose a reason for hiding this comment

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

lgtm, tested in preview env:

  • was able to connect over SSH with VS Code Desktop
  • updating a key propagated to running workspace

@roboquat roboquat merged commit 2c259c4 into main Mar 13, 2023
@roboquat roboquat deleted the fo/adv-3 branch March 13, 2023 13:50
@roboquat roboquat added deployed: workspace Workspace team change is running in production deployed Change is completely running in production labels Mar 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deployed: workspace Workspace team change is running in production deployed Change is completely running in production feature: ws-manager-mk2 release-note-none size/M team: workspace Issue belongs to the Workspace team
Projects
No open projects
Status: In Validation
Development

Successfully merging this pull request may close these issues.

5 participants