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

fix: Updated Permissions on files/directory created by security agent. #176

Merged
merged 2 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions lib/instrumentation-security/core/sec-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,11 @@ function getExecutionId(){
function createPathIfNotExist (dir) {
try {
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, 777, { recursive: true });
fs.mkdirSync(dir, 770, { recursive: true });
logger.info(dir + ' Created');
fs.chmodSync(dir, 0o777);
fs.chmodSync(dir, 0o770);
} else {
fs.chmodSync(dir, 0o777);
fs.chmodSync(dir, 0o770);
logger.debug(dir + ' Already Exists');
}
} catch (error) {
Expand Down
8 changes: 4 additions & 4 deletions lib/nr-security-agent/lib/core/commonUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ function runtimeSupportsAsyncFunctionGenerators() {
function createPathIfNotExist(dir) {
try {
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, 777, { recursive: true });
fs.mkdirSync(dir, 770, { recursive: true });
logger.info(dir + ' Created');
fs.chmodSync(dir, 0o777);
fs.chmodSync(dir, 0o770);
} else {
fs.chmodSync(dir, 0o777);
fs.chmodSync(dir, 0o770);
logger.debug(dir + ' Already Exists');
}
} catch (error) {
Expand Down Expand Up @@ -139,7 +139,7 @@ function createDirectories() {
createPathIfNotExist(`${CSEC_HOME}${SLASH}nr-security-home${SLASH}tmp${SLASH}language-agent${SLASH}${getUUID()}`);
createPathIfNotExist(`${CSEC_HOME}${SLASH}nr-security-home${SLASH}tmp${SLASH}language-agent${SLASH}${getUUID()}${SLASH}ds-tmp`);
try {
fs.chmodSync(`${CSEC_HOME}${SLASH}nr-security-home`, 0o777);
fs.chmodSync(`${CSEC_HOME}${SLASH}nr-security-home`, 0o770);
} catch (error) {
}
}
Expand Down
10 changes: 5 additions & 5 deletions lib/nr-security-agent/lib/core/logging.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ const CSEC_ROOT = `${CSEC_HOME}${sep}nr-security-home${sep}`;
function createLogPathIfNotExist(dir) {
try {
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, 777, { recursive: true });
fs.chmodSync(dir, 0o777);
fs.mkdirSync(dir, 770, { recursive: true });
fs.chmodSync(dir, 0o770);
}
else {
fs.chmodSync(dir, 0o777);
fs.chmodSync(dir, 0o770);
}
} catch (error) {
}
Expand Down Expand Up @@ -168,8 +168,8 @@ function getLogger(applicationUUID = process.env.applicationUUID) {
logger = log4js.getLogger('NR_CSEC');
const initLogger = getInitLogger();
try {
fs.chmodSync(`${logFileName}`, 0o777);
fs.chmodSync(`${initLogFileName}`, 0o777);
fs.chmodSync(`${logFileName}`, 0o660);
fs.chmodSync(`${initLogFileName}`, 0o660);
} catch (error) {
}
initLogger.info("[STEP-2] => Generating unique identifier:", applicationUUID)
Expand Down
4 changes: 2 additions & 2 deletions lib/nr-security-agent/lib/core/statusUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ function getFormattedData() {
function writeSnapshot() {
const snapshot = getFormattedData();
commonUtils.removeOlderSnapshots();
fs.writeFile(statusFile, snapshot, { mode: 0o777 }, function (err) {
fs.writeFile(statusFile, snapshot, { mode: 0o660 }, function (err) {
if (err) {
logger.debug(err.message);
const LogMessage = require('./LogMessage');
const logMessage = new LogMessage.logMessage("SEVERE", 'Error in creating snapshot file', __filename, err);
commonUtils.addLogEventtoBuffer(logMessage);
} else {
logger.info('Snapshot updated to file: %s', statusFile);
fs.chmod(statusFile, 0o777, (err) => {
fs.chmod(statusFile, 0o660, (err) => {
if (err) {
addErrortoBuffer(err);
}
Expand Down
Loading