mirror of
https://github.com/hanzoai/runtime.git
synced 2026-10-30 18:23:13 +00:00
Every sandbox was created privileged under the daemon's default runtime, and the setting that would have changed it defaulted to an empty string that silently meant runc. For a service whose whole premise is running code somebody else wrote, that is not a boundary. An org sets its isolation and the create request carries it, so a sandbox records what it was made with: changing the policy moves new sandboxes and leaves running ones alone. gvisor is the default. firecracker is delivered through kata's shim, which is why it is one name rather than two. runc is refused unless the runner names that org, and an empty list names nobody. Absent means the default, unknown is a refusal, and a runtime the daemon does not have is a refusal. Nothing substitutes quietly. The runner took an organization in a field called UserId with a note beside it saying so. Deciding who may have runc through a field named after something else is not reviewable. Privileged is replaced by dropping everything and granting the eight the daemon uses. Nothing the sandbox does broke; what stopped working is mount, mknod, raw sockets, chroot, writing to proc, and seeing the host's disks. AUDIT_WRITE is among them because without it sudo works and complains every time. The creation histogram's lowest bucket was a tenth of a second, so the metric could not observe the claim the product makes about its own speed. It can now, and it carries the isolation, so comparing them is a query. Co-authored-by: Hanzo Dev <[email protected]>
123 lines
2.2 KiB
Go
123 lines
2.2 KiB
Go
// Copyright 2025 Hanzo Industries Inc.
|
|
// SPDX-License-Identifier: AGPL-3.0
|
|
|
|
package util
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/charmbracelet/bubbles/spinner"
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
"github.com/charmbracelet/lipgloss"
|
|
"github.com/hanzoai/runtime/apps/cli/views/common"
|
|
log "github.com/sirupsen/logrus"
|
|
"golang.org/x/term"
|
|
)
|
|
|
|
var isAborted bool
|
|
|
|
type model struct {
|
|
spinner spinner.Model
|
|
quitting bool
|
|
message string
|
|
inline bool
|
|
}
|
|
|
|
type Msg string
|
|
|
|
func initialModel(message string, inline bool) model {
|
|
s := spinner.New()
|
|
s.Spinner = spinner.Dot
|
|
s.Style = lipgloss.NewStyle().Foreground(common.Green)
|
|
return model{spinner: s, message: message, inline: inline}
|
|
}
|
|
|
|
func (m model) Init() tea.Cmd {
|
|
return m.spinner.Tick
|
|
}
|
|
|
|
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|
switch msg := msg.(type) {
|
|
case Msg:
|
|
m.quitting = true
|
|
return m, tea.Quit
|
|
|
|
case tea.KeyMsg:
|
|
switch keypress := msg.String(); keypress {
|
|
case "ctrl+c":
|
|
isAborted = true
|
|
m.quitting = true
|
|
return m, tea.Quit
|
|
}
|
|
}
|
|
var cmd tea.Cmd
|
|
m.spinner, cmd = m.spinner.Update(msg)
|
|
return m, cmd
|
|
|
|
}
|
|
|
|
func WithSpinner(message string, fn func() error) error {
|
|
if isTTY() {
|
|
p := start(message, false)
|
|
defer stop(p)
|
|
}
|
|
return fn()
|
|
}
|
|
|
|
func WithInlineSpinner(message string, fn func() error) error {
|
|
if isTTY() {
|
|
p := start(message, true)
|
|
defer stop(p)
|
|
}
|
|
return fn()
|
|
}
|
|
|
|
func start(message string, inline bool) *tea.Program {
|
|
var p *tea.Program
|
|
if inline {
|
|
p = tea.NewProgram(initialModel(message, true))
|
|
} else {
|
|
p = tea.NewProgram(initialModel(message, false), tea.WithAltScreen())
|
|
}
|
|
go func() {
|
|
if _, err := p.Run(); err != nil {
|
|
fmt.Println(err)
|
|
os.Exit(1)
|
|
}
|
|
if isAborted {
|
|
fmt.Println("Operation cancelled")
|
|
os.Exit(1)
|
|
}
|
|
}()
|
|
return p
|
|
|
|
}
|
|
|
|
func stop(p *tea.Program) {
|
|
p.Send(Msg("quit"))
|
|
err := p.ReleaseTerminal()
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func (m model) View() string {
|
|
if m.quitting {
|
|
return ""
|
|
}
|
|
|
|
str := ""
|
|
if m.inline {
|
|
str = common.GetInfoMessage(fmt.Sprintf("%s %s ...", m.spinner.View(), m.message))
|
|
} else {
|
|
str = common.NameStyle.Render(fmt.Sprintf("\n\n %s %s ...\n\n", m.spinner.View(), m.message))
|
|
}
|
|
|
|
return str
|
|
}
|
|
|
|
func isTTY() bool {
|
|
return term.IsTerminal(int(os.Stdout.Fd()))
|
|
}
|