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

feat: use self-signed jwt for service account #665

Merged
merged 19 commits into from Feb 1, 2021
Merged

Conversation

busunkim96
Copy link
Contributor

@busunkim96 busunkim96 commented Jan 12, 2021

https://google.aip.dev/auth/4111
Googlers see this doc for detailed design.

Create a self-signed JWT from the service account credentials when the following conditions are met:

  1. A service account is being used
  2. A scope has not been set by the user. (Enforced by adding a new default_scopes that is separate from scopes).
  3. A target_audience has not been set by the user (not relevant at the moment since no client option for audience exists).
  4. An api_endpoint has not been set by the user (taken care of in the GAPIC client library).

Other Changes:

  • Add default_scopes to all ScopedCredentials. For non-service account credentials, the default_scopes are used when scopes is not set. Otherwise the default_scopes are ignored.

This change is only being made to synchronous credentials and the gRPC transport. The async credentials and other transports will be handled in follow up PRs.

@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Jan 12, 2021
@@ -277,7 +286,7 @@ class Scoped(ReadOnlyScoped):
"""

@abc.abstractmethod
def with_scopes(self, scopes):
def with_scopes(self, scopes, default_scopes=None):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is adding an additional optional parameter to an abstract method a breaking change?

Copy link
Contributor

Choose a reason for hiding this comment

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

@busunkim96 busunkim96 added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jan 14, 2021
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jan 14, 2021
@busunkim96 busunkim96 marked this pull request as ready for review January 15, 2021 19:39
@busunkim96 busunkim96 requested a review from a team as a code owner January 15, 2021 19:39
Copy link
Contributor

@arithmetic1728 arithmetic1728 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@bshaffer bshaffer left a comment

Choose a reason for hiding this comment

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

One nit, otherwise this is great

google/auth/transport/grpc.py Outdated Show resolved Hide resolved
@busunkim96 busunkim96 added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jan 21, 2021
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jan 21, 2021
@busunkim96
Copy link
Contributor Author

Looks like I accidentally removed the system tests from the presubmit last year 🤦‍♀️ . I was hoping it would be a small fix but it looks like some issues have piled up. I'll pull those changes into a separate PR and revisit this one later.

@busunkim96 busunkim96 added the automerge Merge the pull request once unit tests and other checks pass. label Feb 1, 2021
@busunkim96 busunkim96 merged commit bf5ce0c into master Feb 1, 2021
@busunkim96 busunkim96 deleted the self-signed-jwt branch February 1, 2021 22:17
@gcf-merge-on-green gcf-merge-on-green bot removed the automerge Merge the pull request once unit tests and other checks pass. label Feb 1, 2021
gcf-merge-on-green bot pushed a commit to googleapis/python-spanner that referenced this pull request Feb 5, 2021
The assertions for credential scope in the `client` unit tests were broken by [a PR in the auth library](googleapis/google-auth-library-python#665). This does raise the question of whether we should be asserting the scopes like this in this library.

This PR fixes the assertions. Removal of these assertions can be done in a separate PR if it is decided they don't belong in this library.
busunkim96 added a commit to googleapis/gapic-generator-python that referenced this pull request Apr 21, 2021
See [RFC (internal only)](https://docs.google.com/document/d/1SNCVTmW6Rtr__u-_V7nsT9PhSzjj1z0P9fAD3YUgRoc/edit#) and https://aip.dev/auth/4111.

Support the self-signed JWT flow for service accounts by passing `default_scopes` and `default_host` in calls to the auth library and `create_channel`. This depends on features exposed in the following PRs: googleapis/python-api-core#134, googleapis/google-auth-library-python#665.

It may be easier to look at https://github.com/googleapis/python-translate/pull/107/files for a diff on a real library.

This change is written so that the library is (temporarily) compatible with older `google-api-core` and `google-auth` versions. Because of this it not possible to reach 100% coverage on a single unit test run. `pytest` runs twice in two of the `nox` sessions.

Miscellaneous changes:
- sprinkled in `__init__.py` files in subdirs of the `test/` directory, as otherwise pytest-cov seems to fail to collect coverage properly in some instances.
- new dependency on `packaging` for Version comparison https://pypi.org/project/packaging/

Co-authored-by: Brent Shaffer <betterbrent@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants