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

Add verification code protection #110856

Merged
merged 8 commits into from
Sep 6, 2021

Conversation

thomheymann
Copy link
Contributor

@thomheymann thomheymann commented Sep 1, 2021

Summary

Add verification code protection to interactive setup.

Verification modal

This modal will only be displayed if the user opens Kibana manually instead of opening the setup link generated during startup.

Screenshot 2021-09-01 at 18 30 41

Kibana server

Screenshot 2021-09-01 at 18 32 03

@thomheymann thomheymann added Team:Security Team focused on: Auth, Users, Roles, Spaces, Audit Logging, and more! v8.0.0 release_note:skip Skip the PR/issue when compiling release notes backport:skip This commit does not require backporting labels Sep 1, 2021
@azasypkin
Copy link
Member

ACK: Reviewing...

Copy link
Member

@azasypkin azasypkin left a comment

Choose a reason for hiding this comment

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

Looks great. The only thing I'm concerned with is that we don't verify code in manual mode before we ping the address user provides. Is there any reason we don't want to do this?

src/plugins/interactive_setup/server/verification_code.ts Outdated Show resolved Hide resolved
src/plugins/interactive_setup/server/verification_code.ts Outdated Show resolved Hide resolved
src/plugins/interactive_setup/server/verification_code.ts Outdated Show resolved Hide resolved
Comment on lines 28 to 30
message: verificationCode.remainingAttempts
? 'Invalid verification code.'
: 'Maximum number of attempts exceeded.',
Copy link
Member

Choose a reason for hiding this comment

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

question: (sorry haven't looked at the client side yet), if we display these errors in UI we'd need to use i18n for them

src/plugins/interactive_setup/public/use_visibility.ts Outdated Show resolved Hide resolved
src/plugins/interactive_setup/server/verification_code.ts Outdated Show resolved Hide resolved
@thomheymann thomheymann marked this pull request as ready for review September 4, 2021 07:42
@thomheymann thomheymann requested review from a team as code owners September 4, 2021 07:42
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-security (Team:Security)

Copy link
Contributor

@tylersmalley tylersmalley left a comment

Choose a reason for hiding this comment

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

Limits change LGTM

Copy link
Member

@azasypkin azasypkin left a comment

Choose a reason for hiding this comment

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

Looks great! Just a few minor suggestions and questions.

Comment on lines +36 to +42
const sanitize = (str: string) => {
return str
.split('')
.filter((char) => char.match(pattern))
.join('')
.substr(0, length);
};
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: it took me sometime to understand the idea behind being so forgiving to the input (filtering out non-digits and accepting any length) and not just using something like ^[0-9]{6}$ after trim(). Would be great if you can leave a comment here for the future readers.

question: any reason we make pattern, length and separator configurable (via props)? Feels a bit like a premature generalization to me.

Copy link
Contributor Author

@thomheymann thomheymann Sep 6, 2021

Choose a reason for hiding this comment

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

suggestion: it took me sometime to understand the idea behind being so forgiving to the input (filtering out non-digits and accepting any length) and not just using something like ^[0-9]{6}$ after trim(). Would be great if you can leave a comment here for the future readers.

ok, done!

question: any reason we make pattern, length and separator configurable (via props)? Feels a bit like a premature generalization to me.

This doesn't add any complexity. I'd need to declare variables for these params anyways unless you want me to hard code them which would make it less readable.

Copy link
Member

Choose a reason for hiding this comment

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

This doesn't add any complexity.

That's only true when we don't test both default pattern and custom patterns 🙂

I'd need to declare variables for these params anyways unless you want me to hard code them which would make it less readable.

Yeah, I was thinking about constants, like we created for length already. But feel free to keep what you have if you feel strongly about it. I usually try to not parameterize anything if I don't need it to make it easier to test and change (for any breaking change you'd need to go and check all consumers that may theoretically pass the parameter you're going to change).

verificationCode.verify('invalid');
verificationCode.verify('invalid');
verificationCode.verify('invalid');
expect(verificationCode['failedAttempts']).toBe(3); // eslint-disable-line dot-notation
Copy link
Member

Choose a reason for hiding this comment

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

question: why not rely on public remainingAttempts instead (here and in tests below)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because then I need to calculate the difference myself. Here it maps directly to the number of times I called verify which is easier to see in the test

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, but it's a private field and wouldn't even work at all if you switch to the native JS private fields.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
interactiveSetup 34 46 +12

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
interactiveSetup 8 9 +1

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
interactiveSetup 64.1KB 75.4KB +11.3KB
Unknown metric groups

API count

id before after diff
interactiveSetup 18 19 +1

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @thomheymann

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team:Security Team focused on: Auth, Users, Roles, Spaces, Audit Logging, and more! v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants