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: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@ a required BuildKit secret, never through build arguments or committed files.

## Catalog and release

The next app release is **0.1.11**, also recorded in `web/package.json`.
The next app release is **0.1.12**, also recorded in `web/package.json`.
`catalog/entry.yaml` carries no committed version: the first tag (`v0.1.0`)
created `versions[]` with `ghcr.io/appthrust/tracker@sha256:<index-digest>`,
stream `0.1`; later tags append at publication time. Do not add a version with
an unbuilt or placeholder image digest. OpenAPI's `info.version` describes the
API schema, not the app release. This repository has no hand-maintained changelog.

After the release prerequisites are available, push the SemVer tag `v0.1.11`.
After the release prerequisites are available, push the SemVer tag `v0.1.12`.
The tag workflow:

1. Performs one multi-platform build on `ubuntu-24.04` for Linux amd64 and arm64,
Expand All @@ -146,8 +146,8 @@ The tag workflow:
Publication commands used by the workflow:

```sh
bun hack/publish-entry.ts submit --version 0.1.11 --digest sha256:<image-index-digest>
bun hack/publish-entry.ts await --version 0.1.11 --digest sha256:<image-index-digest>
bun hack/publish-entry.ts submit --version 0.1.12 --digest sha256:<image-index-digest>
bun hack/publish-entry.ts await --version 0.1.12 --digest sha256:<image-index-digest>
```

Writers are serialized by `tracker-catalog-publish`; the workflow is guarded to
Expand All @@ -168,7 +168,7 @@ After publication, each estate's `AppCatalogSource` syncs the signed catalog.
Install Issues from the Project Marketplace (Directory is an automatic
dependency). Existing `follow` installations on stream `0.1` roll to the new
version; `pinned` installations show `UpdateAvailable` and require an explicit
version update. Confirm the installation is Ready, `/releasez` reports `0.1.11`,
version update. Confirm the installation is Ready, `/releasez` reports `0.1.12`,
the Project lists the `tracker` Access Key space as Ready, and an exchanged key reads `/api/tracker/v1/me`. These are release steps,
not actions performed by a source-only version bump.

Expand Down
21 changes: 18 additions & 3 deletions cmd/server/internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,15 @@ func (a *API) route(pattern string, mutation, roles bool, fn endpoint) {
return
}
s := &request{r: r, w: w}
if claims.Principal.Kind == "key" {
key := claims.Principal.Kind == "key"
if key {
actor, err := keyActor(claims.Principal, a.workspace, mutation)
if err != nil {
httpx.WriteError(w, err, "tracker")
return
}
// The assertion is addressed to Tracker only: it is never forwarded
// to Directory, so people stay the stored snapshots.
// to Directory. The person's name comes from Tracker's own record.
s.actor = actor
if mutation {
log.Printf("tracker access key mutation: %s %s key=%q subject=%q request_id=%q", r.Method, r.URL.Path, claims.Principal.KeyName, actor.Sub, r.Header.Get("X-Request-Id"))
Expand Down Expand Up @@ -149,7 +150,21 @@ func (a *API) route(pattern string, mutation, roles bool, fn endpoint) {
}
var body any
var status int
err := a.store.InWorkspace(ctx, a.workspace, mutation, func(tx *store.Tx) error { s.tx = tx; var err error; body, status, err = fn(s); return err })
err := a.store.InWorkspace(ctx, a.workspace, mutation, func(tx *store.Tx) error {
s.tx = tx
if key {
name, err := tx.KnownName(s.actor.Sub)
if err != nil {
return err
}
if name != "" {
s.actor.Name = name
}
}
var err error
body, status, err = fn(s)
return err
})
if err != nil {
writeStoreError(w, err)
return
Expand Down
19 changes: 19 additions & 0 deletions cmd/server/internal/api/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"encoding/base64"
"encoding/json"
"io"
"net/http"
Expand Down Expand Up @@ -75,6 +76,24 @@ func TestAccessKeyActsAsItsUserWithinScopeAndProject(t *testing.T) {
page := call[store.Page](h, "admin", "GET", "/issues?filter="+url.QueryEscape(`{"reporter":["me"]}`), nil, 200)
require.Len(t, page.Items, 1, "the signed-in user owns what their key reported")

// A key carries no name: it takes the one its user last wrote under while
// signed in, and falls back to the subject before any such write.
require.Equal(t, "admin", issue.Reporter.Name)
owner := assertion("pj-test", user("owner"), scopeRead, scopeWrite)
status, data = do(owner, "GET", "/me", nil)
require.Equal(t, 200, status, string(data))
require.Contains(t, string(data), `"name":"owner"`)
claims, err := json.Marshal(map[string]string{"sub": "owner", "email": "owner@example.test", "name": "Olivia Owner"})
require.NoError(t, err)
session := "Bearer " + base64.RawURLEncoding.EncodeToString([]byte(`{"alg":"none"}`)) + "." + base64.RawURLEncoding.EncodeToString(claims) + "."
status, data = do(session, "POST", "/issues", map[string]string{"title": "Signed in", "type": "task"})
require.Equal(t, 201, status, string(data))
status, data = do(owner, "POST", "/issues/"+issue.ID+"/comments", map[string]string{"body": "From the key"})
require.Equal(t, 201, status, string(data))
var comment domain.Comment
require.NoError(t, json.Unmarshal(data, &comment))
require.Equal(t, domain.Person{Sub: "owner", Name: "Olivia Owner"}, comment.Author)

issue2 := map[string]string{"title": "Refused", "type": "task"}
for _, test := range []struct {
name, bearer, method, path string
Expand Down
2 changes: 1 addition & 1 deletion cmd/server/internal/api/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"openapi": "3.1.0",
"info": {
"title": "Tracker API",
"version": "0.1.11",
"version": "0.1.12",
"description": "Contract: design/API.md. One workspace per PLATFORM_PROJECT_ID. The bearer is the signed-in user's token or an Access Key assertion (audience tracker; scope tracker:read for GET, tracker:write otherwise)."
},
"servers": [
Expand Down
2 changes: 2 additions & 0 deletions cmd/server/internal/store/migrations/012_activity_actor.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Access Key requests resolve the caller's display name from their latest signed-in write.
CREATE INDEX tracker_activity_actor ON tracker_activity (actor_sub, created_at DESC);
19 changes: 19 additions & 0 deletions cmd/server/internal/store/people.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package store

import (
"database/sql"
"errors"
)

// KnownName returns the display name most recently recorded for a person by a
// signed-in write, or "" when this workspace has never seen one. Access Key
// requests carry no name, and their own writes record the subject as the name,
// so those rows are not a source.
func (t *Tx) KnownName(sub string) (string, error) {
var name string
err := t.SQL.QueryRowContext(t.Context, `SELECT a.actor_name FROM tracker_activity a JOIN tracker_issue i ON i.id=a.issue_id WHERE i.workspace_id=$1 AND a.actor_sub=$2 AND a.actor_name<>a.actor_sub ORDER BY a.created_at DESC LIMIT 1`, t.WorkspaceID, sub).Scan(&name)
if errors.Is(err, sql.ErrNoRows) {
return "", nil
}
return name, err
}
2 changes: 1 addition & 1 deletion cmd/server/internal/store/projects_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func TestProjectsMigrationFromV010(t *testing.T) {
}
var versions int
require.NoError(t, tx.SQL.QueryRowContext(t.Context(), `SELECT count(*) FROM tracker_schema_migrations`).Scan(&versions))
require.Equal(t, 11, versions)
require.Equal(t, 12, versions)
var reporterIndex string
require.NoError(t, tx.SQL.QueryRowContext(t.Context(), `SELECT indexdef FROM pg_indexes WHERE schemaname=current_schema() AND indexname='tracker_issue_reporter'`).Scan(&reporterIndex))
require.Contains(t, reporterIndex, "USING btree (workspace_id, reporter_sub) WHERE (deleted_at IS NULL)")
Expand Down
7 changes: 5 additions & 2 deletions design/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,12 @@ Rules (`cmd/server/internal/api/keys.go`, `keyActor`):

What the user's key creates belongs to that user: `reporter: ['me']` in the
SPA lists it. The assertion carries no name or email and is never forwarded to
Directory, so a key write stores `name = sub` as the person snapshot and
Directory. Since v0.1.12 the key's person takes the display name of that
user's most recent signed-in write in this workspace (`store.KnownName`, from
the activity log); before any such write the name is the subject id. `GET /me`
returns `{ sub, name, role: 'Viewer', isAdmin: false }` with the same name.
`GET /people` answers `source: 'unavailable'`; a signed-in reader still sees
the Directory name. `GET /me` returns `{ sub, name: sub, role: 'Viewer', isAdmin: false }`.
the Directory name.

Each mutation request made with a key writes one `tracker access key mutation:`
log line (method, path, key name, subject, edge `X-Request-Id`) before
Expand Down
2 changes: 1 addition & 1 deletion web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@appthrust/tracker",
"version": "0.1.11",
"version": "0.1.12",
"private": true,
"type": "module",
"scripts": {
Expand Down