Skip to content

feat(core): resolve and flat-merge PORC context via backend.GetContext - #72

Merged
ghaskins merged 1 commit into
manetu:mainfrom
muralisrini:feature/context-resolution
Aug 18, 2026
Merged

feat(core): resolve and flat-merge PORC context via backend.GetContext#72
ghaskins merged 1 commit into
manetu:mainfrom
muralisrini:feature/context-resolution

Conversation

@muralisrini

Copy link
Copy Markdown
Contributor

Adds the context (C) enrichment stage to Authorize, mirroring resource (R) resolution. Backends resolve the request context for the ordered delegation-chain subjects and the engine flat-merges the result into input[context].

  • backend.Service: new GetContext(ctx, subs []string) (map, *PolicyError). Local + mock backends return {} (no external resolver); the remote backend (go-lib) will call the customer context resolver.
  • Authorize: flattenSubs builds the ordered subs list from the principal -- current actor first (principal.act.sub), down the nested act chain, subject (principal.sub) last -- then resolveContext calls GetContext and flat-merges (resolved wins) into input[context]. A failed/empty resolve attaches nothing.
  • new PORC keys: contextKey ("context", named to avoid shadowing the context package) and Act ("act").

Standalone/local path works now (backend returns {}); the platform path lights up once the remote backend implements GetContext (go-lib, issue C).

Tests: flattenSubs (subject-only, single/nested act chain ordering, empty, blank skipping) and flatMergeContext (merge, collision precedence, nil-tolerance, no-mutation). go build ./... + changed-package tests green.

NOTE: the principal.act shape (nested {sub, act}, current-actor outermost) has no prior use in this repo -- the engine only read sub before. Encoded explicitly in flattenSubs + its tests; confirm it matches how go-lib/sidecar builds the principal.

@codecov

codecov Bot commented Aug 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Adds the context (C) enrichment stage to Authorize, mirroring resource (R)
resolution. Backends resolve the request context for the ordered delegation-chain
subjects and the engine flat-merges the result into input[context].

- backend.Service: new GetContext(ctx, subs []string) (map, *PolicyError).
  Local + mock backends return {} (no external resolver); the remote backend
  (go-lib) will call the customer context resolver.
- Authorize: flattenSubs builds the ordered subs list from the principal --
  current actor first (principal.act.sub), down the nested act chain, subject
  (principal.sub) last -- then resolveContext calls GetContext and flat-merges
  (resolved wins) into input[context]. A failed/empty resolve attaches nothing.
- new PORC keys: contextKey ("context", named to avoid shadowing the context
  package) and Act ("act").

Standalone/local path works now (backend returns {}); the platform path lights
up once the remote backend implements GetContext (go-lib, issue C).

Tests: flattenSubs (subject-only, single/nested act chain ordering, empty, blank
skipping) and flatMergeContext (merge, collision precedence, nil-tolerance,
no-mutation). go build ./... + changed-package tests green.

NOTE: the principal.act shape (nested {sub, act}, current-actor outermost) has no
prior use in this repo -- the engine only read `sub` before. Encoded explicitly in
flattenSubs + its tests; confirm it matches how go-lib/sidecar builds the principal.

Signed-off-by: smuralidharan <smuralidharan@manetu.com>
@muralisrini
muralisrini force-pushed the feature/context-resolution branch from 80d67a6 to e851834 Compare August 8, 2026 22:54
Comment thread internal/core/policyengine.go
@ghaskins
ghaskins merged commit 14a5499 into manetu:main Aug 18, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants