googleauth 0.16.2 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a1f96ad8fd7b2aae5671af839775b83db2c3f6b9c31e36622c2dc983d647e54d
4
- data.tar.gz: 58db2385909da01755365839451a6a8bbb79fceaabd76de313dab9496a7ea0dd
3
+ metadata.gz: 5101c77470407b3d53ea18a41ecc2472c3e6b7d86c8a7ce21cc604ed346e030c
4
+ data.tar.gz: b33a1ca384b5178aaf0438a0ac87776bc598326dd221804e4562c5f7b2076e97
5
5
  SHA512:
6
- metadata.gz: 39f9a7e75bbb27ff0cd9bb50ebc077751f83ee22fec724d4de9ed54c3bde97a92e5a9f577859784d2c298405fa9cf57491bddf73043ff5a0cb6a567379fc2cbb
7
- data.tar.gz: 543d6c2e8175ea1262c4235e581124378ef932fe96b7c63e27b75654a2e7cdfc5e427c6f9668141de1b06d770dedfb97ca8b94b1df800d0bdf04c1860644dc2c
6
+ metadata.gz: 8c33deaf116dc8ba017b73525ba5dc4029511530d3e34d03584ad32023689d9b4837b5136344ec66486157651a55693fd16b23e770573912fff0094d33031fd7
7
+ data.tar.gz: 8adfa4263bbcecd04770de3647dae120beb585c140315dd6392d16cbdcb523d438f35cd5a7f0be74a6b824448ff201c8a654a96b774c902ea9cfbdf1c1d9dc94
data/.repo-metadata.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "name": "googleauth",
3
2
  "language": "ruby",
4
- "distribution-name": "googleauth"
5
- }
3
+ "distribution-name": "googleauth",
4
+ "library_type": "AUTH"
5
+ }
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Release History
2
2
 
3
+ ## [0.17.0](https://www.github.com/googleapis/google-auth-library-ruby/compare/google-auth-library-ruby/v0.16.2...google-auth-library-ruby/v0.17.0) (2021-07-30)
4
+
5
+
6
+ ### Features
7
+
8
+ * Allow scopes to be self-signed into jwts ([e67ce40](https://www.github.com/googleapis/google-auth-library-ruby/commit/e67ce40f919b7eb3723c2ec95f5b8d58315ab1ee))
9
+
3
10
  ### [0.16.2](https://www.github.com/googleapis/google-auth-library-ruby/compare/google-auth-library-ruby/v0.16.1...google-auth-library-ruby/v0.16.2) (2021-04-28)
4
11
 
5
12
 
data/SECURITY.md ADDED
@@ -0,0 +1,7 @@
1
+ # Security Policy
2
+
3
+ To report a security issue, please use [g.co/vulnz](https://g.co/vulnz).
4
+
5
+ The Google Security Team will respond within 5 working days of your report on g.co/vulnz.
6
+
7
+ We use g.co/vulnz for our intake, and do coordination and disclosure here using GitHub Security Advisory to privately discuss and fix the issue.
@@ -129,7 +129,7 @@ module Google
129
129
  quota_project_id: @quota_project_id
130
130
  }
131
131
  key_io = StringIO.new MultiJson.dump(cred_json)
132
- alt = ServiceAccountJwtHeaderCredentials.make_creds json_key_io: key_io
132
+ alt = ServiceAccountJwtHeaderCredentials.make_creds json_key_io: key_io, scope: scope
133
133
  alt.apply! a_hash
134
134
  end
135
135
  end
@@ -154,15 +154,13 @@ module Google
154
154
  attr_reader :project_id
155
155
  attr_reader :quota_project_id
156
156
 
157
- # make_creds proxies the construction of a credentials instance
157
+ # Create a ServiceAccountJwtHeaderCredentials.
158
158
  #
159
- # make_creds is used by the methods in CredentialsLoader.
160
- #
161
- # By default, it calls #new with 2 args, the second one being an
162
- # optional scope. Here's the constructor only has one param, so
163
- # we modify make_creds to reflect this.
164
- def self.make_creds *args
165
- new json_key_io: args[0][:json_key_io]
159
+ # @param json_key_io [IO] an IO from which the JSON key can be read
160
+ # @param scope [string|array|nil] the scope(s) to access
161
+ def self.make_creds options = {}
162
+ json_key_io, scope = options.values_at :json_key_io, :scope
163
+ new json_key_io: json_key_io, scope: scope
166
164
  end
167
165
 
168
166
  # Initializes a ServiceAccountJwtHeaderCredentials.
@@ -181,6 +179,7 @@ module Google
181
179
  end
182
180
  @project_id ||= CredentialsLoader.load_gcloud_project_id
183
181
  @signing_key = OpenSSL::PKey::RSA.new @private_key
182
+ @scope = options[:scope]
184
183
  end
185
184
 
186
185
  # Construct a jwt token if the JWT_AUD_URI key is present in the input
@@ -189,7 +188,7 @@ module Google
189
188
  # The jwt token is used as the value of a 'Bearer '.
190
189
  def apply! a_hash, opts = {}
191
190
  jwt_aud_uri = a_hash.delete JWT_AUD_URI_KEY
192
- return a_hash if jwt_aud_uri.nil?
191
+ return a_hash if jwt_aud_uri.nil? && @scope.nil?
193
192
  jwt_token = new_jwt_token jwt_aud_uri, opts
194
193
  a_hash[AUTH_METADATA_KEY] = "Bearer #{jwt_token}"
195
194
  a_hash
@@ -211,16 +210,21 @@ module Google
211
210
  protected
212
211
 
213
212
  # Creates a jwt uri token.
214
- def new_jwt_token jwt_aud_uri, options = {}
213
+ def new_jwt_token jwt_aud_uri = nil, options = {}
215
214
  now = Time.new
216
215
  skew = options[:skew] || 60
217
216
  assertion = {
218
217
  "iss" => @issuer,
219
218
  "sub" => @issuer,
220
- "aud" => jwt_aud_uri,
221
219
  "exp" => (now + EXPIRY).to_i,
222
220
  "iat" => (now - skew).to_i
223
221
  }
222
+
223
+ jwt_aud_uri = nil if @scope
224
+
225
+ assertion["scope"] = Array(@scope).join " " if @scope
226
+ assertion["aud"] = jwt_aud_uri if jwt_aud_uri
227
+
224
228
  JWT.encode assertion, @signing_key, SIGNING_ALGORITHM
225
229
  end
226
230
  end
@@ -31,6 +31,6 @@ module Google
31
31
  # Module Auth provides classes that provide Google-specific authorization
32
32
  # used to access Google APIs.
33
33
  module Auth
34
- VERSION = "0.16.2".freeze
34
+ VERSION = "0.17.0".freeze
35
35
  end
36
36
  end
@@ -44,9 +44,10 @@ require "os"
44
44
 
45
45
  include Google::Auth::CredentialsLoader
46
46
 
47
- shared_examples "jwt header auth" do
47
+ shared_examples "jwt header auth" do |aud="https://www.googleapis.com/myservice"|
48
48
  context "when jwt_aud_uri is present" do
49
- let(:test_uri) { "https://www.googleapis.com/myservice" }
49
+ let(:test_uri) { aud }
50
+ let(:test_scope) { "scope/1 scope/2" }
50
51
  let(:auth_prefix) { "Bearer " }
51
52
  let(:auth_key) { ServiceAccountJwtHeaderCredentials::AUTH_METADATA_KEY }
52
53
  let(:jwt_uri_key) { ServiceAccountJwtHeaderCredentials::JWT_AUD_URI_KEY }
@@ -56,14 +57,16 @@ shared_examples "jwt header auth" do
56
57
  expect(hdr.start_with?(auth_prefix)).to be true
57
58
  authorization = hdr[auth_prefix.length..-1]
58
59
  payload, = JWT.decode authorization, @key.public_key, true, algorithm: "RS256"
59
- expect(payload["aud"]).to eq(test_uri)
60
+
61
+ expect(payload["aud"]).to eq(test_uri) if not test_uri.nil?
62
+ expect(payload["scope"]).to eq(test_scope) if test_uri.nil?
60
63
  expect(payload["iss"]).to eq(client_email)
61
64
  end
62
65
 
63
66
  describe "#apply!" do
64
67
  it "should update the target hash with a jwt token" do
65
68
  md = { foo: "bar" }
66
- md[jwt_uri_key] = test_uri
69
+ md[jwt_uri_key] = test_uri if test_uri
67
70
  @client.apply! md
68
71
  auth_header = md[auth_key]
69
72
  expect_is_encoded_jwt auth_header
@@ -74,31 +77,31 @@ shared_examples "jwt header auth" do
74
77
  describe "updater_proc" do
75
78
  it "should provide a proc that updates a hash with a jwt token" do
76
79
  md = { foo: "bar" }
77
- md[jwt_uri_key] = test_uri
80
+ md[jwt_uri_key] = test_uri if test_uri
78
81
  the_proc = @client.updater_proc
79
82
  got = the_proc.call md
80
83
  auth_header = got[auth_key]
81
84
  expect_is_encoded_jwt auth_header
82
85
  expect(got[jwt_uri_key]).to be_nil
83
- expect(md[jwt_uri_key]).to_not be_nil
86
+ expect(md[jwt_uri_key]).to_not be_nil if test_uri
84
87
  end
85
88
  end
86
89
 
87
90
  describe "#apply" do
88
91
  it "should not update the original hash with a jwt token" do
89
92
  md = { foo: "bar" }
90
- md[jwt_uri_key] = test_uri
93
+ md[jwt_uri_key] = test_uri if test_uri
91
94
  the_proc = @client.updater_proc
92
95
  got = the_proc.call md
93
96
  auth_header = md[auth_key]
94
97
  expect(auth_header).to be_nil
95
98
  expect(got[jwt_uri_key]).to be_nil
96
- expect(md[jwt_uri_key]).to_not be_nil
99
+ expect(md[jwt_uri_key]).to_not be_nil if test_uri
97
100
  end
98
101
 
99
102
  it "should add a jwt token to the returned hash" do
100
103
  md = { foo: "bar" }
101
- md[jwt_uri_key] = test_uri
104
+ md[jwt_uri_key] = test_uri if test_uri
102
105
  got = @client.apply md
103
106
  auth_header = got[auth_key]
104
107
  expect_is_encoded_jwt auth_header
@@ -107,6 +110,7 @@ shared_examples "jwt header auth" do
107
110
  end
108
111
  end
109
112
 
113
+
110
114
  describe Google::Auth::ServiceAccountCredentials do
111
115
  ServiceAccountCredentials = Google::Auth::ServiceAccountCredentials
112
116
  let(:client_email) { "app@developer.gserviceaccount.com" }
@@ -169,14 +173,24 @@ describe Google::Auth::ServiceAccountCredentials do
169
173
  it_behaves_like "jwt header auth"
170
174
  end
171
175
 
172
- context "when enable_self_signed_jwt is set" do
176
+ context "when enable_self_signed_jwt is set with aud" do
173
177
  before :example do
178
+ @client.scope = nil
174
179
  @client.instance_variable_set(:@enable_self_signed_jwt, true)
175
180
  end
176
181
 
177
182
  it_behaves_like "jwt header auth"
178
183
  end
179
184
 
185
+ context "when enable_self_signed_jwt is set with scope" do
186
+ before :example do
187
+ @client.scope = ['scope/1', 'scope/2']
188
+ @client.instance_variable_set(:@enable_self_signed_jwt, true)
189
+ end
190
+
191
+ it_behaves_like "jwt header auth", nil
192
+ end
193
+
180
194
  describe "#from_env" do
181
195
  before :example do
182
196
  @var_name = ENV_VAR
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: googleauth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.2
4
+ version: 0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Emiola
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-28 00:00:00.000000000 Z
11
+ date: 2021-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -164,6 +164,7 @@ files:
164
164
  - Gemfile
165
165
  - LICENSE
166
166
  - README.md
167
+ - SECURITY.md
167
168
  - googleauth.gemspec
168
169
  - integration/helper.rb
169
170
  - integration/id_tokens/key_source_test.rb
@@ -228,7 +229,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
228
229
  - !ruby/object:Gem::Version
229
230
  version: '0'
230
231
  requirements: []
231
- rubygems_version: 3.2.16
232
+ rubygems_version: 3.2.17
232
233
  signing_key:
233
234
  specification_version: 4
234
235
  summary: Google Auth Library for Ruby