openvibers/openvibe.host Commits
shots: hand the capture folder to ovcheck (#294)
Changes
@@@ -18,7 +18,7 @@* Only public pages are captured: the origins come from the inventory, and a page that is not a* path of a public site is refused before Chrome starts.*/--const { spawn } = require('child_process');++const { spawn, execFileSync } = require('child_process');const crypto = require('crypto');const fs = require('fs');const os = require('os');@@@ -74,6 +74,19 @@ function captureWithChrome(targets, { asUser = 'ovcheck', home = '/var/lib/ovcheconst outDir = path.join(dir, 'png');fs.mkdirSync(outDir, { recursive: true });fs.writeFileSync(targetsFile, JSON.stringify(targets));++ // Chrome runs as asUser, and mkdtemp made the folder root's own (0700): hand the folder to that account,++ // still 0700, so it can read the targets and write the PNGs; root reads them back, nobody else can.++ if (asUser && process.getuid && process.getuid() === 0) {++ try {++ const ids = (flag) => Number(String(execFileSync('id', [flag, asUser])).trim());++ const uid = ids('-u'), gid = ids('-g');++ for (const p of [dir, targetsFile, outDir]) fs.chownSync(p, uid, gid);++ } catch (e) {++ fs.rmSync(dir, { recursive: true, force: true });++ resolve({ shots: [], error: `cannot hand the capture folder to ${asUser}: ${e.message}` });++ return;++ }++ }const argv = [SCRIPT, '--targets', targetsFile, '--out', outDir];const child = asUser? spawnFn('runuser', ['-u', asUser, '--', 'env', `HOME=${home || '/tmp'}`, process.execPath, ...argv], { stdio: ['ignore', 'pipe', 'pipe'] })
@@ -18,7 +18,7 @@
@@ -18,7 +18,7 @@
* Only public pages are captured: the origins come from the inventory, and a page that is not a
* Only public pages are captured: the origins come from the inventory, and a page that is not a
* path of a public site is refused before Chrome starts.
* path of a public site is refused before Chrome starts.
*/
*/
-const { spawn } = require('child_process');
+const { spawn, execFileSync } = require('child_process');
const crypto = require('crypto');
const crypto = require('crypto');
const fs = require('fs');
const fs = require('fs');
const os = require('os');
const os = require('os');
@@ -74,6 +74,19 @@ function captureWithChrome(targets, { asUser = 'ovcheck', home = '/var/lib/ovche
@@ -74,6 +74,19 @@ function captureWithChrome(targets, { asUser = 'ovcheck', home = '/var/lib/ovche
const outDir = path.join(dir, 'png');
const outDir = path.join(dir, 'png');
fs.mkdirSync(outDir, { recursive: true });
fs.mkdirSync(outDir, { recursive: true });
fs.writeFileSync(targetsFile, JSON.stringify(targets));
fs.writeFileSync(targetsFile, JSON.stringify(targets));
+ // Chrome runs as asUser, and mkdtemp made the folder root's own (0700): hand the folder to that account,
+ // still 0700, so it can read the targets and write the PNGs; root reads them back, nobody else can.
+ if (asUser && process.getuid && process.getuid() === 0) {
+ try {
+ const ids = (flag) => Number(String(execFileSync('id', [flag, asUser])).trim());
+ const uid = ids('-u'), gid = ids('-g');
+ for (const p of [dir, targetsFile, outDir]) fs.chownSync(p, uid, gid);
+ } catch (e) {
+ fs.rmSync(dir, { recursive: true, force: true });
+ resolve({ shots: [], error: `cannot hand the capture folder to ${asUser}: ${e.message}` });
+ return;
+ }
+ }
const argv = [SCRIPT, '--targets', targetsFile, '--out', outDir];
const argv = [SCRIPT, '--targets', targetsFile, '--out', outDir];
const child = asUser
const child = asUser
? spawnFn('runuser', ['-u', asUser, '--', 'env', `HOME=${home || '/tmp'}`, process.execPath, ...argv], { stdio: ['ignore', 'pipe', 'pipe'] })
? spawnFn('runuser', ['-u', asUser, '--', 'env', `HOME=${home || '/tmp'}`, process.execPath, ...argv], { stdio: ['ignore', 'pipe', 'pipe'] })