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

adds support for SSO credentials #1519

Merged
merged 1 commit into from
Aug 3, 2023
Merged

Conversation

smoench
Copy link
Contributor

@smoench smoench commented Jul 10, 2023

This PR adds SSO (legacy) credentials support. The official SDK supports it and we are using this.

@smoench
Copy link
Contributor Author

smoench commented Jul 10, 2023

@jderusse Would you accept this functionality? The official SDK supports it. In case yes I would make this PR ready to be merged.

docs/clients/sso.md Outdated Show resolved Hide resolved
@jderusse
Copy link
Member

I'm on the fence here..

From one side: You have a use case and we state that we accept all PR that add new operation if people have a use case.

On the other side: This adds a new Client inside the core project (downloaded by everyone), for a legacy feature.

I think we should create a "normal" (not inside core) client, and use if class_exists(SsoClient) ... in core

@stof
Copy link
Member

stof commented Jul 10, 2023

I tend to agree with @jderusse here

@smoench smoench force-pushed the sso-credentials branch 2 times, most recently from 39b1252 to c2e8247 Compare July 10, 2023 14:59
@smoench
Copy link
Contributor Author

smoench commented Jul 10, 2023

Thanks for the feedback. Sounds great.

I already covered the move to its own client and the class_exists. In the next days I'm finishing the PR :-)

@smoench smoench force-pushed the sso-credentials branch 3 times, most recently from 23e39f4 to f141edd Compare July 11, 2023 08:20
@smoench smoench marked this pull request as ready for review July 11, 2023 08:30
@smoench
Copy link
Contributor Author

smoench commented Jul 11, 2023

I tested it locally and it worked :-)

How should I deal with the psalm failure?

@stof
Copy link
Member

stof commented Jul 11, 2023

@jderusse here is the return of this dreaded Psalm caching issue...
Should we really keep caching the Psalm cache between CI runs ?

@smoench
Copy link
Contributor Author

smoench commented Jul 12, 2023

Is there anything left I can do or support you with? I would love to get this merged and released :-)

@smoench smoench force-pushed the sso-credentials branch 2 times, most recently from 0f229d0 to 3d7498b Compare July 18, 2023 08:51
$filepath = sprintf('%s/.aws/sso/cache/%s.json', $this->getHomeDir(), sha1($ssoStartUrl));

if (!@is_readable($filepath)) {
$this->logger->warning('The sso cache file {path} is not readable.', ['path' => $filepath]);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is the right place for this check, and opens up a race condition between here and line 42. file_get_contents could still fail, but we don't properly handle that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Example robust ways to open the file, then read it's contents can be found in the Guzzle Utils class (tryFopen, tryGetContents): https://github.com/guzzle/psr7/blob/2.5.0/src/Utils.php#L340-L434.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you think about this? Would it be enough?

if (!@is_readable($filepath) || false === ($content = file_get_contents($filepath))) {

Copy link
Contributor

Choose a reason for hiding this comment

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

file_get_contents can also raise errors. The linked code handles them and surfaces they back to the user as an exception.

Copy link
Contributor

Choose a reason for hiding this comment

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

Checking is_readable is largely not useful, because the file's readability could change in between that call and then the file_get_contents call.

Copy link
Contributor

Choose a reason for hiding this comment

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

Great - this means we are justified to add a little internal class in the Core namespace to get the contents of a file or throw an exception.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@GrahamCampbell Since the referenced code is written by yourself, would you consider to contribute it here?

Copy link
Contributor Author

@smoench smoench Jul 27, 2023

Choose a reason for hiding this comment

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

Since I didn't get an answer, I will go with following:

if (false === ($contents = @file_get_contents($filepath))) {

I don't feel well to copy the referenced code when the original author is involved here 😉

Copy link
Member

Choose a reason for hiding this comment

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

are you OK with this change @GrahamCampbell

Copy link
Contributor

@GrahamCampbell GrahamCampbell Aug 3, 2023

Choose a reason for hiding this comment

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

Yeh, we could also just "fix it in post", since this is an existing bug, and nobody seems to mind it so far. Are you OK if we make an issue for it, assign me to it, then I'll get to it when I have some time?

@smoench smoench force-pushed the sso-credentials branch 2 times, most recently from 8972136 to 6892109 Compare July 27, 2023 11:05
src/Core/src/Credentials/IniFileProvider.php Outdated Show resolved Hide resolved
@jderusse jderusse merged commit 6421f09 into async-aws:master Aug 3, 2023
@smoench smoench deleted the sso-credentials branch August 3, 2023 11:18
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.

5 participants