Documentation
¶
Overview ¶
Package chalkctl implements the chalk deployment manager's core: config, state, embedded deploy templates, image-signature verification, and the podman bring-up used by `chalkctl init`. Command wiring lives in cmd/chalkctl; this package holds the reusable machinery.
Index ¶
- Constants
- Variables
- func Backup(o BackupOptions) error
- func DetectPublicIP() (string, error)
- func Down(o LifecycleOptions) error
- func EphemeralDisable(o EphemeralOptions) error
- func EphemeralList(o EphemeralOptions) error
- func EphemeralPurge(o EphemeralOptions, channelID string) error
- func FirewallHint() string
- func Images(o ImagesOptions) error
- func Init(o InitOptions) error
- func Maint(o MaintOptions) error
- func MaintStatus(statePath string, out io.Writer) error
- func MaintenanceMessageHTML(msg string) (string, error)
- func Metrics(o MetricsOptions) error
- func PushAPNsClear(o PushOptions, yes bool) error
- func PushAPNsSet(o PushOptions, s APNsSetOptions) error
- func PushDisable(o PushOptions) error
- func PushEnable(o PushOptions) error
- func PushRotateKey(o PushOptions, yes bool) error
- func PushStatus(o PushOptions) error
- func ReconfigureTurn(o ReconfigureTurnOptions) error
- func RequireRoot() error
- func ResolveBackupPassword(passwordFile string, confirm bool) (string, error)
- func ResolvePublicIP(configured string, logf func(string, ...any)) (string, error)
- func Restore(o RestoreOptions) error
- func ReviewInit(o ReviewOptions, ro ReviewInitOptions) error
- func ReviewRegistration(o ReviewOptions, open bool) error
- func ReviewRemove(o ReviewOptions) error
- func ReviewSetUp(o ReviewOptions, up bool) error
- func ReviewStatus(o ReviewOptions) error
- func ServerKeyRotate(o ServerKeyOptions, yes bool) error
- func ServerKeyShow(o ServerKeyOptions) error
- func Status(o LifecycleOptions) error
- func Systemctl(args ...string) (string, error)
- func Up(o LifecycleOptions) error
- func Update(o UpdateOptions) error
- func ValidatePublicIP(s string) error
- func WrapSigDisable(o WrapSigOptions) error
- func WrapSigEnable(o WrapSigOptions, force bool) error
- func WrapSigStatus(o WrapSigOptions) error
- type APNsSetOptions
- type APNsSettings
- type BackupOptions
- type Config
- type CosignVerifier
- type EphemeralOptions
- type ImagesOptions
- type InitOptions
- type InitParams
- type LifecycleOptions
- type MaintOptions
- type Manifest
- type MetricsOptions
- type NoopVerifier
- type Podman
- type PushOptions
- type ReconfigureTurnOptions
- type RestoreOptions
- type ReviewConf
- type ReviewInitOptions
- type ReviewOptions
- type ReviewParams
- type ServerKeyOptions
- type Snapshot
- type State
- type UpdateOptions
- type Verifier
- type WrapSigOptions
- type WrapSigReport
Constants ¶
const ( DefaultConfigPath = "/etc/chalk/chalkctl.conf" DefaultStatePath = "/var/lib/chalk/state.json" DefaultEnvPath = "/etc/chalk/chalk.env" DefaultQuadletDir = "/etc/containers/systemd" DefaultCaddyfile = "/etc/chalk/caddy/Caddyfile" DefaultImage = "ghcr.io/scuq/chalk" DefaultPostgresTag = "18-alpine" DefaultCaddyTag = "2-alpine" DefaultCoturnTag = "4.14.0-r0-alpine" DefaultChannel = "stable" )
Default config/state paths. Overridable via flags for testing.
const ( TurnMinPort = 49160 TurnMaxPort = 49999 )
coturn's UDP relay port range. Every allocation holds a port for its lifetime, so the range has to absorb a whole deployment's calls plus the allocations that outlive a client which left without releasing them. The range and FirewallHint read the same constants: they drift apart at the cost of allocations that succeed while media silently goes nowhere.
const ( DefaultReviewConfPath = "/etc/chalk/review.conf" DefaultReviewEnvPath = "/etc/chalk/review.env" )
Paths and names of the review instance.
const BackupPasswordEnv = "CHALK_BACKUP_PASSWORD"
BackupPasswordEnv is the non-interactive way to supply the password (for the --password-file alternative see ResolveBackupPassword).
const (
DefaultBackupDir = "/var/lib/chalk/backups"
)
72-2: `chalkctl backup` -- everything needed to stand this deployment up on another host, in one password-encrypted file.
What goes in, and why only this:
- the database, which holds every message, channel, membership, device and attachment (attachment ciphertext is a bytea column, not a file), plus the wrapped identity seeds and the encrypted TOTP secrets;
- chalk.env, because CHALK_TOTP_ENC_KEY is the key those TOTP secrets are encrypted under. A database restored without it locks every account out at the second factor;
- chalkctl.conf, so restore can tell the operator which deployment knobs the old host had set.
What stays out: Caddy's certificate volume (the new host issues its own), and the chalk-blobs volume (chalkd never writes to it -- attachments are in Postgres).
const DefaultMaintenanceMessage = "someone is working on the server. it will be back shortly."
DefaultMaintenanceMessage is used when `maint on` is given no --message.
const ManifestFormat = 1
ManifestFormat is the archive's logical layout version, independent of the crypto envelope's archiveVersion.
const MinBackupPasswordLen = 12
MinBackupPasswordLen is the floor for a NEW backup password. Lower than the account password rule (20 chars, 4 classes) on purpose: this one is typed by the operator at a console, often twice, and the archive it protects is at rest on hosts they control. Restore imposes no floor -- an old archive must stay openable whatever it was sealed with.
const RestoreWipeSQL = "DROP SCHEMA IF EXISTS public CASCADE;\nCREATE SCHEMA public;\n"
RestoreWipeSQL is prepended to the dump so the load starts from a clean schema. Dropping it beats relying on a dump's own DROP statements: if this host's chalkd has already applied migrations the backup predates, only a clean slate leaves schema_migrations agreeing with the schema it describes. chalkd applies anything newer forward on its next start.
Variables ¶
var ErrArchivePassword = fmt.Errorf("cannot decrypt backup: wrong password, or the archive is corrupt")
ErrArchivePassword is returned when a frame fails to authenticate, which in practice means the password is wrong (a damaged file reads the same way).
var PGDumpArgs = []string{"--no-owner", "--no-privileges"}
PGDumpArgs keep the dump loadable whatever the target host's role names are: the restore host's chalk role ends up owning everything it loads.
var PSQLLoadArgs = []string{"-q", "-v", "ON_ERROR_STOP=1", "--single-transaction"}
PSQLLoadArgs make the load all-or-nothing: one transaction, aborting on the first error, so a failed restore leaves the database exactly as it was.
var Templates embed.FS
Templates holds the deploy files (Quadlet units, Caddyfile, env, timer) baked into the binary, so `init` writes a complete stack with no external files to fetch. Rendered via text/template against InitParams.
Functions ¶
func Backup ¶ added in v0.5.9
func Backup(o BackupOptions) error
Backup dumps the database and seals it, the env file and the config into an encrypted archive. The stack keeps running throughout: pg_dump reads a consistent snapshot, so there is no window where the backup and a live writer disagree.
func DetectPublicIP ¶ added in v0.3.45
DetectPublicIP asks an external echo service for this host's public IPv4.
func Down ¶
func Down(o LifecycleOptions) error
Down stops the whole stack. It is idempotent and tolerant: a service that is already stopped or was never created is not an error (we reset-failed then stop, ignoring "not loaded"). With PurgeState it removes state.json so `init` can run again; with PurgeData it also removes the postgres volume (destroys the database -- explicit opt-in only).
This replaces the manual `systemctl stop ... && rm state.json && podman volume rm chalk-pgdata` dance.
func EphemeralDisable ¶ added in v0.7.0
func EphemeralDisable(o EphemeralOptions) error
EphemeralDisable turns the feature off: CHALK_EPHEMERAL_ENABLED=false in the env (and the chalkctl config so a later init --force keeps it off), every outstanding link revoked, chalkd restarted to load the flag. Existing rooms and guests live out their TTL -- follow with `ephemeral purge` to destroy them too.
func EphemeralList ¶ added in v0.7.0
func EphemeralList(o EphemeralOptions) error
EphemeralList prints every ephemeral room.
func EphemeralPurge ¶ added in v0.7.0
func EphemeralPurge(o EphemeralOptions, channelID string) error
EphemeralPurge expires one room (channelID != "") or every ephemeral room NOW: links are revoked and expires_at set to now(); chalkd's janitor hard-deletes within the minute (or at its next start if chalkd is down).
func FirewallHint ¶
func FirewallHint() string
FirewallHint returns the ports the operator must open (printed by init).
func Images ¶ added in v0.2.1
func Images(o ImagesOptions) error
Images inspects every image in the stack (chalk app + postgres + coturn) and prints version / revision / created provenance for each. Read-only. The point is to answer "what exactly is deployed?" at a glance -- the gap that made a stale image indistinguishable from a fresh one.
func Init ¶
func Init(o InitOptions) error
Init runs the full bootstrap. Order matters:
- preflight (root, config valid, not already initialized, cosign present)
- verify the image signature (unless --skip-verify)
- pull + resolve the immutable digest (the pin the units carry)
- generate secrets, render env + units + Caddyfile, write to disk
- daemon-reload + start the stack (unless --no-start)
- write config + state, install the weekly update timer
Idempotency: refuses to run if state already exists (points at `update`).
func Maint ¶ added in v0.5.9
func Maint(o MaintOptions) error
Maint switches maintenance mode on or off.
func MaintStatus ¶ added in v0.5.9
MaintStatus reports the current mode without changing anything.
func MaintenanceMessageHTML ¶ added in v0.5.9
MaintenanceMessageHTML validates an operator-supplied notice and returns it ready to embed. The message lands inside a backtick-quoted Caddyfile string that is also HTML, so a backtick would end the string early and a tag would end up live on the page -- the first is rejected outright, the second escaped.
func Metrics ¶ added in v0.6.0
func Metrics(o MetricsOptions) error
Metrics collects and prints a report. With Sample set it takes two readings and reports the difference, which turns cumulative counters into rates.
func PushAPNsClear ¶ added in v0.12.5
func PushAPNsClear(o PushOptions, yes bool) error
PushAPNsClear empties the five CHALK_APNS_* values and restarts chalkd. Native push to every iOS app of this server then stops. If yes is false, PushAPNsClear returns an error and changes nothing.
func PushAPNsSet ¶ added in v0.12.5
func PushAPNsSet(o PushOptions, s APNsSetOptions) error
PushAPNsSet checks the key file and the ids, writes the five CHALK_APNS_* values into the env file, and restarts chalkd. It replaces the lines that exist and appends the others. It does not change other lines. If a check fails, PushAPNsSet changes nothing and does not restart chalkd. It never prints the key. If push is off, it says so and names the command that turns push on.
func PushDisable ¶ added in v0.12.1
func PushDisable(o PushOptions) error
PushDisable turns Web Push off. Subscriptions stay stored. Pushes start again after `chalkctl push enable`.
func PushEnable ¶ added in v0.12.1
func PushEnable(o PushOptions) error
PushEnable turns Web Push on. If the env file has no key pair or no subject, it returns an error, because chalkd would not start.
func PushRotateKey ¶ added in v0.12.1
func PushRotateKey(o PushOptions, yes bool) error
PushRotateKey replaces the VAPID key pair and restarts chalkd. If yes is false, it returns an error, because no device gets a push again until it opens chalk. Rotate the key if a copy of the env file is lost. The private key lets its holder send notifications that look like they come from this server.
func PushStatus ¶ added in v0.12.1
func PushStatus(o PushOptions) error
PushStatus prints the push switch, the subject and the public key.
func ReconfigureTurn ¶ added in v0.2.2
func ReconfigureTurn(o ReconfigureTurnOptions) error
ReconfigureTurn re-renders ONLY the coturn unit (picking up verbose/image-tag/public-IP changes) and restarts coturn. It does not touch chalkd, postgres, caddy, the database, or secrets -- it reuses the existing CHALK_TURN_SECRET from the env file so credentials stay valid.
This is the lightweight path for "I changed a coturn setting" without a full `init --force` (which restarts the whole stack).
func RequireRoot ¶
func RequireRoot() error
RequireRoot fails unless running as uid 0 (rootful base).
func ResolveBackupPassword ¶ added in v0.5.9
ResolveBackupPassword finds the archive password, in order: the file at passwordFile, then $CHALK_BACKUP_PASSWORD, then an interactive prompt. When confirm is set (taking a backup, where a typo is only discovered on the day it matters) the prompt asks twice and enforces MinBackupPasswordLen.
func ResolvePublicIP ¶ added in v0.3.45
ResolvePublicIP returns the configured address, or detects one. Detection result is returned so the caller can persist it: a coturn whose relay address silently changes between runs is a call-breaking surprise.
func Restore ¶ added in v0.5.9
func Restore(o RestoreOptions) error
Restore loads an archive into the current deployment, replacing its database. The archive is read in a single streaming pass -- the manifest arrives first, so the operator sees what they are about to load (and is asked to confirm it) before the dump is touched.
func ReviewInit ¶ added in v0.13.0
func ReviewInit(o ReviewOptions, ro ReviewInitOptions) error
ReviewInit makes the review instance. It does these steps:
- Generate the secrets. Copy CHALK_TURN_SECRET from production.
- Write review.env, the review units, and review.conf.
- Start postgres-review, create the database roles, migrate the database, and write the row of review_instance.
- Start chalkd-review, write the Caddy unit and the Caddyfile, and restart Caddy, which then joins the review network.
Registration is open after init, so that the operator can make the demo accounts. `chalkctl review registration closed` closes it.
func ReviewRegistration ¶ added in v0.13.0
func ReviewRegistration(o ReviewOptions, open bool) error
ReviewRegistration opens or closes registration on the review instance, and restarts chalkd-review if it runs.
func ReviewRemove ¶ added in v0.13.0
func ReviewRemove(o ReviewOptions) error
ReviewRemove deletes the review instance: its services, units, volumes, network, env file, and review.conf. First it asks the operator to type the domain of the review instance. Then it writes the Caddy unit and the Caddyfile without the review lines, and restarts Caddy.
func ReviewSetUp ¶ added in v0.13.0
func ReviewSetUp(o ReviewOptions, up bool) error
ReviewSetUp starts the review instance if up is true, and stops it if up is false. It renders the units again, so that the state stays the same after a reboot. It also renders the Caddyfile again: the proxy when up, the "off" page when down. It does not stop or restart production. Caddy reloads in place.
func ReviewStatus ¶ added in v0.13.0
func ReviewStatus(o ReviewOptions) error
ReviewStatus prints the state of the review instance.
func ServerKeyRotate ¶ added in v0.8.0
func ServerKeyRotate(o ServerKeyOptions, yes bool) error
ServerKeyRotate replaces CHALK_SERVER_ID_KEY with a fresh key. This WALLS every client until its user re-pins, so it refuses without --yes and always prints the new fingerprint to announce. Restarting chalkd is the operator's next step (same as any env change).
func ServerKeyShow ¶ added in v0.8.0
func ServerKeyShow(o ServerKeyOptions) error
ServerKeyShow prints the fingerprint of the configured server identity.
func Status ¶
func Status(o LifecycleOptions) error
Status prints the deployed version/digest from state and each service's active state. Read-only.
func Up ¶
func Up(o LifecycleOptions) error
Up starts the whole stack in dependency order. Requires that init has already written the units (state.json present); otherwise points the operator at init.
func Update ¶ added in v0.2.1
func Update(o UpdateOptions) error
Update pulls the target chalk image, verifies its signature, pins the new digest, restarts chalkd onto it, and health-checks. On health failure it rolls chalkd back to the previous digest. Only the chalk app is swapped; postgres/coturn are untouched (their tags are pinned by init).
This makes the weekly auto-update timer functional (it calls `chalkctl update`), and gives a manual path to move versions without a full re-init.
func ValidatePublicIP ¶ added in v0.3.45
ValidatePublicIP accepts a bare public IPv4 literal.
IPv6 is rejected on purpose: the relay is pinned to one address family, and a coturn told to listen on an IPv6 address while clients offer IPv4 candidates fails in a way that looks like a firewall problem for hours.
func WrapSigDisable ¶ added in v0.7.0
func WrapSigDisable(o WrapSigOptions) error
WrapSigDisable turns enforcement back off. The way out when enabling turns out to have stranded someone: unsigned wraps are accepted again immediately, so a blocked member recovers on their next channel open rather than needing anyone to re-share.
func WrapSigEnable ¶ added in v0.7.0
func WrapSigEnable(o WrapSigOptions, force bool) error
WrapSigEnable turns enforcement on: unsigned wraps are refused server-side on publish, and clients are told (welcome.wrap_sig_required) to refuse them on read. Refuses to run while anyone would be stranded unless force is set.
func WrapSigStatus ¶ added in v0.7.0
func WrapSigStatus(o WrapSigOptions) error
WrapSigStatus prints whether the deployment is ready for enforcement.
Types ¶
type APNsSetOptions ¶ added in v0.12.5
APNsSetOptions are the arguments of PushAPNsSet. KeyFile is the path of the .p8 file. Sandbox selects the APNs sandbox. If Sandbox is false, the environment is production.
type APNsSettings ¶ added in v0.12.5
APNsSettings holds the five CHALK_APNS_* values. Key is the key of Apple as one base64 line (the DER of the .p8 file). Environment is "production" or "sandbox". If Environment is empty, chalkd uses production. The zero value means that no APNs settings exist.
type BackupOptions ¶ added in v0.5.9
type BackupOptions struct {
Cfg Config
Password string
OutPath string // "" -> DefaultBackupDir/chalk-<domain>-<ts>.chalkbak
Podman *Podman
StatePath string
EnvPath string
ConfigPath string
Out io.Writer
}
BackupOptions configures a backup.
type Config ¶
type Config struct {
Domain string // required for init; the public hostname
Image string // GHCR image, no tag (DefaultImage)
PostgresTag string // postgres image tag (pinned; manual major upgrades)
CaddyTag string // caddy image tag
CoturnTag string // coturn image tag (alpine)
TurnVerbose bool // coturn --verbose logging
PublicIP string // coturn listening/relay/external IPv4; detected when empty
Channel string // update channel: stable | <explicit tag>
VoiceEnabled bool // Phase 30 voice on/off
Rootful bool // MUST be true for this base; init requires --rootful
// WebAuthn / passkeys. RPID MUST equal the domain or browsers reject
// passkey enrollment; origins must be the https origin (auto-derived
// from Domain, since chalkd sits behind Caddy and can't infer it).
AdminUsername string // seeds the admin row on first boot; enroll a passkey onto it
AdminEmail string // admin email (first boot)
// Bootstrap: let anyone register so friends can join. TIGHTEN to false
// once everyone's in (then use invites).
OpenRegistration bool
// Optional operational knobs (0/"" = leave chalkd's own default).
VoiceMaxParticipants int // CHALK_VOICE_MAX_PARTICIPANTS (mesh cap)
AttachMaxBytes int64 // CHALK_ATTACH_MAX_BYTES (upload cap; disk guard)
GiphyAPIKey string // CHALK_GIPHY_API_KEY (GIF picker; optional)
ThreadActiveWindowHours int // CHALK_THREAD_ACTIVE_WINDOW_HOURS (thread inbox recency)
// 57-1: link previews. Enabled defaults true (chalkd's own default);
// Domains is the comma-separated whitelist override ("" = chalkd's
// built-in YouTube + Steam list).
LinkPreviewEnabled bool // CHALK_LINKPREVIEW_ENABLED
LinkPreviewDomains string // CHALK_LINKPREVIEW_DOMAINS
// 73-2: load pg_stat_statements into Postgres (per-query timings for
// `chalkctl metrics`). Costs a little on every statement, so it is opt-in.
PgStatStatements bool
// 80-5: ephemeral voice channels with guest magic links. Enabled defaults
// true (chalkd's own default); the hour/count knobs are 0 = chalkd's
// defaults (720 h channel cap, 24 h invite cap, 8 guests). chalkd refuses
// an invite TTL above 24 h outright.
EphemeralEnabled bool // CHALK_EPHEMERAL_ENABLED
EphemeralMaxTTLHours int // CHALK_EPHEMERAL_MAX_TTL_HOURS
EphemeralInviteHours int // CHALK_EPHEMERAL_INVITE_MAX_TTL_HOURS
EphemeralMaxGuests int // CHALK_EPHEMERAL_MAX_GUESTS
// 82-6: refuse unsigned channel-key wraps. Defaults false -- the operator
// flips it once the self-healing sweep has upgraded the wraps in the wild
// (docs/phases/PHASE-82-SIGNEDWRAP.md), and flipping early strands members whose
// wrap has not been re-signed yet.
WrapSigRequired bool // CHALK_WRAP_SIG_REQUIRED
// 65-3: Web Push. PushEnabled is true by default on init. `chalkctl
// update` backfills false into an existing deployment, and `chalkctl push
// enable` turns it on. PushSubject is the operator contact in every VAPID
// token, a mailto: or https: URL. If it is empty, the subject is
// https://<Domain>.
PushEnabled bool // CHALK_PUSH_ENABLED
PushSubject string // CHALK_VAPID_SUBJECT
// 65-11: IPv4 only for the outbound HTTP clients of chalkd. Config key
// OUTBOUND_IPV4_ONLY. `init --ipv4-only` sets it, and `init --force` keeps it.
OutboundIPv4Only bool // CHALK_OUTBOUND_IPV4_ONLY
}
Config is the persisted deployment configuration. It is written to DefaultConfigPath by `init` and re-read by later commands. The on-disk format is stdlib key=value (no TOML dependency): one KEY=value per line, '#' comments, blank lines ignored. FLAGS OVERRIDE FILE VALUES -- Load reads the file first, then the caller applies flag overlays via the With* setters or by constructing flags that default to the file's values.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns the baseline before file/flag overlays.
func LoadConfigFile ¶
LoadConfigFile overlays a key=value file onto cfg. A missing file is not an error (returns cfg unchanged) -- init works purely from flags on a fresh host. Unknown keys are ignored with a note to stderr rather than failing, so a newer config file stays loadable by an older binary.
type CosignVerifier ¶
type CosignVerifier struct {
// Repo is "owner/name" (e.g. "scuq/chalk"), used to build the identity
// regexp that pins the signing workflow.
Repo string
// Bin is the cosign executable name/path ("cosign" by default).
Bin string
}
CosignVerifier shells out to the system `cosign` binary (Ubuntu packages it in universe). This is the permanent implementation -- the project chose shell-cosign over the heavy in-process sigstore dependency tree. The identity is pinned to the release-chalk workflow, any tag.
func NewCosignVerifier ¶
func NewCosignVerifier(repo string) *CosignVerifier
NewCosignVerifier builds a verifier for the given owner/name repo.
func (*CosignVerifier) Describe ¶
func (c *CosignVerifier) Describe() string
func (*CosignVerifier) Verify ¶
func (c *CosignVerifier) Verify(imageRef string) error
Verify runs `cosign verify` with keyless GitHub-OIDC parameters.
type EphemeralOptions ¶ added in v0.7.0
type EphemeralOptions struct {
Cfg Config
Podman *Podman
EnvPath string
ConfigPath string
Out io.Writer
// Confirm gates purge (type-the-domain). nil -> interactive prompt; a
// func returning true for --yes.
Confirm func(prompt string) bool
// Restart restarts chalkd after disable. nil -> systemctl; tests stub it.
Restart func() error
}
EphemeralOptions configures the ephemeral subcommands.
type ImagesOptions ¶ added in v0.2.1
ImagesOptions configures the images command.
type InitOptions ¶
type InitOptions struct {
Cfg Config
Version string // release tag to deploy, e.g. "v0.1.0" or "stable"
Verifier Verifier // CosignVerifier or NoopVerifier
Podman *Podman // nil -> NewPodman()
ConfigPath string // DefaultConfigPath
StatePath string // DefaultStatePath
EnvPath string // DefaultEnvPath
QuadletDir string // DefaultQuadletDir
CaddyfileAt string // DefaultCaddyfile
// 139-2: the review.conf to read, so that the Caddyfile and the Caddy unit
// keep the review instance. Empty means DefaultReviewConfPath.
ReviewConfPath string
NoStart bool // write everything but don't systemctl start
Out io.Writer // progress log; nil -> os.Stdout
// Force re-runs init over an existing deployment (re-render config + env,
// restart). WITHOUT DropDB it PRESERVES the existing DB and secrets (so a
// config-only change doesn't break the database). With DropDB it wipes the
// postgres volume and generates fresh secrets.
Force bool
DropDB bool
// Confirm is called for destructive actions (DropDB). It must return true
// to proceed. nil -> a default interactive prompt (stdin). Set to a
// func returning true for --yes / non-interactive.
Confirm func(prompt string) bool
}
InitOptions carries everything `chalkctl init` needs beyond Config: the paths (overridable for tests), the resolved verifier, and behavior flags.
type InitParams ¶
type InitParams struct {
Domain string
Image string // ghcr.io/owner/chalk (no tag)
Version string // v0.1.0 (for comment provenance)
Digest string // sha256:... (the pin)
PostgresTag string
CaddyTag string
CoturnTag string
TurnVerbose bool
PublicIP string // coturn listening/relay/external address (IPv4)
TurnMinPort int // coturn UDP relay range, low
TurnMaxPort int // coturn UDP relay range, high
VoiceEnabled bool
PGPassword string // secret -> env file only
PGAppPassword string // secret -> env file only (80-1: chalk_app role)
PGGuestPassword string // secret -> env file only (80-1: chalk_guest role)
TurnSecret string // secret -> env file only (voice)
TOTPEncKey string // secret -> env file only (auth v2 TOTP at-rest key)
ServerIDKey string // secret -> env file only (83-6 server identity seed)
AuthDecoyKey string // secret -> env file only (81-3: stable prelogin decoys)
AdminBootstrapToken string // secret -> env file only (one-shot admin claim)
ChalkctlPath string // absolute path to this binary (update timer)
// WebAuthn + admin seed + bootstrap + optional knobs (env file).
AdminUsername string
AdminEmail string
OpenRegistration bool
VoiceMaxParticipants int // 0 = omit (chalkd default)
AttachMaxBytes int64 // 0 = omit
GiphyAPIKey string // "" = omit
ThreadActiveWindowHours int // 0 = omit (chalkd default of 48h)
LinkPreviewEnabled bool // false = write CHALK_LINKPREVIEW_ENABLED=false
LinkPreviewDomains string // "" = omit (chalkd's built-in whitelist)
// 80-5: ephemeral voice channels. 81-3 writes Enabled either way (the
// server default is now off); the 0-valued knobs are omitted (chalkd
// defaults).
EphemeralEnabled bool
EphemeralMaxTTLHours int
EphemeralInviteHours int
EphemeralMaxGuests int
// 82-6: signed-wrap enforcement. Written either way, like Ephemeral's
// Enabled: the knob must be VISIBLE in the env file, because the whole
// migration story is "operator flips it when the sweep is done" -- a knob
// that has to be discovered in docs first never gets flipped.
WrapSigRequired bool
// 65-3: Web Push. The template writes these values in all cases, so the
// switch is visible in the env file. The key pair is generated once and
// kept. After a rotation, each subscription stops working until its
// device opens chalk again.
PushEnabled bool
VAPIDPublicKey string
VAPIDPrivateKey string
VAPIDSubject string
// 136-4c: the APNs values for the iOS app. The template writes the block
// only if APNsKey is not empty. A fresh init has no APNs values.
// `chalkctl push apns set` adds them, and init --force keeps them.
APNsKey string
APNsKeyID string
APNsTeamID string
APNsTopic string
APNsEnvironment string
// 65-11: the value of CHALK_OUTBOUND_IPV4_ONLY in the env file.
OutboundIPv4Only bool
// 72-5: maintenance mode. Caddyfile-only -- when set, Caddy serves the
// notice instead of proxying chalkd. The message is already HTML-escaped
// by the time it gets here (see Maint).
Maintenance bool
MaintenanceMessage string
// 73-2: load pg_stat_statements into Postgres so `chalkctl metrics` can
// report per-query timings. Off unless the operator asks for it.
PgStatStatements bool
// 139-2: DBHost is the Postgres host in the database URLs of the env file.
// Empty means "postgres", the container of production. The review env
// file sets "postgres-review".
DBHost string
// 139-2: the review instance, from review.conf. If ReviewDomain is empty,
// there is no review instance, and the Caddyfile and the Caddy unit have
// no review lines. ReviewUp selects the proxy or the "off" page.
ReviewDomain string
ReviewUp bool
}
InitParams is the data model every template renders against.
type LifecycleOptions ¶
type LifecycleOptions struct {
StatePath string
Out io.Writer
// PurgeState removes state.json so `init` can run fresh (down only).
PurgeState bool
// PurgeData ALSO removes the postgres data volume (down only) -- wipes
// the database. Never implied; requires explicit --purge-data.
PurgeData bool
// Voice controls whether coturn is part of the stack.
Voice bool
}
LifecycleOptions carries paths + output for down/up/status.
type MaintOptions ¶ added in v0.5.9
type MaintOptions struct {
Cfg Config
On bool
Message string // "" -> DefaultMaintenanceMessage (ignored when On is false)
Podman *Podman
StatePath string
CaddyfileAt string
Out io.Writer
// 139-2: ReviewConfPath is the review.conf to read, so that the Caddyfile
// keeps the review block. Empty means DefaultReviewConfPath.
ReviewConfPath string
}
MaintOptions configures a maintenance-mode switch.
type Manifest ¶ added in v0.5.9
type Manifest struct {
Format int `json:"format"`
CreatedAt time.Time `json:"created_at"`
Domain string `json:"domain"`
ChalkVersion string `json:"chalk_version"`
ChalkDigest string `json:"chalk_digest"`
PostgresTag string `json:"postgres_tag"`
AdminUsername string `json:"admin_username"`
VoiceEnabled bool `json:"voice_enabled"`
ChalkctlVersion string `json:"chalkctl_version"`
}
Manifest describes the deployment a backup was taken from. It is the first member of the archive so restore can report what it is about to load before it touches anything.
type MetricsOptions ¶ added in v0.6.0
type MetricsOptions struct {
Cfg Config
Sample time.Duration // 0 = one-shot; otherwise the window between readings
Podman *Podman
Out io.Writer
}
MetricsOptions configures a metrics run.
type NoopVerifier ¶
type NoopVerifier struct{}
NoopVerifier is selected by --skip-verify. It verifies nothing and says so; intended for air-gapped/offline installs where the operator accepts the risk. Every skip is loud.
func (NoopVerifier) Describe ¶
func (NoopVerifier) Describe() string
func (NoopVerifier) Verify ¶
func (NoopVerifier) Verify(string) error
type Podman ¶
type Podman struct {
Bin string // "podman"
}
Podman wraps the rootful podman + systemctl calls init needs. Kept small and shell-based (podman/systemctl are the stable interface); a future k8s driver would implement the same conceptual steps differently.
func (*Podman) ExecIn ¶ added in v0.5.9
ExecIn runs a command inside a running container, streaming r to its stdin.
type PushOptions ¶ added in v0.12.1
type PushOptions struct {
EnvPath string
ConfigPath string
Out io.Writer
// Restart restarts chalkd after a change. If it is nil, PushOptions uses
// systemctl.
Restart func() error
}
PushOptions holds the files to edit and how to restart chalkd.
type ReconfigureTurnOptions ¶ added in v0.2.2
type ReconfigureTurnOptions struct {
Cfg Config
EnvPath string // to read the existing CHALK_TURN_SECRET
ConfigPath string // to persist a newly-detected PUBLIC_IP
QuadletDir string
Out io.Writer
Verbose *bool // nil = keep cfg default; non-nil overrides --turn-verbose
PublicIP string // "" = use the config's, or detect
}
ReconfigureTurnOptions configures a coturn-only reconfigure.
type RestoreOptions ¶ added in v0.5.9
type RestoreOptions struct {
Cfg Config
Path string // archive to load
Password string
Podman *Podman
StatePath string
EnvPath string
ConfigPath string
Out io.Writer
// Confirm gates the destructive load. nil -> the interactive
// type-the-domain prompt; a func returning true for --yes.
Confirm func(prompt string) bool
// SkipHealth skips the post-restore health poll.
SkipHealth bool
HealthURL string
HealthTimeout time.Duration
}
RestoreOptions configures a restore.
type ReviewConf ¶ added in v0.13.0
type ReviewConf struct {
Domain string // the public hostname of the review instance
Up bool // true if the review instance runs
}
ReviewConf is the persisted state of the review instance (review.conf). The zero value means that there is no review instance.
func LoadReviewConf ¶ added in v0.13.0
func LoadReviewConf(path string) (ReviewConf, error)
LoadReviewConf reads review.conf at path. A missing file is the zero ReviewConf and no error.
func (ReviewConf) Exists ¶ added in v0.13.0
func (c ReviewConf) Exists() bool
Exists reports whether the review instance exists.
func (ReviewConf) Save ¶ added in v0.13.0
func (c ReviewConf) Save(path string) error
Save writes c to path with mode 0644. The file has no secrets.
type ReviewInitOptions ¶ added in v0.13.0
type ReviewInitOptions struct {
Domain string // the hostname of the review instance
AdminUsername string // the admin account of the review instance
AdminEmail string
}
ReviewInitOptions holds the values of `chalkctl review init`.
type ReviewOptions ¶ added in v0.13.0
type ReviewOptions struct {
Cfg Config // the config of production
Podman *Podman
ConfigPath string
StatePath string
EnvPath string // the env file of production
ReviewConfPath string
ReviewEnvPath string
QuadletDir string
CaddyfileAt string
NoStart bool // write the files, but do not start or stop a service
Out io.Writer
// Confirm asks the operator before `review remove`. It must return true
// to continue. If it is nil, defaults sets the prompt on stdin.
Confirm func(prompt string) bool
}
ReviewOptions holds the settings of the `chalkctl review` commands.
type ReviewParams ¶ added in v0.13.0
type ReviewParams struct {
Image string // ghcr.io/owner/chalk (no tag)
Version string // written in a comment in the unit
Digest string // the digest of production chalkd
PostgresTag string
VoiceEnabled bool
TurnDomain string // the domain of production, where coturn listens
Up bool // if false, the units have no [Install] section and do not start at boot
}
ReviewParams holds the values of the review unit templates.
type ServerKeyOptions ¶ added in v0.8.0
ServerKeyOptions locates the env file.
type Snapshot ¶ added in v0.6.0
type Snapshot struct {
At time.Time
DB dbStats
Tables []tableStats
Activity activityStats
Unused []indexStats
Checkpoints checkpointStats
Statements []statementStats // empty unless pg_stat_statements is installed
HasStmts bool
}
Snapshot is one reading of the database's statistics views.
type State ¶
type State struct {
Channel string `json:"channel"`
CurrentVersion string `json:"current_version"` // e.g. v0.1.0
CurrentDigest string `json:"current_digest"` // sha256:...
PreviousDigest string `json:"previous_digest,omitempty"`
UpdatedAt time.Time `json:"updated_at"`
// 72-5: maintenance mode is deployment state, not operator config -- it
// says what the Caddyfile currently serves. Kept here so `status` can
// report it and `init --force` can re-render without silently dropping
// it (you are in maintenance precisely because work is in progress).
Maintenance bool `json:"maintenance,omitempty"`
MaintenanceMessage string `json:"maintenance_message,omitempty"`
}
State is chalkctl's record of what is deployed, at DefaultStatePath. update and rollback read/write it; init seeds it. Current is what runs now; Previous is the last-good image to roll back to.
type UpdateOptions ¶ added in v0.2.1
type UpdateOptions struct {
Cfg Config
Version string // target tag; "" -> cfg.Channel (e.g. "stable")
Verifier Verifier // cosign or noop
Podman *Podman
StatePath string
EnvPath string // DefaultEnvPath
Out io.Writer
// ConfigPath is the chalkctl config file. If it is empty, the default is
// DefaultConfigPath. 65-3: update copies a backfilled push switch into it.
ConfigPath string
// HealthURL is polled after the swap; default https://<domain>/healthz.
HealthURL string
// HealthTimeout bounds the post-swap health poll (default 60s).
HealthTimeout time.Duration
// SkipHealth disables the health gate (and thus auto-rollback).
SkipHealth bool
}
UpdateOptions configures an update.
type Verifier ¶
type Verifier interface {
// Verify confirms the image (by tag or digest) carries a valid cosign
// signature from the expected workflow identity. Returns nil on success.
Verify(imageRef string) error
// Describe is a short human label for logs.
Describe() string
}
Verifier checks that an image reference is a genuine, signed release. The seam keeps init/update agnostic to HOW verification happens.
type WrapSigOptions ¶ added in v0.7.0
type WrapSigOptions struct {
Podman *Podman
EnvPath string
ConfigPath string
Out io.Writer
// Restart reloads chalkd after the flag changes. nil -> systemctl.
Restart func() error
}
WrapSigOptions mirrors EphemeralOptions: the paths to edit, how to reach Postgres, and how to restart chalkd once a flag changes.
type WrapSigReport ¶ added in v0.7.0
type WrapSigReport struct {
Totals wrapSigTotals
Lagging []laggingChannel
UnsignedGuests int
}
WrapSigReport is the readiness answer, split from the printing so the verdict is testable without a database.
func (WrapSigReport) Ready ¶ added in v0.7.0
func (r WrapSigReport) Ready() bool
Ready reports whether CHALK_WRAP_SIG_REQUIRED=true can be turned on without stranding anyone: every wrap at every live channel's current key version is signed. Unsigned GUEST INVITES do not gate it (see qWrapSigInvites).