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

[BUG] OSD returns HTTP 500 internal server error messages when the wrapping key is changed #2210

Closed
Tracked by #2433
zhongnansu opened this issue Aug 26, 2022 · 4 comments
Assignees
Labels
bug Something isn't working multiple datasource multiple datasource project

Comments

@zhongnansu
Copy link
Member

OSD returns HTTP 500 internal server error messages when the wrapping key is changed and the service is unable to decrypt the credentials. When the user does not update the credentials and attempts to create a new index pattern, the calls to the target endpoint fails and return HTTP 500 errors. A generic error message is returned in response.

The recommendation will be to return an error message or at least a suggestion to the user asking to verify if the credentials have been updated post changes to the wrapping key.

@zhongnansu zhongnansu added bug Something isn't working multiple datasource multiple datasource project labels Aug 26, 2022
@zhongnansu zhongnansu self-assigned this Aug 26, 2022
@noCharger
Copy link
Contributor

noCharger commented Aug 26, 2022

More context -

When we use random keyring to decrypt the message, an exception will throw with error message unencryptedDataKey has not been set. We have a test case to cover this https://github.com/opensearch-project/OpenSearch-Dashboards/blob/feature/multi-datasource/src/plugins/data_source/server/cryptography/cryptography_client.test.ts#L97-L115

Screen Shot 2022-08-29 at 11 23 01 AM

This exception is caught in the described situation.

@noCharger
Copy link
Contributor

Issue - Internal server error after expection throw

Screen Shot 2022-08-29 at 11 30 01 AM

Screen Shot 2022-08-29 at 11 30 05 AM

Screen Shot 2022-08-29 at 11 30 07 AM

Procedure to reproduce -

  1. Create a new set of credentials
  2. Create a data source and configure the data source to use the newly created credentials
  3. Navigate to Stack Management -> Index Patterns -> Create index pattern
  4. Select the data source created in Step 2 above
  5. Observe that the service is able to retrieve the available indices
  6. From the opensearch_dashboards.yml file change one of the values in
    data_source.encryption.wrappingKey
  7. From the OpenSearch dashboard, navigate to Stack Management -> Index Patterns -> Create index
    pattern
  8. Search for an index pattern, observe that the OSD fails to load any indices
  9. In the browser developer console, under Networks observe that the API requests fail and return HTTP 500
    Internal Server Error responses

@zhongnansu
Copy link
Member Author

zhongnansu commented Aug 29, 2022

@noCharger Thanks for the investigation

Since the correct 400 error is thrown by SavedObjectsErrorHelpers.createBadRequestError(error.message); in the crypto manager side. The issue is more with the opensearch/internal/search API route handler side. It failed to interpret the error object accordingly in the response handling. Because the error is a hapi/boom object.

  • The hapi/boom 400 error object looks like this
isBoom: true,
  isServer: false,
  data: null,
  output: {
    statusCode: 400,
    payload: {
      message: 'unencryptedDataKey has not been set: Bad Request',
      statusCode: 400,
      error: 'Bad Request'
    },
    headers: {}
  },
  [Symbol(SavedObjectsClientErrorCode)]: 'SavedObjectsClient/badRequest'

There are 2 approaches we can solve this.

  1. we don't use SavedObjectsErrorHelpers.createBadRequestError(error.message); to create error object, instead we build our own Error object that has the statusCode field and error message, that search API route handler can understand
  2. We add a wrapper to help search API understand the hapi/boom error object, I also found a code reference
    import Boom from '@hapi/boom';
    import { RequestHandlerWrapper } from './router';
    export const wrapErrors: RequestHandlerWrapper = (handler) => {
    return async (context, request, response) => {
    try {
    return await handler(context, request, response);
    } catch (e) {
    if (Boom.isBoom(e)) {
    return response.customError({
    body: e.output.payload,
    statusCode: e.output.statusCode,
    headers: e.output.headers as { [key: string]: string },
    });
    }
    throw e;

As for the UI/UX side change, not sure if for 400 it already has some UI popup there, you can look into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working multiple datasource multiple datasource project
Projects
None yet
Development

No branches or pull requests

2 participants