Skip to content

[Cisco Duo] - Added fix for 400 and 401 errors in telephony v2 data stream - #11640

Merged
ShourieG merged 8 commits into
elastic:mainfrom
ShourieG:cisco_duo/fix_sdh_5334
Nov 8, 2024
Merged

[Cisco Duo] - Added fix for 400 and 401 errors in telephony v2 data stream#11640
ShourieG merged 8 commits into
elastic:mainfrom
ShourieG:cisco_duo/fix_sdh_5334

Conversation

@ShourieG

@ShourieG ShourieG commented Nov 5, 2024

Copy link
Copy Markdown
Contributor

Type of change

  • Bug

Proposed commit message

Cisco API documentation mentions that the Date header should be equal to the current timestamp. In the current CEL program, the previous execution's state.date is being captured and used in pagination and subsequent requests leading to possible 40103 errors. In a related issue users also observed the error 400: mintime must be within the past 180 days.

This PR:

  • Fixes 40103 by creating Date header during each CEL request.
  • Preemptively fixes the 400 error by checking duration between mintime and maxtime doesn't cross
    180d, based on a similar issue & PR.

Note:

  • This PR was derived from a similar PR here
  • The version bump here is from 2.2.0 to 2.2.2 because this will only be merged after the PR mentioned above is
    merged, and that already increments the version to 2.2.1.

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.
  • I have verified that any added dashboard complies with Kibana's Dashboard good practices

Author's Checklist

  • [ ]

How to test this PR locally

Related issues

Screenshots

@ShourieG
ShourieG requested a review from a team as a code owner November 5, 2024 12:10
@ShourieG ShourieG self-assigned this Nov 5, 2024
@ShourieG ShourieG added integration Label used for meta issues tracking each integration Integration:cisco_duo Cisco Duo bugfix Pull request that fixes a bug issue Team:Security-Service Integrations Security Service Integrations team [elastic/security-service-integrations] labels Nov 5, 2024
@elasticmachine

Copy link
Copy Markdown

Pinging @elastic/security-service-integrations (Team:Security-Service Integrations)

@elastic-vault-github-plugin-prod

elastic-vault-github-plugin-prod Bot commented Nov 5, 2024

Copy link
Copy Markdown
Contributor

🚀 Benchmarks report

To see the full report comment with /test benchmark fullreport

Comment on lines +38 to +40
"maxtime": (int(now - duration("2m"))).as(mx,
mx < int(timestamp(int(state.mintime) / 1000) + duration("4320h")) ? string(mx * 1000) : string(int(timestamp(int(state.mintime) / 1000) + duration("4320h") - duration("2m")) * 1000)
)

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.

Suggested change
"maxtime": (int(now - duration("2m"))).as(mx,
mx < int(timestamp(int(state.mintime) / 1000) + duration("4320h")) ? string(mx * 1000) : string(int(timestamp(int(state.mintime) / 1000) + duration("4320h") - duration("2m")) * 1000)
)
"maxtime":int(now - duration("2m"))).as(mx,
mx < int(timestamp(state.mintime / 1000) + duration("4320h")) ?
mx
:
int(timestamp(state.mintime / 1000) + duration("4320h") - duration("2m"))
) * 1000

Why is the 2m subtracted from the false branch?

@kcreddy kcreddy Nov 6, 2024

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.

Since this PR is same as #11621, I am also addressing the comments.
@ShourieG, please make similar change if @efd6 agrees to the changes.

Why is the 2m subtracted from the false branch?

Makes sense. Addressed in edcac5a.

Did not remove the string( conversion due to reasons in #11640 (comment)

@@ -31,114 +31,108 @@ program: |
state

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.

What happens with the calculation below when this path is taken? I don't see a place where this would have mintime, but it's expected below. what am I missing?

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.

In the case of want_more: true i.e., pagination requests, since we are wrapping the state using .with, it should already contain the mintime from its non-pagination request.

"mintime": state.?cursor.last_published.orValue(int(now - duration(state.initial_interval)) * 1000),
"maxtime": int(now - duration("2m")) * 1000,
"date": now.format(time_layout.RFC1123Z),
"mintime": string(state.?cursor.last_published.orValue(int(now - duration(state.initial_interval)) * 1000)),

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.

Suggested change
"mintime": string(state.?cursor.last_published.orValue(int(now - duration(state.initial_interval)) * 1000)),
"mintime": state.?cursor.last_published.orValue(int(now - duration(state.initial_interval)) * 1000),

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.

When string( is removed from state's mintime and maxtime, CEL gives compile time errors: failed to check program: failed compilation: ERROR: <input>:24:41: found no matching overload for 'trim_right' applied to 'int.(string)'\n | \"url_base\": state.url.trim_right(\"/\"),\n | ........................................^\nERROR: <input>:38:35: found no matching overload for '_+_' applied to '(int, string)'\n | state.integration_key + \":\" + (\n | ..................................^\nERROR: <input>:46:36: found no matching overload for 'bytes' applied to '(int)'\n | .hmac(\"sha1\", bytes(state.secret_key))\n | ...................................^ accessing config.

Essentially, I think whatever is the first value getting assigned inside state (in this case mintime) should be of type string. If not, the rest of the values, such as url, integration_key, etc. are also being treated as the datatype of first assigned value (in this case int). Not sure if this is because of adding dyn(in few places, because it wasn't the issue in current version of the code (which usesmintimeandmaxtimeasint`).

Comment thread packages/cisco_duo/data_stream/telephony_v2/agent/stream/cel.yml.hbs Outdated
@ShourieG

ShourieG commented Nov 7, 2024

Copy link
Copy Markdown
Contributor Author

@efd6, I've updated the PR as per the suggestions made. Let me know if @kcreddy's suggestions are ok atm or if they require further changes.

Comment thread packages/cisco_duo/data_stream/telephony_v2/agent/stream/cel.yml.hbs Outdated
@ShourieG

ShourieG commented Nov 7, 2024

Copy link
Copy Markdown
Contributor Author

@chrisberkhout, I've updated the PR with suggestions made here: #11621

@chrisberkhout

Copy link
Copy Markdown
Contributor

@chrisberkhout, I've updated the PR with suggestions made here: #11621

Thanks. Let's wait for that one to merge and then I'll take a final look at this one.

@elasticmachine

Copy link
Copy Markdown

💚 Build Succeeded

History

cc @ShourieG

@ShourieG

ShourieG commented Nov 8, 2024

Copy link
Copy Markdown
Contributor Author

@chrisberkhout, could you take a final look at the PR since @kcreddy's PR has now been merged

@ShourieG
ShourieG merged commit f4550b7 into elastic:main Nov 8, 2024
@ShourieG
ShourieG deleted the cisco_duo/fix_sdh_5334 branch November 8, 2024 18:33
@elastic-vault-github-plugin-prod

Copy link
Copy Markdown
Contributor

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

harnish-crest-data pushed a commit to chavdaharnish/integrations that referenced this pull request Feb 4, 2025
…tream (elastic#11640)

* added fix in telephony_v2 data stream for 400 & 401 errors
harnish-crest-data pushed a commit to chavdaharnish/integrations that referenced this pull request Feb 4, 2025
…stic#12492)

In an earlier version of the CEL code for `activity`[1] and
`telephony_v2`[2], `cursor.last_published` was set to a UNIX timestamp
value. This was changed to use RFC3339 formatted times in later
PRs[3][4] (with the corresponding read-time parsing added in [5]).

Users who didn't create a new policy may have the current parsing logic
fail when it encounters an old UNIX timestamp value in
`cursor.last_published`.

This PR addresses that issue by renaming `cursor.last_published` to 
`cursor.last_response_ts`. That effectively clears the cursor so that
obsolete values will not be seen.

[1]: https://github.com/elastic/integrations/blob/2ea993/packages/cisco_duo/data_stream/activity/agent/stream/cel.yml.hbs#L111-L114
[2]: https://github.com/elastic/integrations/blob/2ea993/packages/cisco_duo/data_stream/telephony_v2/agent/stream/cel.yml.hbs#L112-L115
[3]: elastic#11640
[4]: elastic#11670
[5]: elastic#11772
harnish-crest-data pushed a commit to chavdaharnish/integrations that referenced this pull request Feb 5, 2025
…tream (elastic#11640)

* added fix in telephony_v2 data stream for 400 & 401 errors
harnish-crest-data pushed a commit to chavdaharnish/integrations that referenced this pull request Feb 5, 2025
…stic#12492)

In an earlier version of the CEL code for `activity`[1] and
`telephony_v2`[2], `cursor.last_published` was set to a UNIX timestamp
value. This was changed to use RFC3339 formatted times in later
PRs[3][4] (with the corresponding read-time parsing added in [5]).

Users who didn't create a new policy may have the current parsing logic
fail when it encounters an old UNIX timestamp value in
`cursor.last_published`.

This PR addresses that issue by renaming `cursor.last_published` to 
`cursor.last_response_ts`. That effectively clears the cursor so that
obsolete values will not be seen.

[1]: https://github.com/elastic/integrations/blob/2ea993/packages/cisco_duo/data_stream/activity/agent/stream/cel.yml.hbs#L111-L114
[2]: https://github.com/elastic/integrations/blob/2ea993/packages/cisco_duo/data_stream/telephony_v2/agent/stream/cel.yml.hbs#L112-L115
[3]: elastic#11640
[4]: elastic#11670
[5]: elastic#11772
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Pull request that fixes a bug issue Integration:cisco_duo Cisco Duo integration Label used for meta issues tracking each integration Team:Security-Service Integrations Security Service Integrations team [elastic/security-service-integrations]

6 participants