console

package
v3.0.0-rc45 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package console is what the console sessions share between the node serving them and the clients attaching to them: the ticket a session is opened with, and the messages exchanged on its websocket.

Index

Constants

View Source
const (
	// MsgResize is sent by the client when its terminal changes size.
	MsgResize = "resize"

	// MsgExit is sent by the node when the session ends, before it closes
	// the websocket.
	MsgExit = "exit"
)

A console session is a websocket. Its binary messages are the bytes of the terminal, in both directions. Its text messages are the control messages below, json encoded.

View Source
const (
	// ReasonExited is the command of the session ending by itself.
	ReasonExited = "exited"

	// ReasonError is the session failing to start or to run.
	ReasonError = "error"
)

Reasons a session ends for.

View Source
const (
	// TokenUse is the token_use claim of a console ticket. It tells a
	// ticket from the access tokens signed with the same key: a ticket
	// is no credential of the api, and an access token opens no console.
	TokenUse = "console"

	// TicketDuration is how long a ticket is accepted for. It bounds the
	// time to connect, not the session: a session opened in time lasts
	// until its client or its command ends it.
	TicketDuration = 30 * time.Second

	// KindTTY is the kind of a console running a command in a terminal.
	KindTTY = "tty"
)

Variables

View Source
var ErrNoTerminal = errors.New("console: attaching a terminal is not supported on this platform")

ErrNoTerminal is returned by the platforms a terminal can not be attached on.

Functions

This section is empty.

Types

type AttachOptions

type AttachOptions struct {
	// URL is the url of the console endpoint, with its ticket.
	URL string

	// TLSConfig is how the endpoint is verified.
	TLSConfig *tls.Config

	// Stdin is where the keystrokes are read from, and Stdout where
	// the output of the session is written. A Stdin that is a
	// terminal is set raw for the time of the session, and its size
	// is the size of the session terminal.
	Stdin  *os.File
	Stdout io.Writer
}

AttachOptions is what a client attaches a terminal to a console session with.

type ExitStatus

type ExitStatus int

ExitStatus is the non-zero exit status of the command of a session, as an error a client command exits with.

A shell exits with the status of the last command typed in it, so it is the exit status of the client, as it is of ssh, and no failure to report.

func (ExitStatus) Error

func (t ExitStatus) Error() string

func (ExitStatus) ExitCode

func (t ExitStatus) ExitCode() int

ExitCode is the exit code the client command exits with.

type Message

type Message struct {
	Type string `json:"type"`

	// Cols and Rows are the terminal size of a resize.
	Cols uint16 `json:"cols,omitempty"`
	Rows uint16 `json:"rows,omitempty"`

	// Code is the exit code of the command, Reason why the session
	// ended, and Text what to tell the user about it.
	Code   int    `json:"code,omitempty"`
	Reason string `json:"reason,omitempty"`
	Text   string `json:"text,omitempty"`
}

Message is a control message of a console session.

func DecodeMessage

func DecodeMessage(b []byte) (Message, error)

DecodeMessage parses a text websocket payload.

func (Message) Encode

func (m Message) Encode() []byte

Encode returns the message as a text websocket payload.

type Result

type Result struct {
	// Code is the exit code of the command of the session.
	Code int

	// Reason is why the session ended, and Text what the node said
	// about it.
	Reason string
	Text   string
}

Result is how a console session ended.

func Attach

func Attach(ctx context.Context, o AttachOptions) (Result, error)

Attach opens the console session the url and its ticket name, and connects the terminal to it until the session ends.

A session the node ends is a Result. An error is a session that could not be opened, or a connection lost: the session is over on the node too, as a session ends with its client connection.

type Target

type Target struct {
	// Node is the node the session is served on.
	Node string `json:"node"`

	// Path is the object path.
	Path string `json:"path"`

	// RID is the resource id, empty for the only resource of the
	// object a console can be opened on.
	RID string `json:"rid,omitempty"`

	// Kind is the kind of console.
	Kind string `json:"kind"`
}

Target is what a console session attaches to: a resource of an instance, on the node running it.

type Ticket

type Ticket struct {
	Target   Target `json:"console"`
	TokenUse string `json:"token_use"`
	jwt.RegisteredClaims
}

Ticket is what a client presents to open a console session. It is signed by the node that checked the user may open it.

func NewTicket

func NewTicket(user, issuer string, target Target) (*Ticket, error)

NewTicket returns a ticket for the user to open a console on the target, issued by the node named.

func ParseTicket

func ParseTicket(s string, key *rsa.PublicKey) (*Ticket, error)

ParseTicket verifies a signed ticket and returns it. A token that is not a console ticket is refused, however valid its signature: the access tokens of the api are signed with the same key.

func (*Ticket) Claims

func (t *Ticket) Claims() map[string]any

Claims returns the claims of the ticket, less its expiration, for a signer that sets the expiration itself.

func (*Ticket) Sign

func (t *Ticket) Sign(key *rsa.PrivateKey) (string, error)

Sign returns the ticket signed with the key the cluster signs its tokens with.

func (Ticket) User

func (t Ticket) User() string

User is who the ticket was issued to.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL