blob: 255f33c74ff2f455820d16f100ee05df5483f48a [file] [log] [blame]
Jon Wayne Parrott377f2932016-10-04 10:20:36 -07001Contributing
2============
3
4#. **Please sign one of the contributor license agreements below.**
5#. Fork the repo, develop and test your code changes, add docs.
6#. Make sure that your commit messages clearly describe the changes.
7#. Send a pull request.
8
9Here are some guidelines for hacking on ``google-auth-library-python``.
10
11Making changes
12--------------
13
Bu Sun Kim65e33c02019-10-25 10:45:00 -070014A few notes on making changes to ``google-auth-library-python``.
Jon Wayne Parrott377f2932016-10-04 10:20:36 -070015
16- If you've added a new feature or modified an existing feature, be sure to
17 add or update any applicable documentation in docstrings and in the
18 documentation (in ``docs/``). You can re-generate the reference documentation
Bu Sun Kim65e33c02019-10-25 10:45:00 -070019 using ``nox -s docgen``.
Jon Wayne Parrott377f2932016-10-04 10:20:36 -070020
Tres Seaver560cf1e2021-08-03 16:35:54 -040021- The change must work fully on the following CPython versions:
Tres Seaver19d41f82021-10-07 13:05:19 -040022 3.6, 3.7, 3.8, 3.9, 3.10 across macOS, Linux, and Windows.
Jon Wayne Parrott377f2932016-10-04 10:20:36 -070023
24- The codebase *must* have 100% test statement coverage after each commit.
Bu Sun Kim65e33c02019-10-25 10:45:00 -070025 You can test coverage via ``nox -e cover``.
Jon Wayne Parrott377f2932016-10-04 10:20:36 -070026
27Testing changes
28---------------
29
Bu Sun Kim65e33c02019-10-25 10:45:00 -070030To test your changes, run unit tests with ``nox``::
Jon Wayne Parrott377f2932016-10-04 10:20:36 -070031
Bu Sun Kim65e33c02019-10-25 10:45:00 -070032 $ nox -s unit
33
34
35Running system tests
36--------------------
37
38You can run the system tests with ``nox``::
39
40 $ nox -f system_tests/noxfile.py
41
42To run a single session, specify it with ``nox -s``::
43
44 $ nox -f system_tests/noxfile.py -s service_account
Ryan Kohler48e8be32021-03-25 17:35:43 -070045
46First, set the environment variable ``GOOGLE_APPLICATION_CREDENTIALS`` to a valid service account.
47See `Creating and Managing Service Account Keys`_ for how to obtain a service account.
Bu Sun Kim82e224b2020-03-13 13:21:18 -070048
49Project and Credentials Setup
50-------------------------------
51
52Enable the IAM Service Account Credentials API on the project.
53
Bu Sun Kim65e33c02019-10-25 10:45:00 -070054To run system tests locally, you will need to set up a data directory ::
55
56 $ mkdir system_tests/data
57
Bu Sun Kim82e224b2020-03-13 13:21:18 -070058Your directory should look like this. Follow the instructions below for creating each file. ::
Bu Sun Kim65e33c02019-10-25 10:45:00 -070059
60 system_tests/
61 data/
Bu Sun Kim65e33c02019-10-25 10:45:00 -070062 authorized_user.json
Bu Sun Kim82e224b2020-03-13 13:21:18 -070063 impersonated_service_account.json
64 service_account.json
Bu Sun Kim65e33c02019-10-25 10:45:00 -070065
Bu Sun Kim82e224b2020-03-13 13:21:18 -070066
67``authorized_user.json``
68~~~~~~~~~~~~~~~~~~~~~~~~
Bu Sun Kim65e33c02019-10-25 10:45:00 -070069
70Use the `gcloud CLI`_ to get an authorized user file ::
71
72 $ gcloud auth application-default login --scopes=https://www.googleapis.com/auth/userinfo.email,https://www.googleapis.com/auth/cloud-platform,openid
73
74You will see something like::
75
Bu Sun Kim82e224b2020-03-13 13:21:18 -070076 Credentials saved to file: [/usr/local/home/.config/gcloud/application_default_credentials.json]
Bu Sun Kim65e33c02019-10-25 10:45:00 -070077
78Copy the contents of the file to ``authorized_user.json``.
79
Bu Sun Kim82e224b2020-03-13 13:21:18 -070080Open the IAM page of the Google Cloud Console. Grant the user the `Service Account Token Creator Role`.
81This will allow the user to impersonate service accounts on the project.
82
Bu Sun Kim65e33c02019-10-25 10:45:00 -070083.. _gcloud CLI: https://cloud.google.com/sdk/gcloud/
84
Bu Sun Kim82e224b2020-03-13 13:21:18 -070085
86``service_account.json``
87~~~~~~~~~~~~~~~~~~~~~~~~
88
Ryan Kohler48e8be32021-03-25 17:35:43 -070089Follow `Creating and Managing Service Account Keys`_ to create a service account.
Bu Sun Kim82e224b2020-03-13 13:21:18 -070090
91Copy the credentials file to ``service_account.json``.
92
93Grant the account associated with ``service_account.json`` the following roles.
94
95- App Engine Admin (for App Engine tests)
Ryan Kohler48e8be32021-03-25 17:35:43 -070096- Service Account Token Creator (for impersonated credentials and workload identity federation tests)
Bu Sun Kim82e224b2020-03-13 13:21:18 -070097- Pub/Sub Viewer (for gRPC tests)
98- Storage Object Viewer (for impersonated credentials tests)
Ryan Kohler48e8be32021-03-25 17:35:43 -070099- DNS Viewer (for workload identity federation tests)
bojeil-googleed8e0352021-08-16 12:34:28 -0700100- GCE Storage Bucket Admin (for downscoping tests)
Bu Sun Kim82e224b2020-03-13 13:21:18 -0700101
102``impersonated_service_account.json``
103~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
104
Ryan Kohler48e8be32021-03-25 17:35:43 -0700105Follow `Creating and Managing Service Account Keys`_ to create a service account.
Bu Sun Kim82e224b2020-03-13 13:21:18 -0700106
107Copy the credentials file to ``impersonated_service_account.json``.
108
109.. _Creating and Managing Service Account Keys: https://cloud.google.com/iam/docs/creating-managing-service-account-keys
110
Ryan Kohler48e8be32021-03-25 17:35:43 -0700111``setup_external_accounts``
112~~~~~~~~~~~~~~~~
113
114In order to run the workload identity federation tests, you will need to set up
115a Workload Identity Pool, as well as attach relevant policy bindings for this
116new resource to our service account. To do this, make sure you have IAM Workload
117Identity Pool Admin and Security Admin permissions, and then run:
118
119 $ ./scripts/setup_external_accounts.sh
120
121and then use the output to replace the variables near
122the top of system_tests/system_tests_sync/test_external_accounts.py
123
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700124App Engine System Tests
Bu Sun Kim82e224b2020-03-13 13:21:18 -0700125~~~~~~~~~~~~~~~~~~~~~~~~
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700126
127To run the App Engine tests, you wil need to deploy a default App Engine service.
128If you already have a default service associated with your project, you can skip this step.
129
130Edit ``app.yaml`` so ``service`` is ``default`` instead of ``google-auth-system-tests``.
131From ``system_tests/app_engine_test_app`` run the following commands ::
132
Bu Sun Kim8374e212020-03-20 18:10:05 -0700133 $ pip install --target lib -r requirements.txt
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700134 $ gcloud app deploy -q app.yaml
135
Ryan Kohler48e8be32021-03-25 17:35:43 -0700136After the app is deployed, change ``service`` in ``app.yaml`` back to ``google-auth-system-tests``.
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700137You can now run the App Engine tests: ::
138
139 $ nox -f system_tests/noxfile.py -s app_engine
Ryan Kohler48e8be32021-03-25 17:35:43 -0700140
Bu Sun Kim8374e212020-03-20 18:10:05 -0700141Compute Engine Tests
142^^^^^^^^^^^^^^^^^^^^
143
144These tests cannot be run locally and will be skipped if they are run outside of Google Compute Engine.
Ryan Kohler48e8be32021-03-25 17:35:43 -0700145
Bu Sun Kim8374e212020-03-20 18:10:05 -0700146grpc Tests
147^^^^^^^^^^^^
148
149These tests use the Pub/Sub API. Grant the service account specified by `GOOGLE_APPLICATION_CREDENTIALS`
150permissions to list topics. The service account should have at least `roles/pubsub.viewer`.
Jon Wayne Parrott377f2932016-10-04 10:20:36 -0700151
152Coding Style
153------------
154
155This library is PEP8 & Pylint compliant. Our Pylint config is defined at
156``pylintrc`` for package code and ``pylintrc.tests`` for test code. Use
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700157``nox`` to check for non-compliant code::
Jon Wayne Parrott377f2932016-10-04 10:20:36 -0700158
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700159 $ nox -s lint
Jon Wayne Parrott377f2932016-10-04 10:20:36 -0700160
161Documentation Coverage and Building HTML Documentation
162------------------------------------------------------
163
164If you fix a bug, and the bug requires an API or behavior modification, all
165documentation in this package which references that API or behavior must be
166changed to reflect the bug fix, ideally in the same commit that fixes the bug
167or adds the feature.
168
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700169To build and review docs use ``nox``::
Jon Wayne Parrott377f2932016-10-04 10:20:36 -0700170
Bu Sun Kim65e33c02019-10-25 10:45:00 -0700171 $ nox -s docs
Jon Wayne Parrott377f2932016-10-04 10:20:36 -0700172
173The HTML version of the docs will be built in ``docs/_build/html``
174
175Versioning
176----------
177
178This library follows `Semantic Versioning`_.
179
180.. _Semantic Versioning: http://semver.org/
181
182It is currently in major version zero (``0.y.z``), which means that anything
183may change at any time and the public API should not be considered
184stable.
185
186Contributor License Agreements
187------------------------------
188
189Before we can accept your pull requests you'll need to sign a Contributor License Agreement (CLA):
190
191- **If you are an individual writing original source code** and **you own the intellectual property**, then you'll need to sign an `individual CLA <https://developers.google.com/open-source/cla/individual>`__.
192- **If you work for a company that wants to allow you to contribute your work**, then you'll need to sign a `corporate CLA <https://developers.google.com/open-source/cla/corporate>`__.
193
194You can sign these electronically (just scroll to the bottom). After that, we'll be able to accept your pull requests.