cockpit-go

A library for accessing a remote Linux server over the Cockpit Websocket protocol.

Features

  • Pure Go without CGO
  • Supports multiplexed sessions on a single connection
  • Streaming process output
  • PAM conversations
  • Signals/interruptions
  • Superuser elevation
  • CSRF integration
  • Sample command-line program cockpitssh

Usage

Get the package: go get code.ivysaur.me/cockpit-go

c, err := cockpit.NewClient("https://server.example.com:9090")
if err != nil { ... }

err = c.Login(ctx, "admin", "secret")
if err != nil { ... }

sess, err := c.Session(ctx)
if err != nil { ... }
defer sess.Close()

res, err := sess.Run(ctx, "uptime")
fmt.Println(string(res.Stdout), res.ExitCode)

References

Upstream Cockpit source code used as reference:

  • doc/protocol.md - framing, control commands, "stream" payload (spawn/pty/socket)
  • doc/login.md - /login auth + X-Conversation
  • src/ws/cockpitauth.c - session cookie format
  • pkg/lib/cockpit/_internal/transport.ts - browser handshake, cockpit1 subprotocol, 30s health ping
  • src/cockpit/channels/stream.py - exit-status/message/pid/window

License warning

LGPL-2.1 license. The author believes this is a derivative work of Cockpit itself as this was developed with reference to Cockpit sources.

Therefore, because of Go's static linking, this library can only be used in LGPL-compatible Go projects. ⚠️

Changelog

2026-09-05 v0.1.0

  • First public release
  • Support PAM conversations
  • Add cockpitssh tool

2026-08-22

  • Working PoC

2025-11-23

  • Initial exploration
S
Description
A library for accessing a remote Linux server over the Cockpit Websocket protocol
Readme LGPL-2.1
70 KiB
Languages
Go 100%