|
7 | 7 |
|
8 | 8 | import crypto from 'crypto'; |
9 | 9 | import type { Duration } from 'moment'; |
| 10 | +import path from 'path'; |
10 | 11 |
|
11 | 12 | import type { Type, TypeOf } from '@kbn/config-schema'; |
12 | 13 | import { schema } from '@kbn/config-schema'; |
13 | 14 | import { i18n } from '@kbn/i18n'; |
| 15 | +import { getDataPath } from '@kbn/utils'; |
14 | 16 | import type { Logger } from 'src/core/server'; |
15 | 17 |
|
16 | 18 | import { config as coreConfig } from '../../../../src/core/server'; |
@@ -272,30 +274,21 @@ export const ConfigSchema = schema.object({ |
272 | 274 | schemes: schema.arrayOf(schema.string(), { defaultValue: ['apikey', 'bearer'] }), |
273 | 275 | }), |
274 | 276 | }), |
275 | | - audit: schema.object( |
276 | | - { |
277 | | - enabled: schema.boolean({ defaultValue: false }), |
278 | | - appender: schema.maybe(coreConfig.logging.appenders), |
279 | | - ignore_filters: schema.maybe( |
280 | | - schema.arrayOf( |
281 | | - schema.object({ |
282 | | - actions: schema.maybe(schema.arrayOf(schema.string(), { minSize: 1 })), |
283 | | - categories: schema.maybe(schema.arrayOf(schema.string(), { minSize: 1 })), |
284 | | - types: schema.maybe(schema.arrayOf(schema.string(), { minSize: 1 })), |
285 | | - outcomes: schema.maybe(schema.arrayOf(schema.string(), { minSize: 1 })), |
286 | | - spaces: schema.maybe(schema.arrayOf(schema.string(), { minSize: 1 })), |
287 | | - }) |
288 | | - ) |
289 | | - ), |
290 | | - }, |
291 | | - { |
292 | | - validate: (auditConfig) => { |
293 | | - if (auditConfig.ignore_filters && !auditConfig.appender) { |
294 | | - return 'xpack.security.audit.ignore_filters can only be used with the ECS audit logger. To enable the ECS audit logger, specify where you want to write the audit events using xpack.security.audit.appender.'; |
295 | | - } |
296 | | - }, |
297 | | - } |
298 | | - ), |
| 277 | + audit: schema.object({ |
| 278 | + enabled: schema.boolean({ defaultValue: false }), |
| 279 | + appender: schema.maybe(coreConfig.logging.appenders), |
| 280 | + ignore_filters: schema.maybe( |
| 281 | + schema.arrayOf( |
| 282 | + schema.object({ |
| 283 | + actions: schema.maybe(schema.arrayOf(schema.string(), { minSize: 1 })), |
| 284 | + categories: schema.maybe(schema.arrayOf(schema.string(), { minSize: 1 })), |
| 285 | + types: schema.maybe(schema.arrayOf(schema.string(), { minSize: 1 })), |
| 286 | + outcomes: schema.maybe(schema.arrayOf(schema.string(), { minSize: 1 })), |
| 287 | + spaces: schema.maybe(schema.arrayOf(schema.string(), { minSize: 1 })), |
| 288 | + }) |
| 289 | + ) |
| 290 | + ), |
| 291 | + }), |
299 | 292 | }); |
300 | 293 |
|
301 | 294 | export function createConfig( |
@@ -382,8 +375,32 @@ export function createConfig( |
382 | 375 | sortedProviders.filter(({ type, name }) => providers[type]?.[name].showInSelector).length > |
383 | 376 | 1; |
384 | 377 |
|
| 378 | + const auditLoggingEnabled = config.audit.enabled === true; |
| 379 | + const appender = |
| 380 | + config.audit.appender ?? auditLoggingEnabled |
| 381 | + ? { |
| 382 | + type: 'rolling-file', |
| 383 | + fileName: path.join(getDataPath(), 'audit.log'), |
| 384 | + layout: { |
| 385 | + type: 'json', |
| 386 | + }, |
| 387 | + policy: { |
| 388 | + type: 'time-interval', |
| 389 | + interval: schema.duration().validate('24h'), |
| 390 | + }, |
| 391 | + strategy: { |
| 392 | + type: 'numeric', |
| 393 | + max: 10, |
| 394 | + }, |
| 395 | + } |
| 396 | + : undefined; |
| 397 | + |
385 | 398 | return { |
386 | 399 | ...config, |
| 400 | + audit: { |
| 401 | + ...config.audit, |
| 402 | + appender, |
| 403 | + }, |
387 | 404 | authc: { |
388 | 405 | selector: { ...config.authc.selector, enabled: isLoginSelectorEnabled }, |
389 | 406 | providers, |
|
0 commit comments