09

Add Delegated User Access and Private Connectivity

Add optional on-behalf-of authority and a private network path without confusing reachability with permission.

Run it in the public monorepo

This course is built around the public Zheta Kubernetes Lab monorepo. The excerpt below is runnable source, not pseudocode.

Source: services/shared/auth.py

if claims.get("iss") != issuer or claims.get("aud") != audience or int(claims.get("exp", 0)) <= int(time.time()):
        raise PermissionError("expired or wrong-scope bearer token")
    if not claims.get("sub") or not claims.get("org"):
        raise PermissionError("bearer token lacks tenant identity")
    return Identity(str(claims["sub"]), str(claims["org"]))

Code to reality

Declared intent
Derive actor and tenant authority only from a signed, scoped, unexpired identity token.
Interpreter
The shared authentication adapter verifies cryptographic and semantic claims before MVC dispatch.
Software effect
Accepted requests carry an immutable actor and organization identity; invalid requests stop at the boundary.
Hardware effect
Signature verification consumes service CPU but denied calls allocate no downstream runtime or data resources.
Observable evidence
Positive tenant access and wrong-signature, wrong-audience, and cross-tenant denials identify the boundary.

Start with the people and the result they need

The source tables below remain the detailed contract. Begin with these customer paths:

  • D09-UC-01
    • Person: Enterprise end user
    • Job: Ask an app to read one source item on the user's behalf
    • Observable result: Broker uses workload identity plus user delegation and source allows their intersected scope
  • D09-UC-02
    • Person: Network administrator
    • Job: Expose a source privately without making it public
    • Observable result: Broker resolves private DNS and connects over the approved private route

Turn each customer job into a testable story

Now turn each customer job into a story with a result that an engineer can check:

  • D09-US-01
    • Story: As an enterprise end user, I want explicit delegated consent, so that the app cannot reuse my authority after revocation
    • Observable acceptance: Consent, subject, scopes, expiry, revocation, and source decision are recorded without storing a reusable token in app data
  • D09-US-02
    • Story: As a network administrator, I want source traffic constrained to a private path, so that public reachability is unnecessary
    • Observable acceptance: Private DNS/route succeeds; public probe fails; wrong-scope private request still receives authorization denial

Add real state and observable proof

Finally trace each story through the system that owns its state and the evidence that proves the outcome:

  • D09-FLOW-01
    • Trigger: User approves delegated read of one source collection
    • Responsible systems: Enterprise identity provider, Connector Broker, source authorization
    • Authoritative state: Delegated Grant store plus source authorization records
    • Owned record: DelegatedConnectorGrant
    • Observable evidence: Actor, subject, workload, both grant IDs, effective scope, private endpoint, source request, environment, timestamp, trace ID
    • Failure signal: Invalid consent, revoked token, empty scope intersection, or source denial
  • D09-FLOW-02
    • Trigger: Revoked user asks for a workload-allowed resource
    • Responsible systems: Private DNS, routing/firewall, Connector Broker, source endpoint
    • Authoritative state: Network configuration and flow evidence
    • Owned record: PrivateConnectionEvidence
    • Observable evidence: Revocation, denial rule, zero delegated source call, private-path proof, allowed machine control, immutable evidence ID
    • Failure signal: Public resolution, route/firewall failure, unexpected public flow, or authorization bypass

The enterprise problem and today’s slice

Enterprise problem: A private connection is often treated as authorization, while delegated tokens are treated as replacements for workload grants, allowing reachable workloads to exceed either machine or human scope.

Whole-course context: Provider state can record an intended machine connector name but no broker enforces source authority yet; today designs the separate delegated grant and private route without pretending either exists.

Today’s slice: Design the required intersection of workload and delegated-user scopes, then inspect the authenticated provider identity seam that exists today; delegated grants and private source connectivity are not implemented in the monorepo.

End-of-day evidence: Provider-token success plus missing, tampered, expired, and wrong-audience denials are reproducible; delegated consent, scope intersection, private DNS/route, and source decision remain named acceptance evidence for later implementation.

Still unsolved: Generated-app human identity, collaboration roles, publication, and AWS account implementation remain deferred.

Customer use cases

Some source actions need a named human while scheduled refreshes need machine authority. These use cases keep both grants independent and make the private path observable.

Use case IDActorCustomer jobSuccess outcomeDenial or recovery evidence
D09-UC-01Enterprise end userAsk an app to read one source item on the user's behalfBroker uses workload identity plus user delegation and source allows their intersected scopeUser-only or workload-only excess scope is denied
D09-UC-02Network administratorExpose a source privately without making it publicBroker resolves private DNS and connects over the approved private routePublic-route probe and unauthorized private request are denied while authorized private request succeeds

Actor-centred user stories

Reachability and authority answer different questions. These stories require separate network and policy evidence.

Story IDUse case IDsUser storyObservable acceptance conditions
D09-US-01D09-UC-01As an enterprise end user, I want explicit delegated consent, so that the app cannot reuse my authority after revocationConsent, subject, scopes, expiry, revocation, and source decision are recorded without storing a reusable token in app data
D09-US-02D09-UC-02As a network administrator, I want source traffic constrained to a private path, so that public reachability is unnecessaryPrivate DNS/route succeeds; public probe fails; wrong-scope private request still receives authorization denial

End-to-end product flows

The user chooses Connect as me for one source operation. Connector Broker computes the intersection of the machine and human grants before it uses the private route.

Flow IDUse case IDsPathTriggerNumbered stepsTerminal evidence
D09-FLOW-01D09-UC-01, D09-UC-02HappyUser approves delegated read of one source collection1. Identity provider records consent.; 2. Broker validates user and workload grants.; 3. Compute scope intersection.; 4. Resolve private DNS.; 5. Call source privately.; 6. Record source decision.Actor, subject, workload, both grant IDs, effective scope, private endpoint, source request, environment, timestamp, trace ID
D09-FLOW-02D09-UC-01, D09-UC-02DeniedRevoked user asks for a workload-allowed resource1. Private route remains reachable.; 2. Broker finds revoked delegation.; 3. Deny before source call.; 4. Workload-only scheduled read repeats as positive control.Revocation, denial rule, zero delegated source call, private-path proof, allowed machine control, immutable evidence ID

The user grants optional on-behalf-of authority. This action neither creates the workload grant nor grants membership inside the generated application.

System design derived from the flows

A private endpoint controls the network path but cannot decide whether a user may read a record. Connector Broker combines plane-local grants; the source system remains the final authority.

Use case IDEntry pointResponsible servicesAuthoritative storeFailure evidence
D09-UC-01Connector consent and broker requestEnterprise identity provider, Connector Broker, source authorizationDelegated Grant store plus source authorization recordsInvalid consent, revoked token, empty scope intersection, or source denial
D09-UC-02Broker DNS and connectionPrivate DNS, routing/firewall, Connector Broker, source endpointNetwork configuration and flow evidencePublic resolution, route/firewall failure, unexpected public flow, or authorization bypass

Broker access is constrained by both grants, then transported privately. A green network connection is not a green authorization decision.

Data model and ownership

Delegated credentials in app tables would survive user revocation and cross a plane boundary. Connector Broker owns encrypted grant material and exposes only opaque status to the app.

Generated-application database: Not created in this runnable slice — no delegated credential or connection status is persisted; both the generated-app store and connector grant store remain explicit production work.

Record or entityStore and ownerPrimary keyForeign key or opaque referenceTenant keyMaterial constraintLifecycle and deletionUse case IDs
DelegatedConnectorGrantConnector grant store and secret manager, owned by Connector Brokerdelegated_grant_idOpaque user, workload grant, consent, and secret-version referencesorganization_idEffective scope is intersection; encrypted material never enters generated-app storageConsented, active, refreshed, expired/revoked; secret deleted and evidence retainedD09-UC-01, D09-UC-02
PrivateConnectionEvidenceEvidence store, owned by Network Platform and Audit Evidenceevidence_run_idEndpoint, DNS answer, flow, both grants, source request IDsenvironment and organization_idMust include authorized private, denied public, and denied wrong-scope pathsImmutable retention; expires by network evidence policyD09-UC-01, D09-UC-02

The grant record proves current delegated authority; the evidence distinguishes network reachability, broker policy, and source policy.

Prove the intersection

Testing only an authorized request cannot expose accidental union of scopes. The current monorepo verifies a provider bearer token's signature, issuer, audience, expiry, actor, and organization; it has no delegated grant, OAuth exchange, private DNS, firewall, or enterprise source adapter. Read the exact boundary in services/shared/auth.py.

if claims.get("iss") != issuer or claims.get("aud") != audience or int(claims.get("exp", 0)) <= int(time.time()):
    raise PermissionError("expired or wrong-scope bearer token")
if not claims.get("sub") or not claims.get("org"):
    raise PermissionError("bearer token lacks tenant identity")
return Identity(str(claims["sub"]), str(claims["org"]))
Declared intentInterpreterSoftware effectHardware effectEvidence
Accept only a correctly scoped provider token and derive actor plus organization from signed claimsPython verifies HMAC and semantic JWT claims before MVC controller dispatchProduces an immutable Identity or stops the request; it does not create delegated consent or network reachabilityVerification consumes control-plane CPU; a denied request allocates no connector or source resourcesAuthenticationTest proves valid identity plus missing/tampered-token denial; delegated-scope and private-path evidence remain absent

Decision rules

Use workload authority for unattended app operations and delegated authority only when the source action must carry a human subject. Private connectivity reduces exposure; it never expands permission, and revoking either grant must independently stop the combined path.