Skip to content

Commit 971a0b7

Browse files
The127claude
andcommitted
feat: miso agent refuses to run outside the builder VM
Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: karo <karolin.kostial@gmail.com>
1 parent 86ce917 commit 971a0b7

4 files changed

Lines changed: 39 additions & 2 deletions

File tree

‎cmd/miso/agent.go‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"errors"
6+
"os"
7+
8+
"github.com/urfave/cli/v3"
9+
)
10+
11+
var agentCommand = &cli.Command{
12+
Name: "agent",
13+
Usage: "answer the host, as the init of the builder VM",
14+
Hidden: true,
15+
Action: runAgent,
16+
}
17+
18+
func runAgent(context.Context, *cli.Command) error {
19+
if os.Getpid() != 1 {
20+
return errors.New("miso agent runs as the init of the builder VM")
21+
}
22+
23+
return nil
24+
}

‎cmd/miso/main.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func main() {
1212
miso := &cli.Command{
1313
Name: "miso",
1414
Usage: "build systemd-based operating systems from a build file",
15-
Commands: []*cli.Command{planCommand, versionCommand},
15+
Commands: []*cli.Command{planCommand, versionCommand, agentCommand},
1616
}
1717

1818
if err := miso.Run(context.Background(), os.Args); err != nil {

‎justfile‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ test-vm *args:
2121
test-vm-one package *args:
2222
MISO_VMTEST_PACKAGES={{package}} bash hack/test-vm.sh -test.timeout=20s -test.failfast {{args}}
2323

24+
# test the miso binary from the outside, as a user runs it
25+
test-cli: build
26+
MISO={{justfile_directory()}}/bin/miso bats test
27+
2428
# test with a coverage profile
2529
cover:
2630
go test -coverprofile=coverage.out -covermode=atomic ./...
@@ -61,4 +65,4 @@ hooks:
6165
lefthook install
6266

6367
# everything that must pass before a push
64-
ci: lint prose doccheck arch build cover vuln
68+
ci: lint prose doccheck arch build cover test-cli vuln

‎test/agent.bats‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bats
2+
# MISO names the miso binary under test, see just test-cli.
3+
4+
@test "the agent refuses to run outside the builder VM" {
5+
run "$MISO" agent
6+
7+
[ "$status" -eq 1 ]
8+
[[ "$output" == *"miso agent runs as the init of the builder VM"* ]]
9+
}

0 commit comments

Comments
 (0)