Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Stack Connectors][Microsoft Defender] Add caching of OAuth access token to connector #206975

Conversation

paul-tavares
Copy link
Contributor

@paul-tavares paul-tavares commented Jan 16, 2025

Summary

  • Adds caching of the OAuth token needed to call Microsoft Defender's API to the connector along with auto-regenerate when it expires

Checklist

@paul-tavares paul-tavares added release_note:skip Skip the PR/issue when compiling release notes Team:Defend Workflows “EDR Workflows” sub-team of Security Solution backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) v8.18.0 labels Jan 16, 2025
@paul-tavares paul-tavares self-assigned this Jan 16, 2025
@paul-tavares paul-tavares marked this pull request as ready for review January 16, 2025 16:33
@paul-tavares paul-tavares requested a review from a team as a code owner January 16, 2025 16:33
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-defend-workflows (Team:Defend Workflows)

@paul-tavares paul-tavares requested review from tomsonpl and removed request for pzl January 16, 2025 16:34
@elasticmachine
Copy link
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] Jest Tests #7 / Case Owner Selection renders all options
  • [job] [logs] Jest Tests #7 / FileNameLink renders clickable name if file is image

Metrics [docs]

✅ unchanged

History

cc @paul-tavares

@paul-tavares paul-tavares merged commit 1e688f2 into elastic:main Jan 21, 2025
8 checks passed
@paul-tavares paul-tavares deleted the task/olm-ms-connector-cache-access-token branch January 21, 2025 19:59
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.x

https://github.com/elastic/kibana/actions/runs/12894824912

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jan 21, 2025
…ken to connector (elastic#206975)

## Summary

- Adds caching of the OAuth token needed to call Microsoft Defender's
API to the connector along with auto-regenerate when it expires

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

(cherry picked from commit 1e688f2)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.x

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Jan 21, 2025
…ess token to connector (#206975) (#207435)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Stack Connectors][Microsoft Defender] Add caching of OAuth access
token to connector
(#206975)](#206975)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Paul
Tavares","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-01-21T19:59:14Z","message":"[Stack
Connectors][Microsoft Defender] Add caching of OAuth access token to
connector (#206975)\n\n## Summary\r\n\r\n- Adds caching of the OAuth
token needed to call Microsoft Defender's\r\nAPI to the connector along
with auto-regenerate when it expires\r\n\r\n\r\n### Checklist\r\n\r\n-
[x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"1e688f2cbea273809dfda3f88ee52b70593cce6b","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:Defend
Workflows","backport:prev-minor","v8.18.0"],"title":"[Stack
Connectors][Microsoft Defender] Add caching of OAuth access token to
connector","number":206975,"url":"https://github.com/elastic/kibana/pull/206975","mergeCommit":{"message":"[Stack
Connectors][Microsoft Defender] Add caching of OAuth access token to
connector (#206975)\n\n## Summary\r\n\r\n- Adds caching of the OAuth
token needed to call Microsoft Defender's\r\nAPI to the connector along
with auto-regenerate when it expires\r\n\r\n\r\n### Checklist\r\n\r\n-
[x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"1e688f2cbea273809dfda3f88ee52b70593cce6b"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/206975","number":206975,"mergeCommit":{"message":"[Stack
Connectors][Microsoft Defender] Add caching of OAuth access token to
connector (#206975)\n\n## Summary\r\n\r\n- Adds caching of the OAuth
token needed to call Microsoft Defender's\r\nAPI to the connector along
with auto-regenerate when it expires\r\n\r\n\r\n### Checklist\r\n\r\n-
[x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"1e688f2cbea273809dfda3f88ee52b70593cce6b"}},{"branch":"8.x","label":"v8.18.0","branchLabelMappingKey":"^v8.18.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Paul Tavares <[email protected]>
Copy link
Contributor

@tomsonpl tomsonpl left a comment

Choose a reason for hiding this comment

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

Looks good, just wondering about that token service. What would happen if we generate a token and cache it, and then change the credentials in the connector? Would it still have the prev token, or regenerate?

I think I am facing this issue with CrowdStrike tokens, so wondering how we could approach it, but my assumption is that you're using a service exposed by response-ops so this should probably be covered, right?

connector: { id: connectorId },
logger,
} = this.params;
const connectorTokenClient = this.params.services.connectorTokenClient;
Copy link
Contributor

Choose a reason for hiding this comment

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

is this services.connectorTokenClient a functionality exposed by response ops team, or you created that in a separate PR before?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is exposed by the ResponseOps framework. Its purpose is to only store tokens so they can be reused across instances of kibana.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you, I'll try to rebuild the token cache in CS to use this one 👍

@paul-tavares
Copy link
Contributor Author

Thanks for the review @tomsonpl .

Re:

What would happen if we generate a token and cache it, and then change the credentials in the connector? Would it still have the prev token, or regenerate?

Thats a good point and I'll follow up with another PR to introduce some logic to mitigate that. The previously generated token would still be used until it expires - then a new one would be generated.

Re:

but my assumption is that you're using a service exposed by response-ops so this should probably be covered, right?

No, that is not correct. The service from ResponseOps provides only a mechanism for storing the token - I do think they have some logic that checks the expiration date to see if it is expired based on the expiration date we provide when we store the token, but thats it.

viduni94 pushed a commit to viduni94/kibana that referenced this pull request Jan 23, 2025
…ken to connector (elastic#206975)

## Summary

- Adds caching of the OAuth token needed to call Microsoft Defender's
API to the connector along with auto-regenerate when it expires


### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) release_note:skip Skip the PR/issue when compiling release notes Team:Defend Workflows “EDR Workflows” sub-team of Security Solution v8.18.0 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants