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

ADC can load a json of impersonated service account credentials generated by gcloud #762

Closed
liuchaoren opened this issue May 27, 2021 · 15 comments · Fixed by #956 or #962
Closed

ADC can load a json of impersonated service account credentials generated by gcloud #762

liuchaoren opened this issue May 27, 2021 · 15 comments · Fixed by #956 or #962
Assignees
Labels
type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@liuchaoren
Copy link
Contributor

google-auth-library-java supported ADC impersonation and it is proposed in aip-dev/google.aip.dev#728.

@busunkim96 busunkim96 added the type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. label May 27, 2021
@MadJlzz
Copy link

MadJlzz commented Oct 7, 2021

I have created a question around this issue on SO here.

From impersonated_credentials.py, this functionnality seems already implemented but when we try to actually use it in others libraries like google-cloud-storage, it fails with:

google.auth.exceptions.DefaultCredentialsError: The file C:\Users\klaer\AppData\Roaming\gcloud\application_default_credentials.json does not have a valid type. Type is impersonated_service_account, expected one of ('authorized_user', 'service_account', 'external_account').

Thas is thrown after I loged in with a service account I can impersonate:

gcloud auth application-default login --impersonate-service-account=<SA email>

and running a piece of code like this:

from google.cloud import storage

client = storage.Client()
print(next(client.list_buckets()))

Am I missing something? Can I do something to help you support this feature?

@liuchaoren
Copy link
Contributor Author

I have created a question around this issue on SO here.

From impersonated_credentials.py, this functionnality seems already implemented but when we try to actually use it in others libraries like google-cloud-storage, it fails with:

google.auth.exceptions.DefaultCredentialsError: The file C:\Users\klaer\AppData\Roaming\gcloud\application_default_credentials.json does not have a valid type. Type is impersonated_service_account, expected one of ('authorized_user', 'service_account', 'external_account').

Thas is thrown after I loged in with a service account I can impersonate:

gcloud auth application-default login --impersonate-service-account=<SA email>

and running a piece of code like this:

from google.cloud import storage

client = storage.Client()
print(next(client.list_buckets()))

Am I missing something? Can I do something to help you support this feature?

@liuchaoren liuchaoren reopened this Oct 7, 2021
@liuchaoren
Copy link
Contributor Author

Sorry, closed by accident!

impersonation credentials were implemented in impersonated_credentials.py, what is missing is that ADC cannot read the file generated by the gcloud command and construct the impersonation credentials object. ADC is used by client libraries (for example storage) to construct credential objects.

I think what we need to do is extending the load_credentials_from_file to handle the impersonation credential json generated by gcloud and construct a impersonation credential object.

@MadJlzz
Copy link

MadJlzz commented Oct 7, 2021

Thanks for answering!

So yeah, that being said, the error message I am getting makes fully sense. I can try to do that if you think that it might help.

@MadJlzz
Copy link

MadJlzz commented Oct 27, 2021

@liuchaoren what do you think? Do you think I can help to implement this? (or even test it!!)

@liuchaoren
Copy link
Contributor Author

@MadJlzz sorry for the late response! Yes, please see https://github.com/googleapis/google-auth-library-python/blob/main/CONTRIBUTING.rst for how to contribute to the repo.

@DBCerigo
Copy link

Is not supporting impersonated_service_account a regression? I'm quite sure that we were using service account impersonation with python clients back in August 2020 (ref: https://stackoverflow.com/questions/69412702/how-to-manage-google-cloud-credentials-for-local-development/69417606)

@MadJlzz
Copy link

MadJlzz commented Nov 12, 2021

@DBCerigo What I am sure of is that you can use it directly from the code (like in my SO thread) but not from the default ADC

@MadJlzz
Copy link

MadJlzz commented Nov 13, 2021

I made a PR with a first implementation that works for a simple example.

@sloev
Copy link

sloev commented Dec 2, 2021

thanks for doing some work on this @MadJlzz
coming from AWS, (which has STS for temporary credentials), i must say google is quite inferior on this point.
Its a necessity to be able to run my code locally as a service account in order to develop the strict and narrow permissions my program needs once deployed.

the gcloud auth application-default login --impersonate-service-account=[SA EMAIL] is painful (too much friction when context switching between local projects) but it is utterly useless when pythons cloud sdk can't recognize the credentials produced.

crossing my fingers for this to be fixed soon :-)

@MadJlzz
Copy link

MadJlzz commented Dec 15, 2021

Hey @sloev, thanks for your message. I was out from some time and was stuck with the environment I was working (Windows)
Wasn't able to run all unit tests because spme are using os and not pathlib if I remind correctly. I will try to move forward on this issue to have a fix asap.

@liuchaoren
Copy link
Contributor Author

liuchaoren commented Jan 18, 2022

Hi @MadJlzz we noticed some some issues which are blocked by this one. Do you think it is possible to fix this issue in one week? I am happy to take it over if it is not feasible. Thanks!

@MadJlzz
Copy link

MadJlzz commented Jan 19, 2022

Hi @liuchaoren. I don't think I have experience enough with the way your testing this project finish this in one week. Also the PR is waiting your review for the next milestone I have to achieve (which should be covering the new section of the code)
Happy to let you finish if you guys need to be quick on this one.

@liuchaoren
Copy link
Contributor Author

@MadJlzz Thank you for your contribution! I am happy to pick it up from what you have. I will send a PR on the coming Monday.

@liuchaoren
Copy link
Contributor Author

It seems that the scopes are not passed successfully to the impersonated credentials by the default() function. I think we should change the impersonated credentials to inherit the Scoped base class so that the default() can add scopes correctly to it. I will reopen it and will follow up with a PR to fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
5 participants