Git Product home page Git Product logo

cloudshell's Introduction

Cloudshell

License Docker Image Version (latest by date) GitHub go.mod Go version pipeline status

This project contains an Xterm.js frontend that connets to a Go backend to provide a shell to the host system. Basically, access your shell from a browser.

Screengrab of demo

Some use cases I had:

  1. Deploy to a compute instance in your networks and expose it when needed to gain shell access to your network over the browser
  2. Deploy to a Kubernetes cluster with appropriate (Cluster)Role and (Cluster)RoleBinding resources to allow some level of access to developers
  3. Exposing a CLI tool (see ./examples/k9s for an example) over the browser. Think CLI-as-a-frontend
  4. Doing a demo for a CLI tool over the browser

Table of Contents

Development

Install dependencies

Run make init to install both Node.js and Golang dependencies.

Test run it

Run make start to start the Go backend which will also serve the static files for the website.

Open your browser at http://localhost:8376 to view your shell in the browser.

Build/Release

Building the project

To build this project, run make build to build the binary

Creating the Docker image

Run make package to create the Docker image. To customise the package process:

  1. Create a file named Makefile.properties (this will be -included by the Makefile)
  2. Set image_namespace to your desired namespace (defaults to zephinzer)
  3. Set image_name to your desired image name (defaults to cloudshell)
  4. Set image_tag to your desired tag (defaults to the first 8 characters of the Git commit hash)

Publishing the Docker image

Run make publish to publish the Docker image. Same customisations as above apply.

Publishing example Docker images

Run make publish-example id=${id} to publish the example Docker images where ${id} is the directory name of the directory in the ./examples directory.

Usage/Configuration

Cloudshell CLI tool

Configurations can be set via flags or environment variables. To view available configurations in your binary instance, run cloudshell --help. Otherwise, flags and environment variables follow a rule of kebab-lower-case for flags and SNAKE_UPPER_CASE for environment variables.

Configuration Flag Environment Variable Default Value Description
Allowed hostnames --allowed-hostnames ALLOWED_HOSTNAMES "localhost" Comma delimited list of hostnames that are allowed to connect to the websocket
Arguments --arguments ARGUMENTS "-l" Comma delimited list of arguments that should be passed to the target binary
Command --command COMMAND "/bin/bash" Absolute path to the binary to run
Connection error limit --connection-error-limit CONNECTION_ERROR_LIMIT 10 Number of times a connection should be re-attempted by the server to the XTerm.js frontend before the connection is considered dead and shut down
Keepalive ping timeout --keepalive-ping-timeout KEEPALIVE_PING_TIMEOUT 20 Maximum duration in seconds between a ping and pong message to tolerate
Maximum buffer size in bytes --max-buffer-size-bytes MAX_BUFFER_SIZE_BYTES 512 Maximum length of input from the browser terminal
Log format --log-format LOG_FORMAT "text" Format with which to output logs, one of "json" or "text"
Log level --log-level LOG_LEVEL "debug" Minimum level of logs to output, one of "trace", "debug", "info", "warn", "error"
Liveness probe path --path-liveness PATH_LIVENESS "/healthz" Path to liveness probe handler endpoint
Metrics probe path --path-metrics PATH_METRICS "/metrics" Path to metrics endpoint
Readiness probe path --path-readiness PATH_READINESS "/readiness" Path to readiness probe handler endpoint
Xterm.js path --path-xtermjs PATH_XTERMJS "/xterm.js" Path to xterm.js websocket endpoint
Server address --server-address SERVER_ADDRESS "0.0.0.0" IP interface the server should listen on
Server port --server-port SERVER_PORT 8376 Port the server should listen on
Working directory --workdir WORKDIR "." Path to the working directory that Cloudshell should use

Deploy

Running the Docker image

Run make run to run the Docker image locally

Deploying via Helm

Go to ./deploy/cloudshell and run helm install --values ./values.yaml --set-url url=cloudshell.yourdomainname.com cloudshell .. Replace cloudshell.yourdomainname.com with your own domain name. You could also set the url property inside the ./values.yaml file.

CI/CD

The following environment variables should be set in the CI pipeline:

Key Example Description
DOCKER_REGISTRY_URL "docker.io" URL of the Docker registry to push the image to
DOCKER_REGISTRY_USER "zephinzer" User to identify with for the registry at DOCKER_REGISTRY_URL
DOCKER_REGISTRY_PASSWORD "p@ssw0rd" Password for the user identified in DOCKER_REGISTRY_USER for the registry at DOCKER_REGISTRY_URL

License

This project is licensed under the MIT license.

cloudshell's People

Contributors

zephinzer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cloudshell's Issues

typos

Hi zephinzer,

two harmless typos in pkg/xtermjs/handler_websocket.go:

  • line 101: webscoket -> websocket
  • line 177: uunknown -> unknown

Gerhard

no TERM environment

Great project, like it is in go, so easy portable...

But I find there is a issue , there is no TERM environment set.

 40f72c8c915f:/$ echo $TERM
dumb

So some application will fail, need to set TERM manual.
export TERM=xterm-256color

But this should be done when opening the shell, from the go binairy.

something like this? cmd.Env = append(os.Environ(), "TERM=xterm-256color")

Utilize go:embed for Embedding Static Assets

Currently, cloudshell directly reading files for static files in public and node_modules from project directory for embedding static assets.

I think we should use go:embed to embed static assets directly into the Go binary. This feature of go will make the distribution of the binary easier, since we dont need to access the static files from the project directory, the downside is the binary will be bigger since it will have node_modules in it, but I think it's worth because we dont need to clone the whole project to use cloudshell, just the released binary is enough.

Thank you

race between goroutines: panic: sync: negative WaitGroup counter

Hi zephinzer,

Cool project!
I face a race condition, have a suggestion to fix this.
Program now and then panics with "panic: sync: negative Waitgroup Counter". This is because there is only once waiter.Add(1) being called, but there are more than one waiter.Done() calls in different goroutines.

In all cases so far, the pingpong gorountine finishes (logs) first, in line 124 is the 1st waiter.Done() being called.
Then line 149 also wants to decrement the counter:

WARN[15:07:08]handler_websocket.go xtermjs.GetHandler.func1.4 failed to read from tty: read /dev/ptmx: input/output error connection_uuid="75bd5ed0-1550-11ec-b29c-005056000bac"โ†ฒ
WARN[15:07:08]handler_websocket.go xtermjs.GetHandler.func1.4 failed to send termination message from tty to xterm.js: use of closed network connection connection_uuid="75bd5ed0-1550-11ec-b29c-005056000bac"
panic: sync: negative WaitGroup counter

To fix it, I am using 3 channels (abortChan{1,2,3}), a channel for each of the 3 goroutines. Goroutines are the sender, and close (or could send an describing string) and return when they face a "serious" error, rather than decrement a WaitGroup.

The handler is the receiver, blocks using select for one of the goroutines to close (or to send a short message).
There is another channel: stopChan, handler is the sender. Handler closes stopChan when select got a "signal" on one of the abortChans. The (remaining) goroutines do a non-blocking select on this stopChan. And return when they detect the close of stopChan.

The pingpong goroutine always returns this way. The other goroutines in most cases not, as they usually block in connection.ReadMessage or tty.Read. Their shutdown (including close of their abortChan) will be handled by the deferred func.

If you are interested I prepare a pull request.

Gerhard

Make init failed

Just tried out your repo on ubuntu.

This is what i get after runing make init

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.