aptible-auth 1.2.7 → 1.3.0
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 +4 -4
- data/.github/workflows/ci.yml +1 -1
- data/.ruby-version +1 -0
- data/lib/aptible/auth/external_aws_oidc_token.rb +24 -0
- data/lib/aptible/auth/external_aws_role.rb +30 -0
- data/lib/aptible/auth/organization.rb +1 -0
- data/lib/aptible/auth/resource.rb +2 -0
- data/lib/aptible/auth/token.rb +1 -1
- data/lib/aptible/auth/version.rb +1 -1
- data/spec/aptible/auth/external_aws_oidc_token_spec.rb +44 -0
- data/spec/aptible/auth/external_aws_role_spec.rb +73 -0
- data/spec/aptible/auth/organization_spec.rb +37 -1
- data/spec/aptible/auth/resource_spec.rb +1 -1
- data/spec/aptible/auth_spec.rb +7 -2
- data/spec/shared/set_env.rb +1 -1
- metadata +10 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fa366e77caf944b6664bf9028ed18951244aa306db65267f4f7cd6abc5b186b6
|
|
4
|
+
data.tar.gz: f8142c1e9887387bf58187937b5f182396b83ff9f68f834811065b5606e33de0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b8e25debb3cca514e6b6fd343d57f1010ca657e34640e7a5a188d45ff98d48a2c1946ff56ff9019d015c22d6f9d5b4b47ec6d927a4dd96f26727f020c778ef2a
|
|
7
|
+
data.tar.gz: 6e4947efb5abd53ea279f90be54d237c289d14d4f968ea5b49e2b7ba570828d6f51708a744ac8c6d7c7cdbadd47a071d0d4b55cc4a1c88d4c0ef27cc8e34678c
|
data/.github/workflows/ci.yml
CHANGED
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.4
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module Aptible
|
|
2
|
+
module Auth
|
|
3
|
+
class ExternalAwsOidcToken
|
|
4
|
+
attr_reader :aws_web_identity_token_file_content, :aws_role_arn
|
|
5
|
+
|
|
6
|
+
def initialize(attributes = {})
|
|
7
|
+
@aws_web_identity_token_file_content =
|
|
8
|
+
attributes['aws_web_identity_token_file_content'] ||
|
|
9
|
+
attributes[:aws_web_identity_token_file_content]
|
|
10
|
+
@aws_role_arn =
|
|
11
|
+
attributes['aws_role_arn'] ||
|
|
12
|
+
attributes[:aws_role_arn]
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def to_s
|
|
16
|
+
aws_web_identity_token_file_content.to_s
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def token
|
|
20
|
+
aws_web_identity_token_file_content
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module Aptible
|
|
2
|
+
module Auth
|
|
3
|
+
class ExternalAwsRole < Resource
|
|
4
|
+
belongs_to :organization
|
|
5
|
+
|
|
6
|
+
field :id
|
|
7
|
+
field :external_aws_account_id
|
|
8
|
+
field :aws_account_id
|
|
9
|
+
field :role_type
|
|
10
|
+
field :role_arn
|
|
11
|
+
field :last_verified_at, type: Time
|
|
12
|
+
field :created_at, type: Time
|
|
13
|
+
field :updated_at, type: Time
|
|
14
|
+
|
|
15
|
+
def external_aws_oidc_token!
|
|
16
|
+
response = HyperResource::Link.new(
|
|
17
|
+
self,
|
|
18
|
+
'href' => "#{href}/external_aws_oidc_token"
|
|
19
|
+
).post(
|
|
20
|
+
self.class.normalize_params(
|
|
21
|
+
aws_account_id: attributes[:aws_account_id],
|
|
22
|
+
role_arn: attributes[:role_arn],
|
|
23
|
+
role_type: attributes[:role_type]
|
|
24
|
+
)
|
|
25
|
+
)
|
|
26
|
+
ExternalAwsOidcToken.new(response.body)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -24,6 +24,8 @@ require 'aptible/auth/token'
|
|
|
24
24
|
require 'aptible/auth/user'
|
|
25
25
|
require 'aptible/auth/ssh_key'
|
|
26
26
|
require 'aptible/auth/saml_configuration'
|
|
27
|
+
require 'aptible/auth/external_aws_role'
|
|
28
|
+
require 'aptible/auth/external_aws_oidc_token'
|
|
27
29
|
require 'aptible/auth/whitelist_membership'
|
|
28
30
|
require 'aptible/auth/reauthenticate_organization'
|
|
29
31
|
require 'aptible/auth/ssh_key_pre_authorization'
|
data/lib/aptible/auth/token.rb
CHANGED
|
@@ -53,7 +53,7 @@ module Aptible
|
|
|
53
53
|
# consistent API to consumers, we override it here
|
|
54
54
|
expires_in = options.delete(:expires_in)
|
|
55
55
|
options[:exp] = Time.now.utc.to_i + expires_in if expires_in
|
|
56
|
-
oauth_token = oauth.assertion.get_token({
|
|
56
|
+
oauth_token = oauth.assertion.get_token(**{
|
|
57
57
|
iss: id,
|
|
58
58
|
sub: subject
|
|
59
59
|
}.merge(signing_params_from_secret(secret).merge(options)))
|
data/lib/aptible/auth/version.rb
CHANGED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Aptible::Auth::ExternalAwsOidcToken do
|
|
4
|
+
let(:token_content) { 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...' }
|
|
5
|
+
let(:role_arn) { 'arn:aws:iam::123456789012:role/MyRole' }
|
|
6
|
+
|
|
7
|
+
describe '#initialize' do
|
|
8
|
+
it 'should accept string keys' do
|
|
9
|
+
token = described_class.new(
|
|
10
|
+
'aws_web_identity_token_file_content' => token_content,
|
|
11
|
+
'aws_role_arn' => role_arn
|
|
12
|
+
)
|
|
13
|
+
expect(token.aws_web_identity_token_file_content).to eq token_content
|
|
14
|
+
expect(token.aws_role_arn).to eq role_arn
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it 'should accept symbol keys' do
|
|
18
|
+
token = described_class.new(
|
|
19
|
+
aws_web_identity_token_file_content: token_content,
|
|
20
|
+
aws_role_arn: role_arn
|
|
21
|
+
)
|
|
22
|
+
expect(token.aws_web_identity_token_file_content).to eq token_content
|
|
23
|
+
expect(token.aws_role_arn).to eq role_arn
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
describe '#token' do
|
|
28
|
+
it 'should return the token content' do
|
|
29
|
+
token = described_class.new(
|
|
30
|
+
aws_web_identity_token_file_content: token_content
|
|
31
|
+
)
|
|
32
|
+
expect(token.token).to eq token_content
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
describe '#to_s' do
|
|
37
|
+
it 'should return the token content as a string' do
|
|
38
|
+
token = described_class.new(
|
|
39
|
+
aws_web_identity_token_file_content: token_content
|
|
40
|
+
)
|
|
41
|
+
expect(token.to_s).to eq token_content
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Aptible::Auth::ExternalAwsRole do
|
|
4
|
+
it { should be_a Aptible::Auth::Resource }
|
|
5
|
+
|
|
6
|
+
describe '#organization' do
|
|
7
|
+
let(:organization) { double 'Aptible::Auth::Organization' }
|
|
8
|
+
|
|
9
|
+
it 'should return the organization' do
|
|
10
|
+
allow(subject).to receive(:organization) { organization }
|
|
11
|
+
expect(subject.organization).to eq organization
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
describe '#external_aws_oidc_token!' do
|
|
16
|
+
let(:token_content) { 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...' }
|
|
17
|
+
let(:role_arn) { 'arn:aws:iam::123456789012:role/MyRole' }
|
|
18
|
+
let(:aws_account_id) { '123456789012' }
|
|
19
|
+
let(:role_type) { 'deploy' }
|
|
20
|
+
let(:response) do
|
|
21
|
+
double(
|
|
22
|
+
'response',
|
|
23
|
+
body: {
|
|
24
|
+
'aws_web_identity_token_file_content' => token_content,
|
|
25
|
+
'aws_role_arn' => role_arn
|
|
26
|
+
}
|
|
27
|
+
)
|
|
28
|
+
end
|
|
29
|
+
let(:link) { double('HyperResource::Link') }
|
|
30
|
+
|
|
31
|
+
before do
|
|
32
|
+
allow(subject).to receive(:href) { 'https://auth.aptible.com/external_aws_roles/123' }
|
|
33
|
+
allow(subject).to receive(:attributes).and_return(
|
|
34
|
+
aws_account_id: aws_account_id,
|
|
35
|
+
role_arn: role_arn,
|
|
36
|
+
role_type: role_type
|
|
37
|
+
)
|
|
38
|
+
allow(HyperResource::Link).to receive(:new).and_return(link)
|
|
39
|
+
allow(link).to receive(:post).and_return(response)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it 'should create a link with the correct URL' do
|
|
43
|
+
expect(HyperResource::Link).to receive(:new).with(
|
|
44
|
+
subject,
|
|
45
|
+
'href' => 'https://auth.aptible.com/external_aws_roles/123/external_aws_oidc_token'
|
|
46
|
+
).and_return(link)
|
|
47
|
+
subject.external_aws_oidc_token!
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it 'should POST with the correct parameters' do
|
|
51
|
+
expect(link).to receive(:post).with(
|
|
52
|
+
hash_including(
|
|
53
|
+
aws_account_id: aws_account_id,
|
|
54
|
+
role_arn: role_arn,
|
|
55
|
+
role_type: role_type
|
|
56
|
+
)
|
|
57
|
+
).and_return(response)
|
|
58
|
+
subject.external_aws_oidc_token!
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it 'should return an ExternalAwsOidcToken' do
|
|
62
|
+
token = subject.external_aws_oidc_token!
|
|
63
|
+
expect(token).to be_a Aptible::Auth::ExternalAwsOidcToken
|
|
64
|
+
expect(token.token).to eq token_content
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it 'should populate the returned token with response data' do
|
|
68
|
+
token = subject.external_aws_oidc_token!
|
|
69
|
+
expect(token.aws_web_identity_token_file_content).to eq token_content
|
|
70
|
+
expect(token.aws_role_arn).to eq role_arn
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -5,8 +5,44 @@ describe Aptible::Auth::Organization do
|
|
|
5
5
|
let(:user) { double 'Aptible::Auth::User' }
|
|
6
6
|
|
|
7
7
|
it 'should return the security officer' do
|
|
8
|
-
subject.
|
|
8
|
+
allow(subject).to receive(:security_officer) { user }
|
|
9
9
|
expect(subject.security_officer).to eq user
|
|
10
10
|
end
|
|
11
11
|
end
|
|
12
|
+
|
|
13
|
+
describe '#external_aws_roles' do
|
|
14
|
+
let(:external_aws_role) { double 'Aptible::Auth::ExternalAwsRole' }
|
|
15
|
+
|
|
16
|
+
it 'should return the external_aws_roles' do
|
|
17
|
+
allow(subject).to receive(:external_aws_roles) { [external_aws_role] }
|
|
18
|
+
expect(subject.external_aws_roles).to eq [external_aws_role]
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
describe '#create_external_aws_role!' do
|
|
23
|
+
let(:params) do
|
|
24
|
+
{
|
|
25
|
+
aws_account_id: '123456789012',
|
|
26
|
+
role_arn: 'arn:aws:iam::123456789012:role/MyRole',
|
|
27
|
+
role_type: 'deploy'
|
|
28
|
+
}
|
|
29
|
+
end
|
|
30
|
+
let(:external_aws_role) { double('Aptible::Auth::ExternalAwsRole') }
|
|
31
|
+
let(:external_aws_roles_link) { double('HyperResource::Link') }
|
|
32
|
+
|
|
33
|
+
before do
|
|
34
|
+
allow(subject).to receive(:loaded) { true }
|
|
35
|
+
allow(subject).to receive(:links) { { external_aws_roles: external_aws_roles_link } }
|
|
36
|
+
allow(external_aws_roles_link).to receive(:create).and_return(external_aws_role)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it 'should call create on the external_aws_roles link' do
|
|
40
|
+
expect(external_aws_roles_link).to receive(:create).with(params)
|
|
41
|
+
subject.create_external_aws_role!(params)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it 'should return the created external_aws_role' do
|
|
45
|
+
expect(subject.create_external_aws_role!(params)).to eq external_aws_role
|
|
46
|
+
end
|
|
47
|
+
end
|
|
12
48
|
end
|
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
|
2
2
|
|
|
3
3
|
describe Aptible::Auth::Resource do
|
|
4
4
|
its(:namespace) { should eq 'Aptible::Auth' }
|
|
5
|
-
its(:root_url) { should eq 'https://auth.aptible.com' }
|
|
5
|
+
its(:root_url) { should eq ENV['APTIBLE_AUTH_ROOT_URL'] || 'https://auth.aptible.com' }
|
|
6
6
|
|
|
7
7
|
describe '#bearer_token' do
|
|
8
8
|
it 'should accept an Aptible::Auth::Token' do
|
data/spec/aptible/auth_spec.rb
CHANGED
|
@@ -6,12 +6,17 @@ describe Aptible::Auth do
|
|
|
6
6
|
it 'should have a configurable root_url' do
|
|
7
7
|
config = described_class.configuration
|
|
8
8
|
expect(config).to be_a GemConfig::Configuration
|
|
9
|
-
|
|
9
|
+
set_env 'APTIBLE_AUTH_ROOT_URL', nil do
|
|
10
|
+
load 'aptible/auth.rb'
|
|
11
|
+
config.reset
|
|
12
|
+
expect(config.root_url).to eq 'https://auth.aptible.com'
|
|
13
|
+
end
|
|
10
14
|
end
|
|
11
15
|
|
|
12
|
-
|
|
16
|
+
it 'uses ENV["APTIBLE_AUTH_ROOT_URL"] if defined' do
|
|
13
17
|
config = described_class.configuration
|
|
14
18
|
set_env 'APTIBLE_AUTH_ROOT_URL', 'http://foobar.com' do
|
|
19
|
+
load 'aptible/auth.rb'
|
|
15
20
|
config.reset
|
|
16
21
|
expect(config.root_url).to eq 'http://foobar.com'
|
|
17
22
|
end
|
data/spec/shared/set_env.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: aptible-auth
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Frank Macreery
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: aptible-resource
|
|
@@ -175,6 +174,7 @@ files:
|
|
|
175
174
|
- ".github/workflows/ci.yml"
|
|
176
175
|
- ".gitignore"
|
|
177
176
|
- ".rspec"
|
|
177
|
+
- ".ruby-version"
|
|
178
178
|
- Gemfile
|
|
179
179
|
- LICENSE.md
|
|
180
180
|
- Procfile
|
|
@@ -185,6 +185,8 @@ files:
|
|
|
185
185
|
- lib/aptible/auth.rb
|
|
186
186
|
- lib/aptible/auth/agent.rb
|
|
187
187
|
- lib/aptible/auth/client.rb
|
|
188
|
+
- lib/aptible/auth/external_aws_oidc_token.rb
|
|
189
|
+
- lib/aptible/auth/external_aws_role.rb
|
|
188
190
|
- lib/aptible/auth/invitation.rb
|
|
189
191
|
- lib/aptible/auth/membership.rb
|
|
190
192
|
- lib/aptible/auth/organization.rb
|
|
@@ -201,6 +203,8 @@ files:
|
|
|
201
203
|
- lib/aptible/auth/whitelist_membership.rb
|
|
202
204
|
- lib/oauth2/strategy/token_exchange.rb
|
|
203
205
|
- spec/aptible/auth/agent_spec.rb
|
|
206
|
+
- spec/aptible/auth/external_aws_oidc_token_spec.rb
|
|
207
|
+
- spec/aptible/auth/external_aws_role_spec.rb
|
|
204
208
|
- spec/aptible/auth/organization_spec.rb
|
|
205
209
|
- spec/aptible/auth/resource_spec.rb
|
|
206
210
|
- spec/aptible/auth/token_spec.rb
|
|
@@ -213,7 +217,6 @@ homepage: https://github.com/aptible/aptible-auth-ruby
|
|
|
213
217
|
licenses:
|
|
214
218
|
- MIT
|
|
215
219
|
metadata: {}
|
|
216
|
-
post_install_message:
|
|
217
220
|
rdoc_options: []
|
|
218
221
|
require_paths:
|
|
219
222
|
- lib
|
|
@@ -228,12 +231,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
228
231
|
- !ruby/object:Gem::Version
|
|
229
232
|
version: '0'
|
|
230
233
|
requirements: []
|
|
231
|
-
rubygems_version: 3.
|
|
232
|
-
signing_key:
|
|
234
|
+
rubygems_version: 3.6.9
|
|
233
235
|
specification_version: 4
|
|
234
236
|
summary: Ruby client for auth.aptible.com
|
|
235
237
|
test_files:
|
|
236
238
|
- spec/aptible/auth/agent_spec.rb
|
|
239
|
+
- spec/aptible/auth/external_aws_oidc_token_spec.rb
|
|
240
|
+
- spec/aptible/auth/external_aws_role_spec.rb
|
|
237
241
|
- spec/aptible/auth/organization_spec.rb
|
|
238
242
|
- spec/aptible/auth/resource_spec.rb
|
|
239
243
|
- spec/aptible/auth/token_spec.rb
|