-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Globally enforce internal API restriction #193792
Globally enforce internal API restriction #193792
Conversation
@elasticmachine merge upstream |
@elasticmachine merge upstream |
@@ -68,7 +68,7 @@ export const createConfigService = ({ | |||
shutdownTimeout: moment.duration(30, 'seconds'), | |||
keepaliveTimeout: 120_000, | |||
socketTimeout: 120_000, | |||
restrictInternalApis: false, | |||
restrictInternalApis: false, // disable restriction for Kibana tests |
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.
Leaves the restriction disabled for tests consuming createConfigService
.
packages/core/http/core-http-server-internal/src/http_config.ts
Outdated
Show resolved
Hide resolved
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.
self review.
Pinging @elastic/kibana-core (Team:Core) |
Before we merge - I think we should investigate two things which I just realized weren't in the rollout plan:
Let's also add a bit more detail to our breaking change note. Even though folks shouldn't be using these APIs, we know many are, so again this would be to address the potential wide impact of this change. |
TBH, I've also been thinking along these lines because it's the right thing to do. The tricky part is that restricting access to internal APIs isn't a classic deprecation and we'd need something within the http service to surface external calls in the UA. I'm unsure if that's possible from within the http lifecycle or maybe easier within the router itself. @jloleysens we should discuss our options. As for the KB, I was going to add one anyway ;-)
How about rewording something similar to #156935 to highlight how this change helps consumers? |
We should be able to piggy-back off work Ahmad is doing. He is creating a core usage counter for HTTP stuff that we can use to make a new route counter. The "internal route usage" counter should be registered during setup time. As for where we detect/increment this counter, I think we should do it just before returning the 400 here:
That handler will just need the core usage service injected. But for that we are blocked on #193668 |
@elasticmachine merge upstream |
restrictInternalApis: offeringBasedSchema({ | ||
serverless: schema.boolean({ defaultValue: false }), | ||
traditional: schema.boolean({ defaultValue: false }), | ||
serverless: schema.boolean({ defaultValue: true }), |
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.
Changing the default also meant updating tests to either disable the restriction or add the header required for internal requests.
@@ -82,6 +83,9 @@ describe('checking all opted-in dynamic config settings', () => { | |||
logging: { | |||
loggers: [{ name: 'root', level: 'info', appenders: ['console'] }], | |||
}, | |||
server: { | |||
restrictInternalApis: 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.
It's less work to disable the restriction in createTestServers
than adding the header/query param to tests.
We disable the restriction by default for ftr tests too.
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.
Should/do we have a task for updating these requests in the future or is the plan to leave them unrestricted in tests?
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.
Should/do we have a task for updating these requests in the future or is the plan to leave them unrestricted in tests
The plan is to update requests if and when we need to, which is consistent with the base config for our FTR tests.
As for this specific test, createRootWithSettings
explicitly enables the restriction. Here, we change that in setup, and is an example of how consumers can override the default should they choose to.
@elasticmachine merge upstream |
/ci |
/ci |
@lukeelmers I've fleshed out the release note and double-checked that the UA work and KB article are in the meta issue. The plan is to merge the implementation and follow up with the UA hook once that's ready. |
@elasticmachine merge upstream |
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.
Great work @TinaHeiligers for chasing down all those test cases. Implementation of new default LGTM. Left some minor comments.
packages/core/http/core-http-server-internal/src/http_config.ts
Outdated
Show resolved
Hide resolved
@@ -82,6 +83,9 @@ describe('checking all opted-in dynamic config settings', () => { | |||
logging: { | |||
loggers: [{ name: 'root', level: 'info', appenders: ['console'] }], | |||
}, | |||
server: { | |||
restrictInternalApis: 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.
Should/do we have a task for updating these requests in the future or is the plan to leave them unrestricted in tests?
src/plugins/files/server/file_client/integration_tests/es_file_client.test.ts
Outdated
Show resolved
Hide resolved
@elasticmachine merge upstream |
The FTR test failure is unrelated to this PR: #194425 |
I've created #194675 to track the work for surfacing internal API usage in the UA. |
@elasticmachine merge upstream |
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.
Security changes LGTM.
💚 Build Succeeded
Metrics [docs]
History
To update your PR or re-run it, just comment with: |
fix #163654
This PR enforces internal API restrictions in our standard offering.
Internal APIs are subject to rapid change and are intentionally not public. By restricting their access, we protect consumers from these rapid changes.
This PR does not change any public APIs and they remain available for external consumption.
Note to reviewers:
I chose the most practical way of resolving the failures (add the header or disable the restriction).
Details
Requests to internal Kibana APIs will be restricted globally. This allows more flexibility in making breaking changes to internal APIs, without a risk to external consumers.
Why are we doing this?
The restriction is there to help mitigate the risk of breaking external integrations consuming APIs. Internal APIs are subject to frequent changes, necessary for feature development.
What this means to plugin authors :
Kibana core applies the restriction when enabled through HTTP config.
What this means to Kibana consumers:
Explicitly restricting access to internal APIs has advantages for external consumers:
KB article explaining the change (tracked as part of https://github.com/elastic/kibana-team/issues/1044)
Release note
Starting with this release, requests to internal Kibana APIs are globally restricted by default. This change is designed to provide more flexibility in making breaking changes to internal APIs while protecting external consumers from unexpected disruptions.
Key Changes:
• Internal API Access: External consumers no longer have access to Kibana’s internal APIs, which are now strictly reserved for internal development and subject to frequent changes. This helps ensure that external integrations only interact with stable, public APIs.
• Error Handling: When a request is made to an internal API without the proper internal identifier (header or query parameter), Kibana will respond with a 400 Bad Request error, indicating that the route exists but is not allowed under the current Kibana configuration.
How to test this
Running kibana
server.restrictInternalApis: true
inkibana.yml
curl request to get the config for 9.0:
The request should be successful.
curl:
The response should be an error similar to:
{"statusCode":400,"error":"Bad Request","message":"uri [/api/kibana/management/saved_objects/_bulk_get] with method [post] exists but is not available with the current configuration"}
Remove
server.restrictInternalApis
fromkibana.yml
or set it tofalse
.Repeat both curl requests above. Both should respond without an error.
Checklist
Delete any items that are not applicable to this PR.
Risk Matrix
internal
APIsinternal
APIs failFor maintainers