@newrelic/security-agent 0.0.8 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/lib/instrumentation-security/core/constants.js +2 -2
- package/lib/instrumentation-security/core/sec-trace.js +4 -1
- package/lib/instrumentation-security/core/sec-utils.js +4 -1
- package/lib/nr-security-agent/index.js +2 -2
- package/lib/nr-security-agent/lib/core/Policy.js +4 -1
- package/lib/nr-security-agent/lib/core/applicationinfo.js +1 -3
- package/lib/nr-security-agent/lib/core/commonUtils.js +21 -17
- package/lib/nr-security-agent/lib/core/connections/websocket/response/fuzz-request-handler.js +2 -2
- package/lib/nr-security-agent/lib/core/logging.js +10 -5
- package/lib/nr-security-agent/lib/core/sec-agent-constants.js +5 -4
- package/lib/nr-security-agent/lib/core/statusUtils.js +3 -2
- package/lib/nr-security-agent/resources/config.js +7 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
### v0.1.0
|
|
2
|
+
* Handling to use OS specific path separator.
|
|
3
|
+
* Functionality to create directories in windows environment.
|
|
4
|
+
* IAST support for windows.
|
|
5
|
+
* Log file permission fix.
|
|
1
6
|
### v0.0.8
|
|
2
7
|
* Handling for IP resolving to IPV4 as Node.js v17 and above no longer re-sorts results of IP address lookups and returns them as-is.
|
|
3
8
|
* Third Party Notices update
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
const AWS_LAMBDA_NODE_EXEC_ENV_IDENTIFIER = /^AWS_Lambda_nodejs.*$/g;
|
|
10
10
|
const AWS_EXECUTION_ENV_VAR = 'AWS_EXECUTION_ENV';
|
|
11
|
+
const sep = require('path').sep;
|
|
11
12
|
|
|
12
13
|
module.exports = {
|
|
13
14
|
|
|
@@ -33,7 +34,7 @@ module.exports = {
|
|
|
33
34
|
COLON: ':',
|
|
34
35
|
OPEN_PARANTHESIS: '(',
|
|
35
36
|
CLOSE_PARANTHESIS: ')',
|
|
36
|
-
SLASH:
|
|
37
|
+
SLASH: sep,
|
|
37
38
|
INCOMING_MSG: 'IncomingMessage',
|
|
38
39
|
OBJECT: 'object',
|
|
39
40
|
STRING: 'string',
|
|
@@ -59,7 +60,6 @@ module.exports = {
|
|
|
59
60
|
SLASHDOTDOT: '/..',
|
|
60
61
|
UNDEFINED: 'undefined',
|
|
61
62
|
SELF_FD_PATH: '/proc/self/fd/',
|
|
62
|
-
SLASH: '/',
|
|
63
63
|
CSEC_LAST_FUZZ_REQUEST_TIME: 'CSEC_LAST_FUZZ_REQUEST_TIME',
|
|
64
64
|
NR_CSEC_FUZZ_REQUEST_ID: 'nr-csec-fuzz-request-id',
|
|
65
65
|
|
|
@@ -6,7 +6,10 @@
|
|
|
6
6
|
const path = require('path');
|
|
7
7
|
const API = require("../../nr-security-api");
|
|
8
8
|
const NRAgent = API.getNRAgent();
|
|
9
|
-
|
|
9
|
+
let AGENT_DIR = path.join(__dirname, '../../');
|
|
10
|
+
if(process.platform == 'win32'){
|
|
11
|
+
AGENT_DIR = path.join(__dirname, "..\\..\\..\\");
|
|
12
|
+
}
|
|
10
13
|
const NR_LIB = '/newrelic/lib';
|
|
11
14
|
let LOAD_LIST;
|
|
12
15
|
const { IS_LAMBDA_ENV, LAMBDA_RUNTIME_DIR_VAR } = require('./constants');
|
|
@@ -10,8 +10,11 @@ const requestManager = require('./request-manager');
|
|
|
10
10
|
const routeManager = require('./route-manager');
|
|
11
11
|
const async_hooks = require('async_hooks');
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
let AGENT_DIR = path.join(__dirname, '../../');
|
|
14
14
|
|
|
15
|
+
if(process.platform == 'win32'){
|
|
16
|
+
AGENT_DIR = path.join(__dirname, "..\\..\\");
|
|
17
|
+
}
|
|
15
18
|
const NR_LIB = '/newrelic/lib';
|
|
16
19
|
|
|
17
20
|
const ANONYMOUS_FUNCTION = '<anonymous>';
|
|
@@ -18,12 +18,12 @@ const {
|
|
|
18
18
|
IS_LAMBDA_ENV,
|
|
19
19
|
AWS_LAMBDA_FUNCTION_NAME_ENV_IDENTIFIER,
|
|
20
20
|
LAMBDA_TASK_ROOT_ENV_IDENTIFIER,
|
|
21
|
-
LOG_MESSAGES } = njsAgentConstants;
|
|
21
|
+
LOG_MESSAGES, SLASH } = njsAgentConstants;
|
|
22
22
|
const commonUtils = require('./lib/core/commonUtils');
|
|
23
23
|
|
|
24
24
|
const { AGENT_DIR } = agentConfig;
|
|
25
25
|
// eslint-disable-next-line no-unused-vars
|
|
26
|
-
const DIR_IDENTIFIER =
|
|
26
|
+
const DIR_IDENTIFIER = SLASH;
|
|
27
27
|
const SPACE_CHARACTER = ' ';
|
|
28
28
|
// eslint-disable-next-line no-control-regex
|
|
29
29
|
const NULL_CHAR_REGEX = /\u0000/g;
|
|
@@ -61,7 +61,10 @@ function setPolicyData(data) {
|
|
|
61
61
|
|
|
62
62
|
// function to setup default policy provided in resources directory
|
|
63
63
|
function setDefaultPolicy() {
|
|
64
|
-
|
|
64
|
+
let default_policy_file = path.resolve(__dirname, '../../resources/default-policy.yaml');
|
|
65
|
+
if(process.platform == 'win32'){
|
|
66
|
+
default_policy_file = path.resolve(__dirname, '..\\..\\resources\\default-policy.yaml');
|
|
67
|
+
}
|
|
65
68
|
// Get document, or throw exception on error
|
|
66
69
|
try {
|
|
67
70
|
const default_policy = yaml.load(fs.readFileSync(default_policy_file, 'utf8'));
|
|
@@ -34,7 +34,7 @@ const SELF_PROC_DIR = '/proc/self';
|
|
|
34
34
|
const CGROUP_FILE_NAME = '/proc/self/cgroup';
|
|
35
35
|
const STAT = '/stat';
|
|
36
36
|
const CMD_LINE_FILE = '/cmdline';
|
|
37
|
-
const DIR_IDENTIFIER =
|
|
37
|
+
const DIR_IDENTIFIER = SLASH;
|
|
38
38
|
const NEW_LINE_SEPERATOR = '\n';
|
|
39
39
|
const CGROUP_FILE = '/cgroup';
|
|
40
40
|
const ESCAPED_DOT = '.';
|
|
@@ -440,8 +440,6 @@ function isK8S () {
|
|
|
440
440
|
|
|
441
441
|
function getHostName () {
|
|
442
442
|
try {
|
|
443
|
-
// const hostFile = fs.readFileSync("/etc/hostname");
|
|
444
|
-
// return hostFile.toString().trim();
|
|
445
443
|
return OS.hostname();
|
|
446
444
|
} catch (err) {
|
|
447
445
|
return EMPTY_STRING;
|
|
@@ -13,7 +13,7 @@ const OS = require('os');
|
|
|
13
13
|
const path = require('path');
|
|
14
14
|
const checkDiskSpace = require('check-disk-space').default;
|
|
15
15
|
const AgentStatus = require('../core/agent-status');
|
|
16
|
-
const { LOG_MESSAGES, CSEC_HOME } = require('./sec-agent-constants');
|
|
16
|
+
const { LOG_MESSAGES, CSEC_HOME, SLASH } = require('./sec-agent-constants');
|
|
17
17
|
|
|
18
18
|
const prettyBytes = require('pretty-bytes');
|
|
19
19
|
const njsAgentConstants = require('./sec-agent-constants');
|
|
@@ -120,15 +120,15 @@ function getOS () {
|
|
|
120
120
|
* Utility to create directories
|
|
121
121
|
*/
|
|
122
122
|
function createDirectories () {
|
|
123
|
-
createPathIfNotExist(`${CSEC_HOME}
|
|
124
|
-
createPathIfNotExist(`${CSEC_HOME}
|
|
125
|
-
createPathIfNotExist(`${CSEC_HOME}
|
|
126
|
-
createPathIfNotExist(`${CSEC_HOME}
|
|
127
|
-
createPathIfNotExist(`${CSEC_HOME}
|
|
128
|
-
createPathIfNotExist(`${CSEC_HOME}
|
|
129
|
-
createPathIfNotExist(`${CSEC_HOME}
|
|
123
|
+
createPathIfNotExist(`${CSEC_HOME}${SLASH}nr-security-home`);
|
|
124
|
+
createPathIfNotExist(`${CSEC_HOME}${SLASH}nr-security-home${SLASH}logs`);
|
|
125
|
+
createPathIfNotExist(`${CSEC_HOME}${SLASH}nr-security-home${SLASH}logs${SLASH}snapshots`);
|
|
126
|
+
createPathIfNotExist(`${CSEC_HOME}${SLASH}nr-security-home${SLASH}tmp`);
|
|
127
|
+
createPathIfNotExist(`${CSEC_HOME}${SLASH}nr-security-home${SLASH}tmp${SLASH}language-agent`);
|
|
128
|
+
createPathIfNotExist(`${CSEC_HOME}${SLASH}nr-security-home${SLASH}tmp${SLASH}language-agent${SLASH}${getUUID()}`);
|
|
129
|
+
createPathIfNotExist(`${CSEC_HOME}${SLASH}nr-security-home${SLASH}tmp${SLASH}language-agent${SLASH}${getUUID()}${SLASH}ds-tmp`);
|
|
130
130
|
try {
|
|
131
|
-
fs.chmodSync(`${CSEC_HOME}
|
|
131
|
+
fs.chmodSync(`${CSEC_HOME}${SLASH}nr-security-home`, 0o777);
|
|
132
132
|
} catch (error) {
|
|
133
133
|
}
|
|
134
134
|
}
|
|
@@ -254,14 +254,14 @@ function iastRestClientStatus () {
|
|
|
254
254
|
*/
|
|
255
255
|
function removeOlderSnapshots () {
|
|
256
256
|
try {
|
|
257
|
-
const basePath = njsAgentConstants.LOG_DIR + 'snapshots
|
|
257
|
+
const basePath = njsAgentConstants.LOG_DIR + 'snapshots'+ SLASH;
|
|
258
258
|
const directoryContent = fs.readdirSync(basePath);
|
|
259
259
|
const files = directoryContent.filter((filename) => {
|
|
260
|
-
return fs.statSync(`${basePath}
|
|
260
|
+
return fs.statSync(`${basePath}${SLASH}${filename}`).isFile();
|
|
261
261
|
});
|
|
262
262
|
const sorted = files.sort((a, b) => {
|
|
263
|
-
const firstStat = fs.statSync(`${basePath}
|
|
264
|
-
const secondStat = fs.statSync(`${basePath}
|
|
263
|
+
const firstStat = fs.statSync(`${basePath}${SLASH}${a}`);
|
|
264
|
+
const secondStat = fs.statSync(`${basePath}${SLASH}${b}`);
|
|
265
265
|
return new Date(secondStat.mtime).getTime() - new Date(firstStat.mtime).getTime();
|
|
266
266
|
});
|
|
267
267
|
for (let i = 99; i < sorted.length; i++) {
|
|
@@ -292,12 +292,12 @@ function removeOlderlogfiles () {
|
|
|
292
292
|
// eslint-disable-next-line array-callback-return
|
|
293
293
|
const files = directoryContent.filter((filename) => {
|
|
294
294
|
if (filename.match(backupLogFileRegex)) {
|
|
295
|
-
return fs.statSync(`${basePath}
|
|
295
|
+
return fs.statSync(`${basePath}${SLASH}${filename}`).isFile();
|
|
296
296
|
}
|
|
297
297
|
});
|
|
298
298
|
const sorted = files.sort((a, b) => {
|
|
299
|
-
const firstStat = fs.statSync(`${basePath}
|
|
300
|
-
const secondStat = fs.statSync(`${basePath}
|
|
299
|
+
const firstStat = fs.statSync(`${basePath}${SLASH}${a}`);
|
|
300
|
+
const secondStat = fs.statSync(`${basePath}${SLASH}${b}`);
|
|
301
301
|
return new Date(secondStat.mtime).getTime() - new Date(firstStat.mtime).getTime();
|
|
302
302
|
});
|
|
303
303
|
|
|
@@ -384,7 +384,11 @@ function getCSECmode(){
|
|
|
384
384
|
* @returns
|
|
385
385
|
*/
|
|
386
386
|
function getPathOfCACert(){
|
|
387
|
-
|
|
387
|
+
let relativePath = path.resolve(__dirname, '../../resources/cert.pem');
|
|
388
|
+
if(process.platform == 'win32'){
|
|
389
|
+
relativePath = path.resolve(__dirname, '..\\..\\resources\\cert.pem');
|
|
390
|
+
}
|
|
391
|
+
const certPath = NRAgent && NRAgent.config.security.ca_bundle_path ? NRAgent.config.security.ca_bundle_path : relativePath;
|
|
388
392
|
return certPath
|
|
389
393
|
}
|
|
390
394
|
|
package/lib/nr-security-agent/lib/core/connections/websocket/response/fuzz-request-handler.js
CHANGED
|
@@ -10,7 +10,7 @@ const restClient = require('../../restclient');
|
|
|
10
10
|
const { Agent } = require('../../../agent');
|
|
11
11
|
const { FuzzFailEvent } = require('../../../FuzzFailEvent');
|
|
12
12
|
const { hasWorker: isWorkerSupported } = require('../../../commonUtils');
|
|
13
|
-
const { CSEC_HOME_TMP, COLON, NR_CSEC_FUZZ_REQUEST_ID } = require('../../../sec-agent-constants');
|
|
13
|
+
const { CSEC_HOME_TMP, COLON, NR_CSEC_FUZZ_REQUEST_ID, SLASH } = require('../../../sec-agent-constants');
|
|
14
14
|
const LOCALHOST = 'localhost';
|
|
15
15
|
const COLON_SLASH_SLASH = '://';
|
|
16
16
|
const http = require('http');
|
|
@@ -24,7 +24,7 @@ const {
|
|
|
24
24
|
} = require('../../../sec-agent-constants');
|
|
25
25
|
const statusUtils = require('../../../statusUtils');
|
|
26
26
|
|
|
27
|
-
const find =
|
|
27
|
+
const find = `${SLASH}{{NR_CSEC_VALIDATOR_HOME_TMP}}`;
|
|
28
28
|
const CSEC_HOME_TMP_CONST = new RegExp(find, 'g');
|
|
29
29
|
|
|
30
30
|
let logger;
|
|
@@ -9,7 +9,6 @@ const fs = require('fs');
|
|
|
9
9
|
|
|
10
10
|
const log4js = require('log4js');
|
|
11
11
|
const { ENV: env } = require('../../resources/config');
|
|
12
|
-
const cp = require('child_process');
|
|
13
12
|
|
|
14
13
|
const INFO = 'info';
|
|
15
14
|
const LOG_FILE_SIZE = 50485760 * 10000;
|
|
@@ -17,11 +16,14 @@ const LOG_PATTERN_OBJ = {
|
|
|
17
16
|
type: 'pattern',
|
|
18
17
|
pattern: '%[%d[%p][%c][%h][%z]%] %m'
|
|
19
18
|
};
|
|
20
|
-
const {
|
|
19
|
+
const { LOG_DIR } = require('./sec-agent-constants');
|
|
21
20
|
let logger;
|
|
22
21
|
const API = require('../../../nr-security-api');
|
|
23
22
|
const NRAgent = API.getNRAgent();
|
|
24
23
|
|
|
24
|
+
const logFileName = `${LOG_DIR}node-security-collector.log`;
|
|
25
|
+
const initLogFileName = `${LOG_DIR}node-security-collector-init.log`;
|
|
26
|
+
|
|
25
27
|
function createLogPathIfNotExist (dir) {
|
|
26
28
|
try {
|
|
27
29
|
if (!fs.existsSync(dir)) {
|
|
@@ -57,9 +59,6 @@ function initialize (applicationUUID) {
|
|
|
57
59
|
} catch (error) {
|
|
58
60
|
}
|
|
59
61
|
|
|
60
|
-
const logFileName = `${LOG_DIR}node-security-collector.log`;
|
|
61
|
-
const initLogFileName = `${LOG_DIR}node-security-collector-init.log`;
|
|
62
|
-
|
|
63
62
|
Object.assign(appenders.NR_CSEC, {
|
|
64
63
|
filename: logFileName,
|
|
65
64
|
maxLogSize: LOG_FILE_SIZE,
|
|
@@ -143,6 +142,12 @@ function getLogger (applicationUUID = process.env.applicationUUID) {
|
|
|
143
142
|
initialize(applicationUUID);
|
|
144
143
|
logger = log4js.getLogger('NR_CSEC');
|
|
145
144
|
const initLogger = getInitLogger();
|
|
145
|
+
try {
|
|
146
|
+
fs.chmodSync(`${logFileName}`, 0o777);
|
|
147
|
+
fs.chmodSync(`${initLogFileName}`, 0o777);
|
|
148
|
+
} catch (error) {
|
|
149
|
+
logger.error("Error while setting up permissions on log files", error);
|
|
150
|
+
}
|
|
146
151
|
initLogger.info("[STEP-2] => Generating unique identifier:",applicationUUID )
|
|
147
152
|
if (NRAgent) {
|
|
148
153
|
setLevel(NRAgent.config.logging.level);
|
|
@@ -10,6 +10,7 @@ const AWS_EXECUTION_ENV_VAR = 'AWS_EXECUTION_ENV';
|
|
|
10
10
|
const path = require('path');
|
|
11
11
|
const API = require('../../../nr-security-api');
|
|
12
12
|
const NRAgent = API.getNRAgent();
|
|
13
|
+
const sep = require('path').sep;
|
|
13
14
|
|
|
14
15
|
let CSEC_HOME = NRAgent && NRAgent.config.newrelic_home ? NRAgent.config.newrelic_home : require('path').join(process.cwd());
|
|
15
16
|
const CSEC_GROUP_NAME = NRAgent ? NRAgent.config.security.mode : 'IAST';
|
|
@@ -19,11 +20,11 @@ const agentStartTime = new Date().toString();
|
|
|
19
20
|
module.exports = {
|
|
20
21
|
CSEC_HOME: CSEC_HOME,
|
|
21
22
|
CSEC_GROUP_NAME: CSEC_GROUP_NAME,
|
|
22
|
-
LOG_DIR: `${CSEC_HOME}
|
|
23
|
-
CSEC_HOME_TMP: `${CSEC_HOME}
|
|
23
|
+
LOG_DIR: `${CSEC_HOME}${sep}nr-security-home${sep}logs${sep}`,
|
|
24
|
+
CSEC_HOME_TMP: `${CSEC_HOME}${sep}nr-security-home${sep}tmp${sep}language-agent${sep}${process.env.applicationUUID}`,
|
|
24
25
|
AGENT_START_TIME: agentStartTime,
|
|
25
26
|
FRAMEWORK: '',
|
|
26
|
-
STATUS_LOG_FILE: `${CSEC_HOME}
|
|
27
|
+
STATUS_LOG_FILE: `${CSEC_HOME}${sep}nr-security-home${sep}logs${sep}snapshots${sep}node-security-collector-status-${process.env.applicationUUID}.log`,
|
|
27
28
|
|
|
28
29
|
DB_LIST: {
|
|
29
30
|
MYSQL: 'MYSQL',
|
|
@@ -83,7 +84,7 @@ module.exports = {
|
|
|
83
84
|
COLON: ':',
|
|
84
85
|
OPEN_PARANTHESIS: '(',
|
|
85
86
|
CLOSE_PARANTHESIS: ')',
|
|
86
|
-
SLASH:
|
|
87
|
+
SLASH: sep,
|
|
87
88
|
INCOMING_MSG: 'IncomingMessage',
|
|
88
89
|
OBJECT: 'object',
|
|
89
90
|
STRING: 'string',
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
/* eslint-disable new-cap */
|
|
7
7
|
|
|
8
8
|
const njsAgentConstants = require('./sec-agent-constants');
|
|
9
|
-
const
|
|
9
|
+
const agentConfig = require('../../resources/config');
|
|
10
|
+
const { AGENT_DIR } = agentConfig;
|
|
10
11
|
const lodash = require('lodash');
|
|
11
12
|
|
|
12
13
|
let errors = [];
|
|
@@ -26,7 +27,7 @@ const statusFile = njsAgentConstants.STATUS_LOG_FILE;
|
|
|
26
27
|
const statusTemplate = 'Snapshot timestamp: : %s\n' +
|
|
27
28
|
`CSEC Agent start timestamp: ${njsAgentConstants.AGENT_START_TIME} with application uuid:${commonUtils.getUUID()}\n` +
|
|
28
29
|
`SEC_HOME: ${njsAgentConstants.CSEC_HOME}\n` +
|
|
29
|
-
`Agent location: ${
|
|
30
|
+
`Agent location: ${AGENT_DIR}\n` +
|
|
30
31
|
`Using CSEC Agent for Node.js, Node version:${process.version}, PID:${process.pid}\n` +
|
|
31
32
|
`Process title: ${process.title}\n` +
|
|
32
33
|
`Process binary: ${process.execPath}\n` +
|
|
@@ -2,9 +2,15 @@
|
|
|
2
2
|
* Copyright 2023 New Relic Corporation. All rights reserved.
|
|
3
3
|
* SPDX-License-Identifier: New Relic Pre-Release
|
|
4
4
|
*/
|
|
5
|
+
const { platform } = require('os');
|
|
5
6
|
const path = require('path');
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
let AGENT_DIR = path.join(__dirname, '../../../');
|
|
9
|
+
|
|
10
|
+
if(process.platform == 'win32'){
|
|
11
|
+
AGENT_DIR = path.join(__dirname, "..\\..\\..\\");
|
|
12
|
+
}
|
|
13
|
+
|
|
8
14
|
const uuidv4 = require('uuid/v4');
|
|
9
15
|
process.env.applicationUUID = process.env.applicationUUID || uuidv4();
|
|
10
16
|
|