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

updating action config yields Unsupported state or unable to authenticate data #40177

Closed
pmuellr opened this issue Jul 2, 2019 · 6 comments · Fixed by #40694
Closed

updating action config yields Unsupported state or unable to authenticate data #40177

pmuellr opened this issue Jul 2, 2019 · 6 comments · Fixed by #40694
Assignees

Comments

@pmuellr
Copy link
Member

pmuellr commented Jul 2, 2019

Kibana version: master

Elasticsearch version: n/a

Server OS version: n/a

Browser version: n/a

Browser OS version: n/a

Original install method (e.g. download page, yum, from source, etc.): dev

Describe the bug:

The slack action throws a not useful error when the webhook url is invalid.

Steps to reproduce:

  1. install kbn-action
  2. start the functional test server
  3. run
kbn-action create .email "email action" '{"user":"X","password":"X","from":"x@gmail.com","service":"gmail"}'
  1. get the action id from the response, to use in the next commands
  2. run (changing from using config service to using host and port instead)
kbn-action update ${actionID} "email action" '{"user":"X", "password":"X","from":"x@gmail.com", "host":"example.com", "port": 80}'
  1. run
kbn-action fire ${actionID} '{"subject":"testing","message":"hallo","to":["pmuellr@gmail.com"]}'

kbn-action logs:

kbn-action: status code 500
body: {
    "statusCode": 500,
    "error": "Internal Server Error",
    "message": "An internal server error occurred"
}

Expected behavior:

if the various parms had been valid, should send an email

Provide logs and/or server output (if relevant):

   │ proc [kibana] server    log   [12:28:13.401] [error][encrypted_saved_objects] Failed to decrypt "actionTypeConfigSecrets" attribute: Unsupported state or unable to authenticate data
   │ proc [kibana] server   error  [12:28:13.373]  Error: Unable to decrypt attribute "actionTypeConfigSecrets"
   │ proc [kibana]     at EncryptedSavedObjectsService.decryptAttributes (/Users/pmuellr/Projects/elastic/kibana/x-pack/legacy/plugins/encrypted_saved_objects/server/lib/encrypted_saved_objects_service.ts:244:15)
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-stack-services

@pmuellr pmuellr added this to To do - Beta / 7.4 in Make it Action Jul 2, 2019
@pmuellr
Copy link
Member Author

pmuellr commented Jul 2, 2019

wonder if this is somehow related to AAD w/encrypted saved objects, but I was poking through those bits yesterday and I think we've done the right thing there ...

@pmuellr
Copy link
Member Author

pmuellr commented Jul 2, 2019

Appears to be AAD-related:

attributesToExcludeFromAAD: new Set(['description']),

@pmuellr
Copy link
Member Author

pmuellr commented Jul 2, 2019

Also, appears we are doing "partial updates", and the result from an update and subsequent get are not the same.

In the case below, the action has a config property of "service": "gmail" before the update, but we really want that removed and replaced with the new "host" and "port" properties:

$ kbn-action update cfe35848-0304-4374-b919-299ce1bb6b88 "email action" \
    '{"user":"X", "password":"X","from":"x@gmail.com", "host":"example.com", "port": 80}'
{
    "id": "cfe35848-0304-4374-b919-299ce1bb6b88",
    "type": "action",
    "updated_at": "2019-07-02T16:26:56.467Z",
    "version": "WzI4LDFd",
    "references": [],
    "attributes": {
        "description": "email action",
        "actionTypeConfig": {
            "host": "example.com",
            "port": 80,
            "from": "x@gmail.com"
        },
        "actionTypeId": ".email"
    }
}

$ kbn-action get cfe35848-0304-4374-b919-299ce1bb6b88
{
    "id": "cfe35848-0304-4374-b919-299ce1bb6b88",
    "type": "action",
    "updated_at": "2019-07-02T16:26:56.467Z",
    "version": "WzI4LDFd",
    "attributes": {
        "actionTypeId": ".email",
        "description": "email action",
        "actionTypeConfig": {
            "service": "gmail",
            "from": "x@gmail.com",
            "port": 80,
            "host": "example.com"
        }
    },
    "references": []
}

@pmuellr pmuellr self-assigned this Jul 8, 2019
pmuellr added a commit to pmuellr/kibana that referenced this issue Jul 9, 2019
pmuellr added a commit to pmuellr/kibana that referenced this issue Jul 9, 2019
pmuellr added a commit to pmuellr/kibana that referenced this issue Jul 9, 2019
fixes elastic#40177

Prior to this, the `actionTypeConfig` was not excluded from AAD when using
encrypted saved objects in actions.

https://github.com/elastic/kibana/blob/d0da71c2b4b154fe2efe86b44869c06709c15d14/x-pack/legacy/plugins/actions/server/init.ts#L31-L35

This caused a problem when updating values in the `actionTypeConfig`, as per
issue elastic#40177

Also added `x-pack/test/functional/es_archives/actions/README.md` to explain
how to get the id and encrypted value string, if this needs to be done again
later, since it's a little tricky.
pmuellr added a commit to pmuellr/kibana that referenced this issue Jul 9, 2019
fixes elastic#40177

Prior to this, the `actionTypeConfig` was not excluded from AAD when using
encrypted saved objects in actions.

https://github.com/elastic/kibana/blob/d0da71c2b4b154fe2efe86b44869c06709c15d14/x-pack/legacy/plugins/actions/server/init.ts#L31-L35

This caused a problem when updating values in the `actionTypeConfig`, as per
issue elastic#40177

Also added `x-pack/test/functional/es_archives/actions/README.md` to explain
how to get the id and encrypted value string, if this needs to be done again
later, since it's a little tricky.
@pmuellr pmuellr moved this from To do - Beta / 7.4 to In progress in Make it Action Jul 9, 2019
@pmuellr
Copy link
Member Author

pmuellr commented Jul 10, 2019

So the consensus seems to be that the existing "partial updates" that are happening in master are what's causing the AAD issue, and that if we fix that, the original symptom we're seeing of Unsupported state or unable to authenticate data won't happen.

Also, since we're not exposing AAD to clients via the API directly, clients can't build an action config where non-encrypted config properties are made part of AAD - it's all or nothing, and we need to decide which it will be. Safer to be all, it seems, since there's little downside to this (eg, performance-wise).

Given all that, seems like we'll end up NOT merging this PR. I'm going to start working on a separate PR to fix the partial update problem, which will hopefully resolve the original issue.

@pmuellr
Copy link
Member Author

pmuellr commented Jul 11, 2019

Rather than close the original PR #40694 that was open to "fix" this issue, since I initially fixed it "wrong", I decided to just do the right thing with more commits - I already had some decent test cases and such.

So current status is:

  • existing actions have been converted to use @kbn/schema-config to describe their config and params
  • the email config has been set up via config-schema to never use undefined values for properties, but null instead - the undefined values it was allowing was the cause of the "partial updates" we were seeing
  • the non-encrypted config properties are now considered for AAD, just as they were before I created this branch; with email config no longer doing partial updates, we shouldn't see the original issue reported at the top

Side-effects of using @kbn-schema-config:

  • the validation errors messages provided are MUCH better than the ones we had to scrape out of joi
  • we also get TS types from them, and can be used with "extra validation" functions action providers might want to use, like our email one: (note: bit of a hack to a avoid a circular reference):

function validateConfig(configObject: any): string | void {
// avoids circular reference ...
const config: ActionTypeConfigType = configObject;
// Make sure service is set, or if not, both host/port must be set.
// If service is set, host/port are ignored, when the email is sent.
if (config.service == null) {
if (config.host == null && config.port == null) {
return 'either [service] or [host]/[port] is required';
}
if (config.host == null) {
return '[host] is required if [service] is not provided';
}
if (config.port == null) {
return '[port] is required if [service] is not provided';
}
} else {
// service is not null
if (!isValidService(config.service)) {
return `[service] value "${config.service}" is not valid`;
}
}
}

pmuellr added a commit that referenced this issue Jul 15, 2019
…40694)

* Adds actionTypeConfig to AAD exclusion for action ESOs

fixes #40177

Prior to this, the `actionTypeConfig` was not excluded from AAD when using
encrypted saved objects in actions.

https://github.com/elastic/kibana/blob/d0da71c2b4b154fe2efe86b44869c06709c15d14/x-pack/legacy/plugins/actions/server/init.ts#L31-L35

This caused a problem when updating values in the `actionTypeConfig`, as per
issue #40177

Also added `x-pack/test/functional/es_archives/actions/README.md` to explain
how to get the id and encrypted value string, if this needs to be done again
later, since it's a little tricky.

* change alertings reference to actions archived action

Alert happened to reuse the archived action, so it's reference to the
action also had to be updated.
pmuellr added a commit to pmuellr/kibana that referenced this issue Jul 15, 2019
…lastic#40694)

* Adds actionTypeConfig to AAD exclusion for action ESOs

fixes elastic#40177

Prior to this, the `actionTypeConfig` was not excluded from AAD when using
encrypted saved objects in actions.

https://github.com/elastic/kibana/blob/d0da71c2b4b154fe2efe86b44869c06709c15d14/x-pack/legacy/plugins/actions/server/init.ts#L31-L35

This caused a problem when updating values in the `actionTypeConfig`, as per
issue elastic#40177

Also added `x-pack/test/functional/es_archives/actions/README.md` to explain
how to get the id and encrypted value string, if this needs to be done again
later, since it's a little tricky.

* change alertings reference to actions archived action

Alert happened to reuse the archived action, so it's reference to the
action also had to be updated.
pmuellr added a commit that referenced this issue Jul 15, 2019
…40694) (#41161)

* Adds actionTypeConfig to AAD exclusion for action ESOs

fixes #40177

Prior to this, the `actionTypeConfig` was not excluded from AAD when using
encrypted saved objects in actions.

https://github.com/elastic/kibana/blob/d0da71c2b4b154fe2efe86b44869c06709c15d14/x-pack/legacy/plugins/actions/server/init.ts#L31-L35

This caused a problem when updating values in the `actionTypeConfig`, as per
issue #40177

Also added `x-pack/test/functional/es_archives/actions/README.md` to explain
how to get the id and encrypted value string, if this needs to be done again
later, since it's a little tricky.

* change alertings reference to actions archived action

Alert happened to reuse the archived action, so it's reference to the
action also had to be updated.
@pmuellr pmuellr removed this from In progress in Make it Action Jul 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants