Skip to content
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

kasm VNC #250

Merged
merged 48 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
9b9dd76
wip
matifali Sep 21, 2023
f68b31b
add kasmVNC
matifali Sep 21, 2023
aabf35c
TODO
matifali Sep 21, 2023
dec64c7
fixup!
matifali Sep 21, 2023
bf90b16
update tags
matifali Sep 21, 2023
92794a2
Delete .icons/kasm.png
matifali Sep 22, 2023
d44bd60
Update README.md
matifali Sep 22, 2023
1ac4840
Update main.tf
matifali Sep 22, 2023
805f692
merge `main`
matifali May 17, 2024
0fa43a7
`bun fmt`
matifali May 17, 2024
048cffb
bump version and fix typo
matifali May 17, 2024
2318f31
update KasmVNC version to 1.0.15 in README.md files
matifali May 17, 2024
6009778
rename version to kasm_version
matifali May 17, 2024
3333d3a
improve compatibility and cleanup
matifali May 17, 2024
d6e6cb3
update README.md
matifali May 17, 2024
b308ea5
fixup!
matifali May 17, 2024
41ef969
fixup!
matifali May 17, 2024
6698cb8
Install libdatetime-perl
matifali May 17, 2024
c8cdc95
fixup!
matifali May 17, 2024
c8db45e
fixup!
matifali May 17, 2024
a6c449e
add healtcheck
matifali May 17, 2024
b697e72
Merge branch 'main' into kasmVNC
matifali May 17, 2024
d5b49c2
Merge branch 'main' into kasmVNC
matifali May 21, 2024
f00f8de
chore: Update KasmVNC to use XFCE desktop environment
matifali May 30, 2024
a76095f
Merge branch 'main' into kasmVNC
matifali May 30, 2024
a254fd3
remove options
matifali May 30, 2024
71a2e6c
add wait for script
matifali May 30, 2024
39bc745
fixup!
matifali May 30, 2024
c2698be
fixup!
matifali May 30, 2024
d61f14d
fixup!
matifali May 30, 2024
12e4d35
`bun fmt`
matifali May 30, 2024
eda0e5d
Merge branch 'main' into kasmVNC
matifali Jun 21, 2024
de525a3
Merge branch 'main' into kasmVNC
matifali Sep 20, 2024
6017b05
Refactor KasmVNC installation script logic
matifali Sep 20, 2024
2ee02a3
fix: remove duplicate validation value
Parkreiner Sep 20, 2024
59041b3
chore: get basic tests in place
Parkreiner Sep 20, 2024
3ce7ef5
fix: update test text for more clarity
Parkreiner Sep 20, 2024
382c76b
Merge branch 'main' into kasmVNC
matifali Sep 30, 2024
c10a2ba
Bump KasmVNC module version to 1.0.20
matifali Sep 30, 2024
cf3159c
Update README.md
matifali Oct 2, 2024
c6895b5
Update KasmVNC to version 1.3.2 and add support
matifali Oct 4, 2024
4020ec0
Refine architecture mapping for specific distros
matifali Oct 4, 2024
f4cdb15
fix(kasmvnc): correct .deb file installation path
matifali Oct 4, 2024
18570aa
Improve Debian package installation command
matifali Oct 4, 2024
a63c365
Fix RPM installation path in kasmvnc script
matifali Oct 4, 2024
43a353c
Update README.md
matifali Oct 17, 2024
05135af
Merge branch 'main' into kasmVNC
matifali Oct 17, 2024
457621c
update version
matifali Oct 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions kasmvnc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
display_name: KasmVNC
description: A modern open source VNC server
icon: ../.icons/kasmvnc.svg
maintainer_github: coder
verified: true
tags: [helper, vnc, desktop]
---

# KasmVNC

Automatically install [KasmVNC](https://kasmweb.com/kasmvnc) in a workspace, and create an app to access it via the dashboard.

```tf
module "kasmvnc" {
source = "registry.coder.com/modules/kasmvnc/coder"
version = "1.0.20"
agent_id = coder_agent.example.id
desktop_environment = "xfce"
}
phorcys420 marked this conversation as resolved.
Show resolved Hide resolved
```

> **Note:** This module only works on workspaces with a pre-installed desktop environment.
37 changes: 37 additions & 0 deletions kasmvnc/main.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { describe, expect, it } from "bun:test";
import {
runTerraformApply,
runTerraformInit,
testRequiredVariables,
} from "../test";

const allowedDesktopEnvs = ["xfce", "kde", "gnome", "lxde", "lxqt"] as const;
type AllowedDesktopEnv = (typeof allowedDesktopEnvs)[number];

type TestVariables = Readonly<{
agent_id: string;
desktop_environment: AllowedDesktopEnv;
port?: string;
kasm_version?: string;
}>;

describe("Kasm VNC", async () => {
await runTerraformInit(import.meta.dir);
testRequiredVariables<TestVariables>(import.meta.dir, {
agent_id: "foo",
desktop_environment: "gnome",
});

it("Successfully installs for all expected Kasm desktop versions", async () => {
for (const v of allowedDesktopEnvs) {
const applyWithEnv = () => {
runTerraformApply<TestVariables>(import.meta.dir, {
agent_id: "foo",
desktop_environment: v,
});
};

expect(applyWithEnv).not.toThrow();
}
});
});
63 changes: 63 additions & 0 deletions kasmvnc/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
terraform {
required_version = ">= 1.0"

required_providers {
coder = {
source = "coder/coder"
version = ">= 0.12"
}
}
}

variable "agent_id" {
type = string
description = "The ID of a Coder agent."
}

variable "port" {
type = number
description = "The port to run KasmVNC on."
default = 6800
}

variable "kasm_version" {
type = string
description = "Version of KasmVNC to install."
default = "1.3.1"
}

variable "desktop_environment" {
type = string
description = "Specifies the desktop environment of the workspace. This should be pre-installed on the workspace."
validation {
condition = contains(["xfce", "kde", "gnome", "lxde", "lxqt"], var.desktop_environment)
error_message = "Invalid desktop environment. Please specify a valid desktop environment."
}
}

resource "coder_script" "kasm_vnc" {
agent_id = var.agent_id
display_name = "KasmVNC"
icon = "/icon/kasmvnc.svg"
script = templatefile("${path.module}/run.sh", {
PORT : var.port,
DESKTOP_ENVIRONMENT : var.desktop_environment,
VERSION : var.kasm_version
})
run_on_start = true
}

resource "coder_app" "kasm_vnc" {
agent_id = var.agent_id
slug = "kasm-vnc"
display_name = "kasmVNC"
url = "http://localhost:${var.port}"
icon = "/icon/kasmvnc.svg"
subdomain = true
share = "owner"
healthcheck {
url = "http://localhost:${var.port}/app"
interval = 5
threshold = 5
}
}
153 changes: 153 additions & 0 deletions kasmvnc/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
#!/usr/bin/env bash
matifali marked this conversation as resolved.
Show resolved Hide resolved

#!/bin/bash

# Function to check if vncserver is already installed
check_installed() {
if command -v vncserver &> /dev/null; then
echo "vncserver is already installed."
return 0 # Don't exit, just indicate it's installed
else
return 1 # Indicates not installed
fi
}

# Function to install kasmvncserver for debian-based distros
install_deb() {
local url=$1
wget $url -O /tmp/kasmvncserver.deb
sudo apt-get install ./kasmvncserver_*.deb -y
sudo adduser $USER ssl-cert
rm /tmp/kasmvncserver.deb
}

# Function to install kasmvncserver for Oracle 8
install_rpm_oracle8() {
local url=$1
wget $url -O /tmp/kasmvncserver.rpm
sudo dnf config-manager --set-enabled ol8_codeready_builder
sudo dnf install oracle-epel-release-el8 -y
sudo dnf localinstall ./kasmvncserver_*.rpm -y
sudo usermod -a -G kasmvnc-cert $USER
rm /tmp/kasmvncserver.rpm
}

# Function to install kasmvncserver for CentOS 7
install_rpm_centos7() {
local url=$1
wget $url -O /tmp/kasmvncserver.rpm
sudo yum install epel-release -y
sudo yum install ./kasmvncserver_*.rpm -y
sudo usermod -a -G kasmvnc-cert $USER
rm /tmp/kasmvncserver.rpm
}

# Function to install kasmvncserver for rpm-based distros
install_rpm() {
local url=$1
wget $url -O /tmp/kasmvncserver.rpm
sudo rpm -i /tmp/kasmvncserver.rpm
rm /tmp/kasmvncserver.rpm
}

# Function to install kasmvncserver for Alpine Linux
install_alpine() {
local url=$1
wget $url -O /tmp/kasmvncserver.tgz
tar -xzf /tmp/kasmvncserver.tgz -C /usr/local/bin/
rm /tmp/kasmvncserver.tgz
}

# Detect system information
distro=$(grep "^ID=" /etc/os-release | awk -F= '{print $2}')
version=$(grep "^VERSION_ID=" /etc/os-release | awk -F= '{print $2}' | tr -d '"')
arch=$(uname -m)

echo "Detected Distribution: $distro"
echo "Detected Version: $version"
echo "Detected Architecture: $arch"

# Map arch to package arch
if [[ "$arch" == "x86_64" ]]; then
arch="x86_64"
elif [[ "$arch" == "aarch64" || "$arch" == "arm64" ]]; then
arch="aarch64"
else
echo "Unsupported architecture: $arch"
exit 1
fi

# Check if vncserver is installed, and install if not
if ! check_installed; then
case $distro in
ubuntu | debian | kali)
case $version in
"18.04")
install_deb "https://github.com/kasmtech/KasmVNC/releases/download/v${VERSION}/kasmvncserver_bionic_${VERSION}_$${arch}.deb"
;;
"20.04")
install_deb "https://github.com/kasmtech/KasmVNC/releases/download/v${VERSION}/kasmvncserver_focal_${VERSION}_$${arch}.deb"
;;
"22.04")
install_deb "https://github.com/kasmtech/KasmVNC/releases/download/v${VERSION}/kasmvncserver_jammy_${VERSION}_$${arch}.deb"
;;
*)
echo "Unsupported Ubuntu/Debian/Kali version: $${version}"
exit 1
;;
esac
;;
oracle)
if [[ "$version" == "8" ]]; then
install_rpm_oracle8 "https://github.com/kasmtech/KasmVNC/releases/download/v${VERSION}/kasmvncserver_oracle_8_${VERSION}_$${arch}.rpm"
else
echo "Unsupported Oracle version: $${version}"
exit 1
fi
;;
centos)
if [[ "$version" == "7" ]]; then
install_rpm_centos7 "https://github.com/kasmtech/KasmVNC/releases/download/v${VERSION}/kasmvncserver_centos_core_${VERSION}_$${arch}.rpm"
else
install_rpm "https://github.com/kasmtech/KasmVNC/releases/download/v${VERSION}/kasmvncserver_centos_core_${VERSION}_$${arch}.rpm"
fi
;;
alpine)
if [[ "$version" == "3.17" || "$version" == "3.18" || "$version" == "3.19" ]]; then
install_alpine "https://github.com/kasmtech/KasmVNC/releases/download/v${VERSION}/kasmvnc.alpine_$${version}_$${arch}.tgz"
else
echo "Unsupported Alpine version: $${version}"
exit 1
fi
;;
fedora | opensuse)
install_rpm "https://github.com/kasmtech/KasmVNC/releases/download/v${VERSION}/kasmvncserver_$${distro}_$${version}_${VERSION}_$${arch}.rpm"
;;
*)
echo "Unsupported distribution: $${distro}"
exit 1
;;
esac
else
echo "vncserver already installed. Skipping installation."
fi

# Coder port-forwarding from dashboard only supports HTTP
sudo bash -c "cat > /etc/kasmvnc/kasmvnc.yaml <<EOF
network:
protocol: http
websocket_port: ${PORT}
ssl:
require_ssl: false
udp:
public_ip: 127.0.0.1
EOF"

# This password is not used since we start the server without auth.
# The server is protected via the Coder session token / tunnel
# and does not listen publicly
echo -e "password\npassword\n" | vncpasswd -wo -u $USER

# Start the server
printf "🚀 Starting KasmVNC server...\n"
sudo -u $USER bash -c "vncserver -select-de ${DESKTOP_ENVIRONMENT} -disableBasicAuth" > /tmp/kasmvncserver.log 2>&1 &