googleauth 1.17.8 → 1.17.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b4438b5a4afacb0eb2223370a7a193fb7185ff0c7a26a4e36faf82e8946448fb
4
- data.tar.gz: 35cb94da761a317c43ddb3554ee77aedd53ad1384892f6007b9ea7cb31fdb6cf
3
+ metadata.gz: b77dadaea113147f4389a23552c3d4ee8d5b12f29f18d34a4e466895aa19e18e
4
+ data.tar.gz: 07157407a654a168159a7c9551c2abaaeac4d0493bbba558c95a80d95869d5d0
5
5
  SHA512:
6
- metadata.gz: 356edb19a4de19b21ff1aa25681b329aa4eb72f1499575c009649efd042f0e0560ec03cc3332bd7d750627ecca85391134a8424ba94300abba113a80bce8b452
7
- data.tar.gz: c1e894da2db997443e65f6151668b7d617446127c9dc991a9ee770232263c6dc9ffc8362909d58ed3bdf5dec7f3ca4395c26235efdb2b7065467ed1470636aa2
6
+ metadata.gz: f69c31d1c87ba35eaeeffc301c315017fd4d0633315959af16702daafb7d362f1a44d71c526145f91c0c5e0485b52f112c6fc278d4262a10233abb4bcbf3d744
7
+ data.tar.gz: 76e69a6401f0469692f03333e9e4ce4b4bd9a28e4685cff4a9a71d8c0a1812530ed071c459a1de3e9dd9e7e05240a5e9eb7c821d12fb83082d68ccab2548cfea
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Release History
2
2
 
3
+ ### 1.17.9 (2026-12-03)
4
+
5
+ #### Bug Fixes
6
+
7
+ * default universe_domain to googleapis.com in UserRefreshCredentials ([#617](https://github.com/googleapis/google-auth-library-ruby/issues/617))
8
+ * preserve top-level universe_domain in ImpersonatedServiceAccountCredentials ([#615](https://github.com/googleapis/google-auth-library-ruby/issues/615))
9
+ * prevent OAuth2 token requests for non-default universe in ServiceAccountCredentials ([#620](https://github.com/googleapis/google-auth-library-ruby/issues/620))
10
+ * reject non-default universe_domain in UserRefreshCredentials ([#614](https://github.com/googleapis/google-auth-library-ruby/issues/614))
11
+
3
12
  ### 1.17.8 (2026-11-22)
4
13
 
5
14
  #### Bug Fixes
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Google Auth Library for Ruby
2
2
 
3
3
  <dl>
4
- <dt>Homepage</dt><dd><a href="http://www.github.com/googleapis/google-auth-library-ruby">http://www.github.com/googleapis/google-auth-library-ruby</a></dd>
4
+ <dt>Homepage</dt><dd><a href="https://github.com/googleapis/google-auth-library-ruby">https://github.com/googleapis/google-auth-library-ruby</a></dd>
5
5
  <dt>Authors</dt><dd><a href="mailto:temiola@google.com">Tim Emiola</a></dd>
6
6
  <dt>Copyright</dt><dd>Copyright © 2015 Google, Inc.</dd>
7
7
  <dt>License</dt><dd>Apache 2.0</dd>
@@ -286,12 +286,12 @@ See [CONTRIBUTING][contributing].
286
286
  ## Support
287
287
 
288
288
  Please
289
- [report bugs at the project on Github](https://github.com/google/google-auth-library-ruby/issues). Don't
289
+ [report bugs at the project on Github](https://github.com/googleapis/google-auth-library-ruby/issues). Don't
290
290
  hesitate to
291
291
  [ask questions](http://stackoverflow.com/questions/tagged/google-auth-library-ruby)
292
292
  about the client or APIs on [StackOverflow](http://stackoverflow.com).
293
293
 
294
294
  [application default credentials]: https://cloud.google.com/docs/authentication/provide-credentials-adc
295
295
  [contributing]: https://github.com/googleapis/google-auth-library-ruby/blob/main/.github/CONTRIBUTING.md
296
- [license]: https://github.com/googleapis/google-auth-library-ruby/tree/main/LICENSE
296
+ [license]: https://github.com/googleapis/google-auth-library-ruby/blob/main/LICENSE
297
297
 
@@ -127,6 +127,8 @@ module Google
127
127
  "use delegates to chain impersonation."
128
128
  end
129
129
 
130
+ source_credentials_info = merge_universe_domain impersonated_json, source_credentials_info
131
+
130
132
  source_credentials = DefaultCredentials.make_creds(
131
133
  json_key_io: StringIO.new(JSON.generate(source_credentials_info))
132
134
  )
@@ -142,6 +144,27 @@ module Google
142
144
  end
143
145
  private_class_method :make_creds_from_json
144
146
 
147
+ # @private
148
+ def self.merge_universe_domain impersonated_json, source_credentials_info
149
+ universe_domain = impersonated_json["universe_domain"]
150
+ return source_credentials_info if universe_domain.nil?
151
+
152
+ unless universe_domain.is_a?(String) && !universe_domain.empty?
153
+ raise Google::Auth::InitializationError,
154
+ "Invalid universe_domain: #{universe_domain.inspect}"
155
+ end
156
+
157
+ source_universe_domain = source_credentials_info["universe_domain"]
158
+ if !source_universe_domain.nil? && source_universe_domain != universe_domain
159
+ raise Google::Auth::InitializationError,
160
+ "Universe domain '#{source_universe_domain}' in source_credentials does not match " \
161
+ "top-level universe_domain '#{universe_domain}'"
162
+ end
163
+
164
+ source_credentials_info.merge "universe_domain" => universe_domain
165
+ end
166
+ private_class_method :merge_universe_domain
167
+
145
168
  # Initializes a new instance of ImpersonatedServiceAccountCredentials.
146
169
  #
147
170
  # @param options [Hash] A hash of options to configure the credentials.
@@ -45,6 +45,9 @@ module Google
45
45
  # @type [::String] The type name for this credential.
46
46
  CREDENTIAL_TYPE_NAME = "service_account".freeze
47
47
 
48
+ DEFAULT_UNIVERSE_DOMAIN = "googleapis.com".freeze
49
+ private_constant :DEFAULT_UNIVERSE_DOMAIN
50
+
48
51
  # @private
49
52
  # @type [Array<Symbol>] Allowed option keys for make_creds.
50
53
  VALID_MAKE_CREDS_OPTIONS = [
@@ -63,7 +66,8 @@ module Google
63
66
  # obtain an OAuth token, OR if there are scopes but also an assertion
64
67
  # that they are default scopes that shouldn't be used to fetch a token,
65
68
  # OR we are not in the default universe and thus OAuth isn't supported.
66
- target_audience.nil? && (scope.nil? || @enable_self_signed_jwt || universe_domain != "googleapis.com")
69
+ target_audience.nil? &&
70
+ (scope.nil? || token_credential_uri.nil? || @enable_self_signed_jwt || non_default_universe_domain?)
67
71
  end
68
72
 
69
73
  # Creates a ServiceAccountCredentials.
@@ -77,9 +81,10 @@ module Google
77
81
  # @param default_connection [Faraday::Connection, nil] Optional. The connection object to use
78
82
  # @param connection_builder [Proc, nil] Optional. A Proc that returns a Faraday connection
79
83
  # @raise [ArgumentError] If both scope and target_audience are specified
80
- # @raise [InitializationError] If json_key_io is not an IO object, or
81
- # if required credential fields (private_key or client_email) are missing
82
- def self.make_creds options = {} # rubocop:disable Metrics/MethodLength
84
+ # @raise [InitializationError] If json_key_io is not an IO object,
85
+ # if required credential fields (private_key or client_email) are missing,
86
+ # or if target_audience is specified for a non-default universe domain
87
+ def self.make_creds options = {}
83
88
  validate_make_creds_options options
84
89
 
85
90
  json_key_io, scope, enable_self_signed_jwt, target_audience, audience, token_credential_uri =
@@ -88,30 +93,17 @@ module Google
88
93
  raise ArgumentError, "Cannot specify both scope and target_audience" if scope && target_audience
89
94
 
90
95
  private_key, client_email, project_id, quota_project_id, universe_domain =
91
- if json_key_io
92
- unless json_key_io.respond_to? :read
93
- raise InitializationError, "Expected an IO object for json_key_io"
94
- end
95
- json_key = JSON.parse json_key_io.read
96
- if json_key.key? "type"
97
- json_key_io.rewind
98
- else # Defaults to class credential 'type' if missing.
99
- json_key["type"] = CREDENTIAL_TYPE_NAME
100
- json_key_io = StringIO.new JSON.generate(json_key)
101
- end
102
- CredentialsLoader.load_and_verify_json_key_type json_key_io, CREDENTIAL_TYPE_NAME
103
- read_json_key json_key_io
104
- else
105
- creds_from_env
106
- end
96
+ load_credentials json_key_io
107
97
 
108
98
  raise InitializationError, "Missing required field: private_key" unless private_key
109
99
  raise InitializationError, "Missing required field: client_email" unless client_email
110
100
 
111
101
  project_id ||= CredentialsLoader.load_gcloud_project_id
102
+ universe_domain = DEFAULT_UNIVERSE_DOMAIN if universe_domain.nil?
103
+ default_token_uri = universe_domain == DEFAULT_UNIVERSE_DOMAIN ? TOKEN_CRED_URI : nil
112
104
 
113
- new(token_credential_uri: token_credential_uri || TOKEN_CRED_URI,
114
- audience: audience || TOKEN_CRED_URI,
105
+ new(token_credential_uri: token_credential_uri || default_token_uri,
106
+ audience: audience || default_token_uri,
115
107
  scope: scope,
116
108
  enable_self_signed_jwt: enable_self_signed_jwt,
117
109
  target_audience: target_audience,
@@ -119,7 +111,7 @@ module Google
119
111
  signing_key: OpenSSL::PKey::RSA.new(private_key),
120
112
  project_id: project_id,
121
113
  quota_project_id: quota_project_id,
122
- universe_domain: universe_domain || "googleapis.com")
114
+ universe_domain: universe_domain)
123
115
  .configure_connection(options)
124
116
  end
125
117
 
@@ -161,12 +153,72 @@ module Google
161
153
  end
162
154
 
163
155
  def initialize options = {}
164
- @project_id = options[:project_id]
165
- @quota_project_id = options[:quota_project_id]
166
- @enable_self_signed_jwt = options[:enable_self_signed_jwt] ? true : false
156
+ options ||= {}
157
+ @project_id = nil
158
+ @quota_project_id = nil
159
+ @enable_self_signed_jwt = false
160
+ @universe_domain = DEFAULT_UNIVERSE_DOMAIN
167
161
  super options
168
162
  end
169
163
 
164
+ # Sets the universe domain for these credentials, normalizing `nil` to
165
+ # the default universe domain (`googleapis.com`).
166
+ #
167
+ # @param value [String, nil] The universe domain.
168
+ # @raise [Google::Auth::InitializationError] If a non-default universe
169
+ # domain is combined with a non-nil `target_audience`.
170
+ def universe_domain= value
171
+ value = normalized_universe_domain value
172
+ validate_target_audience_universe_domain! target_audience, value
173
+ super value
174
+ end
175
+
176
+ # Sets the target audience for ID token requests.
177
+ #
178
+ # @param new_target_audience [String, nil] The target audience.
179
+ # @raise [Google::Auth::InitializationError] If a non-nil `target_audience`
180
+ # is set for a non-default universe domain.
181
+ def target_audience= new_target_audience
182
+ validate_target_audience_universe_domain! new_target_audience, universe_domain
183
+ super
184
+ end
185
+
186
+ # Fetches an OAuth 2.0 token from the token endpoint.
187
+ #
188
+ # @param options [Hash] Options forwarded to `Signet::OAuth2::Client#fetch_access_token`.
189
+ # @raise [Google::Auth::CredentialsError] If called with a non-default universe domain.
190
+ def fetch_access_token options = {}
191
+ ensure_default_universe_domain! "fetch_access_token"
192
+ super
193
+ end
194
+
195
+ # Fetches an OAuth 2.0 token from the token endpoint and updates client state.
196
+ #
197
+ # @param options [Hash] Options forwarded to `Signet::OAuth2::Client#fetch_access_token!`.
198
+ # @raise [Google::Auth::CredentialsError] If called with a non-default universe domain.
199
+ def fetch_access_token! options = {}
200
+ ensure_default_universe_domain! "fetch_access_token!"
201
+ super
202
+ end
203
+
204
+ # Generates an OAuth 2.0 access token request payload.
205
+ #
206
+ # @param options [Hash] Options forwarded to `Signet::OAuth2::Client#generate_access_token_request`.
207
+ # @raise [Google::Auth::CredentialsError] If called with a non-default universe domain.
208
+ def generate_access_token_request options = {}
209
+ ensure_default_universe_domain! "generate_access_token_request"
210
+ super
211
+ end
212
+
213
+ # Signs a JWT assertion for OAuth 2.0 token exchange.
214
+ #
215
+ # @param options [Hash] Options forwarded to `Signet::OAuth2::Client#to_jwt`.
216
+ # @raise [Google::Auth::CredentialsError] If called with a non-default universe domain.
217
+ def to_jwt options = {}
218
+ ensure_default_universe_domain! "to_jwt"
219
+ super
220
+ end
221
+
170
222
  # Extends the base class to use a transient
171
223
  # ServiceAccountJwtHeaderCredentials for certain cases.
172
224
  def apply! a_hash, opts = {}
@@ -194,20 +246,47 @@ module Google
194
246
  # * `project_id` the project id to use during the authentication
195
247
  # * `quota_project_id` the quota project id to use
196
248
  # during the authentication
249
+ # @raise [Google::Auth::InitializationError] If the resulting state combines
250
+ # a non-nil `target_audience` with a non-default universe domain.
197
251
  # @return [Google::Auth::ServiceAccountCredentials]
198
252
  def update! options = {}
199
253
  # Normalize all keys to symbols to allow indifferent access.
200
254
  options = deep_hash_normalize options
255
+ new_universe_domain =
256
+ options.key?(:universe_domain) ? normalized_universe_domain(options[:universe_domain]) : universe_domain
257
+ new_target_audience = options.key?(:target_audience) ? options[:target_audience] : target_audience
258
+ validate_target_audience_universe_domain! new_target_audience, new_universe_domain
259
+
260
+ # Clear target_audience before super sets a non-default universe_domain so
261
+ # valid transitions never pass through (non-default universe, non-nil target_audience).
262
+ self.target_audience = nil if new_target_audience.nil? && new_universe_domain != DEFAULT_UNIVERSE_DOMAIN
201
263
 
202
- @enable_self_signed_jwt = options[:enable_self_signed_jwt] ? true : false
264
+ if options.key? :enable_self_signed_jwt
265
+ @enable_self_signed_jwt = options[:enable_self_signed_jwt] ? true : false
266
+ end
203
267
  @project_id = options[:project_id] if options.key? :project_id
204
268
  @quota_project_id = options[:quota_project_id] if options.key? :quota_project_id
205
269
 
206
- super(options)
270
+ super options
207
271
 
208
272
  self
209
273
  end
210
274
 
275
+ # Updates token parameters on these credentials.
276
+ #
277
+ # @param options [Hash] Token parameter overrides.
278
+ # @raise [Google::Auth::InitializationError] If updating `universe_domain`
279
+ # to a non-default value while `target_audience` is set.
280
+ # @return [Google::Auth::ServiceAccountCredentials]
281
+ def update_token! options = {}
282
+ options = deep_hash_normalize options
283
+ if options.key? :universe_domain
284
+ new_ud = normalized_universe_domain options[:universe_domain]
285
+ validate_target_audience_universe_domain! target_audience, new_ud
286
+ end
287
+ super options
288
+ end
289
+
211
290
  # Returns the client email as the principal for service account credentials
212
291
  # @private
213
292
  # @return [String] the email address of the service account
@@ -217,6 +296,36 @@ module Google
217
296
 
218
297
  private
219
298
 
299
+ def non_default_universe_domain?
300
+ universe_domain != DEFAULT_UNIVERSE_DOMAIN
301
+ end
302
+
303
+ def normalized_universe_domain value
304
+ value.nil? ? DEFAULT_UNIVERSE_DOMAIN : value
305
+ end
306
+
307
+ def validate_target_audience_universe_domain! audience, domain
308
+ return if audience.nil? || domain == DEFAULT_UNIVERSE_DOMAIN
309
+
310
+ raise InitializationError,
311
+ "target_audience is not supported for ServiceAccountCredentials in " \
312
+ "non-default universe domain #{domain.inspect} (default is #{DEFAULT_UNIVERSE_DOMAIN})"
313
+ end
314
+
315
+ def ensure_default_universe_domain! operation
316
+ return unless non_default_universe_domain?
317
+
318
+ message = "OAuth 2.0 token exchange (#{operation}) is not supported for " \
319
+ "ServiceAccountCredentials in non-default universe domain " \
320
+ "#{universe_domain.inspect} (default is #{DEFAULT_UNIVERSE_DOMAIN}); " \
321
+ "use apply! for self-signed JWT authentication"
322
+ raise CredentialsError.with_details(
323
+ message,
324
+ credential_type_name: self.class.name,
325
+ principal: principal
326
+ )
327
+ end
328
+
220
329
  def apply_self_signed_jwt! a_hash
221
330
  # Use the ServiceAccountJwtHeaderCredentials using the same cred values
222
331
  alt = ServiceAccountJwtHeaderCredentials.new(
@@ -231,6 +340,23 @@ module Google
231
340
  alt.apply! a_hash
232
341
  end
233
342
 
343
+ # @private
344
+ # Loads service account credentials from a JSON key IO or environment variables.
345
+ def self.load_credentials json_key_io
346
+ return creds_from_env unless json_key_io
347
+ raise InitializationError, "Expected an IO object for json_key_io" unless json_key_io.respond_to? :read
348
+
349
+ json_key = JSON.parse json_key_io.read
350
+ if json_key.key? "type"
351
+ json_key_io.rewind
352
+ else # Defaults to class credential 'type' if missing.
353
+ json_key["type"] = CREDENTIAL_TYPE_NAME
354
+ json_key_io = StringIO.new JSON.generate(json_key)
355
+ end
356
+ CredentialsLoader.load_and_verify_json_key_type json_key_io, CREDENTIAL_TYPE_NAME
357
+ read_json_key json_key_io
358
+ end
359
+
234
360
  # @private
235
361
  # Loads service account credential details from environment variables.
236
362
  #
@@ -256,7 +382,7 @@ module Google
256
382
  warn "Unrecognized option(s) for ServiceAccountCredentials.make_creds: #{unknown_keys.map(&:inspect).join ', '}"
257
383
  end
258
384
 
259
- private_class_method :creds_from_env, :validate_make_creds_options
385
+ private_class_method :load_credentials, :creds_from_env, :validate_make_creds_options
260
386
  end
261
387
  end
262
388
  end
@@ -43,6 +43,10 @@ module Google
43
43
  # @type [::String] The type name for this credential.
44
44
  CREDENTIAL_TYPE_NAME = "authorized_user".freeze
45
45
 
46
+ # @private Default universe domain.
47
+ DEFAULT_UNIVERSE_DOMAIN = "googleapis.com".freeze
48
+ private_constant :DEFAULT_UNIVERSE_DOMAIN
49
+
46
50
  # Create a UserRefreshCredentials.
47
51
  #
48
52
  # @param json_key_io [IO] An IO object containing the JSON key
@@ -69,6 +73,8 @@ module Google
69
73
  "universe_domain" => nil
70
74
  }
71
75
  end
76
+ universe_domain = user_creds["universe_domain"]
77
+ universe_domain = DEFAULT_UNIVERSE_DOMAIN if universe_domain.nil?
72
78
  new(token_credential_uri: TOKEN_CRED_URI,
73
79
  client_id: user_creds["client_id"],
74
80
  client_secret: user_creds["client_secret"],
@@ -76,7 +82,7 @@ module Google
76
82
  project_id: user_creds["project_id"],
77
83
  quota_project_id: user_creds["quota_project_id"],
78
84
  scope: scope,
79
- universe_domain: user_creds["universe_domain"] || "googleapis.com")
85
+ universe_domain: universe_domain)
80
86
  .configure_connection(options)
81
87
  end
82
88
 
@@ -101,9 +107,27 @@ module Google
101
107
  @project_id = options[:project_id]
102
108
  @project_id ||= CredentialsLoader.load_gcloud_project_id
103
109
  @quota_project_id = options[:quota_project_id]
110
+ @universe_domain = DEFAULT_UNIVERSE_DOMAIN
104
111
  super options
105
112
  end
106
113
 
114
+ # Sets the universe domain for these credentials, normalizing `nil` to
115
+ # the default universe domain (`googleapis.com`). Only the default
116
+ # universe is supported for user refresh credentials.
117
+ #
118
+ # @param value [String, nil] The universe domain
119
+ # @raise [Google::Auth::InitializationError] If a non-default universe domain is provided
120
+ def universe_domain= value
121
+ value = DEFAULT_UNIVERSE_DOMAIN if value.nil?
122
+ unless value == DEFAULT_UNIVERSE_DOMAIN
123
+ raise InitializationError,
124
+ "UserRefreshCredentials is only supported in the default universe " \
125
+ "(#{DEFAULT_UNIVERSE_DOMAIN}), got #{value.inspect}"
126
+ end
127
+
128
+ super value
129
+ end
130
+
107
131
  # Creates a duplicate of these credentials
108
132
  # without the Signet::OAuth2::Client-specific
109
133
  # transient state (e.g. cached tokens)
@@ -16,6 +16,6 @@ module Google
16
16
  # Module Auth provides classes that provide Google-specific authorization
17
17
  # used to access Google APIs.
18
18
  module Auth
19
- VERSION = "1.17.8".freeze
19
+ VERSION = "1.17.9".freeze
20
20
  end
21
21
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: googleauth
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.17.8
4
+ version: 1.17.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Google LLC