Skip to content
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

Move audit logs to a dedicated logs directory #116562

Merged
merged 8 commits into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ types.eslint.config.js
.eslintcache
/plugins/
/data
/logs
disabledPlugins
webpackstats.json
/config/*
Expand Down
2 changes: 1 addition & 1 deletion docs/settings/security-settings.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ For more details and a reference of audit events, refer to <<xpack-security-audi
xpack.security.audit.enabled: true
xpack.security.audit.appender: <1>
type: rolling-file
fileName: ./data/audit.log
fileName: ./logs/audit.log
policy:
type: time-interval
interval: 24h <2>
Expand Down
Empty file added logs/.empty
Empty file.
28 changes: 21 additions & 7 deletions packages/kbn-utils/src/path/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,35 @@
*/

import { accessSync, constants } from 'fs';
import { getConfigPath, getDataPath, getConfigDirectory } from './';
import { createAbsolutePathSerializer } from '@kbn/dev-utils';
import { getConfigPath, getDataPath, getLogsPath, getConfigDirectory } from './';

expect.addSnapshotSerializer(createAbsolutePathSerializer());

describe('Default path finder', () => {
it('should find a kibana.yml', () => {
const configPath = getConfigPath();
expect(() => accessSync(configPath, constants.R_OK)).not.toThrow();
it('should expose a path to the config directory', () => {
expect(getConfigDirectory()).toMatchInlineSnapshot('<absolute path>/config');
});

it('should find a data directory', () => {
const dataPath = getDataPath();
expect(() => accessSync(dataPath, constants.R_OK)).not.toThrow();
it('should expose a path to the kibana.yml', () => {
expect(getConfigPath()).toMatchInlineSnapshot('<absolute path>/config/kibana.yml');
});

it('should expose a path to the data directory', () => {
expect(getDataPath()).toMatchInlineSnapshot('<absolute path>/data');
});

it('should expose a path to the logs directory', () => {
expect(getLogsPath()).toMatchInlineSnapshot('<absolute path>/logs');
});

it('should find a config directory', () => {
const configDirectory = getConfigDirectory();
expect(() => accessSync(configDirectory, constants.R_OK)).not.toThrow();
});

it('should find a kibana.yml', () => {
const configPath = getConfigPath();
expect(() => accessSync(configPath, constants.R_OK)).not.toThrow();
});
});
8 changes: 8 additions & 0 deletions packages/kbn-utils/src/path/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const CONFIG_DIRECTORIES = [

const DATA_PATHS = [join(REPO_ROOT, 'data'), '/var/lib/kibana'].filter(isString);

const LOGS_PATHS = [join(REPO_ROOT, 'logs'), '/var/log/kibana'].filter(isString);

function findFile(paths: string[]) {
const availablePath = paths.find((configPath) => {
try {
Expand Down Expand Up @@ -57,6 +59,12 @@ export const getConfigDirectory = () => findFile(CONFIG_DIRECTORIES);
*/
export const getDataPath = () => findFile(DATA_PATHS);

/**
* Get the directory containing logs
* @internal
*/
export const getLogsPath = () => findFile(LOGS_PATHS);

export type PathConfigType = TypeOf<typeof config.schema>;

export const config = {
Expand Down
1 change: 1 addition & 0 deletions src/dev/build/tasks/clean_tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ export const CleanEmptyFolders: Task = {
await deleteEmptyFolders(log, build.resolvePath('.'), [
build.resolvePath('plugins'),
build.resolvePath('data'),
build.resolvePath('logs'),
]);
},
};
6 changes: 5 additions & 1 deletion src/dev/build/tasks/create_empty_dirs_and_files_task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export const CreateEmptyDirsAndFiles: Task = {
description: 'Creating some empty directories and files to prevent file-permission issues',

async run(config, log, build) {
await Promise.all([mkdirp(build.resolvePath('plugins')), mkdirp(build.resolvePath('data'))]);
await Promise.all([
mkdirp(build.resolvePath('plugins')),
mkdirp(build.resolvePath('data')),
mkdirp(build.resolvePath('logs')),
]);
},
};
3 changes: 3 additions & 0 deletions src/dev/build/tasks/os_packages/run_fpm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ export async function runFpm(
// copy the data directory at /var/lib/kibana
`${resolveWithTrailingSlash(fromBuild('data'))}=/var/lib/kibana/`,

// copy the logs directory at /var/log/kibana
Copy link
Member

@jbudz jbudz Nov 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add an '--exclude', usr/share/kibana/logs, a few lines up so we don't copy the .gitempty/folder over twice?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 👍

`${resolveWithTrailingSlash(fromBuild('logs'))}=/var/log/kibana/`,

// copy package configurations
`${resolveWithTrailingSlash(__dirname, 'service_templates/systemd/')}=/`,

Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/security/server/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jest.mock('crypto', () => ({
}));

jest.mock('@kbn/utils', () => ({
getDataPath: () => '/mock/kibana/data/path',
getLogsPath: () => '/mock/kibana/logs/path',
}));

import { loggingSystemMock } from 'src/core/server/mocks';
Expand Down Expand Up @@ -1720,7 +1720,7 @@ describe('createConfig()', () => {
).audit.appender
).toMatchInlineSnapshot(`
Object {
"fileName": "/mock/kibana/data/path/audit.log",
"fileName": "/mock/kibana/logs/path/audit.log",
"layout": Object {
"type": "json",
},
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/security/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import path from 'path';
import type { Type, TypeOf } from '@kbn/config-schema';
import { schema } from '@kbn/config-schema';
import { i18n } from '@kbn/i18n';
import { getDataPath } from '@kbn/utils';
import { getLogsPath } from '@kbn/utils';
import type { AppenderConfigType, Logger } from 'src/core/server';

import { config as coreConfig } from '../../../../src/core/server';
Expand Down Expand Up @@ -378,7 +378,7 @@ export function createConfig(
config.audit.appender ??
({
type: 'rolling-file',
fileName: path.join(getDataPath(), 'audit.log'),
fileName: path.join(getLogsPath(), 'audit.log'),
layout: {
type: 'json',
},
Expand Down