Skip to content

Instantly share code, notes, and snippets.

@kelseyhightower
Created February 9, 2018 03:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kelseyhightower/6c26791e9ca65d6b391051a3c4069c6b to your computer and use it in GitHub Desktop.
Save kelseyhightower/6c26791e9ca65d6b391051a3c4069c6b to your computer and use it in GitHub Desktop.
'use strict';
exports.denyenv = function denyenv (req, res) {
var admissionRequest = req.body;
// Get a reference to the pod spec
var object = admissionRequest.request.object;
console.log(`validating the ${object.metadata.name} pod`);
var admissionResponse = {
allowed: false
};
var found = false;
for (var container of object.spec.containers) {
if ("env" in container) {
console.log(`${container.name} is using env vars`);
admissionResponse.status = {
status: 'Failure',
message: `${container.name} is using env vars`,
reason: `${container.name} is using env vars`,
code: 402
};
found = true;
};
};
if (!found) {
admissionResponse.allowed = true;
}
var admissionReview = {
response: admissionResponse
};
res.setHeader('Content-Type', 'application/json');
res.send(JSON.stringify(admissionReview));
res.status(200).end();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment