Skip to content

Control plane: spike — should Cognito identity ownership move out of MDR? (ADR extending 0002) #1190

Open

Description

@bjagg

Part of #1041. Design spike — the epic and ADR 0002 both call this out as the bigger open question, deliberately deferred.

Why

ADR 0002: "Identity ownership is the bigger open question. The Cognito self-serve identity is MDR's today." Moving developer keys is mechanical once #1180 lands; moving identity is not. The self-serve tenant flow (#882/#883/#884, docs/design/cross-cutting/self-serve-tenant-auth.md) spans Cognito sign-up, schema-per-tenant provisioning, workspace selection, and invite tokens — and tenant provisioning is genuinely an MDR concern, while sign-in is genuinely a control-plane concern.

Questions to answer

  • Which parts of the self-serve flow are identity (control plane) and which are tenant/metadata provisioning (MDR)? The seam is not obvious — /tenants/provision needs both.
  • Who owns the Cognito user pool, and what happens to existing users and sessions in a move?
  • How do invite tokens and workspace selection work across the split?
  • Is a move even warranted, or is "identity stays with MDR, keys move" a defensible end state? This spike is allowed to conclude "don't move it" — that is a real outcome, not a failure.
  • Migration cost and blast radius: this touches live sign-in for both environments.

Done when

An ADR extending 0002 records the decision with its reasoning, and — if a move is recommended — a sized set of follow-on issues exists. If not, #1041 is amended to drop identity from its scope.

Note

Do not start this before the key extraction (#1180) and the service (#1182) are done. Sequencing it first is how this epic stalls.

Activity

  1. bjagg commented on Sep 26, 2026

    @bjagg
    ContributorAuthor

    Input for this spike: a non-Cognito local-login path is being added to MDR in #1316, so a deployer can test-drive LIF with username/password logins they configure, with no Cognito and a single schema.

    Today MDR's HS256 /login checks a hardcoded list of demo users against one shared password (bases/lif/mdr_restapi/core.py). #1316 makes that list configurable. If this spike concludes that sign-in should move out of MDR to the control plane, that local-login path has to move with it and keep working. It's the only way into a Cognito-less deployment. Please treat it as a requirement on whatever identity split comes out of this, not only the Cognito self-serve flow.

    (#1185 doesn't touch it: that issue moves developer API keys, a different domain from user sign-in.)

  2. dereck-symmetry commented on Oct 5, 2026

    @dereck-symmetry
    Contributor

    ADR 0006 gives this spike one concrete question that #1183 is waiting on: what identifies a workspace in the control plane's key store, and how does issuance confirm the caller belongs to it?

    Today the check maps the caller's Cognito group to a schema with tenant_schema_for_group (components/lif/tenant_routing/core.py:45). The ADR deliberately doesn't choose between the tenant_* schema name, the Cognito group, and a new ID. It also says the control plane shouldn't inherit MDR's tenant_* naming by default.

    One constraint, from bjagg's 09-26 comment about local logins: an HS256 or local-login user has no cognito:groups claim. resolve_tenant_schema sends such callers to the service schema (components/lif/tenant_routing/core.py:58). So a workspace defined as "the Cognito group" can't work in a Cognito-less deployment. Whatever this spike picks has to work for both login paths.

    Sequencing. The issue's note still holds: don't start the spike before #1180 and #1182. But #1183 can't finish without this one answer, so I'd answer the workspace question first, before the rest of the identity split.

  3. dereck-symmetry commented on Oct 7, 2026

    @dereck-symmetry
    Contributor

    Taking this, but only one slice of it for now. The note above still holds for the rest: #1180 is waiting on #1363 to merge, and #1182 hasn't started.

    In scope now: the workspace question from my 10-05 comment, because #1183 can't finish without it.

    1. What identifies a workspace in the control plane's key store: the tenant_* schema name, the Cognito group, or a new ID?
    2. How does key issuance confirm the caller belongs to that workspace? It has to work for both Cognito users and local/HS256 logins (Test-drive LIF on a non-AWS cloud, stage 1: MDR, single schema, locally configured logins #1316), and the local logins carry no cognito:groups claim.

    Out of scope until #1182 lands: the wider identity split. That covers who owns the user pool, the self-serve flow seam, invite tokens across the split, and whether sign-in moves at all.

    I'll post the findings here as a recommendation with the code it's grounded in. The ADR extending 0002 comes once the full spike can run, unless you'd rather the workspace answer get its own ADR now.

  4. dereck-symmetry commented on Oct 7, 2026

    @dereck-symmetry
    Contributor

    @bjagg findings on the workspace question, the slice I took on above. This doesn't cover the wider identity split. It's grounded on main at 588757a.

    What a workspace is today

    Nothing in the database records a workspace. It's the pair (Cognito group, tenant_{sanitized group} schema), worked out on each request (components/lif/mdr_services/workspace_service.py:22-27, components/lif/tenant_routing/core.py:28-55). None of the migrations V1.0–V1.6 creates a workspace or tenant table, so the schema itself is the only durable record.

    When a user is in several groups, the MDR picks one with the lif_workspace cookie. The cookie is HMAC-signed with the JWT secret and is rechecked against cognito:groups on every request (components/lif/mdr_auth/workspace_cookie.py:51-53, components/lif/mdr_auth/core.py:291-298). With no cookie, the first group wins.

    Each kind of caller ends up at a schema:

    Caller What request.state gets Schema
    Cognito JWT principal (email or sub), cognito_groups, cognito_sub (mdr_auth/core.py:237-239) the selected group's tenant_*
    Local / HS256 login (#1316) principal = sub = the username. No groups, no cognito_sub (mdr_auth/core.py:240-248; /login at bases/lif/mdr_restapi/core.py:418) the service schema
    Service API key service:<name> (mdr_auth/core.py:199-205) X-API-Tenant-Schema, or the service schema

    Issuing a key today depends on request.state.cognito_sub and returns a 400 without it (bases/lif/mdr_restapi/developer_api_key_endpoints.py:20-29). The key's workspace is whichever schema search_path picked; the row has no workspace column (V1.5:14-24).

    Recommendation: the tenant schema name, stored as an opaque string

    I'm proposing this for the workspace column that ADR 0006 leaves open, with the two questions below.

    • It's the only identifier every caller already has. Cognito users get it through the group. Local logins get it through the service schema. Service callers already pass it in X-API-Tenant-Schema.
    • Control plane: migrate the developer-key store to control-plane-owned storage (dev + demo, non-destructive) #1183's copy gets it for free. Each row's source schema is its workspace, so nothing has to be looked up or invented.
    • It's what a key's consumers route on. The LDE and the Translator reach the MDR by schema name (components/lif/translator_client/core.py:39, components/lif/mdr_client/core.py:48-53).

    On ADR 0006's caution about inheriting MDR's tenant_* naming: the control plane would treat the value as opaque. It would never parse or build the prefix itself. The group-to-schema rule stays in the pure tenant_routing brick, which the control plane can import without depending on MDR.

    Issuance would check membership like this:

    • The request names the workspace explicitly. The control plane can't read lif_workspace, because that cookie is signed with MDR's secret.
    • A Cognito caller is allowed if one of their groups satisfies tenant_schema_for_group(group) == workspace. That's the same rule find_workspace applies today.
    • A local-login caller is allowed only for the deployment's service schema. That matches Test-drive LIF on a non-AWS cloud, stage 1: MDR, single schema, locally configured logins #1316's single-schema premise.

    Alternatives considered:

    • The Cognito group name. Rejected:
      • local logins have no group, so it can't work in a Cognito-less deployment;
      • renaming a group orphans the workspace;
      • two names can map to one schema (see finding 2 below).
    • A new control-plane workspace ID, a Workspaces table that maps an ID to a schema and an IdP group. Deferred, not rejected. It's the most correct shape, but owning workspace records is the identity-ownership question this spike is holding until Control plane: create the control-plane service (base + project + deploy pipeline) #1182. If that half adopts it, it's a one-time backfill from the schema names.

    Two findings beyond the question

    1. A key's owner can't stay a bare Cognito sub if local users may issue keys. A local login carries only its username. The owner would need to be issuer-qualified (for example cognito:<sub> / local:<username>). That changes the Control plane: extract developer-key logic out of MDR-domain bricks into a portable developer_keys brick #1180 brick's model and Control plane: migrate the developer-key store to control-plane-owned storage (dev + demo, non-destructive) #1183's copy, where existing OwnerSub values would become cognito:<sub>.
    2. Two group names can map to the same schema. I measured tenant_schema_for_group("Foo-Bar") and tenant_schema_for_group("foo_bar"): both return tenant_foo_bar, and nothing detects it. This exists in MDR today, independent of the control plane. I can file it separately if you agree it's worth tracking.

    Two questions before I take this further

    • Q1: Should local-login users be able to issue developer keys at all? Today they can't. Finding 1 only matters if the answer is yes.
    • Q2: Is the schema name, stored as an opaque string, acceptable as the workspace identifier for now, despite ADR 0006's caution? A dedicated workspace ID would then be revisited in the identity half.

    Once you've answered, I'll record the decision where you prefer. That could be a short ADR now, since #1183 needs it, or part of the ADR extending 0002 when the rest of this spike runs.

  5. added a commit that references this issue on Oct 9, 2026
  6. added a commit that references this issue on Oct 9, 2026
  7. dereck-symmetry commented on Oct 13, 2026

    @dereck-symmetry
    Contributor

    @bjagg a nudge on Q1 and Q2 from my 10-07 comment above, because #1182 now depends on them too. I've claimed #1182 and am starting the control-plane service without its key endpoints.

    The key table I'd add next has to choose two columns, and each one depends on an open question:

    • Workspace: ADR 0006 gives the store an explicit workspace column, and its value is Q2. My recommendation is the tenant schema name, stored as an opaque string.
    • Owner: whether OwnerSub stays a bare Cognito sub or becomes issuer-qualified (cognito:<sub> / local:<username>) depends on Q1, whether local-login users can issue keys.

    Both are cheap to decide now and expensive to change after a migration ships. The service skeleton doesn't need either answer, so nothing is blocked yet. Once you've answered, I'll record the decision wherever you prefer, as a short ADR now or as part of the ADR extending 0002.

  8. dereck-symmetry commented on Oct 26, 2026

    @dereck-symmetry
    Contributor

    @bjagg, a second nudge on Q1 and Q2 from my 10-07 comment (issuecomment-6048941868). They are now the only thing blocking the next slice of #1182.

    Where things stand. The control-plane skeleton, draft #1384, is up to date: main is merged in, and it's moved onto lif.auth since #1398 deleted cognito_auth. Its tests and the local compose run are green. The next step is the developer-key table and its endpoints, and that migration has to fix two columns:

    To make it a quick answer, my defaults are Q1 = no and Q2 = yes. They are the smallest change from what runs today. The one catch: if Q1 later becomes yes, the owner column has to be rewritten, so say so now if local-login key issuance is on the roadmap. If those defaults work for you, a 👍 on this comment is enough. I'll then record the decision as a short ADR, since #1183 needs it before the rest of this spike runs, and write the key-table migration.

    Both answers are cheap now and expensive after a migration ships, which is why I'm asking before writing it.

  9. bjagg commented on Nov 3, 2026

    @bjagg
    ContributorAuthor

    Defaults OK for Q1 and Q2: local-login users can't issue developer keys, so OwnerSub stays a bare Cognito sub, and the tenant schema name, stored as an opaque string, is the workspace identifier for now.

  10. added 3 commits that reference this issue on Nov 3, 2026
  11. dereck-symmetry commented on Nov 9, 2026

    @dereck-symmetry
    Contributor

    Status update, so it's clear what's left here.

    Done: the workspace slice (Q1 and Q2). Bill accepted the defaults on 11-03, and ADR 0008 (docs/design/adr/general/0008-control-plane-key-owner-and-workspace.md) records them:

    1. Local-login users can't issue developer keys, so a key's owner is a bare Cognito sub.
    2. A workspace is identified by its tenant schema name, stored as an opaque string.

    The control plane's key endpoints are built on them (#1466, for #1182), and #1183's migration will use the same columns.

    Still open: the spike's main question. Should Cognito identity ownership move out of the MDR into the control plane, or stay where it is? This issue's "done when" asks for an ADR extending 0002 on that. Nothing has decided it yet. ADR 0008 deliberately records only the key-store choices and leaves identity ownership here.

    I'm leaving this open for that question. It isn't blocking any current #1041 work, so it can wait until the control plane needs it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions