Let applications ask whether a caller may act on a step (tm.MayAct), then move file references into core

Aperta
#337 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go

Direzione di ricerca

Start with CompleteTaskStep and checkRequiredPreResume to understand the existing write guard, then inspect how PRE_RESUME extensions are declared and executed. The first deliverable is tm.MayAct with an optional Authorizer interface and coverage for guarded steps and extensions that do or do not implement it; done means callers can check whether a command is allowed without side effects. The file reference migration is explicitly later and spans core and application interfaces.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Priority/Low refactor Type/Improvement
Current Limitation

Core enforces who may complete or draft a step, but it gives an application no way to ask that same question without making the write. So an application that needs the answer while it renders a task works it out itself, from config core owns.

nsw-srilanka is the case today. GET /api/v1/tasks/{id} gives a reader file references with submit only when the reader may act on the active step. To decide that, it:

  • loads the active step template and finds its PRE_RESUME authz entry itself (stepCanAct in internal/bootstrap/app.go, MayActOnStep in internal/tasks/extensions/authz);
  • evaluates that entry's rules itself, asking "may this reader run any command in this state?" rather than whether a given command would pass;
  • repeats core's rule for whether a step is guarded. Core's declaresExtension / checkRequiredPreResume refuse a step with no authz, and OpenNSW/nsw-srilanka#848 adds a separate declared flag in MayActOnStep so that reads agree with it.

Problems with this:

  • The guard is defined twice. If core changes what counts as guarded (which phase, which ids, what WithRequiredPreResumeExtensions is given), the write path follows and the read path doesn't. Readers would then be offered actions that are refused, or the other way round, with nothing failing.
  • The read reaches into write-side config. The application reads the PRE_RESUME entry of a step template and runs the rules itself, instead of asking the code that enforces them.
  • It is tied to one extension. The answer is "what the authz rules say", not "what core would allow", so it breaks if write authorization ever moves to another or a second extension.

File references themselves (the reference format, their read/submit scopes, binding them on read and on submit/draft, and the read-only reference sent to an OGA on EXTERNAL_REVIEW) live in nsw-srilanka too (internal/storage/fileaccess, internal/tasks/file_binding.go). Yet what they protect is declared generically in the artifacts: a render config's files paths, and the rule that a submission must hand back a reference issued to the submitter with submit. Nothing about it is specific to one deployment.

Suggested Improvement

1. A dry-run authorization check on the task manager (do this first; it is small and useful on its own).

  • An optional interface a PRE_RESUME extension can implement beside Execute, which checks the caller without side effects:

    // Authorizer is a PRE_RESUME extension that can say, without side effects,
    // whether the caller in ctx may run command on the step.
    type Authorizer interface {
        Authorize(ctx context.Context, record store.TaskRecord, command string, properties json.RawMessage) error
    }
    
  • tm.MayAct(ctx, taskID, stepID, command) error, which:

    1. loads the active step template, as CompleteTaskStep does;
    2. applies checkRequiredPreResume, the same guard writes use;
    3. calls Authorize on each declared PRE_RESUME extension that implements Authorizer.

    Extensions that only check the payload (e.g. a payload-schema check) don't implement it and are skipped, since a dry run has no payload.

  • The caller's identity stays in ctx, as it is for Execute, so core stays identity-agnostic.

  • The view's real question is "can they run some command?". Either add a MayActAny, or let the caller pass the commands its render state offers. The second is more precise: it's exactly the buttons the user would see.

With this, nsw-srilanka's stepCanAct and MayActOnStep become a call to tm.MayAct, and the guard has one definition.

2. Move file references into core (later, building on 1).

Core would own:

  • the reference format, its scopes and who it was issued to;
  • binding on read (GetTask, using MayAct to decide on submit) and on submit/draft;
  • the outbound reference on an EXTERNAL_REVIEW dispatch.

The storage backend and the principal stay behind interfaces the application provides.

Version

main

Additional Context
  • Came up reviewing OpenNSW/nsw-srilanka#848, which turns on WithRequiredPreResumeExtensions("authz") (#323) and makes the read path match it. #848 is correct as it stands; this is cleanup to do afterwards, not a blocker.
  • File reference behaviour today: nsw-srilanka docs/WORKFLOW_GUIDE.md, "File fields".
Lingua principale
Go
Stelle
6
Fork
8
Merge medio
21h 36m
PR unite (30g)
42

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di OpenNSW/core

Tutte le issue di OpenNSW/core

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.