1// SPDX-License-Identifier: MIT
2
3// Internal wire format between the host process of ermite-runner and the
4// executor running inside a sandbox (vsock in a micro-VM, Unix socket in a
5// container). Frames are length-prefixed on the stream (see frame.go); this file
6// defines the payload. It is internal to ermite-runner: no compatibility is
7// promised between runner versions, which is safe because the host attaches its
8// own executable to every sandbox.
9
10syntax = "proto3";
11
12package ermite.runner.exec.v1;
13
14option go_package = "bnema.dev/ermite-runner/internal/execstream/execpb";
15
16// Frame is the only message on the stream.
17message Frame {
18 oneof body {
19 Hello hello = 1; // executor -> host, first frame
20 Run run = 2; // host -> executor, after Hello
21 Output output = 3; // executor -> host
22 Exit exit = 4; // executor -> host, last frame
23 Cancel cancel = 5; // host -> executor
24 StepStarted step_started = 6; // executor -> host
25 StepCompleted step_completed = 7; // executor -> host
26 Log log = 8; // executor -> host
27 JobResult job_result = 9; // executor -> host, before Exit
28 StepAnnotations step_annotations = 10; // executor -> host, before the StepCompleted of the step
29 StepSummary step_summary = 11; // executor -> host, before the StepCompleted of the step
30 ResolveRequest resolve_request = 12; // executor -> host
31 ResolveResponse resolve_response = 13; // host -> executor, answers a ResolveRequest
32 NamedValue secret = 14; // host -> executor, one per secret, before Run
33 NamedValue var = 15; // host -> executor, one per variable, before Run
34 }
35}
36
37// NamedValue is one secret (Job.secrets) or one variable (Job.vars) of the job.
38// They travel in frames of their own, before Run, rather than in JobSpec: a
39// frame is at most 2 MiB (execstream.MaxFrame) and ermite allows many secrets of
40// 48 KiB, so a map in Run could not carry them. The executor keeps them until
41// Run arrives. Secrets are never logged nor written to disk.
42message NamedValue {
43 string name = 1;
44 string value = 2;
45}
46
47message Hello {
48 string version = 1; // runner version of the executor
49 string sandbox = 2; // "vm" or "container"
50 string hostname = 3;
51}
52
53// Run asks the executor to run a script or a job. Without job it is the stub
54// executor of sandbox-check: the script is run with `sh -c`; an empty script
55// means the built-in diagnostics script. With job the executor runs the job
56// like a GitHub Actions runner and reports it with StepStarted, Log,
57// StepCompleted and JobResult frames, then Exit.
58message Run {
59 string script = 1;
60 map<string, string> env = 2;
61 JobSpec job = 3;
62}
63
64// JobSpec is the job to run: the fields of the job that ermite handed to the
65// host process, minus the tokens (the sandbox never sees them).
66message JobSpec {
67 string workflow_path = 1;
68 string workflow_yaml = 2;
69 string job_key = 3;
70 string matrix = 4; // JSON object
71 string contexts = 5; // JSON object
72 string repo = 6; // repository name
73 int32 timeout_minutes = 7;
74 string runner_name = 8;
75 string runner_version = 9;
76 // runner_environment is the runner.environment value ("github-hosted" or "self-hosted").
77 string runner_environment = 10;
78 bool debug = 11; // ACTIONS_STEP_DEBUG
79 // deadline_ms is what is left of the job timeout when the host sends this
80 // Run, in milliseconds: the timeout counts from the moment the host received
81 // the job (runner.proto: Job.timeout_minutes), not from the start of the
82 // executor, and booting the sandbox takes time. 0 means "use
83 // timeout_minutes from now".
84 int64 deadline_ms = 12;
85 // send_annotations and send_summaries say that the server keeps annotations
86 // (feature ci.annotations) and step summaries (ci.summaries). The executor
87 // sends StepAnnotations and StepSummary frames only when they are set.
88 bool send_annotations = 13;
89 bool send_summaries = 14;
90 // cache_port and cache_token, when set, are the runner's cache service for
91 // this job. The service is not on the network: the executor starts a relay
92 // on the sandbox's own loopback, 127.0.0.1:<cache_port>, that carries each
93 // connection over the host channel (a vsock port, or a Unix socket next to
94 // the executor's) to the service. The executor gives
95 // ACTIONS_CACHE_URL=http://127.0.0.1:<port>/ and the token as
96 // ACTIONS_RUNTIME_TOKEN to node and docker actions only, as the official
97 // runner does, and masks the token. The token is not an ermite credential: it
98 // is a JWT (HS256) that only the runner's runtime services accept, scoped to
99 // this job's repository and refs (and its run, see results).
100 uint32 cache_port = 15;
101 string cache_token = 16;
102 // Job.secrets and Job.vars are not here: they come in NamedValue frames
103 // before Run (see NamedValue). The executor takes the vars of those frames
104 // for the "vars" context when contexts has none.
105 reserved 17, 18;
106 reserved "secrets", "vars";
107 // secrets_withheld is set by the host when the server sends Job.trusted and
108 // the job is not trusted (feature ci.secrets): "Set up job" then says that
109 // secrets are not available. Never set for servers without the feature, for
110 // which an absent Job.trusted only means "not sent".
111 bool secrets_withheld = 19;
112 // id_token_url and id_token_request_token are Job.id_token_url and
113 // Job.id_token_request_token: the OIDC token endpoint of the server, its
114 // origin rewritten as for github.server_url, and the bearer for it. The
115 // executor gives them as ACTIONS_ID_TOKEN_REQUEST_URL and
116 // ACTIONS_ID_TOKEN_REQUEST_TOKEN to run steps, node actions and docker
117 // actions (ScriptHandler.cs:315-319, NodeScriptActionHandler.cs:66-70,
118 // ContainerActionHandler.cs:232-236), and masks the token before anything
119 // runs. Both are set or neither. (21 and 22 are taken by the artifacts
120 // branch.)
121 string id_token_url = 23;
122 string id_token_request_token = 24;
123 // token_permissions are the effective permissions of the job's GITHUB_TOKEN
124 // as the server sent them (Job.permissions, feature ci.secrets): "Set up job"
125 // prints them instead of working them out from the workflow. Unset when the
126 // server sent none (an older server): the executor then reads them from the
127 // workflow.
128 TokenPermissions token_permissions = 20;
129 // cache_mode is ACTIONS_CACHE_MODE of the node and docker actions: "write"
130 // when the job's cache scope has a write ref, "read" when it has none. Unset
131 // without a cache service, and unset when the channel serves the results
132 // service only (results set, no cache scope): no ACTIONS_CACHE_URL then.
133 string cache_mode = 21;
134 // results says that the service behind cache_port also serves artifacts
135 // (Twirp github.actions.results.api.v1.ArtifactService and its blobs) and
136 // that cache_token carries the job's Actions.Results scope. The executor
137 // then gives node and docker actions ACTIONS_RESULTS_URL (the same origin as
138 // ACTIONS_CACHE_URL) and sets GITHUB_SERVER_URL to a *.ghe.localhost host in
139 // the process of the node steps of the artifact actions only (README,
140 // "Artifacts"). Set only when the server has the feature ci.artifacts.
141 bool results = 22;
142}
143
144// TokenPermissions maps a permission key ("contents", "pull-requests", ...) to
145// "read", "write" or "none"; a key that is absent is none.
146message TokenPermissions {
147 map<string, string> levels = 1;
148}
149
150enum StreamKind {
151 STREAM_KIND_UNSPECIFIED = 0;
152 STREAM_KIND_STDOUT = 1;
153 STREAM_KIND_STDERR = 2;
154}
155
156message Output {
157 StreamKind stream = 1;
158 bytes data = 2;
159 int64 unix_nano = 3;
160}
161
162message Exit {
163 int32 code = 1;
164 string error = 2; // set when the executor failed to run the script at all
165}
166
167// Cancel asks the executor to stop the running script. The executor escalates
168// like the official runner: SIGINT to the script's process group at once,
169// SIGTERM 7.5 s later, SIGKILL 2.5 s after that.
170message Cancel {
171 // reason is for the job log and diagnostics ("cancelled by the user",
172 // "job timeout", ...); it never changes the behaviour.
173 string reason = 1;
174 // kind tells the job executor how the job ends: cancelled, timed out, or
175 // cancelled because the runner shuts down. The stub executor ignores it.
176 CancelKind kind = 2;
177}
178
179enum CancelKind {
180 CANCEL_KIND_UNSPECIFIED = 0; // same as USER
181 CANCEL_KIND_USER = 1;
182 CANCEL_KIND_TIMEOUT = 2;
183 CANCEL_KIND_SHUTDOWN = 3;
184}
185
186// Steps are numbered like GitHub's log: "Set up job" is 1, the steps of the
187// workflow follow, "Complete job" is last.
188message StepStarted {
189 int32 number = 1;
190 string name = 2;
191 int64 unix_nano = 3;
192}
193
194message StepCompleted {
195 int32 number = 1;
196 string name = 2;
197 StepConclusion conclusion = 3;
198 int64 unix_nano = 4;
199 // outcome is steps.<id>.outcome: the result before continue-on-error. It
200 // differs from conclusion only for a failed step with continue-on-error.
201 // UNSPECIFIED means the same as conclusion.
202 StepConclusion outcome = 5;
203}
204
205enum AnnotationLevel {
206 ANNOTATION_LEVEL_UNSPECIFIED = 0;
207 ANNOTATION_LEVEL_NOTICE = 1;
208 ANNOTATION_LEVEL_WARNING = 2;
209 ANNOTATION_LEVEL_FAILURE = 3;
210}
211
212// Annotation is one ::notice, ::warning or ::error (or a problem matcher
213// match), masked. The host validates every field again before it sends them.
214message Annotation {
215 AnnotationLevel level = 1;
216 string title = 2;
217 string message = 3;
218 string file = 4; // relative to the repository when the file is in it
219 int32 start_line = 5;
220 int32 end_line = 6;
221 int32 start_column = 7;
222 int32 end_column = 8;
223}
224
225// StepAnnotations is the complete list of the annotations of a step (the ones
226// the runner keeps: at most 10 per level), replacing any earlier list of that
227// step. Annotations of the steps inside a composite action are those of the
228// step of the workflow that uses it.
229message StepAnnotations {
230 int32 step = 1;
231 repeated Annotation annotations = 2;
232}
233
234// StepSummary is the masked content of GITHUB_STEP_SUMMARY after a step, at
235// most 1 MiB.
236message StepSummary {
237 int32 step = 1;
238 string markdown = 2;
239}
240
241enum StepConclusion {
242 STEP_CONCLUSION_UNSPECIFIED = 0;
243 STEP_CONCLUSION_SUCCESS = 1;
244 STEP_CONCLUSION_FAILURE = 2;
245 STEP_CONCLUSION_CANCELLED = 3;
246 STEP_CONCLUSION_SKIPPED = 4;
247 STEP_CONCLUSION_TIMED_OUT = 5; // jobs only
248}
249
250// Log is one line of the job log, without terminator, valid UTF-8. A line of
251// more than 64 KiB is cut by the executor into pieces at character boundaries;
252// every piece but the first has continued set (the AppendLog rule).
253message Log {
254 int32 step = 1;
255 int64 unix_nano = 2;
256 string text = 3;
257 bool continued = 4;
258}
259
260// JobResult is the outcome of the job; Exit follows.
261message JobResult {
262 StepConclusion conclusion = 1;
263 map<string, string> outputs = 2;
264 string error = 3;
265 bool runner_shutdown = 4;
266}
267
268// ResolveRequest asks the host to resolve actions with RunnerService.
269// ResolveActions: the job token stays in the host, so the executor cannot call
270// it. The executor sends one per level of composite actions (the runner's own
271// "one more round per level") and waits for the ResolveResponse with the same id.
272message ResolveRequest {
273 int64 id = 1;
274 repeated string uses = 2; // "owner/repo[/path]@ref", at most 100
275}
276
277// ResolveResponse answers a ResolveRequest. error is set when the call itself
278// failed (the executor fails the job); actions has one entry per uses otherwise.
279message ResolveResponse {
280 int64 id = 1;
281 string error = 2;
282 repeated ResolvedAction actions = 3;
283}
284
285// ResolvedAction mirrors ermite.ResolvedAction (the token is a secret: the
286// executor masks it).
287message ResolvedAction {
288 string ref = 1;
289 string name_with_owner = 2;
290 string path = 3;
291 string resolved_sha = 4;
292 string tarball_url = 5;
293 string token = 6;
294 string source = 7;
295 string error = 8;
296 // auth_origin (scheme://host[:port], as the sandbox reaches it) is the only
297 // origin the token may be sent to; empty means the token is never sent. The
298 // host sets it for archives served by the ermite server, from its own
299 // configuration, never from the URL alone.
300 string auth_origin = 9;
301}