bastion 0.60.0
ci / personal-data (push) Successful in 4s
ci / test (push) Successful in 3m36s
ci / fuzz (push) Successful in 3m35s

This commit is contained in:
Privatae
2026-11-02 00:10:58 +00:00
parent 4a5c310482
commit 4f8285ef18
100 changed files with 11537 additions and 840 deletions
+33 -5
View File
@@ -99,17 +99,30 @@ func serviceStateEnv(goos string, installed, authority bool, systemRoot string)
// serviceGuardedCommands would each act on a bastion in the caller's own
// profile. Beside a system service that is a second bastion (pair, run) or a
// view of an empty one (status, and `switch --list`, which would print the
// caller's own pairings and switches as though they were the machine's).
var serviceGuardedCommands = map[string]bool{"pair": true, "run": true, "status": true, "switch": true}
// view of an empty one (status, `switch --list`, activity and report, which
// would print the caller's own records as though they were the machine's).
var serviceGuardedCommands = map[string]bool{"pair": true, "run": true, "status": true, "switch": true,
"activity": true, "report": true}
// serviceLaneReads are the guarded commands that, on Linux and macOS, read
// the machine's bastion itself over its socket (reads.go) rather than a
// bastion of the caller's own: not refused here, and refused there for any
// account but the owner's.
var serviceLaneReads = map[string]bool{"status": true, "activity": true, "report": true}
// serviceGuard refuses a guarded command from an account that does not
// administer a machine whose bastion is a system service.
//
// On Linux the service is the systemd unit, and the caller says whether it is
// there (linuxSystemUnitPresent). Before the bastion was installed for the
// whole machine by default, Linux was left out: `status` from the person's
// account then said NOT RUNNING and told them to `run` a second, empty
// bastion of their own.
func serviceGuard(goos, cmd string, installed, authority bool) error {
if !installed || authority || !serviceGuardedCommands[cmd] {
return nil
}
if goos != "darwin" && goos != "windows" {
if serviceLaneReads[cmd] && goos != "windows" {
return nil
}
return fmt.Errorf("this machine's bastion runs as a system service, and it belongs to whoever administers the machine.\n"+
@@ -117,6 +130,17 @@ func serviceGuard(goos, cmd string, installed, authority bool) error {
" To work with the machine's bastion, %s", cmd, adminHowToFor(goos))
}
// linuxSystemUnitPath is where the installers write the bastion's systemd unit
// (deploy/install.sh; `npx cseries` writes the same unit).
const linuxSystemUnitPath = "/etc/systemd/system/privatae-bastion.service"
// linuxSystemUnitPresent: the bastion is installed for the whole machine on
// this Linux box. A variable so the suite decides it.
var linuxSystemUnitPresent = func() bool {
_, err := os.Stat(linuxSystemUnitPath)
return err == nil
}
// launchdPlist is the launchd job for the daemon. KeepAlive restarts it
// whenever it exits, which is also how a self-update takes effect: update.go
// exits after swapping the binary, exactly as it does under systemd's
@@ -350,7 +374,11 @@ func adoptSystemServiceState() {
// guardServiceFork is serviceGuard for this process.
func guardServiceFork(cmd string) error {
return serviceGuard(runtime.GOOS, cmd, systemService.installed, systemService.authority)
installed := systemService.installed
if runtime.GOOS == "linux" {
installed = linuxSystemUnitPresent()
}
return serviceGuard(runtime.GOOS, cmd, installed, systemService.authority)
}
// cmdService is `privatae-bastion service install|uninstall|status`.