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

Secure env vars deployed together with the plain ones as clear text #47

Closed
prein opened this issue May 14, 2021 · 8 comments
Closed

Secure env vars deployed together with the plain ones as clear text #47

prein opened this issue May 14, 2021 · 8 comments
Labels
bug Something isn't working

Comments

@prein
Copy link

prein commented May 14, 2021

Not sure if I understand what is happening in the following piece:

this._getEnvironmentVariables(environmentVariables, secureEnvironmentVariables);

but it looks like the secure is mixed together with insecure?

This can also be observed if I use Terraform azurerm_container_group resource to deploy the same container group instance and have both environment_variables and secure_environment_variables defined in both places.

For example, if my github workflow goes like this:

    [...]
    - name: Deploy to Azure Container Instances
      uses: azure/aci-deploy@v1
      with:
        [...]
        environment-variables: FOO = "bar"
        secure-environment-variables: BAR = "foo"

And my TF goes like this

resource "azurerm_container_group" "containergroup" {

   [...]
   container {
     [...]
     environment_variables = {
      FOO = "bar"
     }
     secure_environment_variables = {
      BAR = "foo"
     }
  }
}

Then terraform plan will find BAR among clear text variables

          ~ environment_variables        = { # forces replacement
              - "BAR"  = "foo" -> null
            }

One can also confirm the secure env vars are stored as clear text using az container show or in the azure portal
Example

$ az container show -g my-group --name my-container | jq .containers[].environmentVariables
[
  {
    "name": "BAR",
    "secureValue": null,
    "value": "foo"
  },

@prein
Copy link
Author

prein commented May 14, 2021

Just realized I created dup to #42
Feel free to merge.

@dbrooks5
Copy link

The az cli supports two forms of environment variables for azure container instances.
--secure-environment-variables - all variables specified in this block have their values obfuscated in the azure portal so they are not visible and cannot be retrieved via the cli. This functionality is useful for things like passwords.
--environment-variables - all variables specified here have their values visible in the azure portal and cli.

It appears that the github action is grouping both flags together and just treating them all as environment variables.

In the taskparameters.ts file it appears that the two flags are being processed independently, but the processes for both is the same.

private _getEnvironmentVariables(environmentVariables: string, secureEnvironmentVariables: string) {
	if(environmentVariables) {
		// split on whitespace, but ignore the ones that are enclosed in quotes
		let keyValuePairs = environmentVariables.match(/(?:[^\s"]+|"[^"]*")+/g) || [];
		keyValuePairs.forEach((pair: string) => {
			// value is either wrapped in quotes or not
			let pairList = pair.split(/=(?:"(.+)"|(.+))/);
			let obj: ContainerInstanceManagementModels.EnvironmentVariable = { 
				"name": pairList[0], 
				"value": pairList[1] || pairList[2]
			};
			this._environmentVariables.push(obj);
		})
	}
	if(secureEnvironmentVariables) {
		// split on whitespace, but ignore the ones that are enclosed in quotes
		let keyValuePairs = secureEnvironmentVariables.match(/(?:[^\s"]+|"[^"]*")+/g) || [];
		keyValuePairs.forEach((pair: string) => {
			// value is either wrapped in quotes or not
			let pairList = pair.split(/=(?:"(.+)"|(.+))/);
			let obj: ContainerInstanceManagementModels.EnvironmentVariable = { 
				"name": pairList[0], 
				"value": pairList[1] || pairList[2]
			};
			this._environmentVariables.push(obj);
		})
	}
}

@github-actions
Copy link

github-actions bot commented Jun 2, 2021

This issue is marked need-to-triage for generating issues report.

@kanika1894
Copy link
Contributor

kanika1894 commented Jun 2, 2021

@prein @dbrooks5 Is there anything that we can help you with?
(Seems like you have figured out something on your own :) )

@kanika1894 kanika1894 added bug Something isn't working and removed need-to-triage labels Jun 3, 2021
@el-pato
Copy link
Contributor

el-pato commented Jun 3, 2021

@kanika1894 @prein @dbrooks5 fix should be to usesecureValue instead of value when adding secure environment variables to _environmentVariables, per the snippet below. I tested this on one of my projects and confirm that secure environment variables are no longer visible in the properties of the the container instance. Also created a PR: #51

Problem code:

if(secureEnvironmentVariables) {
// split on whitespace, but ignore the ones that are enclosed in quotes
let keyValuePairs = secureEnvironmentVariables.match(/(?:[^\s"]+|"[^"]*")+/g) || [];
keyValuePairs.forEach((pair: string) => {
// value is either wrapped in quotes or not
let pairList = pair.split(/=(?:"(.+)"|(.+))/);
let obj: ContainerInstanceManagementModels.EnvironmentVariable = {
"name": pairList[0],
"value": pairList[1] || pairList[2]
};
this._environmentVariables.push(obj);
})
}

Potential fix:

if(secureEnvironmentVariables) {
            // split on whitespace, but ignore the ones that are enclosed in quotes
            let keyValuePairs = secureEnvironmentVariables.match(/(?:[^\s"]+|"[^"]*")+/g) || [];
            keyValuePairs.forEach((pair: string) => {
                // value is either wrapped in quotes or not
                let pairList = pair.split(/=(?:"(.+)"|(.+))/);
                let obj: ContainerInstanceManagementModels.EnvironmentVariable = { 
                    "name": pairList[0], 
                    "secureValue": pairList[1] || pairList[2]
                };
                this._environmentVariables.push(obj);
            })

@kanika1894
Copy link
Contributor

Fixed by the PR : #51

@sroebert
Copy link

It is fixed in the source ts file, but not in the lib js file, so when using it in Github actions secure environment variables are still passed on as normal environment variables.

@el-pato
Copy link
Contributor

el-pato commented Aug 12, 2021

@sroebert yeah, this project needs to be built again (and preferably a new release). More info in #57

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants