Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion .github/workflows/installer-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,31 @@ jobs:
run: go test -race -v ./...
working-directory: installer

privilege-test:
name: Installer Privilege Regression
needs: build
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: installer/go.mod
- uses: arduino/setup-task@v2
with:
repo-token: ${{ github.token }}
- name: Install privilege test dependencies
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends sudo expect passwd util-linux
- name: Test installer privileges on the disposable Ubuntu runner
run: task test:privilege
working-directory: installer
env:
INSTALLER_PRIVILEGE_TEST_DISPOSABLE: '1'

e2e-test:
name: E2E Tests
needs: build
Expand Down Expand Up @@ -385,19 +410,22 @@ jobs:
ci-status:
name: Installer CI Status
if: always()
needs: [changes, build, test, e2e-test]
needs: [changes, build, test, privilege-test, e2e-test]
runs-on: ubuntu-latest
steps:
- name: Check job results
run: |
echo "changes: ${{ needs.changes.result }}"
echo "build: ${{ needs.build.result }}"
echo "test: ${{ needs.test.result }}"
echo "privilege-test: ${{ needs.privilege-test.result }}"
echo "e2e-test: ${{ needs.e2e-test.result }}"

if [[ "${{ needs.changes.result }}" == "failure" || \
"${{ needs.build.result }}" == "failure" || \
"${{ needs.test.result }}" == "failure" || \
"${{ needs.privilege-test.result }}" == "failure" || \
"${{ needs.privilege-test.result }}" == "cancelled" || \
"${{ needs.e2e-test.result }}" == "failure" ]]; then
echo "One or more jobs failed"
exit 1
Expand Down
5 changes: 2 additions & 3 deletions .opencode/agents/cheapest-go-worker.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
name: cheapest-go-worker
description: "Use this project-local worker for Go implementation tasks assigned to the cheapest model tier. It is intended for straightforward Go/config changes with clear acceptance criteria."
mode: subagent
model: openai/gpt-5.5
reasoningEffort: low
model: openai/gpt-6-luna#high
permission:
edit: allow
bash: allow
Expand All @@ -19,7 +18,7 @@ permission:
building-go-binaries: allow
---

You are a project-local Go implementation worker running at the cheapest tier with low reasoning effort.
You are a project-local Go implementation worker running at the cheapest tier with high reasoning effort.

Load these skills immediately before working: `managing-chezmoi`, `writing-go-code`, `writing-go-tests`, `testing-go-code`, `linting-go-code`, and `building-go-binaries`.

Expand Down
3 changes: 1 addition & 2 deletions .opencode/agents/mid-tier-go-worker.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
name: mid-tier-go-worker
description: "Use this project-local worker for Go implementation tasks assigned to the mid-tier model. It is intended for Go changes with moderate integration, edge cases, or coordination risk."
mode: subagent
model: openai/gpt-5.5
reasoningEffort: medium
model: openai/gpt-6.1-terra#medium
permission:
edit: allow
bash: allow
Expand Down
3 changes: 1 addition & 2 deletions .opencode/agents/most-capable-go-worker.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
name: most-capable-go-worker
description: "Use this project-local worker for Go implementation tasks assigned to the most capable model tier. It is intended for complex Go work requiring broad reasoning or high correctness confidence."
mode: subagent
model: openai/gpt-5.5
reasoningEffort: xhigh
model: openai/gpt-6.1-sol#medium
permission:
edit: allow
bash: allow
Expand Down
4 changes: 4 additions & 0 deletions installer/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
# Expect scripts
!test-interactive-gpg.exp

# Shared privilege integration checks
!tests/privilege/*.sh
!tests/privilege/*.exp

# Agent rules
!AGENTS.md
!CLAUDE.md
38 changes: 35 additions & 3 deletions installer/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ installer/
│ └── httpclient/ # HTTP client interface
├── cli/ # Interactive UI components
├── internal/config/ # Embedded YAML configs
├── tests/privilege/ # Shared real-sudo integration test scripts
├── Taskfile.yml # Task runner commands
└── .goreleaser.yaml # Release configuration
```
Expand Down Expand Up @@ -91,11 +92,16 @@ OS-level operations (user management, environment, program queries, permissions)

### Privilege Escalator (utils/privilege/)

Smart privilege escalation (prefers sudo, falls back to doas):
Privilege escalation selects commands without probing authentication: root runs
the command directly; a non-root user uses installed `sudo` in preference to
installed `doas`; and a non-root user with neither tool receives an actionable
error. Authentication occurs when the selected command runs. In particular,
`sudo` may prompt through the terminal; the installer does not read or store the
password.

```go
escalatedCmd, escalatedArgs, err := escalator.EscalateCommand("apt-get", []string{"install", "git"})
isRoot := escalator.IsRunningAsRoot()
escalated, err := escalator.EscalateCommand("apt-get", []string{"install", "git"})
isRoot, err := escalator.IsRunningAsRoot()
```

## Development Commands
Expand All @@ -110,6 +116,32 @@ isRoot := escalator.IsRunningAsRoot()
| `task cov` | Generate coverage report |
| `task bench` | Run benchmarks |
| `task sloc` | Print lines of code stats |
| `task test:privilege:build` | Cross-compile the Linux privilege test binary |
| `task test:privilege` | Run the real-sudo privilege checks on disposable Ubuntu or Debian |

## Privilege Integration Tests

The privilege integration test checks real authentication during APT setup
and shell setup, each with a cold sudo cache and either the correct password or
a rejected password. It uses the default progress display.

The shared test logic is in `tests/privilege/`. It creates a separate
password-required user and a temporary root-owned workspace, drives the real
password prompt through a terminal, and records calls to real `apt`, `tee`, and
`usermod`. The checks use an offline local package and per-command APT source
options, so they do not change the machine's configured APT sources. The shell
check uses a unique temporary shell symlink and does not remove system shells.

Successful authentication must produce the protected root-owned effect. Before
authentication, and after a rejected password, the checks require no effects and
no unprivileged retry. The runner resets state between checks and cleans up the
user, package, sudo rules, temporary workspace, and `/etc/shells`.

Run `task test:privilege` only on a disposable Ubuntu or Debian machine. The
runner checks the distribution before it changes state, and it requires
`INSTALLER_PRIVILEGE_TEST_DISPOSABLE=1`; do not run it on a personal Linux
machine. GitHub Actions runs it directly on an `ubuntu-latest` runner without
Docker.

## Adding Features

Expand Down
24 changes: 24 additions & 0 deletions installer/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,30 @@ tasks:
cmds:
- go test -race ./... {{ .CLI_ARGS }}

test:privilege:build:
desc: Compile the installer privilege caller test for Linux
vars:
TARGET_ARCH: '{{default .ARCH .PRIVILEGE_TEST_ARCH}}'
OUTPUT: '{{default "bin/privilege.test" .OUTPUT}}'
env:
GOOS: linux
GOARCH: '{{.TARGET_ARCH}}'
CGO_ENABLED: '0'
cmds:
- mkdir -p bin
- go test -c -o '{{.OUTPUT}}' ./cmd

test:privilege:
desc: Run real-authentication checks (disposable Ubuntu/Debian only)
preconditions:
- sh: test "$(uname -s)" = Linux
msg: Run task privilege:test from installer/docker/ for local testing on macOS
- sh: test "${INSTALLER_PRIVILEGE_TEST_DISPOSABLE:-}" = 1
msg: Set INSTALLER_PRIVILEGE_TEST_DISPOSABLE=1 only on a disposable Linux machine
cmds:
- task: test:privilege:build
- sudo env INSTALLER_PRIVILEGE_TEST_DISPOSABLE=1 bash tests/privilege/run.sh bin/privilege.test

build:
desc: Compile the project binary
sources:
Expand Down
72 changes: 72 additions & 0 deletions installer/cmd/privilege_integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package cmd

import (
"os"
"path/filepath"
"runtime"
"testing"

"github.com/MrPointer/dotfiles/installer/lib/compatibility"
"github.com/MrPointer/dotfiles/installer/lib/pkgmanager"
"github.com/stretchr/testify/require"
)

// Test_InstallingSystemChanges_Should_RequireAuthorization_When_RunAsNormalUser
// is driven by tests/privilege/test.exp on a disposable Linux machine.
func Test_InstallingSystemChanges_Should_RequireAuthorization_When_RunAsNormalUser(t *testing.T) {
work := os.Getenv("INSTALLER_PRIVILEGE_TEST_DIR")
if testing.Short() || work == "" {
t.Skip("requires the disposable installer privilege test environment")
}

require.Equal(t, "linux", runtime.GOOS)
marker, err := os.ReadFile(filepath.Join(work, "ready"))
require.NoError(t, err)
require.Equal(t, "installer-privilege-tests\n", string(marker))
require.NotZero(t, os.Geteuid(), "the installer must run as a normal user")
terminal, terminalErr := os.Open("/dev/tty")
require.NoError(t, terminalErr)
require.NoError(t, terminal.Close())

// Use the CLI's real display policy, logger, commander, and OS manager.
// Do not pause progress or attach stdin on behalf of production callers.
plainFlag = false
nonInteractive = false
initLogger()
t.Cleanup(func() { require.NoError(t, cliLogger.Close()) })
initCommander()
initOsManager()

switch os.Getenv("INSTALLER_PRIVILEGE_TEST_CALLER") {
case "shell":
shellName = filepath.Base(os.Getenv("INSTALLER_PRIVILEGE_TEST_SHELL"))
shellSource = "system"
globalSysInfo = compatibility.SystemInfo{OSName: "linux", DistroName: "debian"}
err = installShell(cliLogger)
case "apt":
require.NoError(t, cliLogger.StartProgress("Installing privilege regression package"))
manager := createNativePackageManager("linux", "debian")
err = manager.InstallPackage(pkgmanager.RequestedPackageInfo{Name: filepath.Join(work, "protected.deb")})
if err != nil {
require.NoError(t, cliLogger.FailProgress("Package installation failed", err))
} else {
require.NoError(t, cliLogger.FinishProgress("Package installation completed"))
}
default:
t.Fatal("unknown privilege test caller")
}

if os.Getenv("INSTALLER_PRIVILEGE_TEST_SCENARIO") == "reject" {
require.Error(t, err)
if os.Getenv("INSTALLER_PRIVILEGE_TEST_CALLER") == "apt" {
require.Contains(t, err.Error(), "failed to update package list")
} else {
require.Contains(t, err.Error(), "failed to add shell to /etc/shells")
}
t.Log("AUTHORIZATION_REJECTED")
return
}

require.NoError(t, err)
t.Log("AUTHORIZED_OPERATION_COMPLETED")
}
35 changes: 34 additions & 1 deletion installer/docker/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ docker/
├── validate.sh # Environment validation script
├── ubuntu/ # Ubuntu (apt)
├── debian/ # Debian (apt)
└── fedora/ # Fedora (dnf)
├── fedora/ # Fedora (dnf)
└── privilege/ # Optional local privilege test image and launcher
```

## Container Management
Expand All @@ -26,6 +27,7 @@ Run `task` commands from `installer/docker/`:
| `task <distro>:clean` | Stop container and remove image |
| `task stop-all` | Stop all containers |
| `task validate-all` | Validate all environments |
| `task privilege:test` | Run the privilege integration checks in a local container |

Where `<distro>` is `ubuntu`, `debian`, or `fedora`.

Expand All @@ -41,4 +43,35 @@ Where `<distro>` is `ubuntu`, `debian`, or `fedora`.
- Containers use `testuser` (passwordless sudo) via docker-compose, or `root` with `docker run`
- Homebrew on Linux installs to `/home/linuxbrew/.linuxbrew/` and is NOT in PATH by default

## Privilege Integration Tests

Run `task privilege:test` from `installer/docker/` for local testing on macOS.
The task runs `task test:privilege:build` first, which cross-compiles
`bin/privilege.test` for Linux. Set `PRIVILEGE_TEST_ARCH` to select the target
architecture; it defaults to the host architecture. The Docker engine and image
must support that architecture, as with the existing Docker test environments.

The task builds the optional `installer privilege test image`
(`installer-privilege-test`) from `privilege/Dockerfile`. The Ubuntu 24.04 image
contains only dependencies for repeated local runs. The test binary and shared
scripts are bind-mounted read-only. The container has no network access and runs
all checks in one disposable container, resetting state between checks.

The Docker launcher uses the Docker-independent scripts in
`../tests/privilege/`. They exercise the real APT and shell-setup caller paths
with a cold sudo cache, once with the correct password and once with a rejected
password. Expect provides the terminal and password exchange. The shared runner
creates a password-required user, verifies that no protected operation occurs
before authentication, and verifies either the protected root-owned effect after
success or no effects and no unprivileged retry after rejection.

`privilege/run.sh` runs Docker commands asynchronously so it can handle signals.
Its first INT or TERM stops the child and force-removes the active container. A
second signal aborts stalled cleanup, so removal can remain incomplete if the
Docker daemon is unresponsive.

CI runs the same checks natively on a disposable Ubuntu runner; Docker is not
part of CI. For the native runner and its safety requirements, see [Privilege
Integration Tests](../AGENTS.md#privilege-integration-tests).

For E2E testing procedures, load the `testing-e2e-containers` skill.
10 changes: 10 additions & 0 deletions installer/docker/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ tasks:
cmds:
- task --list

privilege:test:
desc: Run privilege checks locally using the installer privilege test image
dir: ..
preconditions:
- sh: command -v docker
msg: Docker is required for the local installer privilege test image
cmds:
- task test:privilege:build
- bash docker/privilege/run.sh

check:
desc: Check if Docker and Docker Compose are available
cmds:
Expand Down
7 changes: 7 additions & 0 deletions installer/docker/privilege/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Installer privilege test image: cache dependencies for repeated local runs.
# Tests and test users are supplied at runtime by the shared Linux runner.
FROM ubuntu:24.04

RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends sudo expect passwd util-linux \
&& rm -rf /var/lib/apt/lists/*
Loading
Loading