Porting ttyd to Golang Part II

Continuing from previous post, this post is about how to handle ttyd using golang. Overview The golang handler consists of 3 parts: sending frontend, sending auth token and handling websocket connection. Sending Frontend Golang can embed static assets in the compiled binary so there is no need to specify a path to the file. The frontend can be extracted using devtools. //go:embed ttyd.html var ttydHtml string func index(writer http.ResponseWriter, request *http....

published on June 7, 2023 · 6 min · 1229 words

Porting ttyd to Golang Part I

Previously I have written a post about ttyd that describes how to authenticate requests for ttyd sessions. The problem is that vanilla ttyd only supports running a predefined command, and it’s nearly impossible to customize what command to run based on the authenticated user. To solve this problem we need to port ttyd to another language. But first we need to understand how ttyd works. Request Waterfall When a browser connects to a ttyd instance, below is the order in which resources are requested....

published on April 27, 2023 · 5 min · 919 words

Writing a Forward Auth for ttyd

Background ttyd is a simple tool for sharing terminal over the web. It can be used in place of ssh clients to manage remote servers as it only requires the presence of a browser with internet connectivity. It can be used with a variety of commands ranging from showing the output of top command to fully interactive bash session. However, ttyd itself only supports basic auth and auth proxy. In basic auth mode, ttyd authenticates requests from a predefined list of users....

published on February 28, 2023 · last edited on April 21, 2023 · 5 min · 940 words