Skip to content

Add explicit installation scope for dashboard inspection reads - #680

Draft
Christdej wants to merge 3 commits into
mainfrom
christdej-dashboard-application-permissions
Draft

Christdej wants to merge 3 commits into
mainfrom
christdej-dashboard-application-permissions

Conversation

@Christdej

@Christdej Christdej commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Ready for review checklist:

  • A self-review has been performed
  • All commits run individually
  • Temporary changes have been removed, like logging, TODO, etc.
  • The PR has been tested locally
  • A test has been written
    • This change doesn't need a new test
  • Relevant issues are linked
  • Remaining work is documented in issues
    • There is no remaining work from this PR that requires new issues
  • The changes do not introduce dead code as unused imports, functions etc.

Summary

Reuse existing installation-scoped Role.Observer.<CODE> application permissions, including existing analysis feedback submission/update. No new role or authorization policy. Add explicit request-level narrowing so Flotilla can safely proxy inspection data for a device whose installations are a subset of its backend application's grants.

This supersedes the earlier tests/docs-only scope: a backend token with Observer.KAA+NLS plus the existing InstallationCode=KAA substring filter still authorizes a nested analysis shared by KAA and NLS. Merely checking the returned root installation or partially populated nested navigation collections cannot safely establish device-scoped authorization.

Companions: equinor/flotilla#3197 and equinor/robotics-infrastructure#1501.

API contract

Optional repeated InstallationScope query parameters are supported ONLY on:

  • GET /api/inspection-record
  • GET /api/inspection-record/id/{id}
  • GET /api/inspection-record/inspection-id/{inspectionId}

Example: ?InstallationScope=KAA&InstallationScope=NLS. Each code must contain exactly three ASCII letters or digits; codes normalize to uppercase, deduplicate and sort. Empty/malformed/comma-separated values return 400. Any requested installation outside the caller's Observer grants returns 403 rather than silently intersecting. Admin may request any valid installation, but its global-access fast paths cannot bypass explicit narrowing.

The same scope constrains outer records and every linked inspection of each nested analysis, before AnalysisTypes filtering, count/pagination, DTO construction or SAS generation. Omitted scope preserves current callers; existing InstallationCode substring filtering can only further narrow results. Scoped detail reads retain existing missing-record behavior: Observer 403, Admin 404.

Successful explicitly scoped responses, including empty lists, emit X-Inspection-Installation-Scope with the sorted unique uppercase comma-separated requested scope. Unscoped/rejected requests do not receive acknowledgement. Flotilla must derive query values from authenticated device grants, reject missing/mismatched acknowledgement (including older SARA deployments silently ignoring the query), and verify returned root installation codes. The scope is a narrowing mechanism, not a new identity assertion or grant.

All other endpoint policies remain unchanged. Observer feedback stays allowed within its authorized installations; this change adds no feedback scope contract or proxy. Inspection creation/deletion, adding analyses and feedback deletion remain Admin-only. The earlier proposed ReadOnly role was removed in a normal follow-up commit; history was not rewritten.

Validation

  • dotnet test --project api.Tests/api.test.csproj --no-restore --filter 'FullyQualifiedName~InspectionApplicationAccessTests|FullyQualifiedName~AnalysisRunControllerTests|FullyQualifiedName~FeedbackControllerTests|FullyQualifiedName~InspectionMeasurementControllerTests' --verbosity quiet --no-progress — passed, 27 tests.
  • dotnet test --project api.Tests/api.test.csproj --no-build --filter 'FullyQualifiedName~InspectionRecordServiceTests|FullyQualifiedName~AuthenticationConfigurationsTests|FullyQualifiedName~ProtectedEndpointsTests|FullyQualifiedName~BlobStorageServiceTests' --verbosity quiet --no-progress — passed, 48 tests.
  • dotnet csharpier check api/Controllers/InspectionRecordController.cs api/Services/InspectionRecordService.cs api/Services/InstallationAccess.cs api.Tests/Controllers/InspectionApplicationAccessTests.cs api.Tests/Mocks/BlobStorageServiceMock.cs — passed.
  • git diff --check — passed before commit.

Tests use locally signed app-only JWTs with roles and no delegated scope through the real JWT bearer handler/claim mapping, replacing only issuer/signing trust. They cover existing Observer reads/feedback, Admin-only mutation denial, and explicit narrowing for both a multi-installation Observer and Admin. Shared-analysis tests verify counts exclude records whose only matching analysis crosses the requested scope, all three endpoints omit mixed results/runs/SAS, and the blob fake records no SAS generation for excluded analyses. Additional cases cover acknowledgement, omitted scope, duplicate/lowercase/multiple codes, unauthorized/malformed values, conflicting root filters and detail denial.

External prerequisites and review context

Ensure existing Role.Observer.<CODE> app roles include Application in allowedMemberTypes on each actual SARA resource registration, then assign only approved installations to the Flotilla backend service principal. Confirm identifier URI, role IDs, audience and deployment-specific assignments externally. No new ReadOnly roles are needed, no resource IDs are invented, and no grants are applied here. Acquire an application token for the confirmed resource's /.default, not delegated user_impersonation. Do not grant Role.Admin for dashboard inspection reads or analysis feedback.

Flotilla verifies its opaque device credentials and enforces device grants. Existing inspection image SAS URLs grant blob reads for one hour, independently of device revocation. Live tenant grants and deployed end-to-end flows are not verified by these local tests.

No existing issue was supplied for this milestone. External provisioning and end-to-end verification remain outstanding and have not been filed as issues, so the corresponding checklist items remain unchecked. Keep this PR draft for team discussion; no deployment, permission grant or merge is part of this change.

@Christdej Christdej changed the title Add installation-scoped dashboard inspection read permissions Verify Observer application access for dashboard integration Dec 1, 2026
@Christdej Christdej changed the title Verify Observer application access for dashboard integration Add explicit installation scope for dashboard inspection reads Dec 1, 2026

This branch has not been deployed

No deployments
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.

1 participant