Skip to content

fix(plugins/gcpaudit): route gcp.policyDelta by IAM proto, not gcs_bucket allowlist#1355

Open
raajheshkannaa wants to merge 1 commit into
falcosecurity:mainfrom
raajheshkannaa:fix/gcpaudit-policydelta-resource-types
Open

fix(plugins/gcpaudit): route gcp.policyDelta by IAM proto, not gcs_bucket allowlist#1355
raajheshkannaa wants to merge 1 commit into
falcosecurity:mainfrom
raajheshkannaa:fix/gcpaudit-policydelta-resource-types

Conversation

@raajheshkannaa

Copy link
Copy Markdown
Contributor

What type of PR is this?

/kind bug

Any specific area of the project related to this PR?

/area plugins

What this PR does / why we need it:

Before this change, `gcp.policyDelta` only returned the correct value for `gcs_bucket` resources. Every other resource type fell through to `protoPayload.metadata.datasetChange.bindingDeltas`, which only exists on BigQuery `dataset.setIamPolicy` events. `project`, `folder`, `organization`, `service_account`, and any other GCP resource that uses the generic IAM SetIamPolicy flow returned an empty field, breaking Falco rules that match on `%gcp.policyDelta`.

The generic IAM proto (`google.iam.v1.PolicyDelta`) is emitted under `protoPayload.serviceData.policyDelta.bindingDeltas` for every service that uses the shared IAM `SetIamPolicy` endpoint. BigQuery is the documented outlier and emits its deltas under `protoPayload.metadata.datasetChange` as part of `BigQueryAuditMetadata`.

Route `bigquery_dataset` explicitly to the `metadata.datasetChange` path and default every other resource type to the `serviceData.policyDelta` path. This matches both the reporter's description ("the else path is really only used by `bigquery_dataset` type") and the published GCP audit log schema, and it stays correct for any future IAM-using resource type without further code changes.

Routing is extracted into a `policyDeltaPath` helper so the policy is unit-testable. The `gcpaudit` package had no test file before this change.

Test:

Added `extract_test.go` with 8 cases asserting the path for `gcs_bucket`, `project`, `folder`, `organization`, `service_account`, an unknown resource type, an empty string (all serviceData), and `bigquery_dataset` (datasetChange).

Which issue(s) this PR fixes:

Fixes #1351

Special notes for your reviewer:

The reporter suggested an additive fix (add the new resource types to the existing `gcs_bucket` allowlist). I inverted the default instead so unenumerated resource types like `gae_app`, `pubsub_topic`, etc. resolve correctly. The behavior change for unenumerated resources moves them from returning empty (current bug) to the generic IAM path (expected per GCP docs).

`gofmt` reports one whitespace nit on `extract.go` line 173 (`req.SetValueOffset(sdk.PluginEventPayloadOffset + uint32(...))`). This is pre-existing on upstream/main at `5855f3e`, not introduced by this PR. Happy to fold a gofmt fix in if you'd prefer.

Does this PR introduce a user-facing change?:

```release-note
fix(plugins/gcpaudit): `gcp.policyDelta` now resolves for project, folder, organization, service_account, and other IAM resource types instead of returning empty.
```

…cket allowlist

Before, gcp.policyDelta sent every resource type except gcs_bucket
through protoPayload.metadata.datasetChange.bindingDeltas. That path
only exists for BigQuery dataset.setIamPolicy. Every other GCP IAM
SetIamPolicy event emits the deltas under
protoPayload.serviceData.policyDelta.bindingDeltas (the generic
google.iam.v1.PolicyDelta proto), so project, folder, organization,
service_account, and any future IAM-using resource type returned an
empty field, breaking rules that match on %gcp.policyDelta.

Route bigquery_dataset to the metadata.datasetChange path and default
every other resource type to the generic serviceData.policyDelta
path. This matches both the GCP audit log schema and the reporter's
description ("the else path is really only used by bigquery_dataset
type"). Unknown future resource types now resolve correctly without
another code change.

Extract the routing into a small policyDeltaPath helper so the policy
is unit-testable; the gcpaudit package previously had no tests.

Closes falcosecurity#1351

Signed-off-by: Raajhesh Kannaa Chidambaram <495042+raajheshkannaa@users.noreply.github.com>
@poiana

poiana commented May 17, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: raajheshkannaa
Once this PR has been reviewed and has the lgtm label, please assign ahmedameenaim for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@poiana
poiana requested review from ahmedameenaim and irozzo-1A May 17, 2026 23:03
Comment on lines +200 to +206
// policyDeltaPath returns the JSON path that contains the bindingDeltas array
// for a SetIamPolicy audit event on the given resource type. The generic IAM
// AuditData proto (google.iam.v1.PolicyDelta) is emitted under
// protoPayload.serviceData.policyDelta for every resource type that uses the
// shared IAM service. BigQuery's dataset.setIamPolicy is the outlier and emits
// its deltas under protoPayload.metadata.datasetChange as part of the
// BigQueryAuditMetadata. See issue #1351.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice improvement over the old logic 🙏 defaulting to serviceData.policyDelta and special-casing BigQuery is the right direction, and I don't see a breaking change here (gcs_bucket and bigquery_dataset keep the same paths).

A couple of caveats about this rationale though:

  • protoPayload.serviceData is officially deprecated by Google (they recommend metadata now), and it's shared by several services, not just BigQuery. So "BigQuery is the outlier" is a bit of an oversimplification - not a blocker, but the comment may not hold as more services migrate to metadata.

  • More importantly, this plugin ingests exported logs via the Pub/Sub sink, and serviceData is known to be stripped on exported entries even when it's populated in Logs Explorer 👉 https://permiso.io/blog/gcp-servicedata-officially-deprecated-actively-dangerous

So for the very resources #1351 is about (project/folder/org/service_account), gcp.policyDelta may still come back empty in practice after this change. Have you confirmed it's populated on a real exported setIamPolicy event? 🤔 If not, we may need metadata as a fallback.


for _, tc := range cases {
t.Run(tc.resource, func(t *testing.T) {
got := policyDeltaPath(tc.resource)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test covers the path selection nicely, but it stops at policyDeltaPath() and never exercises Extract() with a real event, so it won't catch the case where the selected path exists but is empty on the wire (see my comment on extract.go).

May you add a fixture-based test that feeds a captured exported setIamPolicy event (e.g. project-level) through Extract and asserts gcp.policyDelta is non-empty? That would guard the actual #1351 symptom, not just the routing. 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(gcpaudit) gcp.policyDelta: add additional resource types

3 participants