Cannot create a fleet policy without specifying package_policies in Kibana.yml

Hello,

I'm doing some tests to try to create a docker compose that would spin up a quick cluster to be used as development and for this I want to have 2 fleet policies in kibana.yml.

One would be the fleet server policy and this seems to work without any issue, the other policy would be a empty policy to be used as the default agent policy, this policy would have no integrations, it is just to enroll the agents that would be moved to other policies.

The documentation says that package_policies is an optional setting.

The only required settings are id and name, so I would expect to be able to create a policy specifying just the id and name in kibana.yml.

I have this in my kibana.yml.

xpack.fleet.packages:
  - name: fleet_server
    version: latest
xpack.fleet.agentPolicies:
  - name: fleet-server-policy
    id: fleet-server-policy
    is_default_fleet_server: true
    is_managed: false
    namespace: default
    package_policies:
      - name: fleet-server
        package:
          name: fleet_server
  - name: agent-policy
    id: agent-default-policy
    namespace: default

And when trying to start it, I got a FATAL error regarding the missing package_policies in the second policy defined in kibana.yml.

kibana           | [2024-05-01T01:19:37.859+00:00][INFO ][root] Kibana is shutting down
kibana           | [2024-05-01T01:19:37.861+00:00][FATAL][root] Reason: [config validation of [xpack.fleet].agentPolicies.1.package_policies]: expected value of type [array] but got [undefined]
kibana           | Error: [config validation of [xpack.fleet].agentPolicies.1.package_policies]: expected value of type [array] but got [undefined]
kibana           |     at ObjectType.validate (/usr/share/kibana/node_modules/@kbn/config-schema/src/types/type.js:91:13)
kibana           |     at ConfigService.validateAtPath (/usr/share/kibana/node_modules/@kbn/config/src/config_service.js:252:19)
kibana           |     at /usr/share/kibana/node_modules/@kbn/config/src/config_service.js:262:204
kibana           |     at /usr/share/kibana/node_modules/rxjs/dist/cjs/internal/operators/map.js:10:37
kibana           |     at OperatorSubscriber._this._next (/usr/share/kibana/node_modules/rxjs/dist/cjs/internal/operators/OperatorSubscriber.js:33:21)
kibana           |     at OperatorSubscriber.Subscriber.next (/usr/share/kibana/node_modules/rxjs/dist/cjs/internal/Subscriber.js:51:18)
kibana           |     at /usr/share/kibana/node_modules/rxjs/dist/cjs/internal/operators/distinctUntilChanged.js:18:28
kibana           |     at OperatorSubscriber._this._next (/usr/share/kibana/node_modules/rxjs/dist/cjs/internal/operators/OperatorSubscriber.js:33:21)
kibana           |     at OperatorSubscriber.Subscriber.next (/usr/share/kibana/node_modules/rxjs/dist/cjs/internal/Subscriber.js:51:18)
kibana           |     at /usr/share/kibana/node_modules/rxjs/dist/cjs/internal/operators/map.js:10:24
kibana           |     at OperatorSubscriber._this._next (/usr/share/kibana/node_modules/rxjs/dist/cjs/internal/operators/OperatorSubscriber.js:33:21)
kibana           |     at OperatorSubscriber.Subscriber.next (/usr/share/kibana/node_modules/rxjs/dist/cjs/internal/Subscriber.js:51:18)
kibana           |     at ReplaySubject._subscribe (/usr/share/kibana/node_modules/rxjs/dist/cjs/internal/ReplaySubject.js:54:24)
kibana           |     at ReplaySubject.Observable._trySubscribe (/usr/share/kibana/node_modules/rxjs/dist/cjs/internal/Observable.js:41:25)
kibana           |     at ReplaySubject.Subject._trySubscribe (/usr/share/kibana/node_modules/rxjs/dist/cjs/internal/Subject.js:123:47)
kibana           |     at /usr/share/kibana/node_modules/rxjs/dist/cjs/internal/Observable.js:35:31
kibana           |     at Object.errorContext (/usr/share/kibana/node_modules/rxjs/dist/cjs/internal/util/errorContext.js:22:9)
kibana           |     at ReplaySubject.Observable.subscribe (/usr/share/kibana/node_modules/rxjs/dist/cjs/internal/Observable.js:26:24)
kibana           |     at /usr/share/kibana/node_modules/rxjs/dist/cjs/internal/operators/share.js:65:18
kibana           |     at OperatorSubscriber.<anonymous> (/usr/share/kibana/node_modules/rxjs/dist/cjs/internal/util/lift.js:14:28)
kibana           |     at /usr/share/kibana/node_modules/rxjs/dist/cjs/internal/Observable.js:30:30
kibana           |     at Object.errorContext (/usr/share/kibana/node_modules/rxjs/dist/cjs/internal/util/errorContext.js:22:9)
kibana           |     at Observable.subscribe (/usr/share/kibana/node_modules/rxjs/dist/cjs/internal/Observable.js:26:24)
kibana           |     at /usr/share/kibana/node_modules/rxjs/dist/cjs/internal/operators/map.js:9:16
kibana           |     at OperatorSubscriber.<anonymous> (/usr/share/kibana/node_modules/rxjs/dist/cjs/internal/util/lift.js:14:28)
kibana           |     at /usr/share/kibana/node_modules/rxjs/dist/cjs/internal/Observable.js:30:30
kibana           |     at Object.errorContext (/usr/share/kibana/node_modules/rxjs/dist/cjs/internal/util/errorContext.js:22:9)
kibana           |     at Observable.subscribe (/usr/share/kibana/node_modules/rxjs/dist/cjs/internal/Observable.js:26:24)
kibana           |     at /usr/share/kibana/node_modules/rxjs/dist/cjs/internal/operators/distinctUntilChanged.js:13:16
kibana           |     at OperatorSubscriber.<anonymous> (/usr/share/kibana/node_modules/rxjs/dist/cjs/internal/util/lift.js:14:28)
kibana           |     at /usr/share/kibana/node_modules/rxjs/dist/cjs/internal/Observable.js:30:30
kibana           |     at Object.errorContext (/usr/share/kibana/node_modules/rxjs/dist/cjs/internal/util/errorContext.js:22:9)
kibana           |     at Observable.subscribe (/usr/share/kibana/node_modules/rxjs/dist/cjs/internal/Observable.js:26:24)
kibana           |     at /usr/share/kibana/node_modules/rxjs/dist/cjs/internal/operators/map.js:9:16
kibana           |     at OperatorSubscriber.<anonymous> (/usr/share/kibana/node_modules/rxjs/dist/cjs/internal/util/lift.js:14:28)
kibana           |     at /usr/share/kibana/node_modules/rxjs/dist/cjs/internal/Observable.js:30:30
kibana           |     at Object.errorContext (/usr/share/kibana/node_modules/rxjs/dist/cjs/internal/util/errorContext.js:22:9)
kibana           |     at Observable.subscribe (/usr/share/kibana/node_modules/rxjs/dist/cjs/internal/Observable.js:26:24)
kibana           |     at /usr/share/kibana/node_modules/rxjs/dist/cjs/internal/operators/take.js:13:20
kibana           |     at OperatorSubscriber.<anonymous> (/usr/share/kibana/node_modules/rxjs/dist/cjs/internal/util/lift.js:14:28)
kibana           |     at /usr/share/kibana/node_modules/rxjs/dist/cjs/internal/Observable.js:30:30
kibana           |     at Object.errorContext (/usr/share/kibana/node_modules/rxjs/dist/cjs/internal/util/errorContext.js:22:9)
kibana           |     at Observable.subscribe (/usr/share/kibana/node_modules/rxjs/dist/cjs/internal/Observable.js:26:24)
kibana           |     at /usr/share/kibana/node_modules/rxjs/dist/cjs/internal/operators/throwIfEmpty.js:11:16
kibana           |     at SafeSubscriber.<anonymous> (/usr/share/kibana/node_modules/rxjs/dist/cjs/internal/util/lift.js:14:28)
kibana           |     at /usr/share/kibana/node_modules/rxjs/dist/cjs/internal/Observable.js:30:30
kibana           |     at Object.errorContext (/usr/share/kibana/node_modules/rxjs/dist/cjs/internal/util/errorContext.js:22:9)
kibana           |     at Observable.subscribe (/usr/share/kibana/node_modules/rxjs/dist/cjs/internal/Observable.js:26:24)
kibana           |     at /usr/share/kibana/node_modules/rxjs/dist/cjs/internal/Observable.js:86:19
kibana           |     at new Promise (<anonymous>)
kibana           | 
kibana           |  FATAL  Error: [config validation of [xpack.fleet].agentPolicies.1.package_policies]: expected value of type [array] but got [undefined]

Why is this failing if package_policies is an optional settings? I'm able to create an empty policy on Fleet UI, but not through kibana.yml.

This seems to be a bug.

EDIT:

Opened an issue: Optional setting for Preconfigured fleet policy in kibana.yml is being required by the config validator resulting in Kibana not starting · Issue #182213 · elastic/kibana · GitHub

Thanks for raising the issue, we will fix it soon.