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

Multiple envs vars mapped to same SSM parameter can fail #10

Open
drjamesj opened this issue Jan 24, 2024 · 1 comment
Open

Multiple envs vars mapped to same SSM parameter can fail #10

drjamesj opened this issue Jan 24, 2024 · 1 comment

Comments

@drjamesj
Copy link

Ran into an edge case today where my project has multiple environment variables referencing the same SSM parameter.

For example:

  environment:
    DB_HOST_1: bref-ssm:/my-secret
    DB_HOST_2: bref-ssm:/my-secret

In this case, during parsing, only one of the values is replaced and the other was not being replaced. After a bit of headscratching I believe the suspect code is:

        foreach ($parameters as $parameterName => $parameterValue) {
            $envVar = array_search($parameterName, $ssmNames, true);
            $_SERVER[$envVar] = $_ENV[$envVar] = $parameterValue;
            putenv("$envVar=$parameterValue");
        }

When we expect only one occurrence of the SSM parameter in the list of $envVarsToDecrypt, array_search is sufficient. But it only returns the first matching key and so results in subsequent variables not being replaced with their SSM value. The solution is to iterate through all envVars that match this SSM parameter.

On the same note, I also found that there is some small inefficiency with retrieving the paramters from SSM, because the duplicates are not removed. Some kind of array_unique could be useful there.

Will try and find the time for a PR at some point.

@selfsimilar
Copy link

I wrote a fix for this about six months ago, but it still hasn't been merged. #9

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

No branches or pull requests

2 participants