Created
February 9, 2018 03:18
-
-
Save kelseyhightower/6c26791e9ca65d6b391051a3c4069c6b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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