-
Notifications
You must be signed in to change notification settings - Fork 8k
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
NP Security HTTP Interceptors #39477
Merged
Merged
Changes from all commits
Commits
Show all changes
54 commits
Select commit
Hold shift + click to select a range
d4f7e8e
We have a NP plugin! :celebration:
kobelb 3ebd52f
Redirecting to login on all 401s
kobelb 16c8e29
Merge remote-tracking branch 'upstream/master' into np/security-http-…
kobelb 7c9f4b8
Adding commented out code for when credentials are omitted
kobelb 249bbfa
Merge remote-tracking branch 'upstream/master' into np/security-http-…
kobelb 9041c15
Fixing types
kobelb 2c6b3aa
Respond 403 when user changes password with incorrect current password
kobelb 007bc82
Adding AnonymousPaths where we ignore all 401s
kobelb 67af74c
Adding anonymous path tests
kobelb 984bf56
Extracted a dedicated SessionExpires class and added tests
kobelb f672b72
Fixing plugin after refactoring to add SessionExpired
kobelb c7ff2f0
Beginning to work on the session timeout interceptor
kobelb 181d951
Fixing UnauthorizedResponseInterceptor anonymous path test
kobelb ba84476
Removing test anonymous path
kobelb a551a5e
Trying to improve readability
kobelb 643729a
Merge remote-tracking branch 'upstream/master' into np/security-http-…
kobelb 32d9385
Displaying session logout warning
kobelb 824086c
Mocking out the base path
kobelb 0384182
Revert "Mocking out the base path"
kobelb acb61ee
Changing coreMock to use a concrete instance of BasePath
kobelb 41cbc8c
Adding session timeout interceptor tests
kobelb 147edbd
Adding session timeout tests
kobelb ddab529
Adding more tests for short session timeouts
kobelb 3b8711e
Moving some files to a session folder
kobelb f37cf88
More thrashing around: renaming and reorganizing
kobelb 93206ad
Renaming Interceptor to HttpInterceptor
kobelb eb860e8
Merge remote-tracking branch 'upstream/master' into np/security-http-…
kobelb 3bd02fb
Fixing some type errors
kobelb bae2ef9
Fixing legacy chrome API tests
kobelb da8b846
Fixing other tests to use the concrete instance of BasePath
kobelb fb00dc4
Adjusting some types
kobelb 51bdb02
Putting DeeplyMocked back, I don't get how DeeplyMockedKeys works
kobelb 837ba11
Merge remote-tracking branch 'upstream/master' into np/security-http-…
kobelb e23cf8f
Moving anonymousPaths to public core http
kobelb 2c98227
Reading sessionTimeout from injected vars and supporting null timeout
kobelb 32751a4
Doesn't extend session when there is no response
kobelb 4b0ea10
Updating docs and snapshots
kobelb 9432988
Casting sessionTimeout injectedVar to "number | null"
kobelb e169fbe
Fixing i18n issues
kobelb 3582111
Merge branch 'master' into np/security-http-interceptors
elasticmachine edac0ec
Update x-pack/plugins/security/public/plugin.ts
kobelb 85a655e
Adding milliseconds postfix to SessionTimeout private fields
kobelb a70ac40
Even better anonymous paths, with some validation
kobelb 248c580
Adjusting public method docs for IAnonymousPaths
kobelb 5697aa2
Adjusting spelling of base-path to basePath
kobelb 4af0d8a
Update x-pack/plugins/security/public/session/session_timeout.tsx
kobelb 5a91232
Update src/core/public/http/anonymous_paths.ts
kobelb 50237cb
Update src/core/public/http/anonymous_paths.ts
kobelb 40a3697
AnonymousPaths implements IAnonymousPaths and uses IBasePath
kobelb 08aa526
Removing DeeplyMocked
kobelb c4ec25c
Removing TODOs
kobelb 15ff621
Fixing types...
kobelb 5a9b9a5
Now, ever more normal
kobelb 43425b1
Merge remote-tracking branch 'upstream/master' into np/security-http-…
kobelb File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
.../development/core/public/kibana-plugin-public.httpservicebase.anonymouspaths.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [HttpServiceBase](./kibana-plugin-public.httpservicebase.md) > [anonymousPaths](./kibana-plugin-public.httpservicebase.anonymouspaths.md) | ||
|
||
## HttpServiceBase.anonymousPaths property | ||
|
||
APIs for denoting certain paths for not requiring authentication | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
anonymousPaths: IAnonymousPaths; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
docs/development/core/public/kibana-plugin-public.ianonymouspaths.isanonymous.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [IAnonymousPaths](./kibana-plugin-public.ianonymouspaths.md) > [isAnonymous](./kibana-plugin-public.ianonymouspaths.isanonymous.md) | ||
|
||
## IAnonymousPaths.isAnonymous() method | ||
|
||
Determines whether the provided path doesn't require authentication | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
isAnonymous(path: string): boolean; | ||
``` | ||
|
||
## Parameters | ||
|
||
| Parameter | Type | Description | | ||
| --- | --- | --- | | ||
| path | <code>string</code> | | | ||
|
||
<b>Returns:</b> | ||
|
||
`boolean` | ||
|
21 changes: 21 additions & 0 deletions
21
docs/development/core/public/kibana-plugin-public.ianonymouspaths.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [IAnonymousPaths](./kibana-plugin-public.ianonymouspaths.md) | ||
|
||
## IAnonymousPaths interface | ||
|
||
APIs for denoting paths as not requiring authentication | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
export interface IAnonymousPaths | ||
``` | ||
|
||
## Methods | ||
|
||
| Method | Description | | ||
| --- | --- | | ||
| [isAnonymous(path)](./kibana-plugin-public.ianonymouspaths.isanonymous.md) | Determines whether the provided path doesn't require authentication | | ||
| [register(path)](./kibana-plugin-public.ianonymouspaths.register.md) | Register <code>path</code> as not requiring authentication | | ||
|
24 changes: 24 additions & 0 deletions
24
docs/development/core/public/kibana-plugin-public.ianonymouspaths.register.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [IAnonymousPaths](./kibana-plugin-public.ianonymouspaths.md) > [register](./kibana-plugin-public.ianonymouspaths.register.md) | ||
|
||
## IAnonymousPaths.register() method | ||
|
||
Register `path` as not requiring authentication | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
register(path: string): void; | ||
``` | ||
|
||
## Parameters | ||
|
||
| Parameter | Type | Description | | ||
| --- | --- | --- | | ||
| path | <code>string</code> | | | ||
|
||
<b>Returns:</b> | ||
|
||
`void` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { AnonymousPaths } from './anonymous_paths'; | ||
import { BasePath } from './base_path_service'; | ||
|
||
describe('#register', () => { | ||
it(`allows paths that don't start with /`, () => { | ||
const basePath = new BasePath('/foo'); | ||
const anonymousPaths = new AnonymousPaths(basePath); | ||
anonymousPaths.register('bar'); | ||
}); | ||
|
||
it(`allows paths that end with '/'`, () => { | ||
const basePath = new BasePath('/foo'); | ||
const anonymousPaths = new AnonymousPaths(basePath); | ||
anonymousPaths.register('/bar/'); | ||
}); | ||
}); | ||
|
||
describe('#isAnonymous', () => { | ||
it('returns true for registered paths', () => { | ||
const basePath = new BasePath('/foo'); | ||
const anonymousPaths = new AnonymousPaths(basePath); | ||
anonymousPaths.register('/bar'); | ||
expect(anonymousPaths.isAnonymous('/foo/bar')).toBe(true); | ||
}); | ||
|
||
it('returns true for paths registered with a trailing slash, but call "isAnonymous" with no trailing slash', () => { | ||
const basePath = new BasePath('/foo'); | ||
const anonymousPaths = new AnonymousPaths(basePath); | ||
anonymousPaths.register('/bar/'); | ||
expect(anonymousPaths.isAnonymous('/foo/bar')).toBe(true); | ||
}); | ||
|
||
it('returns true for paths registered without a trailing slash, but call "isAnonymous" with a trailing slash', () => { | ||
const basePath = new BasePath('/foo'); | ||
const anonymousPaths = new AnonymousPaths(basePath); | ||
anonymousPaths.register('/bar'); | ||
expect(anonymousPaths.isAnonymous('/foo/bar/')).toBe(true); | ||
}); | ||
|
||
it('returns true for paths registered without a starting slash', () => { | ||
const basePath = new BasePath('/foo'); | ||
const anonymousPaths = new AnonymousPaths(basePath); | ||
anonymousPaths.register('bar'); | ||
expect(anonymousPaths.isAnonymous('/foo/bar')).toBe(true); | ||
}); | ||
|
||
it('returns true for paths registered with a starting slash', () => { | ||
const basePath = new BasePath('/foo'); | ||
const anonymousPaths = new AnonymousPaths(basePath); | ||
anonymousPaths.register('/bar'); | ||
expect(anonymousPaths.isAnonymous('/foo/bar')).toBe(true); | ||
}); | ||
|
||
it('when there is no basePath and calling "isAnonymous" without a starting slash, returns true for paths registered with a starting slash', () => { | ||
const basePath = new BasePath('/'); | ||
const anonymousPaths = new AnonymousPaths(basePath); | ||
anonymousPaths.register('/bar'); | ||
expect(anonymousPaths.isAnonymous('bar')).toBe(true); | ||
}); | ||
|
||
it('when there is no basePath and calling "isAnonymous" with a starting slash, returns true for paths registered with a starting slash', () => { | ||
const basePath = new BasePath('/'); | ||
const anonymousPaths = new AnonymousPaths(basePath); | ||
anonymousPaths.register('/bar'); | ||
expect(anonymousPaths.isAnonymous('/bar')).toBe(true); | ||
}); | ||
|
||
it('returns true for paths whose capitalization is different', () => { | ||
const basePath = new BasePath('/foo'); | ||
const anonymousPaths = new AnonymousPaths(basePath); | ||
anonymousPaths.register('/BAR'); | ||
expect(anonymousPaths.isAnonymous('/foo/bar')).toBe(true); | ||
}); | ||
|
||
it('returns false for other paths', () => { | ||
const basePath = new BasePath('/foo'); | ||
const anonymousPaths = new AnonymousPaths(basePath); | ||
anonymousPaths.register('/bar'); | ||
expect(anonymousPaths.isAnonymous('/foo/foo')).toBe(false); | ||
}); | ||
|
||
it('returns false for sub-paths of registered paths', () => { | ||
const basePath = new BasePath('/foo'); | ||
const anonymousPaths = new AnonymousPaths(basePath); | ||
anonymousPaths.register('/bar'); | ||
expect(anonymousPaths.isAnonymous('/foo/bar/baz')).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { IAnonymousPaths, IBasePath } from 'src/core/public'; | ||
|
||
export class AnonymousPaths implements IAnonymousPaths { | ||
private readonly paths = new Set<string>(); | ||
|
||
constructor(private basePath: IBasePath) {} | ||
|
||
public isAnonymous(path: string): boolean { | ||
const pathWithoutBasePath = this.basePath.remove(path); | ||
return this.paths.has(this.normalizePath(pathWithoutBasePath)); | ||
} | ||
|
||
public register(path: string) { | ||
this.paths.add(this.normalizePath(path)); | ||
} | ||
|
||
private normalizePath(path: string) { | ||
// always lower-case it | ||
let normalized = path.toLowerCase(); | ||
|
||
// remove the slash from the end | ||
if (normalized.endsWith('/')) { | ||
normalized = normalized.slice(0, normalized.length - 1); | ||
} | ||
|
||
// put a slash at the start | ||
if (!normalized.startsWith('/')) { | ||
normalized = `/${normalized}`; | ||
} | ||
|
||
// it's normalized!!! | ||
return normalized; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thoughts on adding: