fix(plugins/gcpaudit): route gcp.policyDelta by IAM proto, not gcs_bucket allowlist#1355
Conversation
…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>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: raajheshkannaa The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
| // 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. |
There was a problem hiding this comment.
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.serviceDatais officially deprecated by Google (they recommendmetadatanow), 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 tometadata. -
More importantly, this plugin ingests exported logs via the Pub/Sub sink, and
serviceDatais 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) |
There was a problem hiding this comment.
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. 🙏
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.
```