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

Alternative credential retrieval - threadsafe #2722

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

paullallier
Copy link

@paullallier paullallier commented Jul 4, 2023

Similar to PR 2155

Description of changes:
Fallback to $_SERVER variable for AWS credentials to avoid using non-threadsafe putenv()

Would you consider allowing this change so that we can avoid having to use the non-threadsafe putenv() function to set AWS credentials - which we're storing in a .env file?

I've tried to write a test for it - not sure it's going to work yet.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@paullallier paullallier marked this pull request as ready for review July 4, 2023 10:55
@paullallier
Copy link
Author

paullallier commented Jul 4, 2023

Found a minor problem. This doesn't seem to fall through to null when $_SERVER[self::ENV_SESSION] is undefined. I'm tempted to revert that line since I don't need it, but maybe there's a better way?

getenv(self::ENV_SESSION) ?: $_SERVER[self::ENV_SESSION] ?: NULL

@ghost
Copy link

ghost commented Sep 5, 2023

Could we get this merged eventually? Thanks!

@paullallier
Copy link
Author

Any chance of a review and comments on how we could make this an acceptable merge, please?

@stobrien89 stobrien89 closed this Jul 1, 2024
@stobrien89 stobrien89 reopened this Jul 1, 2024
@@ -289,8 +289,8 @@ public static function env()
{
return function () {
// Use credentials from environment variables, if available
$key = getenv(self::ENV_KEY);
$secret = getenv(self::ENV_SECRET);
$key = getenv(self::ENV_KEY) ?: $_SERVER[self::ENV_KEY];
Copy link
Member

Choose a reason for hiding this comment

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

The $_SERVER references should check to see if it is set. Also, we should fall back to false if it isn't. I think you could add a null coalescing operator to what's already here and add false on the right side of the operand.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you Sean. And I think that's what I SHOULD have done with the ENV_SESSION variable too. 12 month ago, I was less familiar with the difference between null coalesce and Elvis!

Do we need more tests?

Add a fall-through in case the $_SERVER variable isn't set (and re-introduce the equivalent change for ENV_SESSION)
@paullallier
Copy link
Author

paullallier commented Jul 12, 2024

I'm not sure why I thought @server would set the $_SERVER variable for the test. Fixed this, but is there a cleaner option?

Sorry - I should have run the tests locally (which I have now done with PHP 8.3 at least).

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.

2 participants