ace-hitl 0.13.1 → 0.15.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/.ace-defaults/hitl/config.yml +0 -0
- data/.ace-defaults/nav/protocols/skill-sources/ace-hitl.yml +0 -0
- data/.ace-defaults/nav/protocols/wfi-sources/ace-hitl.yml +0 -0
- data/CHANGELOG.md +25 -0
- data/Rakefile +0 -0
- data/docs/demo/ace-hitl-scope-and-answer.tape.yml +0 -0
- data/docs/demo/fixtures/demo-context.md +0 -0
- data/docs/usage.md +43 -2
- data/handbook/README.md +0 -0
- data/handbook/skills/as-hitl/SKILL.md +0 -0
- data/handbook/workflow-instructions/hitl.wf.md +0 -0
- data/lib/ace/hitl/atoms/hitl_effect_validator.rb +0 -0
- data/lib/ace/hitl/atoms/hitl_file_pattern.rb +0 -0
- data/lib/ace/hitl/atoms/hitl_id_formatter.rb +0 -0
- data/lib/ace/hitl/cli/commands/create.rb +0 -0
- data/lib/ace/hitl/cli/commands/list.rb +0 -0
- data/lib/ace/hitl/cli/commands/serve.rb +37 -0
- data/lib/ace/hitl/cli/commands/show.rb +0 -0
- data/lib/ace/hitl/lifecycle/client.rb +11 -151
- data/lib/ace/hitl/lifecycle/credential_path_policy.rb +183 -0
- data/lib/ace/hitl/lifecycle/frame_exchange.rb +78 -0
- data/lib/ace/hitl/lifecycle/frame_serving.rb +119 -0
- data/lib/ace/hitl/lifecycle/lifecycle_requests.rb +101 -0
- data/lib/ace/hitl/lifecycle/remote_peer.rb +78 -0
- data/lib/ace/hitl/lifecycle/service.rb +38 -111
- data/lib/ace/hitl/lifecycle/store.rb +19 -2
- data/lib/ace/hitl/lifecycle/tls_access_policy.rb +39 -0
- data/lib/ace/hitl/lifecycle/tls_authority.rb +112 -0
- data/lib/ace/hitl/lifecycle/tls_credentials.rb +210 -0
- data/lib/ace/hitl/lifecycle/tls_material.rb +133 -0
- data/lib/ace/hitl/lifecycle/tls_project_scope.rb +68 -0
- data/lib/ace/hitl/lifecycle/tls_service.rb +241 -0
- data/lib/ace/hitl/lifecycle.rb +11 -0
- data/lib/ace/hitl/models/hitl_event.rb +0 -0
- data/lib/ace/hitl/molecules/hitl_answer_editor.rb +0 -0
- data/lib/ace/hitl/molecules/hitl_config_loader.rb +0 -0
- data/lib/ace/hitl/molecules/hitl_creator.rb +0 -0
- data/lib/ace/hitl/molecules/hitl_display_formatter.rb +0 -0
- data/lib/ace/hitl/molecules/hitl_loader.rb +0 -0
- data/lib/ace/hitl/molecules/hitl_resolver.rb +0 -0
- data/lib/ace/hitl/molecules/hitl_scanner.rb +0 -0
- data/lib/ace/hitl/molecules/resume_dispatcher.rb +0 -0
- data/lib/ace/hitl/molecules/worktree_scope_resolver.rb +0 -0
- data/lib/ace/hitl/version.rb +1 -1
- metadata +15 -4
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Ace
|
|
4
|
+
module Hitl
|
|
5
|
+
module Lifecycle
|
|
6
|
+
# The connection-serving half of a lifecycle boundary (spec
|
|
7
|
+
# 8wq.t.34i, reused by the TLS/TCP crossing of spec 8xa.t.nh0):
|
|
8
|
+
# one bounded request frame per dispatch, classified errors cross
|
|
9
|
+
# the wire, idleness and frame size stay bounded. The includer
|
|
10
|
+
# supplies `@idle_seconds`, `@logger` and `store_for(connection)`.
|
|
11
|
+
module FrameServing
|
|
12
|
+
def serve_connection(socket)
|
|
13
|
+
peer = authenticate!(socket)
|
|
14
|
+
store = store_for(peer)
|
|
15
|
+
loop do
|
|
16
|
+
line = read_frame(socket)
|
|
17
|
+
break if line.nil?
|
|
18
|
+
|
|
19
|
+
response = dispatch(store, line)
|
|
20
|
+
write_frame(socket, response)
|
|
21
|
+
end
|
|
22
|
+
rescue Lifecycle::Error => e
|
|
23
|
+
write_frame(socket, Protocol.encode_error(e)) rescue nil
|
|
24
|
+
rescue SystemCallError, IOError
|
|
25
|
+
nil
|
|
26
|
+
ensure
|
|
27
|
+
socket.close rescue nil
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
# One request frame per dispatch; lifecycle failures return
|
|
33
|
+
# classified error frames, transport/frame failures close the
|
|
34
|
+
# connection (serve_connection's rescues).
|
|
35
|
+
def dispatch(store, line)
|
|
36
|
+
request = Protocol.decode_request(line)
|
|
37
|
+
result = execute(store, request[:op], request[:params])
|
|
38
|
+
Protocol.encode_result(result)
|
|
39
|
+
rescue Protocol::FrameError, Lifecycle::Error, ArgumentError, TypeError => e
|
|
40
|
+
Protocol.encode_error(e)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def execute(store, op, params)
|
|
44
|
+
case op
|
|
45
|
+
when "ping" then {"pong" => true}
|
|
46
|
+
when "proposal-create" then store.proposal_create(**symbolize(params))
|
|
47
|
+
when "proposal-show" then store.proposal_show(required(params, "id"), project: required(params, "project"), history_after: params.fetch("history_after", 0))
|
|
48
|
+
when "proposal-revise" then store.proposal_revise(required(params, "id"), project: required(params, "project"), expected_revision: required(params, "expected_revision"),
|
|
49
|
+
operation_id: required(params, "operation_id"), document: required(params, "document"))
|
|
50
|
+
when "proposal-ack"
|
|
51
|
+
store.proposal_acknowledge(required(params, "id"), project: required(params, "project"), submitted_at: required(params, "submitted_at"))
|
|
52
|
+
when "proposal-reply"
|
|
53
|
+
store.proposal_reply(required(params, "id"), project: required(params, "project"), answer: required(params, "answer"),
|
|
54
|
+
received_at: required(params, "received_at"), sequence: required(params, "sequence"))
|
|
55
|
+
when "proposal-reconcile"
|
|
56
|
+
store.proposal_reconcile(required(params, "id"), project: required(params, "project"), checkpoint: required(params, "checkpoint"))
|
|
57
|
+
when "proposal-wake" then store.proposal_wake(project: required(params, "project"), after: params["after"])
|
|
58
|
+
when "proposal-due" then store.proposal_due(project: required(params, "project"), after: params["after"])
|
|
59
|
+
when "proposal-history" then store.proposal_history(project: required(params, "project"),
|
|
60
|
+
query: params.fetch("query", ""), after: params["after"])
|
|
61
|
+
when "create" then store.create(**symbolize(params))
|
|
62
|
+
when "read" then store.read(required(params, "id"))
|
|
63
|
+
when "deliver" then store.deliver(required(params, "id"), answer_reader(params))
|
|
64
|
+
when "consume"
|
|
65
|
+
store.consume(required(params, "id"), timeout: Integer(params["timeout"] || 0),
|
|
66
|
+
operation: params["operation"], native_delivery: params.fetch("native_delivery", false))
|
|
67
|
+
when "cancel" then store.cancel(required(params, "id"), reason: params["reason"].to_s)
|
|
68
|
+
when "pending" then store.pending_page(project: params["project"], after: params["after"])
|
|
69
|
+
when "states" then store.states
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def symbolize(params)
|
|
74
|
+
params.transform_keys { |key| key.to_sym }
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def required(params, key)
|
|
78
|
+
value = params[key]
|
|
79
|
+
raise Protocol::FrameError, "boundary parameter '#{key}' is required" if value.nil? || value.to_s.empty?
|
|
80
|
+
|
|
81
|
+
value
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def answer_reader(params)
|
|
85
|
+
answer = params["answer"].to_s
|
|
86
|
+
->(limit) { answer[0, limit] }
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def read_frame(socket)
|
|
90
|
+
data = +""
|
|
91
|
+
loop do
|
|
92
|
+
ready = IO.select([socket], nil, nil, @idle_seconds)
|
|
93
|
+
return nil unless ready
|
|
94
|
+
|
|
95
|
+
chunk = socket.read_nonblock(4096, exception: false)
|
|
96
|
+
return nil if chunk.nil?
|
|
97
|
+
next sleep(0.01) if chunk == :wait_readable
|
|
98
|
+
|
|
99
|
+
data << chunk
|
|
100
|
+
if data.bytesize > Protocol::MAX_FRAME_BYTES
|
|
101
|
+
write_frame(socket, Protocol.encode_error(Protocol::FrameError.new("request frame is too large"))) rescue nil
|
|
102
|
+
return nil
|
|
103
|
+
end
|
|
104
|
+
return data if data.include?("\n")
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def write_frame(socket, frame)
|
|
109
|
+
socket.write(frame)
|
|
110
|
+
socket.flush
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def log(message)
|
|
114
|
+
@logger&.call("[ace-hitl] #{message}")
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Ace
|
|
4
|
+
module Hitl
|
|
5
|
+
module Lifecycle
|
|
6
|
+
# The client request surface of the scoped store boundary (spec
|
|
7
|
+
# 8wq.t.34i), shared verbatim by the Unix client and the
|
|
8
|
+
# mutual-TLS Hermes client (spec 8xa.t.nh0): the existing bounded
|
|
9
|
+
# lifecycle frames are exchanged unchanged on both transports.
|
|
10
|
+
# The includer implements `#request(op, params, deadline:)`.
|
|
11
|
+
module LifecycleRequests
|
|
12
|
+
def proposal_create(**params)
|
|
13
|
+
request("proposal-create", params)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def proposal_show(id, project:, history_after: 0)
|
|
17
|
+
request("proposal-show", {"id" => id, "project" => project, "history_after" => history_after})
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def proposal_revise(id, project:, expected_revision:, operation_id:, document:)
|
|
21
|
+
request("proposal-revise", {"id" => id, "project" => project, "expected_revision" => expected_revision, "operation_id" => operation_id, "document" => document})
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def proposal_acknowledge(id, project:, submitted_at:)
|
|
25
|
+
request("proposal-ack", {"id" => id, "project" => project, "submitted_at" => submitted_at})
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def proposal_reply(id, project:, **params)
|
|
29
|
+
request("proposal-reply", {"id" => id, "project" => project}.merge(params))
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def proposal_reconcile(id, project:, checkpoint:)
|
|
33
|
+
request("proposal-reconcile", {"id" => id, "project" => project, "checkpoint" => checkpoint})
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def proposal_wake(project:, after: nil)
|
|
37
|
+
request("proposal-wake", {"project" => project, "after" => after}.compact)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def proposal_due(project:, after: nil)
|
|
41
|
+
request("proposal-due", {"project" => project, "after" => after}.compact)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def proposal_history(project:, query: "", after: nil)
|
|
45
|
+
request("proposal-history", {"project" => project, "query" => query, "after" => after}.compact)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def create(deadline: nil, **params)
|
|
49
|
+
request("create", params.transform_keys(&:to_s), deadline: deadline)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def read(id, deadline: nil)
|
|
53
|
+
request("read", {"id" => id}, deadline: deadline)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def deliver(id, answer)
|
|
57
|
+
request("deliver", {"id" => id, "answer" => answer.to_s})
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def consume(id, timeout: 0, operation: nil, native_delivery: false, deadline: nil)
|
|
61
|
+
params = {"id" => id, "timeout" => Integer(timeout)}
|
|
62
|
+
params["operation"] = operation if operation
|
|
63
|
+
params["native_delivery"] = true if native_delivery
|
|
64
|
+
request("consume", params, deadline: deadline)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def cancel(id, reason: "", deadline: nil)
|
|
68
|
+
request("cancel", {"id" => id, "reason" => reason.to_s}, deadline: deadline)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def pending(project: nil)
|
|
72
|
+
items = []
|
|
73
|
+
after = nil
|
|
74
|
+
loop do
|
|
75
|
+
page = pending_page(project: project, after: after)
|
|
76
|
+
items.concat(page.fetch("items"))
|
|
77
|
+
cursor = page.fetch("next")
|
|
78
|
+
break unless cursor
|
|
79
|
+
unless cursor.is_a?(String) && (after.nil? || cursor > after)
|
|
80
|
+
raise TransportError, "pending cursor did not advance"
|
|
81
|
+
end
|
|
82
|
+
after = cursor
|
|
83
|
+
end
|
|
84
|
+
items
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def pending_page(project: nil, after: nil)
|
|
88
|
+
request("pending", {"project" => project, "after" => after}.compact)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def states
|
|
92
|
+
request("states")
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def ping
|
|
96
|
+
request("ping")
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "etc"
|
|
4
|
+
|
|
5
|
+
module Ace
|
|
6
|
+
module Hitl
|
|
7
|
+
module Lifecycle
|
|
8
|
+
# The authenticated caller of one mutually authenticated TLS
|
|
9
|
+
# connection (spec 8xa.t.nh0): resolved from the VERIFIED
|
|
10
|
+
# project-scoped client certificate — single URI SAN, exact
|
|
11
|
+
# fingerprint, issuing CA and EKU checked before any lifecycle
|
|
12
|
+
# frame is decoded — never from payload fields or claim strings.
|
|
13
|
+
#
|
|
14
|
+
# A remote peer has no local uid: every check that would use one
|
|
15
|
+
# fails closed. The username is the exact verified URI SAN token,
|
|
16
|
+
# so requester-only store paths never match a foreign remote peer,
|
|
17
|
+
# and effect callbacks that would need a local privilege drop
|
|
18
|
+
# escalate exactly like the existing non-root transport case. The
|
|
19
|
+
# peer's OWN token materializes to the service identity that
|
|
20
|
+
# terminates the crossing (public projections and attribution of
|
|
21
|
+
# the requests it created); foreign names still resolve through
|
|
22
|
+
# the passwd database and unknown ones fail closed.
|
|
23
|
+
class RemotePeer
|
|
24
|
+
attr_reader :project, :identity
|
|
25
|
+
|
|
26
|
+
def initialize(project:, identity:)
|
|
27
|
+
@project = project.to_s
|
|
28
|
+
@identity = identity
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def username
|
|
32
|
+
@identity
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def root?
|
|
36
|
+
false
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# No local identity exists across the crossing; used only for
|
|
40
|
+
# fail-closed comparisons (see Effects.run).
|
|
41
|
+
def euid
|
|
42
|
+
nil
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def uid
|
|
46
|
+
nil
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def gid
|
|
50
|
+
nil
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def pid
|
|
54
|
+
nil
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def ids
|
|
58
|
+
[nil, nil]
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def user_ids(name)
|
|
62
|
+
return [Process.uid, Process.gid] if name.to_s == @identity
|
|
63
|
+
|
|
64
|
+
entry = Etc.getpwnam(name.to_s)
|
|
65
|
+
[entry.uid, entry.gid]
|
|
66
|
+
rescue ArgumentError
|
|
67
|
+
raise Lifecycle::Error, "unknown requester identity: #{name}"
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def group_id(name)
|
|
71
|
+
Etc.getgrnam(name.to_s).gid
|
|
72
|
+
rescue ArgumentError
|
|
73
|
+
raise Lifecycle::Error, "unknown group identity: #{name}"
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -7,6 +7,7 @@ require_relative "protocol"
|
|
|
7
7
|
require_relative "peer"
|
|
8
8
|
require_relative "store"
|
|
9
9
|
require_relative "otp_vault"
|
|
10
|
+
require_relative "frame_serving"
|
|
10
11
|
|
|
11
12
|
module Ace
|
|
12
13
|
module Hitl
|
|
@@ -22,7 +23,12 @@ module Ace
|
|
|
22
23
|
# nowhere, transfer exactly once, and die with the challenge or
|
|
23
24
|
# the service.
|
|
24
25
|
class Service
|
|
26
|
+
include FrameServing
|
|
27
|
+
|
|
25
28
|
DEFAULT_SOCKET_MODE = 0o660
|
|
29
|
+
BROAD_CONTROL_GROUPS = [Store::DEFAULT_GROUP].freeze
|
|
30
|
+
LEGACY_SHARED_SOCKET_DIRECTORIES = ["/run/lab"].freeze
|
|
31
|
+
LEGACY_LABD_SOCKET = "labd.sock"
|
|
26
32
|
# An idle connection holds a thread; bounded idleness keeps a
|
|
27
33
|
# wedged peer from pinning the service (review 8x327buo).
|
|
28
34
|
DEFAULT_IDLE_SECONDS = 120.0
|
|
@@ -118,43 +124,26 @@ module Ace
|
|
|
118
124
|
# multi-UID acceptance fixture uses to drive real peers through
|
|
119
125
|
# the real dispatch path.
|
|
120
126
|
def serve_connection(socket)
|
|
121
|
-
|
|
122
|
-
store = store_for(peer)
|
|
123
|
-
loop do
|
|
124
|
-
line = read_frame(socket)
|
|
125
|
-
break if line.nil?
|
|
126
|
-
|
|
127
|
-
response = dispatch(store, line)
|
|
128
|
-
write_frame(socket, response)
|
|
129
|
-
end
|
|
130
|
-
rescue Lifecycle::Error => e
|
|
131
|
-
write_frame(socket, Protocol.encode_error(e)) rescue nil
|
|
132
|
-
rescue SystemCallError, IOError
|
|
133
|
-
nil
|
|
134
|
-
ensure
|
|
135
|
-
socket.close rescue nil
|
|
127
|
+
super
|
|
136
128
|
end
|
|
137
129
|
|
|
138
130
|
private
|
|
139
131
|
|
|
140
132
|
def prepare!
|
|
141
133
|
begin
|
|
134
|
+
group_id = verify_control_group!
|
|
142
135
|
verify_socket_directory!
|
|
143
136
|
acquire_endpoint_lock!
|
|
144
137
|
recover_stale_endpoint!
|
|
145
138
|
@server = UNIXServer.open(@socket_path)
|
|
146
139
|
@endpoint_identity = endpoint_identity
|
|
140
|
+
File.chown(nil, group_id, @socket_path)
|
|
141
|
+
File.chmod(DEFAULT_SOCKET_MODE, @socket_path)
|
|
142
|
+
rescue ArgumentError => e
|
|
143
|
+
raise TransportError, "the HITL boundary control group is unavailable (#{e.message})"
|
|
147
144
|
rescue SystemCallError, IOError => e
|
|
148
145
|
raise TransportError, "the HITL boundary endpoint is not usable (#{e.class}: #{e.message})"
|
|
149
146
|
end
|
|
150
|
-
File.chmod(DEFAULT_SOCKET_MODE, @socket_path)
|
|
151
|
-
begin
|
|
152
|
-
File.chown(nil, Etc.getgrnam(@group).gid, @socket_path)
|
|
153
|
-
rescue ArgumentError, SystemCallError
|
|
154
|
-
# A service that cannot set the control group keeps the
|
|
155
|
-
# owner-only socket; the peer-credential gate still applies.
|
|
156
|
-
nil
|
|
157
|
-
end
|
|
158
147
|
begin
|
|
159
148
|
root_store.ensure_layout!
|
|
160
149
|
rescue SystemCallError => e
|
|
@@ -196,15 +185,37 @@ module Ace
|
|
|
196
185
|
# must exist, must not be world-writable, and must be owned by
|
|
197
186
|
# the service identity or root — otherwise anyone who can replace
|
|
198
187
|
# the socket can impersonate the service.
|
|
188
|
+
def verify_control_group!
|
|
189
|
+
group = Etc.getgrnam(@group)
|
|
190
|
+
if group.gid.zero? || BROAD_CONTROL_GROUPS.include?(group.name)
|
|
191
|
+
raise TransportError,
|
|
192
|
+
"HITL boundary control group is too broad: #{group.name} " \
|
|
193
|
+
"(configure a dedicated lifecycle group; root and #{Store::DEFAULT_GROUP} are refused)"
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
group.gid
|
|
197
|
+
end
|
|
198
|
+
|
|
199
199
|
def verify_socket_directory!
|
|
200
200
|
dir = File.dirname(@socket_path)
|
|
201
|
+
expanded_dir = File.expand_path(dir)
|
|
202
|
+
if LEGACY_SHARED_SOCKET_DIRECTORIES.include?(expanded_dir)
|
|
203
|
+
raise TransportError,
|
|
204
|
+
"HITL boundary socket directory is shared with legacy labd: #{dir} " \
|
|
205
|
+
"(configure a dedicated lifecycle directory)"
|
|
206
|
+
end
|
|
207
|
+
|
|
201
208
|
FileUtils.mkdir_p(dir)
|
|
202
209
|
stat = File.lstat(dir)
|
|
203
|
-
|
|
210
|
+
protected_directory = (stat.uid.zero? || stat.uid == Process.uid) && (stat.mode & 0o002).zero?
|
|
211
|
+
legacy_socket = File.join(dir, LEGACY_LABD_SOCKET)
|
|
212
|
+
legacy_socket_exists = File.exist?(legacy_socket) || File.symlink?(legacy_socket)
|
|
213
|
+
return if protected_directory && !legacy_socket_exists
|
|
204
214
|
|
|
205
215
|
raise TransportError,
|
|
206
216
|
"HITL boundary socket directory is not protected: #{dir} " \
|
|
207
|
-
"(
|
|
217
|
+
"(use a dedicated service/root-owned, non-world-writable directory; " \
|
|
218
|
+
"do not share a directory containing unrelated service sockets or legacy labd)"
|
|
208
219
|
end
|
|
209
220
|
|
|
210
221
|
def authenticate!(socket)
|
|
@@ -236,67 +247,10 @@ module Ace
|
|
|
236
247
|
policy: @policy,
|
|
237
248
|
identity: peer,
|
|
238
249
|
vault: @vault,
|
|
239
|
-
proposal_clock: @proposal_clock, stopping: -> { @stopping }
|
|
250
|
+
proposal_clock: @proposal_clock, stopping: -> { @stopping }, group: @group
|
|
240
251
|
)
|
|
241
252
|
end
|
|
242
253
|
|
|
243
|
-
# One request frame per dispatch; lifecycle failures return
|
|
244
|
-
# classified error frames, transport/frame failures close the
|
|
245
|
-
# connection (serve_connection's rescues).
|
|
246
|
-
def dispatch(store, line)
|
|
247
|
-
request = Protocol.decode_request(line)
|
|
248
|
-
result = execute(store, request[:op], request[:params])
|
|
249
|
-
Protocol.encode_result(result)
|
|
250
|
-
rescue Protocol::FrameError, Lifecycle::Error, ArgumentError, TypeError => e
|
|
251
|
-
Protocol.encode_error(e)
|
|
252
|
-
end
|
|
253
|
-
|
|
254
|
-
def execute(store, op, params)
|
|
255
|
-
case op
|
|
256
|
-
when "ping" then {"pong" => true}
|
|
257
|
-
when "proposal-create" then store.proposal_create(**symbolize(params))
|
|
258
|
-
when "proposal-show" then store.proposal_show(required(params, "id"), project: required(params, "project"), history_after: params.fetch("history_after", 0))
|
|
259
|
-
when "proposal-revise" then store.proposal_revise(required(params, "id"), project: required(params, "project"), expected_revision: required(params, "expected_revision"),
|
|
260
|
-
operation_id: required(params, "operation_id"), document: required(params, "document"))
|
|
261
|
-
when "proposal-ack"
|
|
262
|
-
store.proposal_acknowledge(required(params, "id"), project: required(params, "project"), submitted_at: required(params, "submitted_at"))
|
|
263
|
-
when "proposal-reply"
|
|
264
|
-
store.proposal_reply(required(params, "id"), project: required(params, "project"), answer: required(params, "answer"),
|
|
265
|
-
received_at: required(params, "received_at"), sequence: required(params, "sequence"))
|
|
266
|
-
when "proposal-reconcile"
|
|
267
|
-
store.proposal_reconcile(required(params, "id"), project: required(params, "project"), checkpoint: required(params, "checkpoint"))
|
|
268
|
-
when "proposal-wake" then store.proposal_wake(project: required(params, "project"), after: params["after"])
|
|
269
|
-
when "proposal-due" then store.proposal_due(project: required(params, "project"), after: params["after"])
|
|
270
|
-
when "proposal-history" then store.proposal_history(project: required(params, "project"),
|
|
271
|
-
query: params.fetch("query", ""), after: params["after"])
|
|
272
|
-
when "create" then store.create(**symbolize(params))
|
|
273
|
-
when "read" then store.read(required(params, "id"))
|
|
274
|
-
when "deliver" then store.deliver(required(params, "id"), answer_reader(params))
|
|
275
|
-
when "consume"
|
|
276
|
-
store.consume(required(params, "id"), timeout: Integer(params["timeout"] || 0),
|
|
277
|
-
operation: params["operation"], native_delivery: params.fetch("native_delivery", false))
|
|
278
|
-
when "cancel" then store.cancel(required(params, "id"), reason: params["reason"].to_s)
|
|
279
|
-
when "pending" then store.pending_page(project: params["project"], after: params["after"])
|
|
280
|
-
when "states" then store.states
|
|
281
|
-
end
|
|
282
|
-
end
|
|
283
|
-
|
|
284
|
-
def symbolize(params)
|
|
285
|
-
params.transform_keys { |key| key.to_sym }
|
|
286
|
-
end
|
|
287
|
-
|
|
288
|
-
def required(params, key)
|
|
289
|
-
value = params[key]
|
|
290
|
-
raise Protocol::FrameError, "boundary parameter '#{key}' is required" if value.nil? || value.to_s.empty?
|
|
291
|
-
|
|
292
|
-
value
|
|
293
|
-
end
|
|
294
|
-
|
|
295
|
-
def answer_reader(params)
|
|
296
|
-
answer = params["answer"].to_s
|
|
297
|
-
->(limit) { answer[0, limit] }
|
|
298
|
-
end
|
|
299
|
-
|
|
300
254
|
# Keep one stable lock inode for the endpoint. Holding the lock
|
|
301
255
|
# through shutdown prevents simultaneous starters from recovering
|
|
302
256
|
# or replacing a socket another invocation is still acquiring.
|
|
@@ -346,37 +300,10 @@ module Ace
|
|
|
346
300
|
nil
|
|
347
301
|
end
|
|
348
302
|
|
|
349
|
-
def read_frame(socket)
|
|
350
|
-
data = +""
|
|
351
|
-
loop do
|
|
352
|
-
ready = IO.select([socket], nil, nil, @idle_seconds)
|
|
353
|
-
return nil unless ready
|
|
354
|
-
|
|
355
|
-
chunk = socket.read_nonblock(4096, exception: false)
|
|
356
|
-
return nil if chunk.nil?
|
|
357
|
-
next sleep(0.01) if chunk == :wait_readable
|
|
358
|
-
|
|
359
|
-
data << chunk
|
|
360
|
-
if data.bytesize > Protocol::MAX_FRAME_BYTES
|
|
361
|
-
write_frame(socket, Protocol.encode_error(Protocol::FrameError.new("request frame is too large"))) rescue nil
|
|
362
|
-
return nil
|
|
363
|
-
end
|
|
364
|
-
return data if data.include?("\n")
|
|
365
|
-
end
|
|
366
|
-
end
|
|
367
|
-
|
|
368
|
-
def write_frame(socket, frame)
|
|
369
|
-
socket.write(frame)
|
|
370
|
-
socket.flush
|
|
371
|
-
end
|
|
372
|
-
|
|
373
303
|
def root_store
|
|
374
|
-
Store.new(root: @root, binding: @binding, policy: @policy)
|
|
304
|
+
Store.new(root: @root, binding: @binding, policy: @policy, group: @group)
|
|
375
305
|
end
|
|
376
306
|
|
|
377
|
-
def log(message)
|
|
378
|
-
@logger&.call("[ace-hitl] #{message}")
|
|
379
|
-
end
|
|
380
307
|
end
|
|
381
308
|
end
|
|
382
309
|
end
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require "securerandom"
|
|
4
4
|
require "fileutils"
|
|
5
|
+
require "pathname"
|
|
5
6
|
require "ace/hitl/contract"
|
|
6
7
|
require_relative "errors"
|
|
7
8
|
require_relative "identity"
|
|
@@ -79,7 +80,8 @@ module Ace
|
|
|
79
80
|
|
|
80
81
|
def initialize(root:, binding:, policy: AccessPolicy.new,
|
|
81
82
|
identity: Identity, ownership: AtomicJson::DEFAULT_OWNERSHIP,
|
|
82
|
-
poll_seconds: CONSUME_POLL_SECONDS, vault: :file, proposal_clock: -> { Time.now.utc },
|
|
83
|
+
poll_seconds: CONSUME_POLL_SECONDS, vault: :file, proposal_clock: -> { Time.now.utc },
|
|
84
|
+
stopping: -> { false }, group: DEFAULT_GROUP)
|
|
83
85
|
raise ArgumentError, "a binding policy is required (fail closed without one)" unless binding
|
|
84
86
|
raise ArgumentError, "an access policy is required (fail closed without one)" unless policy
|
|
85
87
|
|
|
@@ -92,6 +94,7 @@ module Ace
|
|
|
92
94
|
@vault = vault == :file ? OtpVault::FileVault : vault
|
|
93
95
|
@proposal_clock = proposal_clock
|
|
94
96
|
@stopping = stopping
|
|
97
|
+
@group = group
|
|
95
98
|
end
|
|
96
99
|
|
|
97
100
|
# ---- requester side ------------------------------------------------
|
|
@@ -585,6 +588,7 @@ module Ace
|
|
|
585
588
|
FileUtils.mkdir_p(dir)
|
|
586
589
|
File.chmod(mode, dir)
|
|
587
590
|
end
|
|
591
|
+
retag_public_projections! if @identity.root?
|
|
588
592
|
nil
|
|
589
593
|
end
|
|
590
594
|
|
|
@@ -1083,7 +1087,20 @@ module Ace
|
|
|
1083
1087
|
end
|
|
1084
1088
|
|
|
1085
1089
|
def group_id
|
|
1086
|
-
@group_id ||= @identity.group_id(
|
|
1090
|
+
@group_id ||= @identity.group_id(@group)
|
|
1091
|
+
end
|
|
1092
|
+
|
|
1093
|
+
def retag_public_projections!
|
|
1094
|
+
public_dir.children.each do |path|
|
|
1095
|
+
next unless path.basename.to_s.end_with?(".json")
|
|
1096
|
+
|
|
1097
|
+
stat = File.lstat(path)
|
|
1098
|
+
unless stat.file? && !stat.symlink?
|
|
1099
|
+
raise StateError, "public lifecycle projection is not a regular file"
|
|
1100
|
+
end
|
|
1101
|
+
File.chmod(PUBLIC_MODE, path)
|
|
1102
|
+
@ownership.chown(path, AtomicJson::Ownership.new(uid: stat.uid, gid: group_id))
|
|
1103
|
+
end
|
|
1087
1104
|
end
|
|
1088
1105
|
end
|
|
1089
1106
|
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Ace
|
|
4
|
+
module Hitl
|
|
5
|
+
module Lifecycle
|
|
6
|
+
# The authorization seam of one TLS lifecycle authority (spec
|
|
7
|
+
# 8xa.t.nh0): the verified project-scoped client certificate is
|
|
8
|
+
# the ONLY admitted peer and it is bound to the authority's exact
|
|
9
|
+
# project. A certificate for one project cannot authorize another
|
|
10
|
+
# even when issued by the same CA, and no operation against any
|
|
11
|
+
# other project is reachable through this authority.
|
|
12
|
+
class TlsAccessPolicy < AccessPolicy
|
|
13
|
+
def initialize(project:)
|
|
14
|
+
@project = project.to_s
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def transport?(peer, project: nil)
|
|
18
|
+
bound?(peer) && (project.nil? || project.to_s == @project)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def proposal?(peer, project:)
|
|
22
|
+
transport?(peer, project: project)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# A TLS authority has no Unix service uid; client endpoint
|
|
26
|
+
# verification is certificate-based.
|
|
27
|
+
def service_uid
|
|
28
|
+
nil
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
def bound?(peer)
|
|
34
|
+
peer.is_a?(RemotePeer) && peer.project == @project
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|