config

package
v1.13.2 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: MIT Imports: 17 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package config keeps the CLI's credentials on disk and narrows what the rest of the machine can do with them.

What is narrowed

`~/.alpacon` is held at 0700 and the files inside it at 0600. Anything found wider is narrowed in place before it is read or written rather than only at the moment it is created, because a file that was already wide when this CLI arrived is exactly the one worth closing. This file decides what to narrow; permissions_unix.go holds the guards it refuses on, and the platform-specific opens live in permissions_darwin.go and permissions_linux.go.

Handles, not paths

Each chmod is bound to an open handle rather than to a path, so nothing can be swapped in between the look and the change. Two path-based reads are left, and neither decides a mode by itself: the pre-check in restrictConfigDirectoryMode that asks whether a directory permitting traversal but not reads has anything to narrow at all—safe because the platform helper behind it re-derives the mode from its own handle and only ever ANDs with 0700—and narrowToPublishedFileMode's os.Stat in device.go, which reads the mode a rename is about to stand in for and intersects it, so it can only take bits away.

What a caller must not read past

refuseUnsafeConfigFile rejects anything that is not a regular file, since O_NONBLOCK keeps the open off a named pipe but says nothing about the read behind it—os.NewFile hands a non-blocking descriptor to the poller and io.ReadAll then waits there forever—and it rejects a handle on a file this process does not own, because mode bits say nothing there: root can read anything, and a sudo that keeps HOME would otherwise take an unprivileged user's own file as root's device id. Both carry errUnsafeConfigFile, and that is the one narrowing failure LoadConfig refuses rather than warns about, since a config file another account owns names the host the CLI talks to and decides whether its certificate is checked. LoadConfig reads the very handle this narrowed, and falls back to reopening the path only for a symbolic link, which is refused a chmod but not a read—that fallback runs the same refusal on what the link resolves to.

Best effort everywhere else

The mode is read back after a chmod that reported success, since a filesystem without permission bits answers the call and keeps the mode; only bits that hand another account access count as a failure, because macOS reports every file on a FAT volume as 0700. A chmod that fails outright is held to the same standard, which is what keeps a Linux vfat mount whose fmask already grants no other account access from being read as an exposure. Everything else is best effort—a read-only mount, a directory another account owns, and a modeless filesystem all refuse the chmod—so warnUnrestricted warns once per subject and cause and the command carries on rather than dying over a mode it cannot change. ~/.alpacon/device_id is the exception in the other direction: it fails closed, because an MFA presence proof binds to whatever identifier readDeviceID returns, so a handle it could not protect is treated as no identifier at all and the server falls back to an IP fingerprint.

Windows

All of it is Unix only. Windows chmod changes the read-only attribute rather than access permissions, so nothing is repaired there, the two modes above are not enforced, and the symlink, hard-link and owner refusals are stubs—the device id is not protected on Windows either.

Index

Constants

View Source
const (
	ConfigFileName = "config.json"
	ConfigFileDir  = ".alpacon"

	// ServiceTokenPrefix is the default service-token key prefix, hard-coded here.
	// It matches the server's default SERVICE_TOKEN_PREFIX; if a self-hosted server
	// overrides that setting, its service tokens will not match this prefix and are
	// treated as generic tokens. Personal API tokens use "alpat-".
	ServiceTokenPrefix = "alpst-"
)
View Source
const (
	// DeviceIDFileName holds the per-installation device identifier. It sits
	// beside config.json rather than inside it so it is independent of session
	// state: logout deletes config.json, and the machine has not changed, so the
	// identifier must outlive it. This mirrors the web client, which keeps its
	// own identifier in localStorage rather than alongside its session.
	DeviceIDFileName = "device_id"
)

Variables

This section is empty.

Functions

func CreateConfig

func CreateConfig(workspaceURL, workspaceName, token, expiresAt, accessToken, refreshToken, baseDomain string, expiresIn int, insecure bool) error

func DeleteConfig

func DeleteConfig() error

func GetActiveWorkSession added in v1.4.6

func GetActiveWorkSession() (string, error)

GetActiveWorkSession returns the active work-session UUID for the current workspace. Returns "" (no error) when no session is set, the config is missing the map, or no config file exists.

func GetAuthMethod added in v1.4.8

func GetAuthMethod(cfg Config) string

GetAuthMethod returns a human-readable authentication method string for cfg.

func GetOrCreateDeviceID added in v1.11.0

func GetOrCreateDeviceID() (string, error)

GetOrCreateDeviceID returns the stable per-installation device identifier, generating and persisting a new one when the file is missing or holds a malformed value. The identifier lets the server bind an MFA presence proof to the CLI installation that requested the challenge; without it the server has to fall back to an IP-based fingerprint, which two installations behind one egress IP would share.

It lives in ~/.alpacon/device_id, one line of plain text. That file is per installation rather than per workspace, so every workspace this installation logs in to shares the identifier, and it is untouched by DeleteConfig, so a logout does not orphan the presence proofs bound to it.

The identifier is not a secret in the sense a password or a token is—knowing it grants nothing to someone who cannot also authenticate as the user—but it is not inert either. Under ADR 0054 it is the value an MFA presence proof binds to, and it identifies this installation to the identity provider, travelling there in OAuth requests where it may be recorded in tenant logs. So it is a stable, security-relevant identifier rather than a throwaway: the file is kept at 0600 inside the 0700 config directory, out of reach of other accounts on a shared machine, and it does not belong in logs or bug reports.

func GetSmuxConfig added in v1.0.0

func GetSmuxConfig() *smux.Config

GetSmuxConfig returns a ready-to-use smux configuration.

func IsSaaS added in v1.4.2

func IsSaaS() (bool, error)

IsSaaS returns true if the workspace is an Alpacon Cloud (SaaS) deployment authenticated via Auth0. OnPrem deployments use a legacy API token and return false.

func IsServiceToken added in v1.7.4

func IsServiceToken(token string) bool

IsServiceToken reports whether token is a service token, identified by its key prefix. Service tokens are application principals and have no user profile.

func IsValidDeviceID added in v1.11.0

func IsValidDeviceID(id string) bool

IsValidDeviceID reports whether id is acceptable as a device identifier, applying the same rule as the Auth0 action that consumes it.

func ResolveAuthMethod added in v1.4.8

func ResolveAuthMethod() string

ResolveAuthMethod loads config and returns the auth method string.

func SaveRefreshedAuth0Token

func SaveRefreshedAuth0Token(accessToken string, expiresIn int) error

func SetActiveWorkSession added in v1.4.6

func SetActiveWorkSession(uuid string) error

SetActiveWorkSession persists the work-session UUID for the config's current workspace ("" clears it); a caller holding a client must use SetActiveWorkSessionFor with the client's pinned workspace instead.

func SetActiveWorkSessionFor added in v1.12.0

func SetActiveWorkSessionFor(workspaceName, uuid string) error

SetActiveWorkSessionFor persists the work-session UUID under workspaceName ("" clears it); workspaceName is a parameter, not a fresh read, because create --wait --use can block on approval long enough for another shell's 'alpacon ws use' to file it under a workspace it was never created in.

func SwitchWorkspace added in v1.1.0

func SwitchWorkspace(newURL, newName string) error

SwitchWorkspace updates the workspace URL and name in the existing config.

Types

type Config

type Config struct {
	WorkspaceURL         string `json:"workspace_url"`
	WorkspaceName        string `json:"workspace_name"`
	Token                string `json:"token,omitempty"`
	ExpiresAt            string `json:"expires_at,omitempty"`
	AccessToken          string `json:"access_token,omitempty"`
	RefreshToken         string `json:"refresh_token,omitempty"`
	AccessTokenExpiresAt string `json:"access_token_expires_at,omitempty"`
	BaseDomain           string `json:"base_domain,omitempty"`
	Insecure             bool   `json:"insecure"`
	// ActiveWorkSessions maps workspace name to active work-session UUID.
	// Nil (not an empty map) when the key is absent from the JSON config file.
	ActiveWorkSessions map[string]string `json:"active_work_sessions,omitempty"`
}

Config describes the configuration for Alpacon CLI

func LoadConfig

func LoadConfig() (Config, error)

func (Config) IsMultiWorkspaceMode added in v1.1.0

func (c Config) IsMultiWorkspaceMode() bool

IsMultiWorkspaceMode returns true if the user logged in via Auth0 with a known base domain, enabling workspace listing and switching from the JWT.

func (Config) IsSaaS added in v1.4.2

func (c Config) IsSaaS() bool

Jump to

Keyboard shortcuts

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