Skip to content

Commit 1302352

Browse files
authored
fix: disable always_use_jwt_access (#939)
Some APIs with Cloud Storage integrations have failing samples when non-default scopes are provided. This PR disables the feature globally for now while we investigate. We can no longer rollback da119c7 as some libraries have been released with the change and removing the kwarg would be a breaking change. See internal issue 192297181.
1 parent 678def6 commit 1302352

File tree

22 files changed

+145
-22
lines changed

22 files changed

+145
-22
lines changed

gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/base.py.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class {{ service.name }}Transport(abc.ABC):
131131
# If the credentials is service account credentials, then always try to use self signed JWT.
132132
if always_use_jwt_access and isinstance(credentials, service_account.Credentials) and hasattr(service_account.Credentials, "with_always_use_jwt_access"):
133133
credentials = credentials.with_always_use_jwt_access(True)
134-
134+
135135
# Save the credentials.
136136
self._credentials = credentials
137137

gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/grpc.py.j2

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class {{ service.name }}GrpcTransport({{ service.name }}Transport):
5555
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
5656
quota_project_id: Optional[str] = None,
5757
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
58+
always_use_jwt_access: Optional[bool] = False,
5859
) -> None:
5960
"""Instantiate the transport.
6061

@@ -95,6 +96,8 @@ class {{ service.name }}GrpcTransport({{ service.name }}Transport):
9596
API requests. If ``None``, then default info will be used.
9697
Generally, you only need to set this if you're developing
9798
your own client library.
99+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
100+
be used for service account credentials.
98101

99102
Raises:
100103
google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
@@ -150,7 +153,7 @@ class {{ service.name }}GrpcTransport({{ service.name }}Transport):
150153
scopes=scopes,
151154
quota_project_id=quota_project_id,
152155
client_info=client_info,
153-
always_use_jwt_access=True,
156+
always_use_jwt_access=always_use_jwt_access,
154157
)
155158

156159
if not self._grpc_channel:

gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/grpc_asyncio.py.j2

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ class {{ service.grpc_asyncio_transport_name }}({{ service.name }}Transport):
100100
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
101101
quota_project_id=None,
102102
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
103+
always_use_jwt_access: Optional[bool] = False,
103104
) -> None:
104105
"""Instantiate the transport.
105106

@@ -141,6 +142,8 @@ class {{ service.grpc_asyncio_transport_name }}({{ service.name }}Transport):
141142
API requests. If ``None``, then default info will be used.
142143
Generally, you only need to set this if you're developing
143144
your own client library.
145+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
146+
be used for service account credentials.
144147

145148
Raises:
146149
google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
@@ -195,7 +198,7 @@ class {{ service.grpc_asyncio_transport_name }}({{ service.name }}Transport):
195198
scopes=scopes,
196199
quota_project_id=quota_project_id,
197200
client_info=client_info,
198-
always_use_jwt_access=True,
201+
always_use_jwt_access=always_use_jwt_access,
199202
)
200203

201204
if not self._grpc_channel:

gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,22 @@ def test_{{ service.client_name|snake_case }}_service_account_always_use_jwt(cli
123123
with mock.patch.object(service_account.Credentials, 'with_always_use_jwt_access', create=True) as use_jwt:
124124
creds = service_account.Credentials(None, None, None)
125125
client = client_class(credentials=creds)
126-
use_jwt.assert_called_with(True)
126+
use_jwt.assert_not_called()
127+
128+
129+
@pytest.mark.parametrize("transport_class,transport_name", [
130+
{% if 'grpc' in opts.transport %}
131+
(transports.{{ service.grpc_transport_name }}, "grpc"),
132+
(transports.{{ service.grpc_asyncio_transport_name }}, "grpc_asyncio"),
133+
{% elif 'rest' in opts.transport %}
134+
(transports.{{ service.rest_transport_name }}, "rest"),
135+
{% endif %}
136+
])
137+
def test_{{ service.client_name|snake_case }}_service_account_always_use_jwt_true(transport_class, transport_name):
138+
with mock.patch.object(service_account.Credentials, 'with_always_use_jwt_access', create=True) as use_jwt:
139+
creds = service_account.Credentials(None, None, None)
140+
transport = transport_class(credentials=creds, always_use_jwt_access=True)
141+
use_jwt.assert_called_once_with(True)
127142

128143

129144
@pytest.mark.parametrize("client_class", [

tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/transports/grpc.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def __init__(self, *,
5757
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
5858
quota_project_id: Optional[str] = None,
5959
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
60+
always_use_jwt_access: Optional[bool] = False,
6061
) -> None:
6162
"""Instantiate the transport.
6263
@@ -97,6 +98,8 @@ def __init__(self, *,
9798
API requests. If ``None``, then default info will be used.
9899
Generally, you only need to set this if you're developing
99100
your own client library.
101+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
102+
be used for service account credentials.
100103
101104
Raises:
102105
google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
@@ -150,7 +153,7 @@ def __init__(self, *,
150153
scopes=scopes,
151154
quota_project_id=quota_project_id,
152155
client_info=client_info,
153-
always_use_jwt_access=True,
156+
always_use_jwt_access=always_use_jwt_access,
154157
)
155158

156159
if not self._grpc_channel:

tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/transports/grpc_asyncio.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ def __init__(self, *,
102102
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
103103
quota_project_id=None,
104104
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
105+
always_use_jwt_access: Optional[bool] = False,
105106
) -> None:
106107
"""Instantiate the transport.
107108
@@ -143,6 +144,8 @@ def __init__(self, *,
143144
API requests. If ``None``, then default info will be used.
144145
Generally, you only need to set this if you're developing
145146
your own client library.
147+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
148+
be used for service account credentials.
146149
147150
Raises:
148151
google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
@@ -195,7 +198,7 @@ def __init__(self, *,
195198
scopes=scopes,
196199
quota_project_id=quota_project_id,
197200
client_info=client_info,
198-
always_use_jwt_access=True,
201+
always_use_jwt_access=always_use_jwt_access,
199202
)
200203

201204
if not self._grpc_channel:

tests/integration/goldens/asset/tests/unit/gapic/asset_v1/test_asset_service.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,18 @@ def test_asset_service_client_service_account_always_use_jwt(client_class):
113113
with mock.patch.object(service_account.Credentials, 'with_always_use_jwt_access', create=True) as use_jwt:
114114
creds = service_account.Credentials(None, None, None)
115115
client = client_class(credentials=creds)
116-
use_jwt.assert_called_with(True)
116+
use_jwt.assert_not_called()
117+
118+
119+
@pytest.mark.parametrize("transport_class,transport_name", [
120+
(transports.AssetServiceGrpcTransport, "grpc"),
121+
(transports.AssetServiceGrpcAsyncIOTransport, "grpc_asyncio"),
122+
])
123+
def test_asset_service_client_service_account_always_use_jwt_true(transport_class, transport_name):
124+
with mock.patch.object(service_account.Credentials, 'with_always_use_jwt_access', create=True) as use_jwt:
125+
creds = service_account.Credentials(None, None, None)
126+
transport = transport_class(credentials=creds, always_use_jwt_access=True)
127+
use_jwt.assert_called_once_with(True)
117128

118129

119130
@pytest.mark.parametrize("client_class", [

tests/integration/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/transports/grpc.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def __init__(self, *,
6363
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
6464
quota_project_id: Optional[str] = None,
6565
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
66+
always_use_jwt_access: Optional[bool] = False,
6667
) -> None:
6768
"""Instantiate the transport.
6869
@@ -103,6 +104,8 @@ def __init__(self, *,
103104
API requests. If ``None``, then default info will be used.
104105
Generally, you only need to set this if you're developing
105106
your own client library.
107+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
108+
be used for service account credentials.
106109
107110
Raises:
108111
google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
@@ -155,7 +158,7 @@ def __init__(self, *,
155158
scopes=scopes,
156159
quota_project_id=quota_project_id,
157160
client_info=client_info,
158-
always_use_jwt_access=True,
161+
always_use_jwt_access=always_use_jwt_access,
159162
)
160163

161164
if not self._grpc_channel:

tests/integration/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/transports/grpc_asyncio.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ def __init__(self, *,
108108
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
109109
quota_project_id=None,
110110
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
111+
always_use_jwt_access: Optional[bool] = False,
111112
) -> None:
112113
"""Instantiate the transport.
113114
@@ -149,6 +150,8 @@ def __init__(self, *,
149150
API requests. If ``None``, then default info will be used.
150151
Generally, you only need to set this if you're developing
151152
your own client library.
153+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
154+
be used for service account credentials.
152155
153156
Raises:
154157
google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
@@ -200,7 +203,7 @@ def __init__(self, *,
200203
scopes=scopes,
201204
quota_project_id=quota_project_id,
202205
client_info=client_info,
203-
always_use_jwt_access=True,
206+
always_use_jwt_access=always_use_jwt_access,
204207
)
205208

206209
if not self._grpc_channel:

tests/integration/goldens/credentials/tests/unit/gapic/credentials_v1/test_iam_credentials.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,18 @@ def test_iam_credentials_client_service_account_always_use_jwt(client_class):
105105
with mock.patch.object(service_account.Credentials, 'with_always_use_jwt_access', create=True) as use_jwt:
106106
creds = service_account.Credentials(None, None, None)
107107
client = client_class(credentials=creds)
108-
use_jwt.assert_called_with(True)
108+
use_jwt.assert_not_called()
109+
110+
111+
@pytest.mark.parametrize("transport_class,transport_name", [
112+
(transports.IAMCredentialsGrpcTransport, "grpc"),
113+
(transports.IAMCredentialsGrpcAsyncIOTransport, "grpc_asyncio"),
114+
])
115+
def test_iam_credentials_client_service_account_always_use_jwt_true(transport_class, transport_name):
116+
with mock.patch.object(service_account.Credentials, 'with_always_use_jwt_access', create=True) as use_jwt:
117+
creds = service_account.Credentials(None, None, None)
118+
transport = transport_class(credentials=creds, always_use_jwt_access=True)
119+
use_jwt.assert_called_once_with(True)
109120

110121

111122
@pytest.mark.parametrize("client_class", [

0 commit comments

Comments
 (0)