-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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 ability to specify CORS accepted origins #84316
Conversation
@@ -445,6 +445,15 @@ deprecation warning at startup. This setting cannot end in a slash (`/`). | |||
| [[server-compression]] `server.compression.enabled:` | |||
| Set to `false` to disable HTTP compression for all responses. *Default: `true`* | |||
|
|||
| `server.cors.enabled:` | |||
| experimental[] Set to `true` to allow cross-origin API calls. *Default:* `false` |
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.
@kobelb We should start with marking it as experimental
, I suppose
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.
If we're marking the old server.cors
setting as deprecated, then I'm not sure we should replace it with an experimental setting. Is there a reason to believe this won't be stable enough to mark as GA?
Pinging @elastic/kibana-core (Team:Core) |
x-pack/test/functional_cors/plugins/kibana_cors_test/server/plugin.ts
Outdated
Show resolved
Hide resolved
it('Communicates to Kibana with configured CORS', async () => { | ||
const args: string[] = config.get('kbnTestServer.serverArgs'); | ||
const originSetting = args.find((str) => str.includes('server.cors.origin')); | ||
if (!originSetting) { | ||
throw new Error('Cannot find "server.cors.origin" argument'); | ||
} | ||
const [, value] = originSetting.split('='); | ||
const url = JSON.parse(value); | ||
|
||
await browser.navigateTo(url[0]); | ||
const element = await find.byCssSelector('p'); | ||
expect(await element.getVisibleText()).to.be('content from kibana'); | ||
}); |
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.
:notbad:
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.
++ Nice test!
it('Communicates to Kibana with configured CORS', async () => { | ||
const args: string[] = config.get('kbnTestServer.serverArgs'); | ||
const originSetting = args.find((str) => str.includes('server.cors.origin')); | ||
if (!originSetting) { | ||
throw new Error('Cannot find "server.cors.origin" argument'); | ||
} | ||
const [, value] = originSetting.split('='); | ||
const url = JSON.parse(value); | ||
|
||
await browser.navigateTo(url[0]); | ||
const element = await find.byCssSelector('p'); | ||
expect(await element.getVisibleText()).to.be('content from kibana'); | ||
}); |
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.
++ Nice test!
Co-authored-by: Larry Gregory <[email protected]>
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.
Thanks for adding this, @restrry.
Without the ability to customize the access-control-allow-headers
response header and Kibana not responding to the OPTIONS
pre-flights, the user will be limited to the APIs that they can call using CORS. Do we intend to add those in a separate PR, or is there a reason why we shouldn't do so?
@kobelb What kind of API is cannot be used with the current implementation? I can think of |
We shouldn't be adding APIs to the Currently, all non- FWIW, my prior statement about Kibana not responding to |
Thanks for making these changes, @restrry. This is looking great! |
* add settings * update abab package to version with types * add test case for CORS * add tests for cors config * fix jest tests * add deprecation message * tweak deprecation * make test runable on Cloud * add docs * fix type error * add test to throw on invalid URL * address comments * Update src/core/server/http/http_config.test.ts Co-authored-by: Larry Gregory <[email protected]> * Update docs/setup/settings.asciidoc Co-authored-by: Brandon Kobel <[email protected]> * allow kbn-xsrf headers to be set on CORS request Co-authored-by: Larry Gregory <[email protected]> Co-authored-by: Brandon Kobel <[email protected]> # Conflicts: # src/core/server/config/deprecation/core_deprecations.ts # x-pack/scripts/functional_tests.js
* add settings * update abab package to version with types * add test case for CORS * add tests for cors config * fix jest tests * add deprecation message * tweak deprecation * make test runable on Cloud * add docs * fix type error * add test to throw on invalid URL * address comments * Update src/core/server/http/http_config.test.ts Co-authored-by: Larry Gregory <[email protected]> * Update docs/setup/settings.asciidoc Co-authored-by: Brandon Kobel <[email protected]> * allow kbn-xsrf headers to be set on CORS request Co-authored-by: Larry Gregory <[email protected]> Co-authored-by: Brandon Kobel <[email protected]> # Conflicts: # src/core/server/config/deprecation/core_deprecations.ts # x-pack/scripts/functional_tests.js
💚 Build SucceededMetrics [docs]Distributable file count
History
To update your PR or re-run it, just comment with: |
Resolves #16714.
Summary
The current implementation is based on a discussion in the parent issue.
Kibana supports only 3 CORS options at the moment:
server.cors.enabled
Set to true to allow cross-origin API calls. Default: falseserver.cors.credentials
Set to true to allow browser code to access response body whenever request performed with user credentials. Default: falseserver.cors.origin
List of origins permitted to access resources. You must specify server.cors.origin when server.cors.credentials: true. Default: "*"Kibana extend
Access-Control-Allow-Headers
list with the next headers:['Accept', 'Authorization', 'Content-Type', 'If-None-Match', 'kbn-xsrf']
Checklist
Delete any items that are not applicable to this PR.
Release Notes
Added experimental support for configuring CORS policy:
server.cors.enabled
Set to true to allow cross-origin API calls. Default: falseserver.cors.allowCredentials
Set to true to allow browser code to access response body whenever request performed with user credentials. Default: falseserver.cors.allowOrigin
List of origins permitted to access resources. You must specifyserver.cors.allowOrigin
whenserver.cors.allowCredentials: true
. Default: ["*"]