-
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
[Saved Objects] Adds config flag to toggle hiddenFromHttpApis SO types conditionally #151512
[Saved Objects] Adds config flag to toggle hiddenFromHttpApis SO types conditionally #151512
Conversation
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 on draft
@@ -42,6 +42,8 @@ export const savedObjectsMigrationConfig: ServiceConfigDescriptor<SavedObjectsMi | |||
const soSchema = schema.object({ | |||
maxImportPayloadBytes: schema.byteSize({ defaultValue: 26_214_400 }), | |||
maxImportExportSize: schema.number({ defaultValue: 10_000 }), | |||
// Conditionally set within config, dependening on the env. In prod: allow all access(default), in dev: false | |||
allowHttpApiAccess: 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.
I've gone with defaulting to the "old" behavior where all visible types (those not hidden) use the HTTP APIs. We also need to allow access for self-managed & current cloud offering & cloud 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.
Is there a specific reason to depend on the environment and not distribution?
Instead of doing the override logic between the config and the env inside the code and having to inject the env into the classes, why not just do it from the config defaults here (like the example below). This makes the logic a lot more resilient and easier to understand. wdyt?
schema.conditional(
schema.contextRef('dist'),
true,
schema.boolean({ defaultValue: false }),
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.
Is there a specific reason to depend on the environment and not distribution?
I didn't think to use the distro rather, great idea thanks!
I'll change it and see how it improves the logic.
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.
@Bamieh I've made the change you requested in 96bb95a
(#151512).
Could you take another look, please?
public migration: SavedObjectsMigrationConfigType; | ||
|
||
constructor( | ||
rawConfig: SavedObjectsConfigType, | ||
rawMigrationConfig: SavedObjectsMigrationConfigType | ||
rawMigrationConfig: SavedObjectsMigrationConfigType, | ||
allowHttpApiAccess: boolean |
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.
Naming is hard and hideFromHttpApis
or denyHttpApiAccess
sound rather negative, hence the more "positive" choice.
this.config = new SavedObjectConfig( | ||
savedObjectsConfig, | ||
savedObjectsMigrationConfig, | ||
this.allowHttpApiAccess |
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.
I need to inject if Kibana's running in dev or prod mode from env
and set the new config options from within the SO service to avoid instantiating SavedObjectConfig with:
new SavedObjectConfig(savedObjectsConfig, savedObjectsMigrationConfig, coreContext.env.mode.prod)
let savedObjectsClient: ReturnType<typeof savedObjectsClientMock.create>; | ||
let coreUsageStatsClient: jest.Mocked<ICoreUsageStatsClient>; | ||
|
||
beforeEach(async () => { |
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.
This test and the others in the same folder test the route behavior in a "dev" environment, were we enforce API blocking.
They're verbose to setup (copies of the main route api_integration tests) and ideally should be condensed. I tried but haven't been able to just yet.
|
||
import { SavedObjectConfig } from '@kbn/core-saved-objects-base-server-internal'; | ||
|
||
export function setupConfig(allowAccess: boolean = 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.
Strictly not necessary but I'm reusing the util in almost all the route's tests
@@ -139,6 +139,7 @@ kibana_vars=( | |||
regionmap | |||
savedObjects.maxImportExportSize | |||
savedObjects.maxImportPayloadBytes | |||
savedObjects.allowHttpApiAccess |
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.
New SO config option
Pinging @elastic/kibana-core (Team:Core) |
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.
kibana-docker
@elasticmachine merge upstream |
@rudolf I added you as a reviewer since Pierre is out. Could you 👁️ when you get a chance? cc @jloleysens |
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.
i have a couple of comments/questions
await server.stop(); | ||
}); | ||
|
||
it('returns with status 400 when a type is hidden from the HTTP APIs', async () => { |
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('returns with status 400 when a type is hidden from the HTTP APIs', async () => { | |
it('returns with status 200 when a type is hidden from the HTTP APIs', async () => { |
await server.stop(); | ||
}); | ||
|
||
it('returns with status 200 when a type is hidden from the HTTP APIs', async () => { |
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.
nit: these tests have inconsistent names across the different methods
uses config option allowHttpApiAccess to grant hiddenFromHttpApis types access
vs returns with status 200 when a type is hidden from the HTTP APIs
I prefer the latter
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.
@rudolf change is made: 75e11c7
(#151512)
@elasticmachine merge upstream |
💚 Build Succeeded
Metrics [docs]Public APIs missing comments
Unknown metric groupsAPI count
History
To update your PR or re-run it, just comment with: |
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.
LGTM
Fix #150471
Part of #149287
This PR adds a config option to set if the Saved Objects HTTP APIs should be accessible to types registered with
hiddenFromHttpApis: true
.allowHttpApiAccess: true
--------> grants accessallowHttpApiAccess: false
--------> throws in Saved Objects HTTP APIsallowHttpApiAccess
can be configured inkibana.yml
but we don't plan to document the option as it is not intended for public use.The configuration prevents immediate breaking changes caused by saved objects adopting the option to be hidden from the HTTP APIs and is a stepping stone toward removing the Saved Objects HTTP APIs.
The option is only applicable to saved objects registered as
hiddenFromHttpApis:true
.Checklist
Risk Matrix
For maintainers
How to test this
Ensure that
allowHttpApiAccess
can be set inkibana.yml
to override the default:Add the following debug log line to the SavedObjectsService setup contract after the
config
is set:log config value
Configure logging to include the saved objects service logs:
For example:
kibana.yml
Start kibana (any version of es is fine) and ensure that
allowHttpApiAccess
is set. For example, when run from dev the log should read something like:SAVED_OBJECTS_SERVICE--[2023-02-21T12:06:28.561-07:00][DEBUG][savedobjects-service]---SavedObjects default allowHttpApiAccess configuration: false
In
kibana.yml
, specifically setsavedObjects.allowHttpApiAccess: true
and recheck the logs. Using the same logging config as above, the log line should now read:SAVED_OBJECTS_SERVICE--[2023-02-21T12:06:28.561-07:00][DEBUG][savedobjects-service]---SavedObjects default allowHttpApiAccess configuration: true