lex-vault 0.1.3 → 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/.github/CODEOWNERS +7 -0
- data/.github/dependabot.yml +18 -0
- data/.github/workflows/ci.yml +19 -1
- data/.rubocop.yml +2 -53
- data/CHANGELOG.md +28 -0
- data/CLAUDE.md +35 -44
- data/Gemfile +1 -0
- data/LICENSE +201 -21
- data/README.md +82 -2
- data/lib/legion/extensions/vault/auth/helpers/login.rb +27 -0
- data/lib/legion/extensions/vault/auth/runners/app_role.rb +26 -0
- data/lib/legion/extensions/vault/auth/runners/token.rb +24 -0
- data/lib/legion/extensions/vault/auth/runners/user_pass.rb +26 -0
- data/lib/legion/extensions/vault/auth.rb +33 -0
- data/lib/legion/extensions/vault/client.rb +12 -2
- data/lib/legion/extensions/vault/errors.rb +48 -0
- data/lib/legion/extensions/vault/helpers/auth.rb +67 -0
- data/lib/legion/extensions/vault/helpers/client.rb +28 -1
- data/lib/legion/extensions/vault/runners/consul.rb +61 -0
- data/lib/legion/extensions/vault/runners/kv.rb +43 -35
- data/lib/legion/extensions/vault/runners/leases.rb +13 -12
- data/lib/legion/extensions/vault/runners/namespaces.rb +13 -12
- data/lib/legion/extensions/vault/runners/nomad.rb +72 -0
- data/lib/legion/extensions/vault/runners/pki.rb +32 -27
- data/lib/legion/extensions/vault/runners/system.rb +55 -41
- data/lib/legion/extensions/vault/runners/token.rb +37 -33
- data/lib/legion/extensions/vault/runners/transit.rb +25 -33
- data/lib/legion/extensions/vault/version.rb +1 -1
- data/lib/legion/extensions/vault.rb +31 -1
- metadata +12 -1
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/vault/errors'
|
|
4
|
+
require 'legion/extensions/vault/helpers/client'
|
|
5
|
+
|
|
6
|
+
module Legion
|
|
7
|
+
module Extensions
|
|
8
|
+
module Vault
|
|
9
|
+
module Runners
|
|
10
|
+
module Nomad
|
|
11
|
+
include Legion::Extensions::Vault::Helpers::Client
|
|
12
|
+
|
|
13
|
+
def create_role(name:, policies: nil, global: true, type: 'management', mount: 'nomad', read_only: false, **)
|
|
14
|
+
raise Legion::Extensions::Vault::Errors::ReadOnlyError, 'write operations disabled (read_only mode)' if read_only
|
|
15
|
+
|
|
16
|
+
body = { name: name, policies: policies, global: global, type: type }
|
|
17
|
+
{ status: connection(**).post("/v1/#{mount}/role/#{name}", body).status }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def read_role(name:, mount: 'nomad', **)
|
|
21
|
+
vault_normalize(connection(**).get("/v1/#{mount}/role/#{name}").body)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def list_roles(mount: 'nomad', **)
|
|
25
|
+
vault_normalize(connection(**).get("/v1/#{mount}/role", { list: true }).body)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def delete_role(name:, mount: 'nomad', read_only: false, **)
|
|
29
|
+
raise Legion::Extensions::Vault::Errors::ReadOnlyError, 'write operations disabled (read_only mode)' if read_only
|
|
30
|
+
|
|
31
|
+
{ status: connection(**).delete("/v1/#{mount}/role/#{name}").status }
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Nomad mints credentials via POST /cred/{accessor} — unlike the
|
|
35
|
+
# GET /creds/{role} shape of the other dynamic engines.
|
|
36
|
+
def generate_credential(accessor:, mount: 'nomad', **)
|
|
37
|
+
vault_normalize(connection(**).post("/v1/#{mount}/cred/#{accessor}").body)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def configure_access(mount: 'nomad', read_only: false, **)
|
|
41
|
+
raise Legion::Extensions::Vault::Errors::ReadOnlyError, 'write operations disabled (read_only mode)' if read_only
|
|
42
|
+
|
|
43
|
+
{ status: connection(**).post("/v1/#{mount}/config/access", {}).status }
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def read_config_access(mount: 'nomad', **)
|
|
47
|
+
vault_normalize(connection(**).get("/v1/#{mount}/config/access").body)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def configure_lease(mount: 'nomad', read_only: false, **)
|
|
51
|
+
raise Legion::Extensions::Vault::Errors::ReadOnlyError, 'write operations disabled (read_only mode)' if read_only
|
|
52
|
+
|
|
53
|
+
{ status: connection(**).post("/v1/#{mount}/config/lease", {}).status }
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def read_lease(mount: 'nomad', **)
|
|
57
|
+
vault_normalize(connection(**).get("/v1/#{mount}/config/lease").body)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def delete_lease(mount: 'nomad', read_only: false, **)
|
|
61
|
+
raise Legion::Extensions::Vault::Errors::ReadOnlyError, 'write operations disabled (read_only mode)' if read_only
|
|
62
|
+
|
|
63
|
+
{ status: connection(**).delete("/v1/#{mount}/config/lease").status }
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers, false) &&
|
|
67
|
+
Legion::Extensions::Helpers.const_defined?(:Lex, false)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'legion/extensions/vault/errors'
|
|
3
4
|
require 'legion/extensions/vault/helpers/client'
|
|
4
5
|
|
|
5
6
|
module Legion
|
|
@@ -9,63 +10,67 @@ module Legion
|
|
|
9
10
|
module Pki
|
|
10
11
|
include Legion::Extensions::Vault::Helpers::Client
|
|
11
12
|
|
|
12
|
-
def issue(role:, common_name:, mount: 'pki', alt_names: nil, ttl: nil, **)
|
|
13
|
+
def issue(role:, common_name:, mount: 'pki', alt_names: nil, ttl: nil, read_only: false, **)
|
|
14
|
+
raise Legion::Extensions::Vault::Errors::ReadOnlyError, 'write operations disabled (read_only mode)' if read_only
|
|
15
|
+
|
|
13
16
|
body = { common_name: common_name, alt_names: alt_names, ttl: ttl }.compact
|
|
14
|
-
|
|
15
|
-
{ result: response.body }
|
|
17
|
+
vault_normalize(connection(**).post("/v1/#{mount}/issue/#{role}", body).body)
|
|
16
18
|
end
|
|
17
19
|
|
|
18
|
-
def sign_csr(role:, csr:, common_name:, mount: 'pki', alt_names: nil, ttl: nil, **)
|
|
20
|
+
def sign_csr(role:, csr:, common_name:, mount: 'pki', alt_names: nil, ttl: nil, read_only: false, **)
|
|
21
|
+
raise Legion::Extensions::Vault::Errors::ReadOnlyError, 'write operations disabled (read_only mode)' if read_only
|
|
22
|
+
|
|
19
23
|
body = { csr: csr, common_name: common_name, alt_names: alt_names, ttl: ttl }.compact
|
|
20
|
-
|
|
21
|
-
{ result: response.body }
|
|
24
|
+
vault_normalize(connection(**).post("/v1/#{mount}/sign/#{role}", body).body)
|
|
22
25
|
end
|
|
23
26
|
|
|
24
|
-
def revoke(serial_number:, mount: 'pki', **)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
def revoke(serial_number:, mount: 'pki', read_only: false, **)
|
|
28
|
+
raise Legion::Extensions::Vault::Errors::ReadOnlyError, 'write operations disabled (read_only mode)' if read_only
|
|
29
|
+
|
|
30
|
+
vault_normalize(connection(**).post("/v1/#{mount}/revoke", { serial_number: serial_number }).body)
|
|
27
31
|
end
|
|
28
32
|
|
|
29
33
|
def list_certs(mount: 'pki', **)
|
|
30
|
-
|
|
31
|
-
{ result: response.body }
|
|
34
|
+
vault_normalize(connection(**).get("/v1/#{mount}/certs", { list: true }).body)
|
|
32
35
|
end
|
|
33
36
|
|
|
34
37
|
def get_cert(serial:, mount: 'pki', **)
|
|
35
|
-
|
|
36
|
-
{ result: response.body }
|
|
38
|
+
vault_normalize(connection(**).get("/v1/#{mount}/cert/#{serial}").body)
|
|
37
39
|
end
|
|
38
40
|
|
|
41
|
+
# Plain-text PEM endpoint: the body is not JSON, so it is wrapped to
|
|
42
|
+
# keep the runner-returns-Hash contract.
|
|
39
43
|
def ca_chain(mount: 'pki', **)
|
|
40
|
-
|
|
41
|
-
{
|
|
44
|
+
body = connection(**).get("/v1/#{mount}/ca_chain").body
|
|
45
|
+
body.is_a?(Hash) ? vault_normalize(body) : { data: body }
|
|
42
46
|
end
|
|
43
47
|
|
|
44
48
|
def list_pki_roles(mount: 'pki', **)
|
|
45
|
-
|
|
46
|
-
{ result: response.body }
|
|
49
|
+
vault_normalize(connection(**).get("/v1/#{mount}/roles", { list: true }).body)
|
|
47
50
|
end
|
|
48
51
|
|
|
49
52
|
def get_pki_role(role_name:, mount: 'pki', **)
|
|
50
|
-
|
|
51
|
-
{ result: response.body }
|
|
53
|
+
vault_normalize(connection(**).get("/v1/#{mount}/roles/#{role_name}").body)
|
|
52
54
|
end
|
|
53
55
|
|
|
54
|
-
def create_pki_role(role_name:,
|
|
56
|
+
def create_pki_role(role_name:, allowed_domains: nil, allow_subdomains: nil, max_ttl: nil,
|
|
57
|
+
mount: 'pki', read_only: false, **)
|
|
58
|
+
raise Legion::Extensions::Vault::Errors::ReadOnlyError, 'write operations disabled (read_only mode)' if read_only
|
|
59
|
+
|
|
55
60
|
body = { allowed_domains: allowed_domains, allow_subdomains: allow_subdomains,
|
|
56
61
|
max_ttl: max_ttl }.compact
|
|
57
|
-
|
|
58
|
-
{ result: response.status == 204 }
|
|
62
|
+
{ status: connection(**).post("/v1/#{mount}/roles/#{role_name}", body).status }
|
|
59
63
|
end
|
|
60
64
|
|
|
61
|
-
def tidy(mount: 'pki', tidy_cert_store: true, tidy_revoked_certs: true, **)
|
|
65
|
+
def tidy(mount: 'pki', tidy_cert_store: true, tidy_revoked_certs: true, read_only: false, **)
|
|
66
|
+
raise Legion::Extensions::Vault::Errors::ReadOnlyError, 'write operations disabled (read_only mode)' if read_only
|
|
67
|
+
|
|
62
68
|
body = { tidy_cert_store: tidy_cert_store, tidy_revoked_certs: tidy_revoked_certs }
|
|
63
|
-
|
|
64
|
-
{ result: response.body }
|
|
69
|
+
vault_normalize(connection(**).post("/v1/#{mount}/tidy", body).body)
|
|
65
70
|
end
|
|
66
71
|
|
|
67
|
-
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
|
|
68
|
-
Legion::Extensions::Helpers.const_defined?(:Lex)
|
|
72
|
+
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers, false) &&
|
|
73
|
+
Legion::Extensions::Helpers.const_defined?(:Lex, false)
|
|
69
74
|
end
|
|
70
75
|
end
|
|
71
76
|
end
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'legion/extensions/vault/errors'
|
|
3
4
|
require 'legion/extensions/vault/helpers/client'
|
|
4
5
|
|
|
5
6
|
module Legion
|
|
@@ -9,86 +10,99 @@ module Legion
|
|
|
9
10
|
module System
|
|
10
11
|
include Legion::Extensions::Vault::Helpers::Client
|
|
11
12
|
|
|
13
|
+
# Informational: non-200 statuses (sealed, standby, uninit) are data,
|
|
14
|
+
# so this bypasses the Raiser-registered pipe.
|
|
12
15
|
def health(**)
|
|
13
|
-
|
|
14
|
-
|
|
16
|
+
resolved = auth_resolve(**)
|
|
17
|
+
body = build_connection(address: resolved[:address], token: resolved[:token],
|
|
18
|
+
namespace: resolved[:namespace], raise_errors: false)
|
|
19
|
+
.get('/v1/sys/health').body
|
|
20
|
+
vault_normalize(body)
|
|
15
21
|
end
|
|
16
22
|
|
|
17
23
|
def seal_status(**)
|
|
18
|
-
|
|
19
|
-
|
|
24
|
+
resolved = auth_resolve(**)
|
|
25
|
+
body = build_connection(address: resolved[:address], token: resolved[:token],
|
|
26
|
+
namespace: resolved[:namespace], raise_errors: false)
|
|
27
|
+
.get('/v1/sys/seal-status').body
|
|
28
|
+
vault_normalize(body)
|
|
20
29
|
end
|
|
21
30
|
|
|
22
|
-
def seal(**)
|
|
23
|
-
|
|
24
|
-
|
|
31
|
+
def seal(read_only: false, **)
|
|
32
|
+
raise Legion::Extensions::Vault::Errors::ReadOnlyError, 'write operations disabled (read_only mode)' if read_only
|
|
33
|
+
|
|
34
|
+
{ status: connection(**).put('/v1/sys/seal').status }
|
|
25
35
|
end
|
|
26
36
|
|
|
27
|
-
def unseal(key:, **)
|
|
28
|
-
|
|
29
|
-
|
|
37
|
+
def unseal(key:, read_only: false, **)
|
|
38
|
+
raise Legion::Extensions::Vault::Errors::ReadOnlyError, 'write operations disabled (read_only mode)' if read_only
|
|
39
|
+
|
|
40
|
+
vault_normalize(connection(**).put('/v1/sys/unseal', { key: key }).body)
|
|
30
41
|
end
|
|
31
42
|
|
|
32
|
-
def init(secret_shares: 5, secret_threshold: 3, **)
|
|
43
|
+
def init(secret_shares: 5, secret_threshold: 3, read_only: false, **)
|
|
44
|
+
raise Legion::Extensions::Vault::Errors::ReadOnlyError, 'write operations disabled (read_only mode)' if read_only
|
|
45
|
+
|
|
33
46
|
body = { secret_shares: secret_shares, secret_threshold: secret_threshold }
|
|
34
|
-
|
|
35
|
-
{ result: response.body }
|
|
47
|
+
vault_normalize(connection(**).put('/v1/sys/init', body).body)
|
|
36
48
|
end
|
|
37
49
|
|
|
38
50
|
def list_mounts(**)
|
|
39
|
-
|
|
40
|
-
{ result: response.body }
|
|
51
|
+
vault_normalize(connection(**).get('/v1/sys/mounts').body)
|
|
41
52
|
end
|
|
42
53
|
|
|
43
|
-
def mount(path:, type:, description: nil, config: nil, **)
|
|
54
|
+
def mount(path:, type:, description: nil, config: nil, read_only: false, **)
|
|
55
|
+
raise Legion::Extensions::Vault::Errors::ReadOnlyError, 'write operations disabled (read_only mode)' if read_only
|
|
56
|
+
|
|
44
57
|
body = { type: type, description: description, config: config }.compact
|
|
45
|
-
|
|
46
|
-
{ result: response.status == 204 }
|
|
58
|
+
{ status: connection(**).post("/v1/sys/mounts/#{path}", body).status }
|
|
47
59
|
end
|
|
48
60
|
|
|
49
|
-
def unmount(path:, **)
|
|
50
|
-
|
|
51
|
-
|
|
61
|
+
def unmount(path:, read_only: false, **)
|
|
62
|
+
raise Legion::Extensions::Vault::Errors::ReadOnlyError, 'write operations disabled (read_only mode)' if read_only
|
|
63
|
+
|
|
64
|
+
{ status: connection(**).delete("/v1/sys/mounts/#{path}").status }
|
|
52
65
|
end
|
|
53
66
|
|
|
54
67
|
def list_auth(**)
|
|
55
|
-
|
|
56
|
-
{ result: response.body }
|
|
68
|
+
vault_normalize(connection(**).get('/v1/sys/auth').body)
|
|
57
69
|
end
|
|
58
70
|
|
|
59
|
-
def enable_auth(path:, type:, description: nil, **)
|
|
71
|
+
def enable_auth(path:, type:, description: nil, read_only: false, **)
|
|
72
|
+
raise Legion::Extensions::Vault::Errors::ReadOnlyError, 'write operations disabled (read_only mode)' if read_only
|
|
73
|
+
|
|
60
74
|
body = { type: type, description: description }.compact
|
|
61
|
-
|
|
62
|
-
{ result: response.status == 204 }
|
|
75
|
+
{ status: connection(**).post("/v1/sys/auth/#{path}", body).status }
|
|
63
76
|
end
|
|
64
77
|
|
|
65
|
-
def disable_auth(path:, **)
|
|
66
|
-
|
|
67
|
-
|
|
78
|
+
def disable_auth(path:, read_only: false, **)
|
|
79
|
+
raise Legion::Extensions::Vault::Errors::ReadOnlyError, 'write operations disabled (read_only mode)' if read_only
|
|
80
|
+
|
|
81
|
+
{ status: connection(**).delete("/v1/sys/auth/#{path}").status }
|
|
68
82
|
end
|
|
69
83
|
|
|
70
84
|
def list_policies(**)
|
|
71
|
-
|
|
72
|
-
{ result: response.body }
|
|
85
|
+
vault_normalize(connection(**).get('/v1/sys/policies/acl').body)
|
|
73
86
|
end
|
|
74
87
|
|
|
75
88
|
def get_policy(name:, **)
|
|
76
|
-
|
|
77
|
-
{ result: response.body }
|
|
89
|
+
vault_normalize(connection(**).get("/v1/sys/policies/acl/#{name}").body)
|
|
78
90
|
end
|
|
79
91
|
|
|
80
|
-
def put_policy(name:, policy:, **)
|
|
81
|
-
|
|
82
|
-
|
|
92
|
+
def put_policy(name:, policy:, read_only: false, **)
|
|
93
|
+
raise Legion::Extensions::Vault::Errors::ReadOnlyError, 'write operations disabled (read_only mode)' if read_only
|
|
94
|
+
|
|
95
|
+
{ status: connection(**).put("/v1/sys/policies/acl/#{name}", { policy: policy }).status }
|
|
83
96
|
end
|
|
84
97
|
|
|
85
|
-
def delete_policy(name:, **)
|
|
86
|
-
|
|
87
|
-
|
|
98
|
+
def delete_policy(name:, read_only: false, **)
|
|
99
|
+
raise Legion::Extensions::Vault::Errors::ReadOnlyError, 'write operations disabled (read_only mode)' if read_only
|
|
100
|
+
|
|
101
|
+
{ status: connection(**).delete("/v1/sys/policies/acl/#{name}").status }
|
|
88
102
|
end
|
|
89
103
|
|
|
90
|
-
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
|
|
91
|
-
Legion::Extensions::Helpers.const_defined?(:Lex)
|
|
104
|
+
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers, false) &&
|
|
105
|
+
Legion::Extensions::Helpers.const_defined?(:Lex, false)
|
|
92
106
|
end
|
|
93
107
|
end
|
|
94
108
|
end
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'legion/extensions/vault/errors'
|
|
3
4
|
require 'legion/extensions/vault/helpers/client'
|
|
4
5
|
|
|
5
6
|
module Legion
|
|
@@ -9,74 +10,77 @@ module Legion
|
|
|
9
10
|
module Token
|
|
10
11
|
include Legion::Extensions::Vault::Helpers::Client
|
|
11
12
|
|
|
12
|
-
def create_token(policies: nil, ttl: nil, renewable: nil, display_name: nil, role_name: nil, **)
|
|
13
|
+
def create_token(policies: nil, ttl: nil, renewable: nil, display_name: nil, role_name: nil, read_only: false, **)
|
|
14
|
+
raise Legion::Extensions::Vault::Errors::ReadOnlyError, 'write operations disabled (read_only mode)' if read_only
|
|
15
|
+
|
|
13
16
|
body = { policies: policies, ttl: ttl, renewable: renewable, display_name: display_name }.compact
|
|
14
17
|
path = role_name ? "/v1/auth/token/create/#{role_name}" : '/v1/auth/token/create'
|
|
15
|
-
|
|
16
|
-
{ result: response.body }
|
|
18
|
+
vault_normalize(connection(**).post(path, body).body)
|
|
17
19
|
end
|
|
18
20
|
|
|
19
21
|
def lookup_token(token_to_lookup:, **)
|
|
20
|
-
|
|
21
|
-
{ result: response.body }
|
|
22
|
+
vault_normalize(connection(**).post('/v1/auth/token/lookup', { token: token_to_lookup }).body)
|
|
22
23
|
end
|
|
23
24
|
|
|
24
25
|
def lookup_self(**)
|
|
25
|
-
|
|
26
|
-
{ result: response.body }
|
|
26
|
+
vault_normalize(connection(**).get('/v1/auth/token/lookup-self').body)
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
-
def renew_token(token_to_renew:, increment: nil, **)
|
|
29
|
+
def renew_token(token_to_renew:, increment: nil, read_only: false, **)
|
|
30
|
+
raise Legion::Extensions::Vault::Errors::ReadOnlyError, 'write operations disabled (read_only mode)' if read_only
|
|
31
|
+
|
|
30
32
|
body = { token: token_to_renew, increment: increment }.compact
|
|
31
|
-
|
|
32
|
-
{ result: response.body }
|
|
33
|
+
vault_normalize(connection(**).post('/v1/auth/token/renew', body).body)
|
|
33
34
|
end
|
|
34
35
|
|
|
35
|
-
def renew_self(increment: nil, **)
|
|
36
|
+
def renew_self(increment: nil, read_only: false, **)
|
|
37
|
+
raise Legion::Extensions::Vault::Errors::ReadOnlyError, 'write operations disabled (read_only mode)' if read_only
|
|
38
|
+
|
|
36
39
|
body = increment ? { increment: increment } : {}
|
|
37
|
-
|
|
38
|
-
{ result: response.body }
|
|
40
|
+
vault_normalize(connection(**).post('/v1/auth/token/renew-self', body).body)
|
|
39
41
|
end
|
|
40
42
|
|
|
41
|
-
def revoke_token(token_to_revoke:, **)
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
def revoke_token(token_to_revoke:, read_only: false, **)
|
|
44
|
+
raise Legion::Extensions::Vault::Errors::ReadOnlyError, 'write operations disabled (read_only mode)' if read_only
|
|
45
|
+
|
|
46
|
+
{ status: connection(**).post('/v1/auth/token/revoke', { token: token_to_revoke }).status }
|
|
44
47
|
end
|
|
45
48
|
|
|
46
|
-
def revoke_self(**)
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
def revoke_self(read_only: false, **)
|
|
50
|
+
raise Legion::Extensions::Vault::Errors::ReadOnlyError, 'write operations disabled (read_only mode)' if read_only
|
|
51
|
+
|
|
52
|
+
{ status: connection(**).post('/v1/auth/token/revoke-self').status }
|
|
49
53
|
end
|
|
50
54
|
|
|
51
55
|
def list_accessors(**)
|
|
52
|
-
|
|
53
|
-
{ result: response.body }
|
|
56
|
+
vault_normalize(connection(**).get('/v1/auth/token/accessors', { list: true }).body)
|
|
54
57
|
end
|
|
55
58
|
|
|
56
59
|
def list_token_roles(**)
|
|
57
|
-
|
|
58
|
-
{ result: response.body }
|
|
60
|
+
vault_normalize(connection(**).get('/v1/auth/token/roles', { list: true }).body)
|
|
59
61
|
end
|
|
60
62
|
|
|
61
63
|
def get_token_role(role_name:, **)
|
|
62
|
-
|
|
63
|
-
{ result: response.body }
|
|
64
|
+
vault_normalize(connection(**).get("/v1/auth/token/roles/#{role_name}").body)
|
|
64
65
|
end
|
|
65
66
|
|
|
66
|
-
def create_token_role(role_name:, allowed_policies: nil, orphan: nil, renewable: nil, token_ttl: nil,
|
|
67
|
+
def create_token_role(role_name:, allowed_policies: nil, orphan: nil, renewable: nil, token_ttl: nil,
|
|
68
|
+
read_only: false, **)
|
|
69
|
+
raise Legion::Extensions::Vault::Errors::ReadOnlyError, 'write operations disabled (read_only mode)' if read_only
|
|
70
|
+
|
|
67
71
|
body = { allowed_policies: allowed_policies, orphan: orphan, renewable: renewable,
|
|
68
72
|
token_ttl: token_ttl }.compact
|
|
69
|
-
|
|
70
|
-
{ result: response.status == 204 }
|
|
73
|
+
{ status: connection(**).post("/v1/auth/token/roles/#{role_name}", body).status }
|
|
71
74
|
end
|
|
72
75
|
|
|
73
|
-
def delete_token_role(role_name:, **)
|
|
74
|
-
|
|
75
|
-
|
|
76
|
+
def delete_token_role(role_name:, read_only: false, **)
|
|
77
|
+
raise Legion::Extensions::Vault::Errors::ReadOnlyError, 'write operations disabled (read_only mode)' if read_only
|
|
78
|
+
|
|
79
|
+
{ status: connection(**).delete("/v1/auth/token/roles/#{role_name}").status }
|
|
76
80
|
end
|
|
77
81
|
|
|
78
|
-
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
|
|
79
|
-
Legion::Extensions::Helpers.const_defined?(:Lex)
|
|
82
|
+
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers, false) &&
|
|
83
|
+
Legion::Extensions::Helpers.const_defined?(:Lex, false)
|
|
80
84
|
end
|
|
81
85
|
end
|
|
82
86
|
end
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'legion/extensions/vault/errors'
|
|
3
4
|
require 'legion/extensions/vault/helpers/client'
|
|
4
5
|
|
|
5
6
|
module Legion
|
|
@@ -9,80 +10,71 @@ module Legion
|
|
|
9
10
|
module Transit
|
|
10
11
|
include Legion::Extensions::Vault::Helpers::Client
|
|
11
12
|
|
|
12
|
-
def create_key(name:, mount: 'transit', type: nil, **)
|
|
13
|
+
def create_key(name:, mount: 'transit', type: nil, read_only: false, **)
|
|
14
|
+
raise Legion::Extensions::Vault::Errors::ReadOnlyError, 'write operations disabled (read_only mode)' if read_only
|
|
15
|
+
|
|
13
16
|
body = type ? { type: type } : {}
|
|
14
|
-
|
|
15
|
-
{ result: response.status == 204 }
|
|
17
|
+
{ status: connection(**).post("/v1/#{mount}/keys/#{name}", body).status }
|
|
16
18
|
end
|
|
17
19
|
|
|
18
20
|
def read_key(name:, mount: 'transit', **)
|
|
19
|
-
|
|
20
|
-
{ result: response.body }
|
|
21
|
+
vault_normalize(connection(**).get("/v1/#{mount}/keys/#{name}").body)
|
|
21
22
|
end
|
|
22
23
|
|
|
23
24
|
def list_keys(mount: 'transit', **)
|
|
24
|
-
|
|
25
|
-
{ result: response.body }
|
|
25
|
+
vault_normalize(connection(**).get("/v1/#{mount}/keys", { list: true }).body)
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
-
def delete_key(name:, mount: 'transit', **)
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
def delete_key(name:, mount: 'transit', read_only: false, **)
|
|
29
|
+
raise Legion::Extensions::Vault::Errors::ReadOnlyError, 'write operations disabled (read_only mode)' if read_only
|
|
30
|
+
|
|
31
|
+
{ status: connection(**).delete("/v1/#{mount}/keys/#{name}").status }
|
|
31
32
|
end
|
|
32
33
|
|
|
33
|
-
def rotate_key(name:, mount: 'transit', **)
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
def rotate_key(name:, mount: 'transit', read_only: false, **)
|
|
35
|
+
raise Legion::Extensions::Vault::Errors::ReadOnlyError, 'write operations disabled (read_only mode)' if read_only
|
|
36
|
+
|
|
37
|
+
{ status: connection(**).post("/v1/#{mount}/keys/#{name}/rotate").status }
|
|
36
38
|
end
|
|
37
39
|
|
|
38
40
|
def encrypt(name:, plaintext:, mount: 'transit', context: nil, **)
|
|
39
41
|
body = { plaintext: plaintext, context: context }.compact
|
|
40
|
-
|
|
41
|
-
{ result: response.body }
|
|
42
|
+
vault_normalize(connection(**).post("/v1/#{mount}/encrypt/#{name}", body).body)
|
|
42
43
|
end
|
|
43
44
|
|
|
44
45
|
def decrypt(name:, ciphertext:, mount: 'transit', context: nil, **)
|
|
45
46
|
body = { ciphertext: ciphertext, context: context }.compact
|
|
46
|
-
|
|
47
|
-
{ result: response.body }
|
|
47
|
+
vault_normalize(connection(**).post("/v1/#{mount}/decrypt/#{name}", body).body)
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
def rewrap(name:, ciphertext:, mount: 'transit', **)
|
|
51
|
-
|
|
52
|
-
{ result: response.body }
|
|
51
|
+
vault_normalize(connection(**).post("/v1/#{mount}/rewrap/#{name}", { ciphertext: ciphertext }).body)
|
|
53
52
|
end
|
|
54
53
|
|
|
55
54
|
def datakey(name:, key_type: 'plaintext', mount: 'transit', **)
|
|
56
|
-
|
|
57
|
-
{ result: response.body }
|
|
55
|
+
vault_normalize(connection(**).post("/v1/#{mount}/datakey/#{key_type}/#{name}").body)
|
|
58
56
|
end
|
|
59
57
|
|
|
60
58
|
def sign(name:, input:, mount: 'transit', hash_algorithm: nil, **)
|
|
61
59
|
body = { input: input, hash_algorithm: hash_algorithm }.compact
|
|
62
|
-
|
|
63
|
-
response = connection(**).post(path, body)
|
|
64
|
-
{ result: response.body }
|
|
60
|
+
vault_normalize(connection(**).post("/v1/#{mount}/sign/#{name}", body).body)
|
|
65
61
|
end
|
|
66
62
|
|
|
67
63
|
def verify(name:, input:, signature:, mount: 'transit', hash_algorithm: nil, **)
|
|
68
64
|
body = { input: input, signature: signature, hash_algorithm: hash_algorithm }.compact
|
|
69
|
-
|
|
70
|
-
response = connection(**).post(path, body)
|
|
71
|
-
{ result: response.body }
|
|
65
|
+
vault_normalize(connection(**).post("/v1/#{mount}/verify/#{name}", body).body)
|
|
72
66
|
end
|
|
73
67
|
|
|
74
68
|
def hash_data(input:, mount: 'transit', algorithm: 'sha2-256', **)
|
|
75
|
-
|
|
76
|
-
{ result: response.body }
|
|
69
|
+
vault_normalize(connection(**).post("/v1/#{mount}/hash/#{algorithm}", { input: input }).body)
|
|
77
70
|
end
|
|
78
71
|
|
|
79
72
|
def random_bytes(bytes: 32, mount: 'transit', format: 'base64', **)
|
|
80
|
-
|
|
81
|
-
{ result: response.body }
|
|
73
|
+
vault_normalize(connection(**).post("/v1/#{mount}/random/#{bytes}", { format: format }).body)
|
|
82
74
|
end
|
|
83
75
|
|
|
84
|
-
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
|
|
85
|
-
Legion::Extensions::Helpers.const_defined?(:Lex)
|
|
76
|
+
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers, false) &&
|
|
77
|
+
Legion::Extensions::Helpers.const_defined?(:Lex, false)
|
|
86
78
|
end
|
|
87
79
|
end
|
|
88
80
|
end
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'legion/extensions/vault/version'
|
|
4
|
+
require 'legion/extensions/vault/errors'
|
|
5
|
+
require 'legion/extensions/vault/auth'
|
|
6
|
+
require 'legion/extensions/vault/helpers/auth'
|
|
4
7
|
require 'legion/extensions/vault/helpers/client'
|
|
5
8
|
require 'legion/extensions/vault/runners/system'
|
|
6
9
|
require 'legion/extensions/vault/runners/kv'
|
|
@@ -9,12 +12,39 @@ require 'legion/extensions/vault/runners/transit'
|
|
|
9
12
|
require 'legion/extensions/vault/runners/pki'
|
|
10
13
|
require 'legion/extensions/vault/runners/leases'
|
|
11
14
|
require 'legion/extensions/vault/runners/namespaces'
|
|
15
|
+
require 'legion/extensions/vault/runners/consul'
|
|
16
|
+
require 'legion/extensions/vault/runners/nomad'
|
|
12
17
|
require 'legion/extensions/vault/client'
|
|
13
18
|
|
|
14
19
|
module Legion
|
|
15
20
|
module Extensions
|
|
16
21
|
module Vault
|
|
17
|
-
extend Legion::Extensions::Core if Legion::Extensions.const_defined? :Core
|
|
22
|
+
extend Legion::Extensions::Core if Legion::Extensions.const_defined? :Core, false
|
|
23
|
+
|
|
24
|
+
# No async/AMQP dispatch surface. The task engine does not promise
|
|
25
|
+
# exactly-once execution, and queuing secrets-engine side effects
|
|
26
|
+
# (unseal, put_policy, revoke, writes) behind redelivery is a mismatch.
|
|
27
|
+
# Vault calls are fast synchronous HTTP; use in-process/Client/MCP paths.
|
|
28
|
+
def self.remote_invocable?
|
|
29
|
+
false
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def self.default_settings
|
|
33
|
+
{
|
|
34
|
+
address: 'http://127.0.0.1:8200',
|
|
35
|
+
token: nil,
|
|
36
|
+
namespace: nil,
|
|
37
|
+
runners: {
|
|
38
|
+
kv: { desc: 'KV v2 secret engine operations' },
|
|
39
|
+
token: { desc: 'Token auth engine management' },
|
|
40
|
+
transit: { desc: 'Transit encryption engine operations' },
|
|
41
|
+
pki: { desc: 'PKI certificate engine operations' },
|
|
42
|
+
leases: { desc: 'Lease lookup, renewal, and revocation' },
|
|
43
|
+
namespaces: { desc: 'Enterprise namespace management' },
|
|
44
|
+
system: { desc: 'Vault system and mount administration' }
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
end
|
|
18
48
|
end
|
|
19
49
|
end
|
|
20
50
|
end
|