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

Allow users authenticated with an API keys to manage alerting rules #152140

Closed
mikecote opened this issue Feb 24, 2023 · 6 comments · Fixed by #154189
Closed

Allow users authenticated with an API keys to manage alerting rules #152140

mikecote opened this issue Feb 24, 2023 · 6 comments · Fixed by #154189
Assignees
Labels
Feature:Alerting/RulesFramework Issues related to the Alerting Rules Framework Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams)

Comments

@mikecote
Copy link
Contributor

mikecote commented Feb 24, 2023

As a user, I would like to authenticate with an API key and be able to interact with the alerting APIs (ex: create, update, delete rules).

It is currently not possible because the system attempts to create an API key from an existing API key (elastic/elasticsearch#52244 and elastic/elasticsearch#59304). Instead, we should change our code to re-use the API key in context (from the authentication) and avoid having the system invalidate them when no longer in use.

To make this happen, we will need the following:

Adding blocked label until #152116 is complete.

@mikecote mikecote added blocked Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) Feature:Alerting/RulesFramework Issues related to the Alerting Rules Framework labels Feb 24, 2023
@elasticmachine
Copy link
Contributor

Pinging @elastic/response-ops (Team:ResponseOps)

@mikecote
Copy link
Contributor Author

cc @legrego @kobelb

@ersin-erdal ersin-erdal moved this from Awaiting Triage to Todo in AppEx: ResponseOps - Execution & Connectors Mar 2, 2023
@mikecote mikecote moved this from Todo to Blocked / On hold in AppEx: ResponseOps - Execution & Connectors Mar 6, 2023
@mikecote mikecote moved this from Blocked / On hold to Todo in AppEx: ResponseOps - Execution & Connectors Mar 7, 2023
@mikecote mikecote removed the blocked label Mar 7, 2023
@mikecote
Copy link
Contributor Author

mikecote commented Mar 7, 2023

Removing the blocked label now that #152116 has merged.

@pmuellr
Copy link
Member

pmuellr commented Mar 20, 2023

Modify the API key invalidation logic to NOT invalidate API keys that are re-used

I think the implication is that we'll need to be able to identify API keys in the rule SO that we manage vs those that we don't. Presumably via an additional flag in the SO. Or maybe metadata in the API key (seems fragile to me though).

Interesting that this may be a stepping stone to #106878 - specifically, we'd be in a position where we could support explicit API keys users create and supply for the rules, as well as the implicit ones we create today. Would still require a lot of work - mainly UX-wise I think, but getting closer!

@doakalexi doakalexi self-assigned this Mar 27, 2023
@doakalexi doakalexi moved this from Todo to In Progress in AppEx: ResponseOps - Execution & Connectors Mar 27, 2023
@doakalexi doakalexi moved this from In Progress to In Review in AppEx: ResponseOps - Execution & Connectors Apr 3, 2023
doakalexi added a commit that referenced this issue Apr 11, 2023
…erting rules (#154189)

Resolves #152140

## Summary
Updates the following functions in the Rules Client to re-use the API
key in context and avoid having the system invalidate them when no
longer in use:

- bulk_delete
- bulk_edit
- clone
- create
- delete
- update
- update_api_key

Also adds a new field to the rule SO to help determine when whether an
api key was created by a user or created by us.

### 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

### To verify

- Follow these
[instructions](https://www.elastic.co/guide/en/kibana/master/api-keys.html#create-api-key)
to create an api key. Make sure to copy your api key
- Run the following 
```
curl -X POST "http://localhost:5601/api/alerting/rule/" -H 'Authorization: ApiKey ${API_KEY}' -H 'kbn-xsrf: true' -H 'Content-Type: application/json' -d'
{
  "rule_type_id": "example.pattern",
  "name": "pattern",
  "schedule": {
    "interval": "5s"
  },
  "actions": [
  ],
  "consumer": "alerts",
  "tags": [],
  "notify_when": "onActionGroupChange",
  "params": {
    "patterns": {
      "instA": " a - - a "
    }
  }
}'
```
- Verify that the request returns a rule
with`"api_key_created_by_user":true`
- Try this with the other rules clients functions listed above to verify
that you can manage alerting rules when authenticated with an api key
- Verify that `"api_key_created_by_user":false` when you remove the api
key header and add `-u ${USERNAME}:${PASSWORD}` to authenticate
@francescaforza1983
Copy link

@pkobziak please have a look

@pkobziak
Copy link

pkobziak commented Apr 8, 2024

@MikePaquette This case is reported by DT Security Team, this behavior is quite problematic for them since many people may be using API to create rules. when keys are invalidated rules should work independently from the user key.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Alerting/RulesFramework Issues related to the Alerting Rules Framework Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams)
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

6 participants