-
-
Notifications
You must be signed in to change notification settings - Fork 231
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
Support for SSO credentials #756
Comments
I'd love for you to open a PR for this - I don't have the capacity right now to dig through how SSO works to do it myself, but I have enough to review and give advice. I just (finally) merged #746 , which was a much-needed do-over of the credential chain. The major change is that each auth method is a separate function of type You should now be able to stand up a new Question: Do I understand you correctly, that we aren't expected to handle initial SSO login at all? That will always be done by the Question: Does Responses to your questions:
I don't - you might have to rummage around in an SDK or the CLI source to work out exactly what's going on. The AWS examples show very little useful information in the JSON file, sadly. Since AWS docs say that it's possible to sign into multiple accounts at once, there might be multiple such files - I think you just have to try each in turn using options read from the selected profile (region etc) until you find one that works. Note also that we can't rely on looking up the home directory on windows - have a look at how we search for config files on latest
I agree with the plan -
This sounds right to me, as we can't easily kick the caller back to the browser, and it sounds consistent with documented CLI behvaiour.
I think this might be okay under the new |
Awesome, and thanks for those docs links -- it confirms some things I had figured out by trial & error. I opened #757 as a Draft. I just finished it so I'll take a look over it again with fresh eyes tomorrow. Format, polish, etc.
That is my understanding, based on all the documentation and how we've always used it. I'm sure
That I don't know; I can't imagine why it would successfully return no credentials. For what it's worth, when my SSO JWT expired before testing my PR, I got an unauthorized
I think it's not quite so bad. As far as I can tell, there is always exactly one JWT in a single It makes sense because
It was close! I was able to export functions to do 80% of what I needed, which I'm happy with for now. |
That doesn't seem to be completely true; according to these docs (search "if you specify default" and look for the blue note), you can name the profile That documentation also says this:
I think you're right that this means AWS SSO user accounts are above normal AWS accounts, but I think you can sign into SSO multiple times. I found this snippet inside
Yeah, I think it could be correct to suppress that |
You're right about finding the file, % grep start_url ~/.aws/config
sso_start_url = https://rensso.awsapps.com/start
% ls ~/.aws/sso/cache
05550f54b45317d3e2f26ef32828d84422f231cd.json
% python
>>> import hashlib
>>> start_url = "https://rensso.awsapps.com/start"
>>> hashlib.sha1(start_url.encode('utf-8')).hexdigest()
'05550f54b45317d3e2f26ef32828d84422f231cd' By chance is there a preferred way to get a SHA1 in this project? |
I see you've already found the hash functions in |
👋 We've begun adopting AWS SSO at work, which has made it challenging to continue using amazonka. In an effort to test the 2.0 rc, I've got some local code that adds support for it. If I'm going in the right direction, I'd like to open a PR.
Context
For those that don't know, it works like this:
sso_
bits to~/.aws/config
(account-id and role-name are most important for us here)aws sso login
-- authorize in the browser~/.aws/sso/cache/{uuid}.json
aws
or any other client lib normallysso_
bits of config, and usesso get-role-credentials
to get ephemeral Access KeysStep 5 is further described here, and is basically what my code does.
Code
I was pleasantly surprised that I could build on top of amazonka and get this functional, here is the important bit isolated from the glue required to do it externally. I tried to organize it in the style of the rest of
Amazonka.Auth
.I believe this should drop-in to the
catching
stanza ofDiscover
afterfromEnv
and beforefromFilePath
.Open Questions / Warts
Having to glob for
~/.aws/sso/cache/*.json
makes me uncomfortable. Does anyone know a way to avoid it?Handling Region is tricky: the Region you SSO with may not be the Region you want to interact with using the SSO credentials. Therefore, it's important that
SsoCache{region}
is used for thegetRoleCredentials
call, but we still need to "discover" the actual_envRegion
to use. Therefore, I've basically re-implemented a lot offromFilePath
, hopefully in a way that we can DRY it back up in my PR -- is this a good approach or am I missing an easier way?I'm a little fuzzy on the
fetchAuthInBackground
. The SSO JWT has an expiry, and the credentials retrieved byget-role-credentials
has an expiry. I implemented the refresh loop on the latter, which I imagine would expire first and, if so, be refreshable provided the JWT has not expired. If the JWT has expired, it requires a humanaws sso login
again, so I don't know that auto-refreshing on that is useful. Is that all reasonable?fromSsoCache
can throwMissingFileError
, which we definitely want to ignore since no~/.aws/sso/cache
file is an indication we should not use this method when inDiscover
mode. However, it also throwsInvalidFileError
for two different scenarios: nosso_
configuration bits present and a fatal error reading Region from~/.aws/config
. The former could be another reason so skip, the latter though should probably remain fatal on principle. However, I'm inclined to mask both of these since two of them should be masked and the third one, if masked, would fail again the same way later (I imagine). Am I missing any better way to handle that? The currentcatching
stanza reads so nicely, but there is no example of catching two types of errors like I'm introducing.The text was updated successfully, but these errors were encountered: