BCH-1339: Responsibility-scoped filters, SSP resolution, and posture (Phase 3)#448
Conversation
…(Phase 3) Let a downstream customer-responsibility be a first-class compliance target with its own filter -> evidence -> posture, without minting a synthetic catalog control: - New filter_responsibilities join table (filter_id, responsibility_uuid, ssp_id), a sibling of filter_controls. - resolveSSPsViaFilters gains a second resolution path: matched filter -> filter_responsibilities -> ssp_leverage_links -> downstream SSP. - ResponsibilityPosture computes per-responsibility posture (satisfied / not-satisfied / unknown) from matched evidence, using the same status-count logic as control-keyed posture, and feeds it into the Inherited Capability projection (LeveragedControls). Also fixes a latent schema issue the new join exposed: ControlImplementationResponsibility.ProvidedUuid had no explicit uuid column type, causing a real uuid = text failure against Postgres.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAdds a ChangesResponsibility posture feature
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant SSPLeverageHandler
participant ResponsibilityPosture
participant DB as GormDB
Client->>SSPLeverageHandler: GET /leveraged-controls
SSPLeverageHandler->>SSPLeverageHandler: collect responsibility UUIDs across links
SSPLeverageHandler->>ResponsibilityPosture: ResponsibilityPosture(db, downstreamSSPID, uuids)
ResponsibilityPosture->>DB: query FilterResponsibility links
DB-->>ResponsibilityPosture: link rows
ResponsibilityPosture->>DB: getStatusCountsForFilters(filters)
DB-->>ResponsibilityPosture: status counts
ResponsibilityPosture-->>SSPLeverageHandler: map[UUID]posture
SSPLeverageHandler->>Client: response with responsibilityPosture per link
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/service/relational/filters.go`:
- Around line 30-32: The composite primary key on the filter model does not
match the lookup pattern used by ResponsibilityPosture. Keep the existing
primary key in place, but add a dedicated composite index on the fields used by
the query in profile_compliance.go so the WHERE ssp_id = ? AND
responsibility_uuid IN ? lookup can use an index; update the struct in
filters.go on the type that defines FilterID, ResponsibilityUUID, and SSPID to
include the new index annotation.
- Around line 29-35: The FilterResponsibility model currently has SSPID only as
a primary key field without a foreign-key constraint, so add the missing cascade
relationship for the ssp_id association. Update the schema/migration logic in
migrator.go to mirror the existing filters.ssp_id constraint and ensure
FilterResponsibility.SSPID is constrained with OnDelete:CASCADE, using the
FilterResponsibility struct and its SSPID field as the anchor point.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 44063fa2-55e7-4465-9c40-b82e31889965
📒 Files selected for processing (15)
docs/docs.godocs/swagger.jsondocs/swagger.yamlinternal/api/handler/oscal/profile_compliance.gointernal/api/handler/oscal/profile_compliance_unit_test.gointernal/api/handler/oscal/ssp_leverage.gointernal/api/handler/oscal/ssp_leverage_test.gointernal/api/handler/oscal/ssp_leverage_unit_test.gointernal/service/migrator.gointernal/service/relational/filters.gointernal/service/relational/system_security_plan.gointernal/service/worker/risk_evidence_worker.gointernal/service/worker/risk_evidence_worker_responsibility_integration_test.gointernal/service/worker/risk_evidence_worker_test.gointernal/tests/migrate.go
…ing and FK cascade Adds a composite index leading with ssp_id so ResponsibilityPosture's lookup can use it (the primary key leads with filter_id instead), and adds the missing ssp_id -> system_security_plans FK with ON DELETE CASCADE, mirroring the existing filters.ssp_id constraint.
Summary
Phase 3 of Cross-SSP Control Export/Import: lets a downstream customer-responsibility be a first-class compliance target with its own filter → evidence → posture, without minting a synthetic catalog control. Depends on Phase 2 (#447, merged).
filter_responsibilitiesjoin table (filter_id,responsibility_uuid,ssp_id) — a sibling offilter_controls, not an overload of it.resolveSSPsViaFilters(risk evidence worker) gains a second resolution path: matched filter →filter_responsibilities→ssp_leverage_links→ downstream SSP.ResponsibilityPosturefunction computes per-responsibility posture (satisfied / not-satisfied / unknown) from matched evidence, using the same status-count logic as control-keyed posture, and feeds it into the Inherited Capability projection (LeveragedControls'sresponsibilityPosturefield).ControlImplementationResponsibility.ProvidedUuidhad no explicituuidcolumn type, causing a realuuid = textfailure against Postgres. Fixed with the same tag + idempotentALTER COLUMNpattern already used forfilter_controls.control_catalog_id.Test plan
risk_evidence_worker_test.go, posture-default coverage inprofile_compliance_unit_test.go, wiring coverage inssp_leverage_unit_test.go.TestRiskEvidenceWorkerResponsibilityIntegrationSuite(SSP resolution) andTestResponsibilityFilterFlipsPosture(posture flip against live evidence).filter_controls/ComplianceProgresstests pass unmodified.make reviewable(swag + lint + full integration suite) passes clean.Out of scope
Risk generation (Phase 4).
Summary by CodeRabbit
satisfied,not-satisfied, orunknown.