Skip to content
Open
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
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,53 @@ creates and cleans an isolated schema per test; without a DSN those tests skip.
DOM unit tests use the repository-local `web/test/dom.ts` preload from
`web/bunfig.toml`, with no sibling Dashboard package dependency.

### Sharing and access cutover

All Console sharing writes use the server's `applyAppShare`: app PATCH (including
owner/person changes), access-request approval, and post-bind `POST
/api/console/apps/{id}/share-sync`. Browsers no longer write publish policies.
Before cutover, the legacy policy is applied first and the Console policy plus
`shareRevision`/`shareSync=pending` commit before the fixed binding is replaced.
Binding failure leaves the legacy change intact and records `shareSync=conflict`.
The UI warns instead of reporting completion. The next authorized share change
replaces the fixed binding from the saved legacy policy; it does not union grants,
delete other bindings, or silently approve an access model. Approval remains
pending until both writes are confirmed. No credentials are stored.

Platform contracts (under `/api/v1/projects/{project}/applications/{app}`):

- `GET /role-bindings` supplies management authority, the fixed binding ETag,
organization capabilities and source synchronization status.
- `GET /access/share-groups?externalId=...` maps Directory IDs to supplied
`bindingGroupName` and `sourceUID`. `PUT /role-bindings/share` replaces only
`role: app-user`, `subjects`, and optional `organizationPersonRefs`.
It uses `Idempotency-Key` and `If-Match`, or `If-None-Match: *` on creation.
- Company means `Authenticated`; group means supplied `Group` references plus
explicit people; private means owners and invited people; public means an empty
fixed binding. People use `{sourceUID,personID}` even before identity linking:
being added to sharing is not proof that the person can sign in yet.
- Organization membership disclosure is a separate normal binding POST/DELETE.
It requires explicit model acceptance, an eligible role and a ready source.
The dialog distinguishes absent source, first sync pending and unavailable
status, and retains existing assignments for removal during source outages.
- `GET /access-cutover/diff` supplies bounded gaining/losing member samples and
a revision-bound digest. Only an explicit owner confirmation sends `POST
/access-cutover` with `direction`, `candidateDigest`, `expectedApplicationUID`,
`expectedShareRevision`, `expectedBindingETag` and `confirmedDiffDigest`.
The server rereads the diff and rejects stale or unresolved comparisons.
`GET /access-cutover` supplies progress; `AppEnforced` writes bindings only.
Legacy reapplication is rejected after cutover.
After activation, the restore action requires another explicit owner confirmation
and echoes only Platform's sealed `previousDigest` as `candidateDigest` with
`direction: restore`; the Console never accepts a user-chosen previous version.

Every Platform call uses the current operator's bearer and Platform checks
`access:manage`. Console ownership changes **do not** grant `access-manager`.
Creator bootstrap and explicit Platform assignments remain its only sources;
cutover additionally requires Console ownership. Thus an owner without Platform
management authority cannot share or confirm cutover. No Console admin or
Directory-manager flag substitutes for that authority.

From `web/`, run `bun run mock` and `bun run dev` in separate terminals. The default
ports are 54385 for the mock API and 5199 for Vite; set `CONSOLE_MOCK_PORT` and
`CONSOLE_PORT` to isolate concurrent work. Neither command requires a live Platform.
Expand Down
4 changes: 4 additions & 0 deletions cmd/server/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ func consoleHandler(upstreamURL, projectID string) (*consoleAPI, func(), error)
return nil, err
}
connected := api.New(database, auth, upstream, links, publicURL)
if err := connected.ConfigureSharing(upstreamURL, auth.HTTPClient().Transport); err != nil {
_ = database.Close()
return nil, err
}
connected.ConfigureBuildSessions(conversations, installationID)
connected.ConfigureConsoleAuthority(conversationPlatform)
console.current.Store(connected)
Expand Down
32 changes: 21 additions & 11 deletions cmd/server/internal/api/access_requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"unicode/utf8"

"github.com/appthrust/builder-console/cmd/server/internal/domain"
"github.com/appthrust/builder-console/cmd/server/internal/store"
"github.com/google/uuid"
)

Expand Down Expand Up @@ -175,22 +176,31 @@ func (a *API) approveAccessRequest(s *request) (any, int, error) {
}
requester := domain.NewActor(r.Requester.ID, domain.Roles{}, effectiveGroups, s.groups)
updated := domain.ApproveAccess(app, r.Requester.ID, requester.Visible(app))
// route runs this handler in one write transaction under the store lock.
// Commit legacy intent first. Approval is final only after binding readback.
if err := s.tx.SaveApp(app, updated); err != nil {
return nil, 0, err
}
if err := s.tx.DecideAccessRequest(r.ID, domain.RequestApproved, s.person.ID, time.Now().UTC()); err != nil {
return nil, 0, err
}
r, err = s.tx.AccessRequest(r.ID)
if err != nil {
return nil, 0, err
}
updated, err = s.tx.App(app.ID)
return struct {
result := struct {
Request domain.AppAccessRequest `json:"request"`
App domain.App `json:"app"`
}{r, s.appForCaller(updated)}, http.StatusOK, err
}{r, s.appForCaller(updated)}
decide := func(tx *store.Tx) error {
if err := tx.DecideAccessRequest(r.ID, domain.RequestApproved, s.person.ID, time.Now().UTC()); err != nil {
return err
}
tx.HydratePeople = s.directory.People
var err error
result.Request, err = tx.AccessRequest(r.ID)
return err
}
if app.Bound() {
if err := a.applyAppShare(s, &result.App, decide); err != nil {
return nil, 0, err
}
} else if err := decide(s.tx); err != nil {
return nil, 0, err
}
return &result, http.StatusOK, nil
}

func (a *API) declineAccessRequest(s *request) (any, int, error) {
Expand Down
16 changes: 14 additions & 2 deletions cmd/server/internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type API struct {
builds *buildsession.Service
installationID string
authorityStacks consoleStackReader
sharing *sharePlatform
}

type request struct {
Expand All @@ -55,6 +56,7 @@ type request struct {
claims identity.Identity
authorityApps map[authorityRoute][]domain.App
authorityStackCache map[string]buildsession.ConsoleStack
afterCommit func() error
}

type endpoint func(*request) (any, int, error)
Expand Down Expand Up @@ -83,6 +85,12 @@ func New(database *store.Store, auth *identity.Authenticator, upstream *platform
// Creation and binding resolve fresh Directory authority before the transaction.
a.mux.HandleFunc("POST /api/console/apps", a.routeHandlerMode(true, true, true, true, a.createApp))
a.route("PATCH /api/console/apps/{id}", true, true, a.patchApp)
a.route("POST /api/console/apps/{id}/share-sync", true, true, a.syncAppShare)
a.route("GET /api/console/apps/{id}/share-access", false, true, a.shareAccess)
a.route("POST /api/console/apps/{id}/organization-groups", true, true, a.assignOrganizationGroups)
a.route("DELETE /api/console/apps/{id}/organization-groups/{binding}", true, true, a.removeOrganizationGroups)
a.route("GET /api/console/apps/{id}/share-diff", false, true, a.shareDiff)
a.route("POST /api/console/apps/{id}/access-cutover", true, true, a.startAccessCutover)
a.mux.HandleFunc("POST /api/console/apps/{id}/bind", a.routeHandlerMode(true, true, true, true, a.bindApp))
a.route("DELETE /api/console/apps/{id}", true, true, a.deleteApp)
a.route("GET /api/console/apps/{id}/comments", false, true, a.comments)
Expand Down Expand Up @@ -231,12 +239,16 @@ func (a *API) routeHandlerMode(mutation, needsRoles, transactional, fresh bool,
// uncached Directory view as build sessions before opening the transaction.
func (a *API) withRequest(ctx context.Context, claims identity.Identity, bearer string, mutation, needsRoles, me, fresh bool, handler func(*request) error) error {
return a.withResolvedRequest(ctx, claims, bearer, needsRoles, me, fresh, func(state *request) error {
return directoryError(a.store.Do(ctx, mutation, func(tx *store.Tx) error {
err := a.store.Do(ctx, mutation, func(tx *store.Tx) error {
state.tx = tx
tx.DirectoryGroups = state.groups
tx.HydratePeople = state.directory.People
return handler(state)
}))
})
if err == nil && state.afterCommit != nil {
err = state.afterCommit()
}
return directoryError(err)
})
}

Expand Down
2 changes: 2 additions & 0 deletions cmd/server/internal/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type harness struct {
stackBearer atomic.Value
stacks atomic.Value
database *store.Store
sharing *shareFixture
}

func token(subject string) string {
Expand Down Expand Up @@ -94,6 +95,7 @@ func newHarness(t *testing.T) *harness {
}
h.server = httptest.NewServer(New(database, auth, platform.New(upstream.URL, "pj-test"), h.directory.client(t), ""))
t.Cleanup(h.server.Close)
h.sharing = installShareFixture(t, h)
return h
}

Expand Down
15 changes: 14 additions & 1 deletion cmd/server/internal/api/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ func (a *API) app(s *request) (any, int, error) {
if !s.actor.Visible(app) {
return nil, 0, httpx.NotFound()
}
if app.Bound() && app.AppName != nil && a.sharing != nil {
bindings, err := a.sharing.bindings(s.r.Context(), s.bearer, *app.AppName)
app.CanManageShare = err == nil && bindings.CanManageBindings
}
return s.appForCaller(app), 200, nil
}

Expand Down Expand Up @@ -332,7 +336,16 @@ func (a *API) patchApp(s *request) (any, int, error) {
return nil, 0, err
}
updated, err = s.tx.App(app.ID)
return s.appForCaller(updated), 200, err
if err != nil {
return nil, 0, err
}
if input.Share != nil || input.OwnerIDs != nil {
if err := a.applyAppShare(s, &updated, nil); err != nil {
return nil, 0, err
}
}
updated = s.appForCaller(updated)
return &updated, 200, nil
}

func (a *API) bindApp(s *request) (any, int, error) {
Expand Down
Loading
Loading