Skip to content

Run scheduled tasks with bounded, revocable user authority #373

Closed as duplicate

Description

@jhrozek

Outcome

A user can create a schedule for a fixed agent and operation. Timer and "run now" executions act only within that user-approved scope, until expiry or revocation.

Proposed approach

  • The authenticated owner's successful schedule create/update request is the recorded consent event; there is no mandatory second Mecatl consent screen.
  • The schedule binds an exact agent revision, integration, operation, target, cadence, expiry, and execution limits.
  • It references a signed Scheduled Authority Grant, not a user login token, provider access token, or provider refresh token.
  • The protected authority service holds any provider refresh credential.
  • Every fire checks the current grant state, schedule state, policy, agent/integration revision, and exact requested operation before obtaining fresh short-lived authority.
  • Expiry, revocation, drift, missing credentials, and unavailable/indeterminate policy fail closed.
  • Manual and timer fires share one authority path.

Not in this issue

A generic approval UI, broker replication, service-identity fallback, or silently using "latest" agent/integration configuration.

Dependencies

The protected-operation authority path from #1564 (external action without exposed credentials). Provider OAuth consent, including any offline_access request, remains in the interactive provider-connection flow; it is separate from Mecatl's schedule-create consent event.

Proof

  • An expired or revoked schedule never executes under service/ownerless authority and names the reason.
  • A schedule cannot fire as a different agent, integration, target, or broadened operation.
  • Manual and automatic fires have the same effective authority.
  • Provider credentials never enter Mecatl state or model-visible output.

Hazards (carried over from the original issue body)

Facts that were expensive to find and that nobody re-derives on the way to implementing. Each is verified against code.

  • Never fall back to a service identity when the user's grant expires. That turns an expiry into an escalation.
  • The model must not be able to author the consent record.
  • An absent user cannot consent at fire time, so capture-at-create is the only user-consent path for unattended work. The alternative is an admin pre-authorizing a class of agents, which substitutes organizational authority for the user's. There is no third option, and which one applies should be a stated decision rather than a consequence of the implementation.
  • "Signed" is worth whatever the signing key's custody is worth. A key held in the agent-loop process is reachable from a shell the model drives without touching memory — see Spike: can a model-spawned shell reach the key? #375 for the verified evidence.

Correction to the previous version of this issue

The previous body said authority is replayed "with no live lookup that can fail or drift." That claim does not hold: the signed grant prevents unauthorized row mutation, but only authoritative fire-time checks (grant state, schedule state, policy, credential availability) make revocation, disablement, current policy, and provider-connection loss effective. The design must not silently turn an outdated signature into continuing authority — every fire re-checks live state, per the "Proposed approach" above.

Activity

  1. added
    enhancement
    on Aug 4, 2026
  2. changed the title [-]EP7: a scheduled run acts with bounded, consented authority[/-] [+]A scheduled run acts with bounded, consented authority[/+] on Aug 4, 2026
  3. JAORMX commented on Aug 5, 2026

    @JAORMX
    Contributor

    (mecatl comment, posted on Juan's behalf — color from the #377 Q5 discussion.)

    The "consent is a signed artifact" criterion quietly makes this issue the consent-record holder decision point, and the #377 discussion converged on naming it: the schedule grant is the one consent artifact the design already makes forgery-resistant — signed envelope, verified before every fire, a confirmation interaction the model can't author. When per-agent consent ("which named agents may use Alice's GitHub") gets built, the record most naturally lives wherever this envelope lives, with the same properties. Worth stating in the design notes here so the two don't get built as separate stores with separate signing and verification paths.

    Two threads from that discussion that sharpen criteria already in this issue:

    1. Who signs the envelope. Today mecatl has no signing identity, so "signed artifact" currently means signed by something external (the AS, or a MAC keyed like Store hardening: auth, TLS and snapshot integrity #374's snapshot MAC). The minimal-issuer spike (the amended SPIFFE-issuer deferral on Agent identity in mecatl tracker #377) is what gives mecatl its own key — at which point the envelope can be self-signed and verifiable offline. This issue doesn't have to wait for that, but the envelope format should pick a signature scheme that a mecatl-issued key can later occupy without a format migration.
    2. The shape problem, stated so the signer knows what they're signing: an absent user cannot consent at fire time, so this issue's "captured at create" is the only user-consent path for unattended work — the alternative is admin pre-authorization of an agent class, which substitutes organizational authorization for Alice's. The doc's instruction is to name that trade-off to whoever signs off on the schedule feature; this issue is where that naming happens.

    Also +1 on "manual and automatic fires share one path" — that's the "identity is either derived from a verified credential or absent, no third state" discipline applied to the schedule seam.

  4. jhrozek commented on Aug 5, 2026

    @jhrozek
    ContributorAuthor

    The consent-record holder question got answered while reading the drafts, and it points back here.

    Nothing needs to hold a per-agent consent record that this envelope wouldn't already do better. Every IETF draft that scopes consent puts an AS-signed artifact keyed on the agent definition, and the closest thing to a format worth borrowing is Liu et al.'s authorization_evidence (draft-liu-ai-agent-authorization-integration-00): an object inside RFC 9396 authorization_details carrying displayed_content, user_action and a timestamp, signed. That is the shape this issue's criterion already asks for, a record of the confirmation act the model cannot author. It is an individual draft with no standing, so borrow the format, not the dependency.

    On who signs the envelope. The issuer is now sequenced behind the reachability spike (#375) rather than deferred out of the plan, because the FS grant service needs it. So a mecatl-signed envelope is nearer than it looked. The constraint stands either way: pick a signature scheme a mecatl-issued key can occupy later without a format migration.

    One caveat on that, from the security pass on #374. A signing key held in the agent-loop process is reachable from a shell the model drives, three ways, without touching memory. A flag lands in /proc/<pid>/cmdline. An env var is readable at the parent's /proc/<pid>/environ, since envscrub only strips names from the child's environment. A mounted Secret file is a fixed path, and cat is classified read-only by verb with no path predicate, so an isolated child auto-approves reading it. "Signed by mecatl" is therefore worth whatever the key's custody is worth, which is what #375 is now measuring. An AS-signed envelope does not have that problem today, which is an argument for not waiting on our own signing identity to get the envelope built.

    And the shape problem should be stated in the issue, for whoever signs off on the schedule feature. An absent user cannot consent at fire time. So consent is either captured when the schedule is created, or an admin pre-authorizes a class of agents, which substitutes organizational authority for the user's. There is no third option. That choice deserves to be explicit rather than arrive as a consequence of the implementation.

  5. jhrozek commented on Aug 5, 2026

    @jhrozek
    ContributorAuthor

    Correction to my previous comment, and a reframe.

    The consent model is spike work, not epic work, so this issue no longer tries to settle it. I had written the record's keying into the acceptance criteria as though it were decided; it isn't, and it needs a proper design pass. The body now carries a "consent model is a spike first" section with the questions left open on purpose: who holds the record and who signs it, what it is keyed on, what format to borrow, where consent is captured for unattended work, and whether it must verify with the authorization server unreachable.

    The current leaning on keying, recorded as a leaning rather than a decision: the definition carries the authorization and an instance or session id rides alongside for audit correlation only. That is the shape in draft-liu-ai-agent-authorization-integration-00, where act.sub authorizes and agent_user_id correlates. It reconciles wanting instance attribution with the fact that no relying party can act on an instance name today. The spike can overturn it.

    What stays as acceptance criteria here is the part that isn't consent design: the owner captured at create and replayed at every fire with no live lookup, the grant's lifetime bounded by the schedule's, expiry failing closed with a reason distinguishable from a transient error, manual and automatic fires sharing one path, and the model not being the author of the artifact whatever its shape turns out to be.

    One constraint survives the spike either way: pick a signature scheme a mecatl-issued key can occupy later without a format migration.

  6. jhrozek commented on Aug 11, 2026

    @jhrozek
    ContributorAuthor

    Hazard, verified against code — the schedule's workspace is a model-authored authority field today.

    ScheduleArgs.Workspace (engine/agent/scheduletool.go:64) is model-supplied
    and reaches port.ScheduleSpec verbatim (:386). Nothing on the path validates
    it as a path. scheduleManager.validateScheduleSpec
    (internal/adapter/server/schedule_manager.go) checks presence, profile-aware
    — a default-profile schedule must have a non-empty workspace, a no-fs one must
    have none — and Service.createSession (internal/adapter/server/service.go)
    repeats the same presence check. At fire time
    internal/app/scheduler_fire.go:86 hands the spec's workspace straight to
    CreateSessionWithProfile, and osfsWorkspaceFactory
    (internal/app/build.go:6979) roots the fire session's osfs workspace there,
    building the escape classifier from that same root — so no containment
    check can fire, the same way none fires in #448. There is no filepath.Rel /
    Clean / IsAbs anywhere on the path.

    This makes the fire's filesystem authority strictly a function of a value the
    model writes, one turn removed, and it is not bounded by the deployment's
    --workspace. Concretely it defeats #448's stated mitigation: a model with the
    Schedule tool creates a schedule with workspace: "/", fires it in the same
    turn (FireNow, and the mecak8s scheduler is on by default —
    cmd/mecak8s/flags.go:287), and the fire's Read serves
    /var/run/secrets/kubernetes.io/serviceaccount/token. ADR 0075 fire-result
    delivery then routes the result back to the creating session.

    Four details that cost time to establish and that nobody should re-derive:

    1. The tool is on by default with no flag. registerScheduleTool
      (internal/app/catalog.go) gates only on the store exposing a
      port.ScheduleStore — true for jsonlstore (jsonlstore.go:393), redisstore
      and grpcdriver; only the in-memory memstore lacks it. And it is
      floor-scoped Allow in defaultRules() (internal/app/build.go), so it
      never asks.
    2. Plan mode does not stop the read shape. planAwareScheduleTool
      (engine/agent/scheduletool.go:262-330) denies only a mutating: true
      create and the fire of a mutating schedule. A mutating: false create
      passes, and its fire runs in ModePlan — which still has Read/Grep/Glob.
    3. The origin carries no authority. NewSessionOriginScheduleManager
      (engine/agent/sessionorigin.go) stamps OriginSessionID only;
      validateScheduleOrigin loads that session purely to prove it exists. The
      creating session's root is available at exactly that point and is not read.
      This is the natural capture site for AC1.
    4. A no-fs session can mint a filesystem one. The Schedule tool is
      registered in both profiles by design (catalog.go: "managing a schedule is
      not a filesystem act"), and a no-fs session may create a
      default-profile schedule. Whatever bounds the fire has to hold when the
      creating session has no filesystem authority at all.

    Proposed additional proof bullet: a session rooted at a project directory
    creates a schedule naming a workspace outside it, then fires it; the create is
    refused, or the fire runs bounded by the creating session's root. Both halves
    tested, so "the fire failed" cannot pass for "the fire was bounded".

    Also worth a line in #438: its authority-value criterion says "which paths", and
    #371's slice says "the three spawn seams" — a schedule fire is a fourth
    derivation point that is not a spawn (it is a fresh top-level session minted in
    internal/app/scheduler_fire.go), so an implementation that intersects at
    Subagent/Parallel/Team can satisfy every listed criterion while leaving this
    open.


    A cheap interim mitigation, independent of the identity work (in the spirit of
    #448's second suggestion): reject a schedule create whose Workspace is not the
    creating session's root, or a subpath of it, in validateScheduleSpec — where the
    origin session is already being loaded. That is a create-seam check in the one
    place the tool and the REST/gRPC handlers already funnel through, so it needs no
    second enforcement path.

    Provenance: established by reading code, with the citations above. Not
    demonstrated end to end — a scheduled fire reading the token was not observed, so
    treat this as code-established rather than empirically proven.

  7. removed
    enhancement
    on Aug 12, 2026
  8. self-assigned this
    on Aug 12, 2026
  9. jhrozek commented on Aug 12, 2026

    @jhrozek
    ContributorAuthor

    Dependency note, surfaced while fixing an unrelated-looking bug.

    This epic's first acceptance criterion —

    A schedule carries the authority of its creator, captured when it is created and replayed at every fire, with no live lookup that can fail or drift.

    — rests on schedule origin capture being correct, and on main it was not. #482: two concurrent sessions on a shared Engine could interleave between the per-run origin bind and the Schedule tool's execution, so one session stamped another session's id as a schedule's OriginSessionID — and, because captureScheduleOwner (ADR 0100 decision 6) resolves the owner from that origin, the schedule inherited the other session's owner principal. Atomic access prevented the data race but not the mis-attribution.

    Why that matters here specifically: "captured when it is created" was already the design, and the capture itself was the broken step. Any consent artifact built on top would have been correctly signed, correctly bounded, and attributed to the wrong creator — a failure this epic's proof section would not catch, since every listed adversarial case holds while the captured identity is simply the wrong one. The AC's "no live lookup that can fail or drift" is satisfied either way, which is what made it invisible.

    Fixed in #484 (merged/pending): attribution moved onto the run context, stamped in startRun and read at the single site that builds the ScheduleSpec. Both run-entry seams (Run, ResumeApproval) route through startRun, so an awaiting-approval resume attributes identically to a normal run — relevant to the fourth AC here ("manual and automatic fires share one path"), since that path now has one origin source rather than one per seam.

    So #482 is a precondition for this epic rather than part of it. No action implied for the consent-model spike beyond being able to assume the creator identity reaching it is now the right one.

    One thing worth carrying into the spike, from ADR 0104's consequences: validateScheduleOrigin checks only that the origin session exists, not that the caller owns it. Today the only thing stopping an embedder from naming an arbitrary session as origin is that no exported writer for the origin context value exists. If this epic's design ever needs to attribute a schedule created outside Engine.Run, that ownership check has to land first — otherwise exporting the writer silently reopens exactly what #482 closed.

  10. removed their assignment
    on Aug 13, 2026
  11. self-assigned this
    on Sep 8, 2026
  12. changed the title [-]A scheduled run acts with bounded, consented authority[/-] [+]Run scheduled tasks with bounded, revocable user authority[/+] on Sep 15, 2026
  13. ChrisJBurns commented on Oct 26, 2026

    @ChrisJBurns
    Contributor

    Superseded by #2569 (Scheduled runs: schedule grants), part of phase 2 of the agent identity work (#2545).

    #2569 follows the merged agent identity design, so it doesn't use the signed Scheduled Authority Grant proposed here. A schedule grant is set up from the user's AS-1 token while the user is present, and the broker stores it under the schedule. When the schedule fires, the scheduled session passes the schedule ID, and the broker exchanges the stored grant for a refresh token that expires no later than the grant's horizon.

    This issue's outcome and proof carry over as #2569's acceptance criteria, each with a test:

    • an expired or revoked schedule never runs under a service or ownerless identity, and the run names the reason;
    • a schedule cannot run as a different agent, integration, target, or broader operation than the one set up;
    • manual and timer runs go through the same authority path, with the same effective authority;
    • provider credentials never enter Mecatl state or model-visible output;
    • the model cannot create or change the setup that records the user's consent.

    Closing in favour of #2569.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions