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

[Alerting] Secret Service #28894

Closed
wants to merge 195 commits into from
Closed

Conversation

njd5475
Copy link
Contributor

@njd5475 njd5475 commented Jan 17, 2019

Summary

Main implementation PR for meta issue #26975

Blocked by #28722

Checklist

Use strikethroughs to remove checklist items you don't feel are applicable to this PR.

For maintainers

The secret store should define saved object middleware.
Secret store should use hard crypto algorithms to secure data.
Secret store should use object hashes to validate saved objects are not modified.
src/legacy/server/keystore/keystore.test.js Outdated Show resolved Hide resolved
x-pack/plugins/secret_service/index.ts Outdated Show resolved Hide resolved
x-pack/plugins/secret_service/index.ts Outdated Show resolved Hide resolved
}
};

this.validateKey = async () => {
Copy link
Contributor

@kobelb kobelb Mar 12, 2019

Choose a reason for hiding this comment

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

Validating the key during init in this manner is going to prevent us from ever changing the encryption key.

Copy link
Member

Choose a reason for hiding this comment

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

Can you please elaborate on this a bit? What would be the recommended way of changing/rotating encryption keys in Kibana (e.g. for Reporting)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You would validate you have a valid key first then you would generate a new key, encrypt the new key in an object with the old key or a temporary key indicating a rotation, and begin fetching all the secret objects and updating them by decrypting with the old key and encrypting with the new key until all are fully changed, then update the keystore with the new key.

There would probably need to be a method for marking the secrets as needing to be re-encrypted or you'd just have to force them all to be processed each time the rotation happens starting over but validating all objects have been rotated properly.

@kobelb kobelb requested a review from azasypkin March 13, 2019 14:46
x-pack/plugins/secret_service/index.ts Outdated Show resolved Hide resolved
x-pack/plugins/secret_service/index.ts Outdated Show resolved Hide resolved
}).default();
},

async init(server: any) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: maybe server: Legacy.Server (import { Legacy } from 'kibana';) instead of server: any?

x-pack/plugins/secret_service/index.ts Outdated Show resolved Hide resolved
return dummyObj;
});
const isValid = await subject.validateKey();
expect(isValid).toBeTruthy();
Copy link
Member

Choose a reason for hiding this comment

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

optional nit: expect(isValid).toBe(true); feels a bit more correct (and similar note for test cases below).

return dummyObj;
}
);
savedObjectsClient.get.mockImplementation((type: string, attributes: any, options?: any) => {
Copy link
Member

Choose a reason for hiding this comment

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

nit: there is no need to define unused arguments (here and below)

throw new Error('test error');
}
);
savedObjectsClient.get.mockImplementation((type: string, attributes: any, options?: any) => {
Copy link
Member

Choose a reason for hiding this comment

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

nit: looks like savedObjectsClient.get won't be called? If so, we can just use this:

savedObjectsClient.create.mockRejectedValue(new Error('test error'));

});

it('should throw any error other than conflict', async () => {
savedObjectsClient.create.mockImplementation(
Copy link
Member

Choose a reason for hiding this comment

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

nit: savedObjectsClient.create.mockRejectedValue(new Error('test error'));

}
};

this.validateKey = async () => {
Copy link
Member

Choose a reason for hiding this comment

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

Can you please elaborate on this a bit? What would be the recommended way of changing/rotating encryption keys in Kibana (e.g. for Reporting)?

@kobelb
Copy link
Contributor

kobelb commented Mar 14, 2019

Can you please elaborate on this a bit? What would be the recommended way of changing/rotating encryption keys in Kibana (e.g. for Reporting)?

If we wanted to change/rotate the encryption keys for Reporting/Security, we could just change the keys and all pending Jobs and cookies would be invalid, but outside of that we'd require no additional changes.

The other issue with doing this validation on init is that it's going to prevent multiple instance of Kibana targeting the same .kibana index from ever coming online at the same time if this key isn't explicitly set to the same value. The very first instance will essentially "claim" the encryption key which is used to encrypt this dummy value, and no other instances will be able to start up. It'd be a much better experience for the user where if the encryption keys weren't synchronized across instances that each instance is isolated and only able to use the secrets that they've inserted, as opposed to preventing startup entirely.

njd5475 added 4 commits March 14, 2019 11:29
SavedObjectsRepository needs full typing.
Extract config key constant.
Remove unused mock class.
Convert to correct type for SavedObjectsRepository.
Use typescript auto declared members for class.
Rename the key to encryptionKey.
Use uuid v4 for id generation.
Remove unnecessary data from log messages.
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@njd5475 njd5475 closed this Mar 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New value added to drive a business result Feature:Alerting Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants