Skip to content

[GCP] Fix check on gcp.audit.authorization_info[].granted - #7308

Merged
zmoog merged 3 commits into
elastic:mainfrom
zmoog:zmoog/gcp-audit-logs
Aug 9, 2023
Merged

[GCP] Fix check on gcp.audit.authorization_info[].granted#7308
zmoog merged 3 commits into
elastic:mainfrom
zmoog:zmoog/gcp-audit-logs

Conversation

@zmoog

@zmoog zmoog commented Aug 8, 2023

Copy link
Copy Markdown
Contributor

What does this PR do?

When gcp.audit.authorization_info[] objects do not contain the granted attribute, the if statement fails.

This PR updates the expression in the if to check for null values and uses the granted == true
syntax to avoid another error when there the == operator is not used.

The following error occurs with ... ctx?.gcp?.audit?.authorization_info[0]?.granted and granted is null.

Cannot invoke "Object.getClass()" because "value" is null

Checklist

  • I have reviewed tips for building integrations and this pull request is aligned with them.
  • I have verified that all data streams collect metrics or logs.
  • I have added an entry to my package's changelog.yml file.
  • I have verified that Kibana version constraints are current according to guidelines.

How to test this PR locally

# walk into the GCP integration 
cd packages/gcp 

# start a stack version 8.6.2
elastic-package build && elastic-package stack up -d -v --version 8.6.2

# set up the environment variables 
eval $(elastic-package stack shellinit)

And then run the pipeline tests using the new data_stream/audit/_dev/test/pipeline/test-sdh-3695.log test case:

$ elastic-package test pipeline -v
2023/08/08 17:10:45 DEBUG Enable verbose logging
Run pipeline tests for the package
--- Test results for package: gcp - START ---
╭─────────┬────────────────────┬───────────┬────────────────────────┬────────┬──────────────╮
│ PACKAGE │ DATA STREAM        │ TEST TYPE │ TEST NAME              │ RESULT │ TIME ELAPSED │
├─────────┼────────────────────┼───────────┼────────────────────────┼────────┼──────────────┤
│ gcp     │ audit              │ pipeline  │ test-audit.log         │ PASS   │    12.5545ms │
│ gcp     │ audit              │ pipeline  │ test-sdh-3695.log      │ PASS   │   3.589584ms │
│ gcp     │ compute            │ pipeline  │ test-gcp-compute.json  │ PASS   │      2.933ms │
│ gcp     │ dns                │ pipeline  │ test-dns.log           │ PASS   │     11.807ms │
│ gcp     │ firewall           │ pipeline  │ test-firewall.log      │ PASS   │   9.665667ms │
│ gcp     │ loadbalancing_logs │ pipeline  │ test-load-balancer.log │ PASS   │   2.979667ms │
│ gcp     │ vpcflow            │ pipeline  │ test-vpcflow.log       │ PASS   │  65.097875ms │
╰─────────┴────────────────────┴───────────┴────────────────────────┴────────┴──────────────╯
--- Test results for package: gcp - END   ---
Done

Related issues

@zmoog zmoog self-assigned this Aug 8, 2023
@zmoog zmoog added bug Something isn't working, use only for issues Integration:gcp Google Cloud Platform labels Aug 8, 2023
zmoog added 3 commits August 8, 2023 17:19
When `gcp.audit.authorization_info[]` objects do not contain the
`granted` attribute, the `if` statement fails.

The updated `if` checks for null values and uses the `granted == true`
syntax to avoid another error when there the `==` operator is not
used:

```
Cannot invoke "Object.getClass()" because "value" is null
```
@elasticmachine

elasticmachine commented Aug 8, 2023

Copy link
Copy Markdown

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2023-08-08T15:23:03.590+0000

  • Duration: 19 min 9 sec

Test stats 🧪

Test Results
Failed 0
Passed 65
Skipped 0
Total 65

🤖 GitHub comments

Expand to view the GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

@elasticmachine

elasticmachine commented Aug 8, 2023

Copy link
Copy Markdown

🌐 Coverage report

Name Metrics % (covered/total) Diff
Packages 100.0% (6/6) 💚
Files 100.0% (6/6) 💚
Classes 100.0% (6/6) 💚
Methods 87.826% (101/115) 👎 -12.174
Lines 96.0% (1464/1525) 👎 -0.621
Conditionals 100.0% (0/0) 💚
@zmoog zmoog changed the title Fix check on gcp.audit.authorization_info[].granted Aug 8, 2023
@zmoog
zmoog marked this pull request as ready for review August 8, 2023 15:22
@zmoog
zmoog requested review from a team as code owners August 8, 2023 15:22
@zmoog
zmoog force-pushed the zmoog/gcp-audit-logs branch from 6b11263 to ed458c3 Compare August 8, 2023 15:22

@kcreddy kcreddy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@zmoog
zmoog merged commit 4a2c9e8 into elastic:main Aug 9, 2023
@zmoog
zmoog deleted the zmoog/gcp-audit-logs branch August 9, 2023 20:05
@elasticmachine

Copy link
Copy Markdown

Package gcp - 2.25.1 containing this change is available at https://epr.elastic.co/search?package=gcp

orestisfl pushed a commit to orestisfl/integrations that referenced this pull request May 15, 2026
* Fix check on gcp.audit.authorization_info[].granted

When `gcp.audit.authorization_info[]` objects do not contain the
`granted` attribute, the `if` statement fails.

The updated `if` checks for null values and uses the `granted == true`
syntax to avoid another error when there the `==` operator is not
used:

```
Cannot invoke "Object.getClass()" because "value" is null
```

* Use `override` to avoid using a script expression

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

Labels

bug Something isn't working, use only for issues Integration:gcp Google Cloud Platform

3 participants