Skip to content

Commit 0390b8d

Browse files
authored
Merge pull request #1 from RepublicServicesRepository/US50654-enhanced-masking
US50654: Enhanced Masking
2 parents 96eedf0 + 3d0a878 commit 0390b8d

3 files changed

Lines changed: 28 additions & 9 deletions

File tree

.github/workflows/test-aws-param-to-env.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ jobs:
3030
param-store-base-paths: /test
3131
decrypt-secure-strings: true
3232
debug-logging: true
33+
mask-values: true
3334

3435
# Test the outcome in the GITHUB env.
3536
# Be careful with this, as the values will end up in your Action logs.

actions/aws-param-to-env/action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ inputs:
77
decrypt-secure-strings:
88
description: 'Optional flag to decrypt SecureString values. Set to true if desired and the value will cascade to the AWS call.'
99
required: false
10+
mask-values:
11+
description: 'Optional flag to mask all values retrieved within Github logs.'
12+
required: false
1013
debug-logging:
1114
description: 'Optional flag to output debug logging. If set to true Param Store values will be output to the console.'
1215
required: false

actions/aws-param-to-env/index.js

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const execSync = require("child_process").execSync;
21
const core = require("@actions/core");
32
const aws = require("aws-sdk");
43
const ssm = new aws.SSM();
@@ -7,7 +6,8 @@ async function main() {
76
try {
87
console.log("Begin AWS Param To Env");
98

10-
const debuLogging = core.getInput("debug-logging") === "true";
9+
const debuLogging = core.getInput("debug-logging") === "true";
10+
const maskValues = (core.getInput("mask-values") === "false") ? false : true; // default to masking everything
1111
const decryptSecureStrings =
1212
core.getInput("decrypt-secure-strings") === "true";
1313
const paramStoreBasePathInput = core.getInput("param-store-base-paths", {
@@ -20,7 +20,7 @@ async function main() {
2020
decryptSecureStrings,
2121
debuLogging
2222
);
23-
setParamsInEnvironment(basePath, parameters);
23+
setParamsInEnvironment(basePath, parameters, maskValues);
2424
}
2525

2626
console.log("End AWS Param To Env");
@@ -36,7 +36,7 @@ async function getParamsByPath(path, decrypt, log) {
3636

3737
do {
3838
if (log) {
39-
console.log(`Begin getParametersByPath: ${JSON.stringify(NextToken)}`);
39+
console.log(`Begin getParametersByPath continued: ${!!NextToken}`);
4040
}
4141

4242
ssmResult = await ssm
@@ -49,7 +49,18 @@ async function getParamsByPath(path, decrypt, log) {
4949
.promise();
5050

5151
if (log) {
52-
console.log(`End getParametersByPath: ${JSON.stringify(ssmResult)}`);
52+
if (!decrypt) {
53+
console.log(`End getParametersByPath: ${JSON.stringify(ssmResult)}`);
54+
} else {
55+
const safeToLogResults = ssmResult.Parameters.map(parameter => {
56+
let loggableParam = Object.assign({}, parameter);
57+
if (loggableParam.Type === 'SecureString') {
58+
loggableParam.Value = '***';
59+
}
60+
return loggableParam;
61+
});
62+
console.log(`End getParametersByPath: ${JSON.stringify({ Parameters: safeToLogResults })}`);
63+
}
5364
}
5465

5566
if (ssmResult.Parameters.length) {
@@ -59,7 +70,7 @@ async function getParamsByPath(path, decrypt, log) {
5970
} while (NextToken);
6071

6172
if (log) {
62-
console.log(`Loaded parameters: ${JSON.stringify(parameters)}`);
73+
console.log("Parameter path load complete.");
6374
}
6475

6576
return parameters;
@@ -69,17 +80,21 @@ async function getParamsByPath(path, decrypt, log) {
6980
* Convert the heirarchical param name to a unix-style param name.
7081
* e.g. /test/api/key -> API_KEY
7182
*/
72-
async function setParamsInEnvironment(path, params) {
83+
async function setParamsInEnvironment(path, params, maskValues) {
7384
for (const param of params) {
7485
const shortName = param.Name.replace(path, "");
7586
const unixName = shortName
7687
.replace(/^\//, "")
7788
.replace(/\//g, "_")
7889
.toUpperCase();
7990

80-
// write the value out to the environment and register it as a secret, so github logs will mask it
91+
// write the value out to the environment
8192
core.exportVariable(unixName, param.Value);
82-
core.setSecret(param.Value);
93+
94+
// register it as a secret, so github logs will mask it
95+
if (maskValues) {
96+
core.setSecret(param.Value);
97+
}
8398
}
8499
}
85100

0 commit comments

Comments
 (0)