elastic / kibana

Your window into the Elastic Stack
https://www.elastic.co/products/kibana
Other
19.76k stars 8.16k forks source link

[Fleet] "registryProxyUrl" is not allowed to be empty #137335

Open slhck opened 2 years ago

slhck commented 2 years ago

Kibana version: 8.3.2

Elasticsearch version: 8.3.2

Server OS version: Ubuntu Linux 18.04.6

Browser version: Google Chrome 103.0.5060.134

Browser OS version: macOS 11

Original install method (e.g. download page, yum, from source, etc.): Docker images

Describe the bug:

I have a Docker-based ELK stack that runs in different environments (e.g., on-premise or in the cloud).

Depending on whether the server requires a proxy or not, I want to be able to set the proxy variable through environment variables. This works when I specify the variable explicitly, but when it is an empty string, an error is shown.

For example, assuming the Kibana config:

xpack.fleet.registryProxyUrl: "${KIBANA_PROXY_URL}"

When I launch the Docker container in Docker Compose with:

kibana:
  environment:
    KIBANA_PROXY_URL: ${KIBANA_PROXY_URL:-}

The error I get from Kibana is:

Error: [config validation of [xpack.fleet].registryProxyUrl]: "registryProxyUrl" is not allowed to be empty

When I try to pass an empty string, by changing the Kibana config to:

xpack.fleet.registryProxyUrl: "${KIBANA_PROXY_URL:-}"

I get this error instead:

Error: [config validation of [xpack.fleet].registryProxyUrl]: expected URI with scheme [http|https].

This is a bit of a conundrum. It seems it should be possible for this configuration variable to be either one of the following:

In particular, looking at how the URL is actually used, this check here would ensure that an empty string causes the URL to be ignored:

https://github.com/elastic/kibana/blob/ba8c339d84c1d26441f049650296ab4072147128/x-pack/plugins/fleet/server/services/epm/registry/requests.ts#L100-L102

Allowing the variable to be empty would make it possible to have the same base configuration but populate it differently depending on the environment.

slhck commented 2 years ago

I realize now that if I set XPACK_FLEET_REGISTRYPROXYURL via an .env file (or not), I can achieve the same thing.

Just wondering if it's intended for the URL to be parsed that strictly. Feel free to close this issue otherwise!

elasticmachine commented 2 years ago

Pinging @elastic/fleet (Team:Fleet)

kpollich commented 2 years ago

This seems like maybe a lapse in the behavior of the Kibana config SDL, or perhaps Fleet's usage of it - https://github.com/elastic/kibana/tree/main/packages/kbn-config-schema.

Fleet defines the registryProxyUrl config value using Kibana's provided .maybe utility here:

https://github.com/elastic/kibana/blob/db882a06d689c94d68ffce66d69e9533c2fb24f6/x-pack/plugins/fleet/server/config.ts#L102

I think we could potentially get around the issue where an explicitly provided empty string is considered invalid by passing something like defaultValue: "" or explore using nullable instead of maybe in our validation schema.

I'll keep this issue open and toss it on the Fleet backlog, as I think it's probably worth improving the ergonomics here. However, since there's a workaround here using the specific environment variable, we'll consider this low priority.

Thanks for filing this, @slhck!