Skip to content

Instantly share code, notes, and snippets.

@apstndb
Last active May 28, 2018 13:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apstndb/4ac232dec3941ccc869a40ebd1347881 to your computer and use it in GitHub Desktop.
Save apstndb/4ac232dec3941ccc869a40ebd1347881 to your computer and use it in GitHub Desktop.
Google Cloud Functions should be based on gVisor

deploy function

${PROJECT_NAME} should be your own project name.

$ gcloud functions deploy helloExec --trigger-http --project=${PROJECT_NAME}

execute function

$ curl "https://us-central1-${PROJECT_NAME}.cloudfunctions.net/helloExec" -d '{"file": "/bin/cat", "args": ["/proc/filesystems"]}' -H 'Content-Type:application/json'
*stdout*:
nodev   9p
nodev   devtmpfs
nodev   proc
nodev   ramdiskfs
nodev   sysfs
nodev   tmpfs
$ curl "https://us-central1-${PROJECT_NAME}.cloudfunctions.net/helloExec" -d '{"file": "/bin/cat", "args": ["/proc/stat"]}' -H 'Content-Type:application/json'
*stdout*:
cpu  0 0 0 0 0 0 0 0 0 0
cpu0 0 0 0 0 0 0 0 0 0 0
cpu1 0 0 0 0 0 0 0 0 0 0
cpu2 0 0 0 0 0 0 0 0 0 0
cpu3 0 0 0 0 0 0 0 0 0 0
cpu4 0 0 0 0 0 0 0 0 0 0
cpu5 0 0 0 0 0 0 0 0 0 0
cpu6 0 0 0 0 0 0 0 0 0 0
cpu7 0 0 0 0 0 0 0 0 0 0
intr 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ctxt 0
btime 1527423521
processes 0
procs_running 0
procs_blocked 0
softirq 0 0 0 0 0 0 0 0 0 0 0

They are the same output with the gVisor document(/proc/filesystem, /proc/stat).

Acknowledgement

Thanks to s.hiruta's method.

See also

App Engine Java 8 Standard

Easter Egg

You can read a easter egg by exec dmesg.

$ curl "https://us-central1-${PROJECT_NAME}.cloudfunctions.net/helloExec" -d '{"file": "/bin/dmesg", "args": []}' -H 'Content-Type:application/json'
*stdout*:
[    0.086696] Rewriting operating system in Javascript...
[    0.543600] Forking spaghetti code...
[    0.660117] Creating bureaucratic processes...
[    0.913005] Feeding the init monster...
[    0.922419] Segmenting fault lines...
[    1.072444] Searching for socket adapter...
[    1.249616] Creating process schedule...
[    1.472052] Synthesizing system calls...
[    1.862931] Generating random numbers by fair dice roll...
[    2.167452] Waiting for children...
[    2.481318] Ready!
exports.helloExec = (req, res) => {
var execFile = require('child_process').execFile;
execFile(req.body.file, req.body.args, function(err, stdout, stderr){
res.send(`*stdout*:
${stdout}`);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment