Skip to content

feat(secure): surface Falco static-analyzer warnings as Terraform Diagnostics#733

Draft
ivanlysiuk-sysdig wants to merge 3 commits into
masterfrom
ivanlysiuk/SSPROD-68089-falco-perf-warnings
Draft

feat(secure): surface Falco static-analyzer warnings as Terraform Diagnostics#733
ivanlysiuk-sysdig wants to merge 3 commits into
masterfrom
ivanlysiuk/SSPROD-68089-falco-perf-warnings

Conversation

@ivanlysiuk-sysdig
Copy link
Copy Markdown
Contributor

@ivanlysiuk-sysdig ivanlysiuk-sysdig commented May 21, 2026

Summary

Adds Terraform Diagnostics for Falco static-analyzer warnings (today LOAD_NO_EVTTYPE) emitted by the Sysdig backend on sysdig_secure_rule_falco create/update. The backend has been shipping these under warnings[] on the v2 rule response for a few weeks — the provider's internal SDK just wasn't deserializing the field.

This wires it end-to-end so TF users see warnings inline in terraform apply output.

Opening as draft until the deprecation cleanup in #734 lands.

What it looks like

When applying a rule whose condition causes the backend's Falco validator to emit a perf warning:

│ Warning: Falco performance warning (LOAD_NO_EVTTYPE) on rule "my_test_rule"
│
│   with sysdig_secure_rule_falco.my_test_rule,
│   on main.tf line 12, in resource "sysdig_secure_rule_falco" "my_test_rule":
│   12: resource "sysdig_secure_rule_falco" "my_test_rule" {
│
│ Rule matches too many evt.type values. This has a significant
│ performance penalty.
│
│ Enabled in policies: my-runtime-policy
│ Agent versions: linux-14.5.2

The apply still succeeds — these are advisory, not gates. (The backend supports an opt-in performanceWarningPackGate=true query parameter for "save anyway" semantics; not wired in this PR — leaving it as a follow-up unless there's interest. The TF UX for a gate isn't obvious.)

Changes

File Change
sysdig/internal/client/v2/model.go Add FalcoWarning type and Warnings []FalcoWarning field on Rule. JSON shape mirrors the backend response.
sysdig/falco_warnings.go New shared helper falcoWarningsToDiagnostics(warnings) mapping each warning to a diag.Warning with the Falco code in Summary and message + enabled-in-policies + agent-versions in Detail.
sysdig/resource_sysdig_secure_rule_falco.go Capture rule.Warnings on Create and updatedRule.Warnings on Update; surface via the helper.

Net: +55, -9.

Backwards compatibility

Zero new required fields. Rules whose backend response carries no warnings emit zero diagnostics (helper returns nil on empty input). Existing acceptance tests are unaffected since they don't inspect Diagnostics beyond the error count.

Out of scope (deliberately)

  • sysdig_secure_rule_macro and sysdig_secure_rule_list: macros + lists were de-scoped from the Falco perf warnings v1 effort on the backend side. The backend doesn't surface warnings on those endpoints, so wiring them on the TF side would be no-ops.
  • Performance-warning gate (performanceWarningPackGate=true): mentioned above; defer.
  • V4 endpoints: long-term follow-up.
  • Acceptance test that asserts the new Diagnostics: needs a backend with a deliberately-broken rule; better landed alongside the e2e validation since the warning shape depends on the validator's emission timing.

End-to-end validation

Ran the matrix on a fresh Sysdig stack deployed with a backend image that includes the full warnings stack.

Matrix

Resource Condition Expected Result
sysdig_secure_rule_falco.positive_no_evttype proc.name=ssprod_68089_tf_test (no evt.type) LOAD_NO_EVTTYPE Diagnostic on Create 20 LOAD_NO_EVTTYPE Warnings attached, incl. one named ssprod_68089_tf_no_evttype
sysdig_secure_rule_falco.negative_clean spawned_process and proc.name=… (evt.type filtered via macro) No new Diagnostics from this rule Pass — apply clean for this resource
sysdig_secure_macro.negative_macro trivial macro No Diagnostics (backend descoped) Pass — apply clean
sysdig_secure_list.negative_list trivial list No Diagnostics (backend descoped) Pass — apply clean

Apply complete! Resources: 4 added, 0 changed, 0 destroyed. — apply succeeded; warnings are advisory.

Sample Diagnostic

│ Warning: Falco performance warning (LOAD_NO_EVTTYPE) on rule "ssprod_68089_tf_no_evttype"
│
│   with sysdig_secure_rule_falco.positive_no_evttype,
│   on main.tf line 33, in resource "sysdig_secure_rule_falco" "positive_no_evttype":
│   33: resource "sysdig_secure_rule_falco" "positive_no_evttype" {
│
│ Rule matches too many evt.type values. This has a significant performance
│ penalty.
│ Agent versions: linux-14.6.0

(Enabled in policies: is omitted here because the test rules aren't referenced by any policy; the enrichment populates that line whenever the rule is part of an active policy — exercised via direct backend POST against the same stack.)

Notes

  • All Warnings attach to a single resource in the Diagnostics summary block — Terraform's plugin-sdk de-duplicates identical Diagnostic content emitted from multiple resource Create calls in the same apply. The validator returns the same pack-wide warning set on each rule write, so dedup attributes them to the last resource to finish creating in this graph.
  • sysdig_secure_rule_{container,filesystem,network,process,syscall} weren't exercised here — they're broken end-to-end against current backends, addressed separately in fix(secure): deprecate dead rule resources (container/filesystem/network/process/syscall) #734. This PR will rebase on top of that.
  • sysdig_secure_rule_stateful is intentionally not wired (stateful rules don't go through the Falco static-analyzer path; backend doesn't emit warnings for them).

Test plan

  • go build ./... — clean
  • go vet ./sysdig/... — clean
  • End-to-end on a current Sysdig backend (see matrix above)
  • Negative rule (spawned_process filter) → no Diagnostics on that resource
  • Update path on the positive rule → same Diagnostic shape echoed back (via direct backend curl)

🤖 Generated with Claude Code

ivanlysiuk-sysdig and others added 3 commits May 20, 2026 16:59
…gnostics

When the Sysdig backend processes a create/update on a Falco rule, its
validator may emit static-analyzer warnings (LOAD_NO_EVTTYPE today, per
ADR-0127) signalling rules that match too many syscall event types and
risk a measurable agent performance penalty. The backend ships these on
the v2 rule create/update response under `warnings[]`, but the provider's
internal SDK didn't deserialize them — so TF users had no way to see
them via `terraform apply`.

This change wires the warnings end-to-end:

  - sysdig/internal/client/v2/model.go: add `FalcoWarning` type and a
    `Warnings []FalcoWarning` field on `Rule`. JSON shape mirrors
    secure-backend's `model.FalcoWarning`.

  - sysdig/resource_sysdig_secure_rule_falco.go: capture `rule.Warnings`
    on Create and `updatedRule.Warnings` on Update; convert each into a
    `diag.Warning` Diagnostic via a small `falcoWarningsToDiagnostics`
    helper. Each warning becomes a single Diagnostic with the Falco
    code in Summary and the validator message + EnabledInPolicies +
    AgentVersions in Detail.

Surface in `terraform apply` output:

    │ Warning: Falco performance warning (LOAD_NO_EVTTYPE) on rule "<rule-name>"
    │
    │   with sysdig_secure_rule_falco.my_rule,
    │   on main.tf line 12, in resource "sysdig_secure_rule_falco" "my_rule":
    │   12: resource "sysdig_secure_rule_falco" "my_rule" {
    │
    │ Rule matches too many evt.type values. This has a significant
    │ performance penalty.
    │
    │ Enabled in policies: my-runtime-policy
    │ Agent versions: linux-14.5.2

Backwards compatible: zero new required fields; rules without warnings
emit zero diagnostics (the helper returns nil on empty input). Existing
acceptance tests are unaffected since they don't inspect Diagnostics
beyond the error count.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…ed helper

The first commit wired only sysdig_secure_rule_falco. All seven Sysdig rule
resources (rule_falco, rule_container, rule_filesystem, rule_network,
rule_process, rule_syscall, rule_stateful) translate to Falco rules in the
backend under the hood, so any of them can emit LOAD_NO_EVTTYPE if the
generated condition matches too many evt.type values. This extends the
Diagnostics surfacing to the other six.

Changes:
  - sysdig/falco_warnings.go: new file. Extracts falcoWarningsToDiagnostics
    out of resource_sysdig_secure_rule_falco.go into a package-scoped helper.
    The function lives once now; all rule resources call it.
  - resource_sysdig_secure_rule_falco.go: drops the local copy; relies on the
    shared helper.
  - resource_sysdig_secure_rule_{container,filesystem,network,process,syscall}.go:
    Create captures rule.Warnings, returns Diagnostics. Update captures the
    returned rule (was discarded with `_, err =`), returns Diagnostics.
  - resource_sysdig_secure_rule_stateful.go: same shape; uses the stateful
    rule methods (CreateStatefulRule/UpdateStatefulRule) but returns the
    same Rule type carrying Warnings.

Macro + list resources are NOT wired — the backend doesn't surface warnings
on those endpoints (SSPROD-68085 / SSPROD-68086 resolved Won't Do during the
V2/V4 migration). They'll behave as before: zero diagnostics on apply.

Backwards compatible: rules whose backend response carries no warnings emit
zero diagnostics (helper short-circuits on empty input).

Build/vet: clean on ./... — same as the first commit.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…on stateful

Per @ivanlysiuk: stateful-detection rules don't go through the Falco
static-analyzer path in the backend, so the validator never emits
LOAD_NO_EVTTYPE (or any other Falco warning code) on stateful rule
mutations. The previous commit's wiring of sysdig_secure_rule_stateful
was a no-op at best and misleading documentation at worst.

Revert: sysdig_secure_rule_stateful Create returns to `return nil`; no
Update wiring was actually applied (the sed pattern didn't match due to
different surrounding whitespace).

Also update the docstring in falco_warnings.go to make the exclusion
explicit alongside the macro/list exclusion.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@ivanlysiuk-sysdig ivanlysiuk-sysdig changed the title SSPROD-68089: surface Falco static-analyzer warnings as Terraform Diagnostics feat(secure): surface Falco static-analyzer warnings as Terraform Diagnostics May 21, 2026
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