This repository has been archived by the owner on Nov 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
20 changed files
with
1,293 additions
and
168 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"node": true, | ||
"globalstrict": true, | ||
"predef": [ "describe", "beforeEach", "afterEach", "it" ] | ||
"esnext": true, | ||
"predef": [ "describe", "beforeEach", "afterEach", "it", "__ENV_VARS__", "__HANDLER_REQUIRE__" ] | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2015 Serverless, Inc. http://www.serverless.com | ||
|
||
The following license applies to all parts of this software except as | ||
documented below: | ||
|
||
==== | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
||
==== | ||
|
||
All files located in the node_modules and external directories are | ||
externally maintained libraries used by this software which have their | ||
own licenses; we recommend you read them, as their terms may differ from | ||
the terms above. |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
var AWS = require('aws-sdk'); | ||
var kms = new AWS.KMS({region: 'us-east-1'}); | ||
|
||
CiphertextBlobBase64 = "CiDZOVE8Sg9RUIiajI+8gPaN5ChCUVn2EYTKRtpcDQ+s0RKXAQEBAgB42TlRPEoPUVCImoyPvID2jeQoQlFZ9hGEykbaXA0PrNEAAABuMGwGCSqGSIb3DQEHBqBfMF0CAQAwWAYJKoZIhvcNAQcBMB4GCWCGSAFlAwQBLjARBAz9fryxCa9nQ5Q+JbQCARCAKwAFcGxl3ec9+yzjZN8GRTbB0AGlhnadyf97DIzK+xSF7syOtjoUVKJpH5o=" | ||
|
||
kms.decrypt({CiphertextBlob: new Buffer(CiphertextBlobBase64, 'base64')}, function(err, response) { | ||
if (err) console.log(err, err.stack); | ||
else{ | ||
console.log(new Buffer(response.Plaintext).toString('utf-8')); | ||
} | ||
}); |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use strict'; | ||
|
||
var decryptor = require('./serverless-secrets/decryptor'); | ||
|
||
var envVars = __ENV_VARS__; | ||
for (var key in envVars) { | ||
process.env[key] = envVars[key]; | ||
} | ||
|
||
var originalHandler = __HANDLER_REQUIRE__; | ||
|
||
module.exports.handler = function(event, context, callback) { | ||
decryptor(function(){ | ||
return originalHandler(event, context, callback); | ||
}); | ||
}; |
47 changes: 47 additions & 0 deletions
47
src/decryptors/nodejs4.3/serverless-secrets/decryptor/index.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
'use strict'; | ||
|
||
var providers = require('../providers'); | ||
|
||
/* | ||
The brilliance of this whole plan is that "process.env" is a global variable. | ||
We override an "encrypted" string for a provider, and we only have to do it | ||
once for a single container. process.env acts as a "cache" of sorts. | ||
*/ | ||
|
||
function decryptor(callback){ | ||
var encryptedStrings = []; | ||
|
||
for(var key in process.env){ | ||
var parsedVar = process.env[key].split(/::(.+)/); | ||
|
||
if(typeof providers[parsedVar[0]] !== 'undefined'){ | ||
encryptedStrings.push({key: key, provider:parsedVar[0], rawString: parsedVar[1]}); | ||
} | ||
} | ||
|
||
// Return right away if no encrypted strings | ||
if(!encryptedStrings.length){ | ||
return callback(); | ||
} | ||
|
||
// Avoid other dependencies at all cost for smaller footprint | ||
var decryptedVars = 0; | ||
encryptedStrings.forEach(function(item){ | ||
console.log("Decrypting", item.key); | ||
providers[item.provider](item.rawString, function(err, decryptedVar) { | ||
|
||
if(err) console.log(err); | ||
else{ | ||
process.env[item.key] = decryptedVar; | ||
} | ||
|
||
decryptedVars++; | ||
if(decryptedVars === encryptedStrings.length) { | ||
return callback(); | ||
} | ||
|
||
}); | ||
}); | ||
} | ||
|
||
module.exports = decryptor; |
Oops, something went wrong.