Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug fix] Prevent exposing API key secret in stdout logging #270

Merged
merged 12 commits into from
Jan 20, 2021

Conversation

paulegradie
Copy link
Contributor

Background

A customer revealed to us that we are exposing an api key secret during a call to Write-Verbose in one of our configuration scripts for cTentancleAgent. This was due to a redundant bit of logging that was not passed through our secret scrubber function Get-MaskedOutput. Removing the logging line resolves this problem while leaving the masked logging in tact.

Results

Duplicate logging no longer occurs.

How to review this PR

  • Quality ✔️

We current provide test coverage on the methods used to mask outputs, however we do not text stdout via assent.

This issue has been reported to the School Security for their ongoing secrets related investigations.

Copy link
Contributor

@matt-richardson matt-richardson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one. Should do what it says on the tin.
I'd like to have a discussion around the pull request template before we merge that in.
Also, I'd like to see us fix up the issues around the "not catching all the permutations" that we spotted on the way.

@@ -0,0 +1,41 @@
# Background
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be done as a separate PR... I think there's discussion we want to have around it first.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, we can leave that to another PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah woops - just a heads up on this - I intended to provide a barebones template. Its updated now to that, but I will strip this out into a separate PR momentarily. 👍

@paulegradie paulegradie force-pushed the bug-fix-expose-api-secret branch from fec5730 to 76cb9d1 Compare January 18, 2021 06:00
@paulegradie paulegradie force-pushed the bug-fix-expose-api-secret branch from 29a1ec8 to 50e2c8c Compare January 18, 2021 22:41
@@ -1278,6 +1278,5 @@ function Register-Tentacle {
$registerArguments += @("--tenanted-deployment-participation", $TenantedDeploymentParticipation)
}

Write-Verbose "Registering with arguments: $registerArguments"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main fix - this line is redundant and doesn't pass the arguments through the scrubber.

@@ -158,41 +158,45 @@ Function Get-MaskedOutput
[CmdletBinding()]
param($arguments)

$reg = [System.Text.RegularExpressions.RegEx]::new("--masterkey|--password|--license",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We felt it was prudent to improve the logic around the masking function. Note the edge case clause (the else block).

}

function Invoke-OctopusServerCommand ($cmdArgs) {
# todo: fix this up
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rewriting the function masker helped make it clear that much of this code was redundant, so it has been removed. Args provided to a call to Write-Verbose (or other logging) should always be passed through the masking function.

README.md Outdated
@@ -24,7 +24,7 @@ Version 3.0 of OctopusDSC supports Octopus Deploy 4.x and above with backwards c
## Installation

### [PowerShellGet](https://technet.microsoft.com/en-us/library/dn807169.aspx) / PowerShell 5 (recommended)
1. Install PowerShellGet from [PowerShell Gallery](https://www.powershellgallery.com/GettingStarted)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following the guide, I noticed some of these links no longer work. (the vagrant.io tried to open from within the github domain).

We could consider a little more detail concerning TeamCity env variables.

@paulegradie paulegradie requested a review from jburger January 18, 2021 22:56
Copy link
Contributor

@matt-richardson matt-richardson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Nice one - great to see some TODO comments disappear.

@paulegradie paulegradie merged commit 24b448e into master Jan 20, 2021
@paulegradie paulegradie deleted the bug-fix-expose-api-secret branch January 20, 2021 04:09
@paulegradie
Copy link
Contributor Author

API key printed via DSC

@rikrak
Copy link

rikrak commented Feb 8, 2021

Is there any way to detect if we've been affected by this bug? ...or is it simpler to just change the API key?

@matt-richardson
Copy link
Contributor

You'd have to use the audit log to review changes made via that api key.
Best bet is to also change the api key, just in case.

@attritionorg
Copy link

@paulegradie Sorry for the late question, but what are the default permissions for where this was logged? Is this a proactive "just in case" fix and the file was e.g. 600 or equiv, or was the file world-readable? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants