az-identity 0.1.0 → 0.2.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/CHANGELOG.md +6 -1
- data/README.md +18 -0
- data/lib/az_identity/identity/managed_identity_client.rb +26 -3
- data/lib/az_identity/identity/workload_identity_client.rb +7 -1
- data/lib/az_identity/version.rb +1 -1
- data/lib/az_identity.rb +1 -0
- metadata +8 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f1bb83516802a0a3f08eb32e51f29c633fd8e6caf710a392013b50d31b1325b3
|
|
4
|
+
data.tar.gz: 78a85b87b8c0ceac0990881fa555536422ae1f7379e1ab99fc02376f18a8108d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fbc03ca344fdaab4a50048cf4e7b5209b6713abf7a66fd6f9194cd07002bbf23de76885c5cf7ef8dfe01ee02607f403a4879a870b7e4eb7271483ba60e0898c0
|
|
7
|
+
data.tar.gz: 991ca87312d0f3ecad602160b56a001425f0e5d481fca2a596619bf629cdcdc038fffcedff23821a14a1128736787b436779c07e36c872ad6bfcf35d91513335
|
data/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
##
|
|
1
|
+
## 0.2.0
|
|
2
|
+
|
|
3
|
+
- Accept `client_id:` and `object_id:` options to select one of several identities, overriding `AZURE_CLIENT_ID`.
|
|
4
|
+
- Load `AzIdentity::VERSION` with `require 'az_identity'`.
|
|
5
|
+
|
|
6
|
+
## 0.1.0
|
|
2
7
|
|
|
3
8
|
- Extract Azure identity credential acquisition (workload identity and managed identity) into a standalone gem.
|
|
4
9
|
- Add `RedisCredentialsProvider` for authenticating to Azure Cache for Redis with a Microsoft Entra token.
|
data/README.md
CHANGED
|
@@ -62,6 +62,24 @@ credentials = client.fetch_credentials_if_needed
|
|
|
62
62
|
- `IDENTITY_ENDPOINT` - (Optional) Custom IMDS endpoint
|
|
63
63
|
- `IDENTITY_HEADER` - (Optional) Custom header for IMDS
|
|
64
64
|
|
|
65
|
+
### Selecting an identity
|
|
66
|
+
|
|
67
|
+
`AZURE_CLIENT_ID` applies to the whole process. When one host has several
|
|
68
|
+
identities, for example one for object storage and one for Redis, pass
|
|
69
|
+
`client_id:` or `object_id:` to pick one for a given caller. Either option
|
|
70
|
+
overrides `AZURE_CLIENT_ID`.
|
|
71
|
+
|
|
72
|
+
```ruby
|
|
73
|
+
AzIdentity.redis_credentials_provider(
|
|
74
|
+
resource: 'https://redis.azure.com',
|
|
75
|
+
object_id: '<redis-identity-object-id>'
|
|
76
|
+
)
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
`client_id:` works with managed identity and workload identity. `object_id:`
|
|
80
|
+
works with managed identity only, so workload identity is skipped when it is
|
|
81
|
+
set.
|
|
82
|
+
|
|
65
83
|
#### Azure Environment
|
|
66
84
|
- `AZURE_ENVIRONMENT` - (Optional) Azure cloud: `AzureCloud`, `AzureChinaCloud`, `AzureUSGovernment`
|
|
67
85
|
|
|
@@ -13,17 +13,28 @@ module AzIdentity
|
|
|
13
13
|
class ManagedIdentityClient < BaseClient
|
|
14
14
|
attr_reader :resource
|
|
15
15
|
|
|
16
|
+
# Selects one of several identities on the host. The :client_id or
|
|
17
|
+
# :object_id option wins over AZURE_CLIENT_ID, so two callers in one
|
|
18
|
+
# process (for example object storage and Redis) can use different
|
|
19
|
+
# identities.
|
|
20
|
+
attr_reader :identity_object_id
|
|
21
|
+
|
|
16
22
|
def initialize(options = {})
|
|
17
23
|
super()
|
|
18
24
|
@environment = options[:environment]
|
|
19
25
|
@resource = options[:resource] || storage_resource(@environment)
|
|
26
|
+
@client_id = options[:client_id]
|
|
27
|
+
@identity_object_id = options[:object_id]
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# AZURE_CLIENT_ID is read on each fetch, as before.
|
|
31
|
+
def client_id
|
|
32
|
+
@client_id || ENV.fetch('AZURE_CLIENT_ID', nil)
|
|
20
33
|
end
|
|
21
34
|
|
|
22
35
|
def fetch_credentials
|
|
23
36
|
url = "#{identity_endpoint}?api-version=#{api_version}&resource=#{CGI.escape(resource)}"
|
|
24
|
-
|
|
25
|
-
client_id = ENV.fetch('AZURE_CLIENT_ID', nil)
|
|
26
|
-
url += "&client_id=#{client_id}" if client_id
|
|
37
|
+
url += identity_query
|
|
27
38
|
|
|
28
39
|
headers = { 'Metadata' => 'true' }
|
|
29
40
|
headers['X-IDENTITY-HEADER'] = ENV['IDENTITY_HEADER'] if ENV['IDENTITY_HEADER']
|
|
@@ -34,6 +45,18 @@ module AzIdentity
|
|
|
34
45
|
|
|
35
46
|
private
|
|
36
47
|
|
|
48
|
+
def identity_query
|
|
49
|
+
if identity_object_id
|
|
50
|
+
# App Service (IDENTITY_ENDPOINT) names the object ID principal_id.
|
|
51
|
+
key = ENV['IDENTITY_ENDPOINT'] ? 'principal_id' : 'object_id'
|
|
52
|
+
"&#{key}=#{CGI.escape(identity_object_id)}"
|
|
53
|
+
elsif client_id
|
|
54
|
+
"&client_id=#{CGI.escape(client_id)}"
|
|
55
|
+
else
|
|
56
|
+
''
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
37
60
|
def identity_endpoint
|
|
38
61
|
ENV['IDENTITY_ENDPOINT'] || IDENTITY_ENDPOINT
|
|
39
62
|
end
|
|
@@ -15,7 +15,12 @@ module AzIdentity
|
|
|
15
15
|
@resource = options[:resource] || storage_resource(@environment)
|
|
16
16
|
@authority = ENV['AZURE_AUTHORITY_HOST'] || authority_url(@environment)
|
|
17
17
|
@tenant_id = ENV.fetch('AZURE_TENANT_ID', nil)
|
|
18
|
-
|
|
18
|
+
# An explicit :client_id picks the app registration to federate as,
|
|
19
|
+
# overriding AZURE_CLIENT_ID. Workload identity cannot select by
|
|
20
|
+
# object ID, so with :object_id this client stays unavailable rather
|
|
21
|
+
# than fetching a token for the AZURE_CLIENT_ID identity.
|
|
22
|
+
@identity_object_id = options[:object_id]
|
|
23
|
+
@client_id = options[:client_id] || ENV.fetch('AZURE_CLIENT_ID', nil)
|
|
19
24
|
@token_file = ENV.fetch('AZURE_FEDERATED_TOKEN_FILE', nil)
|
|
20
25
|
|
|
21
26
|
normalize_authority!
|
|
@@ -33,6 +38,7 @@ module AzIdentity
|
|
|
33
38
|
private
|
|
34
39
|
|
|
35
40
|
def federated_credentials_available?
|
|
41
|
+
return false if @identity_object_id
|
|
36
42
|
return false unless authority && tenant_id && client_id && token_file
|
|
37
43
|
|
|
38
44
|
::File.exist?(token_file) && ::File.readable?(token_file)
|
data/lib/az_identity/version.rb
CHANGED
data/lib/az_identity.rb
CHANGED
metadata
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: az-identity
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- GitLab
|
|
8
|
+
autorequire:
|
|
8
9
|
bindir: bin
|
|
9
10
|
cert_chain: []
|
|
10
|
-
date:
|
|
11
|
+
date: 2026-11-22 00:00:00.000000000 Z
|
|
11
12
|
dependencies:
|
|
12
13
|
- !ruby/object:Gem::Dependency
|
|
13
14
|
name: base64
|
|
@@ -39,6 +40,7 @@ dependencies:
|
|
|
39
40
|
version: '2.0'
|
|
40
41
|
description: Credential acquisition for Azure services using workload identity or
|
|
41
42
|
managed identity
|
|
43
|
+
email:
|
|
42
44
|
executables: []
|
|
43
45
|
extensions: []
|
|
44
46
|
extra_rdoc_files: []
|
|
@@ -61,6 +63,7 @@ licenses:
|
|
|
61
63
|
- MIT
|
|
62
64
|
metadata:
|
|
63
65
|
rubygems_mfa_required: 'true'
|
|
66
|
+
post_install_message:
|
|
64
67
|
rdoc_options: []
|
|
65
68
|
require_paths:
|
|
66
69
|
- lib
|
|
@@ -68,14 +71,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
68
71
|
requirements:
|
|
69
72
|
- - ">="
|
|
70
73
|
- !ruby/object:Gem::Version
|
|
71
|
-
version: 3.
|
|
74
|
+
version: 3.2.0
|
|
72
75
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
76
|
requirements:
|
|
74
77
|
- - ">="
|
|
75
78
|
- !ruby/object:Gem::Version
|
|
76
79
|
version: '0'
|
|
77
80
|
requirements: []
|
|
78
|
-
rubygems_version: 3.
|
|
81
|
+
rubygems_version: 3.5.22
|
|
82
|
+
signing_key:
|
|
79
83
|
specification_version: 4
|
|
80
84
|
summary: Azure identity and authentication library for Ruby
|
|
81
85
|
test_files: []
|