chore(deploy): add least-privilege PR-Agent operator access
PR Check / Security scan (Snyk) (pull_request) Skipped
PR Check / Lint + typecheck (pull_request) Failing after 19s
PR Check / Secret scan (gitleaks) (pull_request) Successful in 6s
PR Check / Dependency audit (pull_request) Failing after 9s
PR Check / Dockerfile lint (droast) (pull_request) Successful in 5s

This commit is contained in:
Noel Sabia committed 2026-10-30 21:09:19 +01:00
1 parent 679c0b4858
commit f5810960a8
3 files changed
+235 -4

No files matched your search

+44 -4
View File
@@ -9,9 +9,11 @@ endpoint is not published to the internet.
| Image | `pragent/pr-agent:0.49.0-gitea_app` |
| Container | `pr-agent` |
| Webhook URL, from Gitea | `http://pr-agent:3000/api/v1/gitea_webhooks` |
| Config | `/home/noel/self-hosted/pr-agent/.env` (mode 600) |
| Logs | `docker logs -f pr-agent` |
| Upgrade | bump the image tag, then `docker compose up -d` in this directory |
| Config | `/opt/pr-agent/.env` (root, mode 600) |
| Logs | `ssh … agent@server0 logs` |
| Deploy / restart | `ssh … agent@server0 deploy` |
| Status | `ssh … agent@server0 status` |
| Upgrade | edit the root-owned compose file, then run `deploy` |
## Gitea side
@@ -24,6 +26,36 @@ endpoint is not published to the internet.
Gitea's default egress policy refuses webhook deliveries to private
addresses, including the Docker network.
## Operator access
The agent does not log in as `noel`. A dedicated `agent` account has one
forced command and three actions:
```sh
ssh -i ~/.ssh/pr_agent_control -o IdentitiesOnly=yes agent@91.99.207.62 status
ssh -i ~/.ssh/pr_agent_control -o IdentitiesOnly=yes agent@91.99.207.62 logs
ssh -i ~/.ssh/pr_agent_control -o IdentitiesOnly=yes agent@91.99.207.62 deploy
```
The SSH key is restricted with `restrict,command=…`; the account has no
Docker group, no general sudo, and no shell. Sudo permits only the three
root-owned helper scripts in `/usr/local/sbin`, and those helpers operate on
the fixed `/opt/pr-agent/docker-compose.yml`. The compose file, `.env` and
helpers are root-owned, so the agent cannot turn “restart” into a different
container or a host mount.
`setup-agent-access.sh` creates the account and moves the stack to
`/opt/pr-agent`. `remove-noel-access.sh` then removes the inherited access
from `noel`: the `docker` and `sudo` groups, the keys in
`/home/noel/.ssh/authorized_keys`, and the old PR-Agent directory. Run both
on the server as root, and only run the second after the restricted command
works and you have another admin path.
For git, use a repository-scoped deploy key instead of the personal Gitea
key: `~/.ssh/pr_agent_gitea.pub` is added as a write deploy key on
`CV_Website/CV_Site_Nuxt`. The old personal key must be removed from Gitea,
or it still grants every repository the user can see.
## AI model
The agent uses OpenCode Go's OpenAI-compatible endpoint:
@@ -38,6 +70,14 @@ api base https://opencode.ai/inference/go/openai/v1
the model is not in its token table. The effective review budget is still
capped by PR-Agent's default `config.max_model_tokens` of 32000.
The transfer file used during installation was empty, so set the key as
root and redeploy:
```sh
sudoedit /opt/pr-agent/.env # set OPENAI__KEY=…
sudo /usr/local/sbin/pr-agent-deploy
```
## First check
Open a pull request in `CV_Website/CV_Site_Nuxt`. The server runs `/describe`
@@ -45,7 +85,7 @@ and `/review` on open/reopen; comment commands such as `/review`, `/improve`
and `/ask` are handled from the PR conversation. If nothing appears:
```sh
docker compose logs --tail=100 pr-agent
ssh -i ~/.ssh/pr_agent_control -o IdentitiesOnly=yes agent@91.99.207.62 logs
```
A `403` in the Gitea webhook delivery log means the secret does not match or