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
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,6 @@ jobs:
permissions:
contents: read
steps:
- uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0
id: app
with:
client-id: ${{ vars.TAMIS_CLIENT_ID }}
private-key: ${{ secrets.TAMIS_PRIVATE_KEY }}
owner: your-org
repositories: your-project
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: your-org/your-project
Expand All @@ -129,7 +122,8 @@ jobs:
since: "2026-10-22"
advisory: ${{ inputs.advisory }}
api-key: ${{ secrets.ANTHROPIC_API_KEY }}
github-token: ${{ steps.app.outputs.token }}
app-client-id: ${{ vars.TAMIS_CLIENT_ID }}
app-private-key: ${{ secrets.TAMIS_PRIVATE_KEY }}
bot-login: your-app-slug[bot]
# List every branch your project supports. Each ref must exist in the checkout.
references: master origin/release-branch
Expand Down
12 changes: 10 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@ inputs:
description: Login the comments are posted as, required with a GitHub App token, e.g. `my-app[bot]`. Found through the token otherwise.
required: false
github-token:
description: Token able to read and comment the repository advisories.
required: true
description: Token able to read and comment the repository advisories. Required without `app-client-id`.
required: false
app-client-id:
description: Client ID of the GitHub App tamis mints its installation tokens with, in place of `github-token` and `issues-token`. tamis replaces each token before it expires, so a run can last more than the hour one token lasts.
required: false
app-private-key:
description: Private key of the GitHub App of `app-client-id`.
required: false
repository:
description: Repository owning the advisories.
default: ${{ github.repository }}
Expand Down Expand Up @@ -136,6 +142,8 @@ runs:
MODEL: ${{ inputs.model }}
LLM_API_KEY: ${{ inputs.api-key }}
GH_TOKEN: ${{ inputs.github-token }}
APP_CLIENT_ID: ${{ inputs.app-client-id }}
APP_PRIVATE_KEY: ${{ inputs.app-private-key }}
BOT_LOGIN: ${{ inputs.bot-login }}
REPOSITORY: ${{ inputs.repository }}
REPO_PATH: ${{ inputs.path }}
Expand Down
59 changes: 48 additions & 11 deletions cmd/tamis/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,9 @@ func run(ctx context.Context, log *slog.Logger) error {
if cfg.Repo == "" {
return errors.New("REPOSITORY is required")
}
token := os.Getenv("GH_TOKEN")
if token == "" {
return errors.New("GH_TOKEN is required")
}
if cfg.IssuesRepository != "" {
issues := os.Getenv("ISSUES_TOKEN")
if issues == "" || issues == token {
return errors.New("ISSUES_REPOSITORY needs an ISSUES_TOKEN of its own, which only reaches that repository")
}
cfg.Issues = github.New(issues)
gh, err := githubClients(&cfg)
if err != nil {
return err
}
if v := os.Getenv("CLOSE_DUPLICATES"); v != "" {
if cfg.CloseDuplicates, err = strconv.ParseBool(v); err != nil {
Expand Down Expand Up @@ -242,7 +235,51 @@ func run(ctx context.Context, log *slog.Logger) error {
defer reader.Close()
reader.Daybreak = daybreak

return triage.Run(ctx, cfg, github.New(token), reader, log)
return triage.Run(ctx, cfg, gh, reader, log)
}

// githubClients returns the client of the advisories and the board, and sets the one that writes the issues.
// With the credentials of a GitHub App, tamis mints the tokens itself and replaces them before they expire.
func githubClients(cfg *triage.Config) (*github.Client, error) {
clientID, key := os.Getenv("APP_CLIENT_ID"), os.Getenv("APP_PRIVATE_KEY")
// docker and git inherit the environment, and the key never expires.
os.Unsetenv("APP_PRIVATE_KEY")
if clientID == "" && key == "" {
token := os.Getenv("GH_TOKEN")
if token == "" {
return nil, errors.New("GH_TOKEN, or APP_CLIENT_ID and APP_PRIVATE_KEY, are required")
}
if cfg.IssuesRepository != "" {
issues := os.Getenv("ISSUES_TOKEN")
if issues == "" || issues == token {
return nil, errors.New("ISSUES_REPOSITORY needs an ISSUES_TOKEN of its own, which only reaches that repository")
}
cfg.Issues = github.New(issues)
}

return github.New(token), nil
}
if clientID == "" || key == "" {
return nil, errors.New("APP_CLIENT_ID and APP_PRIVATE_KEY go together")
}
if os.Getenv("GH_TOKEN") != "" || os.Getenv("ISSUES_TOKEN") != "" {
return nil, errors.New("GH_TOKEN and ISSUES_TOKEN must stay unset with APP_CLIENT_ID")
}
app, err := github.NewAppKey(clientID, key)
if err != nil {
return nil, err
}
if cfg.IssuesRepository == "" {
return app.Client([]string{cfg.Repo}, nil)
}
// Only the issues token writes issues, and it cannot reach the repository of the advisories.
issues, err := app.Client([]string{cfg.IssuesRepository}, map[string]string{"issues": "write", "organization_projects": "write"})
if err != nil {
return nil, err
}
cfg.Issues = issues

return app.Client([]string{cfg.Repo, cfg.IssuesRepository}, map[string]string{"repository_advisories": "write", "organization_projects": "write", "issues": "read"})
}

func parseSince(v string) (time.Time, error) {
Expand Down
83 changes: 81 additions & 2 deletions cmd/tamis/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,22 @@ package main

import (
"context"
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"encoding/json"
"encoding/pem"
"fmt"
"io"
"log/slog"
"net/http"
"net/http/httptest"
"os"
"testing"
"time"

"github.com/php/tamis/internal/github"
"github.com/php/tamis/internal/triage"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.yaml.in/yaml/v3"
Expand Down Expand Up @@ -55,13 +65,23 @@ func TestSelectAgent(t *testing.T) {

func TestRunValidatesConfiguration(t *testing.T) {
log := slog.New(slog.NewTextHandler(io.Discard, nil))
rsaKey, err := rsa.GenerateKey(rand.Reader, 2048)
require.NoError(t, err)
key := string(pem.EncodeToMemory(&pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(rsaKey)}))
for name, tc := range map[string]struct {
env map[string]string
want string
}{
"since required": {map[string]string{"REPOSITORY": "o/r", "GH_TOKEN": "t", "LLM_API_KEY": "k", "COMMENT": "true"}, "SINCE is required with COMMENT"},
"since optional": {map[string]string{"REPOSITORY": "o/r", "GH_TOKEN": "t", "LLM_API_KEY": "k"}, "OUTPUT_DIR is required"},
"token required": {map[string]string{"REPOSITORY": "o/r", "SINCE": "2026-10-22", "LLM_API_KEY": "k"}, "GH_TOKEN is required"},
"token required": {map[string]string{"REPOSITORY": "o/r", "SINCE": "2026-10-22", "LLM_API_KEY": "k"}, "GH_TOKEN, or APP_CLIENT_ID and APP_PRIVATE_KEY, are required"},
"app key alone": {map[string]string{"REPOSITORY": "o/r", "LLM_API_KEY": "k", "APP_PRIVATE_KEY": key}, "APP_CLIENT_ID and APP_PRIVATE_KEY go together"},
"app client id alone": {map[string]string{"REPOSITORY": "o/r", "LLM_API_KEY": "k", "APP_CLIENT_ID": "Iv1"}, "APP_CLIENT_ID and APP_PRIVATE_KEY go together"},
"app and token": {map[string]string{"REPOSITORY": "o/r", "LLM_API_KEY": "k", "APP_CLIENT_ID": "Iv1", "APP_PRIVATE_KEY": key, "GH_TOKEN": "t"}, "GH_TOKEN and ISSUES_TOKEN must stay unset with APP_CLIENT_ID"},
"app and issues token": {map[string]string{"REPOSITORY": "o/r", "LLM_API_KEY": "k", "APP_CLIENT_ID": "Iv1", "APP_PRIVATE_KEY": key, "ISSUES_REPOSITORY": "o/r-security", "ISSUES_TOKEN": "t"}, "GH_TOKEN and ISSUES_TOKEN must stay unset with APP_CLIENT_ID"},
"invalid app key": {map[string]string{"REPOSITORY": "o/r", "LLM_API_KEY": "k", "APP_CLIENT_ID": "Iv1", "APP_PRIVATE_KEY": "key"}, "the App private key is not PEM encoded"},
"app on two owners": {map[string]string{"REPOSITORY": "o/r", "LLM_API_KEY": "k", "APP_CLIENT_ID": "Iv1", "APP_PRIVATE_KEY": key, "ISSUES_REPOSITORY": "other/r-security"}, "o/r and other/r-security must be repositories of the same owner"},
"app accepted": {map[string]string{"REPOSITORY": "o/r", "LLM_API_KEY": "k", "APP_CLIENT_ID": "Iv1", "APP_PRIVATE_KEY": key, "ISSUES_REPOSITORY": "o/r-security"}, "OUTPUT_DIR is required"},
"api key required": {map[string]string{"REPOSITORY": "o/r", "SINCE": "2026-10-22", "GH_TOKEN": "t"}, "LLM_API_KEY is required"},
"invalid daybreak": {map[string]string{"REPOSITORY": "o/r", "SINCE": "2026-10-22", "GH_TOKEN": "t", "LLM_API_KEY": "k", "DAYBREAK": "maybe"}, "DAYBREAK"},
"daybreak needs openai": {map[string]string{"REPOSITORY": "o/r", "SINCE": "2026-10-22", "GH_TOKEN": "t", "LLM_API_KEY": "k", "DAYBREAK": "true"}, "DAYBREAK requires ENGINE=openai"},
Expand All @@ -75,11 +95,70 @@ func TestRunValidatesConfiguration(t *testing.T) {
"references required": {map[string]string{"REPOSITORY": "o/r", "SINCE": "2026-10-22", "GH_TOKEN": "t", "LLM_API_KEY": "k", "OUTPUT_DIR": t.TempDir()}, "REFERENCES must list"},
} {
t.Run(name, func(t *testing.T) {
for _, k := range []string{"REPOSITORY", "GITHUB_REPOSITORY", "ADVISORY", "REPO_PATH", "BOT_LOGIN", "DAYBREAK", "SINCE", "GH_TOKEN", "ENGINE", "MODEL", "LLM_API_KEY", "OUTPUT_DIR", "REFERENCES", "PROJECT", "ISSUES_REPOSITORY", "ISSUES_TOKEN", "CLOSE_DUPLICATES", "COMMENT", "PACKS", "FORCE"} {
for _, k := range []string{"REPOSITORY", "GITHUB_REPOSITORY", "ADVISORY", "REPO_PATH", "BOT_LOGIN", "DAYBREAK", "SINCE", "GH_TOKEN", "ENGINE", "MODEL", "LLM_API_KEY", "OUTPUT_DIR", "REFERENCES", "PROJECT", "ISSUES_REPOSITORY", "ISSUES_TOKEN", "CLOSE_DUPLICATES", "COMMENT", "PACKS", "FORCE", "APP_CLIENT_ID", "APP_PRIVATE_KEY"} {
t.Setenv(k, tc.env[k])
}

require.ErrorContains(t, run(context.Background(), log), tc.want)
assert.Empty(t, os.Getenv("APP_PRIVATE_KEY"), "the App private key stays in the environment docker and git inherit")
})
}
}

func TestGitHubClientsScopeTheAppTokens(t *testing.T) {
rsaKey, err := rsa.GenerateKey(rand.Reader, 2048)
require.NoError(t, err)
key := string(pem.EncodeToMemory(&pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(rsaKey)}))
for name, tc := range map[string]struct {
issues string
want map[string]any
}{
"with issues": {"o/r-security", map[string]any{
"o/r": map[string]any{"repositories": []any{"r", "r-security"}, "permissions": map[string]any{"repository_advisories": "write", "organization_projects": "write", "issues": "read"}},
"o/r-security": map[string]any{"repositories": []any{"r-security"}, "permissions": map[string]any{"issues": "write", "organization_projects": "write"}},
}},
"without issues": {"", map[string]any{"o/r": map[string]any{"repositories": []any{"r"}}}},
} {
t.Run(name, func(t *testing.T) {
// Each repository gets an installation of its own, so a minted token names the client it went to.
installations := map[string]string{"/repos/o/r/installation": "1", "/repos/o/r-security/installation": "2"}
owners := map[string]string{"/app/installations/1/access_tokens": "o/r", "/app/installations/2/access_tokens": "o/r-security"}
minted := map[string]any{}
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if id, ok := installations[r.URL.Path]; ok {
fmt.Fprintf(w, `{"id":%s}`, id)
return
}
if repo, ok := owners[r.URL.Path]; ok {
var body map[string]any
assert.NoError(t, json.NewDecoder(r.Body).Decode(&body))
minted[repo] = body
fmt.Fprintf(w, `{"token":"t","expires_at":%q}`, time.Now().Add(time.Hour).UTC().Format(time.RFC3339))
return
}
fmt.Fprint(w, `{"login":"acme-tamis[bot]"}`)
}))
t.Cleanup(srv.Close)
for k, v := range map[string]string{"APP_CLIENT_ID": "Iv1", "APP_PRIVATE_KEY": key, "GH_TOKEN": "", "ISSUES_TOKEN": ""} {
t.Setenv(k, v)
}
cfg := triage.Config{Repo: "o/r", IssuesRepository: tc.issues}

gh, err := githubClients(&cfg)
require.NoError(t, err)
clients := []*github.Client{gh}
if tc.issues != "" {
clients = append(clients, cfg.Issues.(*github.Client))
} else {
assert.Nil(t, cfg.Issues, "an issues client without an issues repository")
}
for _, c := range clients {
c.BaseURL, c.HTTP = srv.URL, srv.Client()
_, err := c.Login(t.Context())
require.NoError(t, err)
}

assert.Equal(t, tc.want, minted)
})
}
}
Expand Down
8 changes: 5 additions & 3 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
| Input | Default | Description |
|---|---|---|
| `api-key` | | Required. API key of the model provider, or a Codex access token with `engine: openai`. |
| `github-token` | | Required. Token able to read and comment the repository advisories, and to write `project`. |
| `app-client-id` | | Client ID of the GitHub App tamis mints its installation tokens with, in place of `github-token` and `issues-token`. tamis replaces each token before it expires, so a run can last more than the hour one token lasts. |
| `app-private-key` | | Private key of the App of `app-client-id`. |
| `github-token` | | Required without `app-client-id`. Token able to read and comment the repository advisories, and to write `project`. An installation token expires after an hour, and every GitHub request of the run fails after it. |
| `references` | | Required, at most ten. Whitespace-separated local git references, one per supported branch. tamis analyses the first and locates the cited code on it. A missing reference fails the analysis. |
| `packs` | | Whitespace-separated [guidance packs](#guidance-packs) added to the agent's method, such as `php-src`. An unknown pack fails the run. |
| `since` | | Triage only advisories created after this date, `2026-10-22` or RFC 3339. Required with `comment: true` unless `advisory` is set, so existing advisories get no comment. Without it, every advisory in triage goes on the board. |
Expand All @@ -19,13 +21,13 @@
| `comment` | `false` | With `issues-repository`, post on each advisory a comment linking it to the issue tamis creates for it. |
| `project` | | Required. Private organisation project the triages go on, as `org/number`, which records the failed attempts in `Attempts`. See [the project board](setup.md#5-project-board). |
| `issues-repository` | | Private repository the board items are created in as issues, so duplicates become sub-issues of their original report. Drafts when unset. See [the project board](setup.md#5-project-board). |
| `issues-token` | | Installation token for `issues-repository` only, with the "Issues" and organisation "Projects" permissions in read and write. Required with `issues-repository`. |
| `issues-token` | | Installation token for `issues-repository` only, with the "Issues" and organisation "Projects" permissions in read and write. Required with `issues-repository` and `github-token`. |
| `close-duplicates` | `false` | Closes the advisory of an issue a maintainer closed as a duplicate. Needs `issues-repository`. See [the project board](setup.md#5-project-board). |
| `runner-image` | tamis agent image, pinned by digest | Image the agent runs in. It must contain the agent CLI, git, curl and `harness-proxy`. The action skips the attestation check for a custom image. |

The action refuses to run from a public workflow repository or from a `uses:` that is not a full commit SHA. Update that SHA through a reviewed pull request.

Outside GitHub Actions, tamis reads the same settings from environment variables: `LLM_API_KEY`, `GH_TOKEN`, `BOT_LOGIN`, `REPOSITORY`, `REPO_PATH`, `SINCE`, `ADVISORY`, `ENGINE`, `MODEL`, `DAYBREAK`, `RUNNER_IMAGE`, `REFERENCES`, `PROJECT`, `ISSUES_REPOSITORY`, `ISSUES_TOKEN`, `CLOSE_DUPLICATES`, `COMMENT` and `PACKS`. `OUTPUT_DIR` must name a private directory for the reports. The action creates it in the runner's temporary storage and uploads it to the workflow repository with a seven-day retention.
Outside GitHub Actions, tamis reads the same settings from environment variables: `LLM_API_KEY`, `GH_TOKEN`, `APP_CLIENT_ID`, `APP_PRIVATE_KEY`, `BOT_LOGIN`, `REPOSITORY`, `REPO_PATH`, `SINCE`, `ADVISORY`, `ENGINE`, `MODEL`, `DAYBREAK`, `RUNNER_IMAGE`, `REFERENCES`, `PROJECT`, `ISSUES_REPOSITORY`, `ISSUES_TOKEN`, `CLOSE_DUPLICATES`, `COMMENT` and `PACKS`. `OUTPUT_DIR` must name a private directory for the reports. The action creates it in the runner's temporary storage and uploads it to the workflow repository with a seven-day retention.

A local run alone also reads `FORCE=true`, which triages every selected advisory again, `ADVISORY` alone or every one in triage, and updates its board item even when it already holds a triage. A failed new triage leaves the previous one on the board. The action has no such input.

Expand Down
3 changes: 2 additions & 1 deletion docs/security.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ tamis reads text from an outside reporter, holds access to embargoed advisories
| Threat | Mitigation |
|---|---|
| A prompt injection makes the agent leak other advisories | See [Duplicate search isolation](#duplicate-search-isolation). |
| The agent leaks secrets | The container holds no secret. The model key stays on the runner, the GitHub token never enters the container, and the container gets only the selected commit and its history, with an empty `.git/config`. |
| The agent leaks secrets | The container holds no secret. The model key stays on the runner, the GitHub token and the App private key never enter the container, and the container gets only the selected commit and its history, with an empty `.git/config`. |
| The agent exfiltrates data over the network | The container sits on an isolated internal network and only reaches a private egress sidecar. Public GitHub access is a read-only service with no credentials or redirects. The model proxy pins the model and rejects remote URLs, remote MCP servers, hosted tools, stored conversations and background calls. |
| The triage loads a remote image carrying data, or pings people | tamis escapes all model text: no links, images, HTML, entities or mentions. |
| A report changes during triage | tamis hashes the title, description, metadata and non-bot comments, reads them again before publication and publishes nothing when the revision changed. It does not triage a completed advisory again after a later edit. |
Expand Down Expand Up @@ -73,6 +73,7 @@ tamis turns off the Codex ChatGPT features that call other routes: plugins, apps
- An internal network without a host gateway needs Docker Engine 28 or newer.
- The agent CLI state is a writable host directory, removed after each advisory. A run can rewrite its own configuration for the correction round and fill the runner disk, though not leave the network or the model proxy.
- The advisory comments API is in public preview and may change.
- With `app-private-key`, tamis holds the App key in memory for the whole run, where a token step holds it for a moment. tamis removes it from the environment docker and git inherit, but a compromised runner exposes a key that works until it is rotated, not a token that expires within the hour.

CI builds both agent images and runs the Docker isolation tests on `ubuntu-latest`. They test the model path, direct and proxied host access, DNS, and IPv4 and IPv6 egress, without real provider credentials. Treat both `isolation` jobs as required checks before releasing or updating the deployment SHA.

Expand Down
Loading
Loading