@fireemu/darwin-arm64 0.50.0 → 0.51.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.
- package/README.md +1 -1
- package/bin/fireemu +2 -2
- package/bin/runner-node/index.mjs +22 -4
- package/bin/runner-node/nested-callable.mjs +25 -15
- package/bin/runner-python/fireemu_runner/dispatch.py +16 -6
- package/bin/runner-python/fireemu_runner/main.py +27 -6
- package/bin/runner-python/fireemu_runner/serve.py +19 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @fireemu/darwin-arm64
|
|
2
2
|
|
|
3
3
|
The [fireemu](https://www.npmjs.com/package/fireemu) daemon built for `darwin-arm64`
|
|
4
|
-
(Rust target `aarch64-apple-darwin`), version 0.
|
|
4
|
+
(Rust target `aarch64-apple-darwin`), version 0.51.0.
|
|
5
5
|
|
|
6
6
|
macOS 13 or newer on Apple silicon.
|
|
7
7
|
|
package/bin/fireemu
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
[diffend] Oversized file quarantined before diffing.
|
|
2
2
|
name: package/bin/fireemu
|
|
3
|
-
size:
|
|
4
|
-
sha256:
|
|
3
|
+
size: 38369776 bytes
|
|
4
|
+
sha256: 52aec9a4febfabab0a1f65229c629e1ddfac507b7b9af878be91778327b1079f
|
|
@@ -344,10 +344,11 @@ const invocationLogger = createInvocationLogger((entry) =>
|
|
|
344
344
|
invocationLogger.install();
|
|
345
345
|
|
|
346
346
|
function parseArgs(argv) {
|
|
347
|
-
const out = { source: process.cwd(), codebase: "default" };
|
|
347
|
+
const out = { source: process.cwd(), codebase: "default", function: undefined };
|
|
348
348
|
for (let i = 0; i < argv.length; i++) {
|
|
349
349
|
if (argv[i] === "--source" && argv[i + 1]) out.source = argv[++i];
|
|
350
350
|
else if (argv[i] === "--codebase" && argv[i + 1]) out.codebase = argv[++i];
|
|
351
|
+
else if (argv[i] === "--function" && argv[i + 1]) out.function = argv[++i];
|
|
351
352
|
}
|
|
352
353
|
return out;
|
|
353
354
|
}
|
|
@@ -385,7 +386,16 @@ function setFunctionIdentity(spec) {
|
|
|
385
386
|
process.env.K_SERVICE = spec?.name ?? "";
|
|
386
387
|
}
|
|
387
388
|
|
|
389
|
+
// A runner started with `--function <name>` (`functions.isolation = "function"`) is one function's instance,
|
|
390
|
+
// as a production instance is: the daemon put FUNCTION_TARGET, FUNCTION_SIGNATURE_TYPE, K_SERVICE and the
|
|
391
|
+
// function's own secrets into its environment at spawn, before any user code loaded, so nothing is rewritten,
|
|
392
|
+
// hidden or queued per call.
|
|
393
|
+
const dedicatedFunction = () => args.function !== undefined;
|
|
394
|
+
|
|
388
395
|
function withFunctionEnvironment(spec, task, invocationId) {
|
|
396
|
+
if (dedicatedFunction()) {
|
|
397
|
+
return invocationLogger.run({ functionName: spec?.name, invocationId }, task);
|
|
398
|
+
}
|
|
389
399
|
const shared = localSecrets.size > 0 && activeInspectorPort === undefined &&
|
|
390
400
|
!(spec?.platformOptions?.secrets || []).some(name => localSecrets.has(name));
|
|
391
401
|
const run = async () => {
|
|
@@ -1398,11 +1408,10 @@ async function makeHttpServer(functions, manifest) {
|
|
|
1398
1408
|
.send(`no HTTP function ${req.params.project}/${req.params.region}/${req.params.name}`);
|
|
1399
1409
|
return;
|
|
1400
1410
|
}
|
|
1401
|
-
//
|
|
1402
|
-
// wrapper nested in it refuses a credential the daemon did not verify (nested-callable.mjs).
|
|
1411
|
+
// Guard nested callable wrappers for every non-callable entry, including task queues.
|
|
1403
1412
|
markNonCallableRequest(req, {
|
|
1404
1413
|
strict: strictProfile(),
|
|
1405
|
-
nonCallableHttp: spec.trigger?.type
|
|
1414
|
+
nonCallableHttp: spec.trigger?.type !== "http" || spec.trigger.callable !== true,
|
|
1406
1415
|
});
|
|
1407
1416
|
const taskIdentity = takeTaskIdentityMarker(req);
|
|
1408
1417
|
// Without App Check a callable that could consume a token never sees one, whichever path
|
|
@@ -1839,6 +1848,15 @@ async function main() {
|
|
|
1839
1848
|
reason: d.ignored.reason,
|
|
1840
1849
|
})),
|
|
1841
1850
|
};
|
|
1851
|
+
if (dedicatedFunction()) {
|
|
1852
|
+
// One function's instance serves one function. Another export stays in the module graph, as in a
|
|
1853
|
+
// production instance, but is neither announced nor routable here.
|
|
1854
|
+
if (!manifest.functions.some((f) => f.name === args.function)) {
|
|
1855
|
+
process.stderr.write(`the function ${args.function} is not exported by the codebase at ${sourceDir}\n`);
|
|
1856
|
+
process.exit(1);
|
|
1857
|
+
}
|
|
1858
|
+
manifest = { ...manifest, functions: manifest.functions.filter((f) => f.name === args.function) };
|
|
1859
|
+
}
|
|
1842
1860
|
startupTrace('function discovery complete');
|
|
1843
1861
|
let httpPort;
|
|
1844
1862
|
if (
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
|
|
21
21
|
/// The field the daemon sets on a request to a non-callable HTTP endpoint in the strict profile.
|
|
22
22
|
export const VERIFIED_CREDENTIAL_HEADER = "x-fireemu-credential-verified";
|
|
23
|
+
export const VERIFIED_APP_CHECK_HEADER = "x-fireemu-appcheck-verified";
|
|
23
24
|
|
|
24
25
|
const CONTEXT = Symbol.for("fireemu.endpointContext");
|
|
25
26
|
|
|
@@ -27,23 +28,28 @@ const CONTEXT = Symbol.for("fireemu.endpointContext");
|
|
|
27
28
|
/// the SDK reads it as an invalid credential without decoding it.
|
|
28
29
|
export const UNVERIFIED_CREDENTIAL = "fireemu-unverified-credential";
|
|
29
30
|
|
|
30
|
-
/// Reads and removes the daemon's
|
|
31
|
-
///
|
|
31
|
+
/// Reads and removes the daemon's markers, then marks requests to non-callable entries.
|
|
32
|
+
/// A missing App Check marker never admits a token. Returns whether the request was marked.
|
|
32
33
|
export function markNonCallableRequest(req, { strict, nonCallableHttp }) {
|
|
33
34
|
const marker = req.headers?.[VERIFIED_CREDENTIAL_HEADER];
|
|
34
|
-
|
|
35
|
+
const appCheckMarker = req.headers?.[VERIFIED_APP_CHECK_HEADER];
|
|
36
|
+
if (req.headers) {
|
|
37
|
+
for (const name of Object.keys(req.headers)) {
|
|
38
|
+
if ([VERIFIED_CREDENTIAL_HEADER, VERIFIED_APP_CHECK_HEADER].includes(name.toLowerCase())) delete req.headers[name];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
35
41
|
if (Array.isArray(req.rawHeaders)) {
|
|
36
42
|
const kept = [];
|
|
37
43
|
for (let i = 0; i + 1 < req.rawHeaders.length; i += 2) {
|
|
38
|
-
if (String(req.rawHeaders[i]).toLowerCase()
|
|
44
|
+
if (![VERIFIED_CREDENTIAL_HEADER, VERIFIED_APP_CHECK_HEADER].includes(String(req.rawHeaders[i]).toLowerCase())) {
|
|
39
45
|
kept.push(req.rawHeaders[i], req.rawHeaders[i + 1]);
|
|
40
46
|
}
|
|
41
47
|
}
|
|
42
48
|
req.rawHeaders = kept;
|
|
43
49
|
}
|
|
44
|
-
if (!
|
|
50
|
+
if (!nonCallableHttp && appCheckMarker === undefined) return false;
|
|
45
51
|
Object.defineProperty(req, CONTEXT, {
|
|
46
|
-
value: Object.freeze({ credentialVerified: marker === "1" }),
|
|
52
|
+
value: Object.freeze({ credentialVerified: !nonCallableHttp || !strict || marker === "1", appCheckVerified: appCheckMarker === "1" }),
|
|
47
53
|
configurable: true,
|
|
48
54
|
});
|
|
49
55
|
return true;
|
|
@@ -54,15 +60,19 @@ export function markNonCallableRequest(req, { strict, nonCallableHttp }) {
|
|
|
54
60
|
/// `Authorization` is [`UNVERIFIED_CREDENTIAL`]. The view leaves the caller's own request untouched.
|
|
55
61
|
export function requestForCallableWrapper(req) {
|
|
56
62
|
const context = req?.[CONTEXT];
|
|
57
|
-
if (!context
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
headers
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
if (!context) return req;
|
|
64
|
+
const headers = { ...req.headers };
|
|
65
|
+
let changed = false;
|
|
66
|
+
if (!context.credentialVerified && typeof headers.authorization === "string" && headers.authorization !== "") {
|
|
67
|
+
headers.authorization = UNVERIFIED_CREDENTIAL;
|
|
68
|
+
changed = true;
|
|
69
|
+
}
|
|
70
|
+
if (!context.appCheckVerified && headers["x-firebase-appcheck"] !== undefined) {
|
|
71
|
+
delete headers["x-firebase-appcheck"];
|
|
72
|
+
changed = true;
|
|
73
|
+
}
|
|
74
|
+
if (!changed) return req;
|
|
75
|
+
return Object.create(req, { headers: { value: headers, enumerable: true } });
|
|
66
76
|
}
|
|
67
77
|
|
|
68
78
|
/// A callable wrapper that reads its request through [`requestForCallableWrapper`]. The result keeps
|
|
@@ -51,8 +51,16 @@ def _bound(text: str, limit: int) -> str:
|
|
|
51
51
|
class Dispatcher:
|
|
52
52
|
"""Runs `invoke` frames against the functions the manifest serves."""
|
|
53
53
|
|
|
54
|
-
def __init__(
|
|
54
|
+
def __init__(
|
|
55
|
+
self,
|
|
56
|
+
functions: dict,
|
|
57
|
+
manifest: dict,
|
|
58
|
+
writer: FrameWriter,
|
|
59
|
+
gate: EnvironmentGate | None = None,
|
|
60
|
+
fixed_identity: bool = False,
|
|
61
|
+
):
|
|
55
62
|
self._gate = gate if gate is not None else EnvironmentGate({})
|
|
63
|
+
self._fixed_identity = fixed_identity
|
|
56
64
|
self._functions = functions
|
|
57
65
|
self._specs = {spec["name"]: spec for spec in manifest["functions"]}
|
|
58
66
|
self._writer = writer
|
|
@@ -98,11 +106,13 @@ class Dispatcher:
|
|
|
98
106
|
return ASYNC_HANDLER, ASYNC_HANDLER
|
|
99
107
|
with self._gate.hold(spec.get("platformOptions", {}).get("secrets")):
|
|
100
108
|
try:
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
109
|
+
if not self._fixed_identity:
|
|
110
|
+
# One process serves the whole codebase, so these name the invocation that started most
|
|
111
|
+
# recently, not a fixed target (the design memo, section 5). A dedicated runner has them from
|
|
112
|
+
# its spawn.
|
|
113
|
+
os.environ["FUNCTION_TARGET"] = spec["entryPoint"]
|
|
114
|
+
os.environ["FUNCTION_SIGNATURE_TYPE"] = _SIGNATURE_TYPES.get(message["trigger"], "cloudevent")
|
|
115
|
+
os.environ["K_SERVICE"] = spec["name"]
|
|
106
116
|
_deliver(message["trigger"], function, message["event"], message.get("rawEventData"))
|
|
107
117
|
except BaseException as error: # a SystemExit in user code must still answer the daemon
|
|
108
118
|
diagnostic, text = describe(error)
|
|
@@ -18,6 +18,9 @@ def _parse(argv):
|
|
|
18
18
|
parser = argparse.ArgumentParser(prog="runner.py")
|
|
19
19
|
parser.add_argument("--source", required=True)
|
|
20
20
|
parser.add_argument("--codebase", default="default")
|
|
21
|
+
# One function's instance (`functions.isolation = "function"`): the daemon fixed the function's identity and secrets
|
|
22
|
+
# in the environment at spawn, so this runner serves that function only and rewrites nothing per call.
|
|
23
|
+
parser.add_argument("--function", default=None)
|
|
21
24
|
return parser.parse_args(argv)
|
|
22
25
|
|
|
23
26
|
|
|
@@ -30,16 +33,32 @@ def load_codebase(source: str) -> dict:
|
|
|
30
33
|
|
|
31
34
|
|
|
32
35
|
def serve(
|
|
33
|
-
functions: dict,
|
|
36
|
+
functions: dict,
|
|
37
|
+
codebase: str,
|
|
38
|
+
secret: str,
|
|
39
|
+
stdin,
|
|
40
|
+
writer: FrameWriter,
|
|
41
|
+
gate: EnvironmentGate | None = None,
|
|
42
|
+
app_check_verified: bool = False,
|
|
43
|
+
blocking_verified: bool = False,
|
|
44
|
+
function: str | None = None,
|
|
34
45
|
) -> int:
|
|
35
|
-
"""Says hello, then serves frames from `stdin` until `shutdown` or the end of the stream.
|
|
46
|
+
"""Says hello, then serves frames from `stdin` until `shutdown` or the end of the stream.
|
|
47
|
+
|
|
48
|
+
With `function`, the runner is that function's instance: only it is announced and served.
|
|
49
|
+
"""
|
|
36
50
|
manifest = build_manifest(functions, app_check_verified)
|
|
51
|
+
if function is not None:
|
|
52
|
+
if not any(spec["name"] == function for spec in manifest["functions"]):
|
|
53
|
+
sys.stderr.write(f"[functions] the function {function} is not exported by the codebase\n")
|
|
54
|
+
return 1
|
|
55
|
+
manifest = {**manifest, "functions": [spec for spec in manifest["functions"] if spec["name"] == function]}
|
|
37
56
|
if not blocking_verified and any(spec["trigger"]["type"] == "blockingAuth" for spec in manifest["functions"]):
|
|
38
57
|
blocking.announce_default_note(sys.stderr)
|
|
39
58
|
server = None
|
|
40
59
|
port = None
|
|
41
60
|
if any(spec["trigger"]["type"] in HTTP_TRIGGERS for spec in manifest["functions"]):
|
|
42
|
-
server, port = start_server(functions, manifest, secret, gate)
|
|
61
|
+
server, port = start_server(functions, manifest, secret, gate, function is not None)
|
|
43
62
|
writer.write(
|
|
44
63
|
{
|
|
45
64
|
"type": "hello",
|
|
@@ -50,7 +69,7 @@ def serve(
|
|
|
50
69
|
"manifest": manifest,
|
|
51
70
|
}
|
|
52
71
|
)
|
|
53
|
-
dispatcher = Dispatcher(functions, manifest, writer, gate)
|
|
72
|
+
dispatcher = Dispatcher(functions, manifest, writer, gate, fixed_identity=function is not None)
|
|
54
73
|
try:
|
|
55
74
|
while True:
|
|
56
75
|
message = read_frame(stdin)
|
|
@@ -96,6 +115,8 @@ def run(argv) -> int:
|
|
|
96
115
|
except BaseException: # a failing import in user code is reported with its traceback
|
|
97
116
|
traceback.print_exc()
|
|
98
117
|
return 1
|
|
118
|
+
# A dedicated runner (`--function`) names its function; otherwise the call is the one the daemon has always seen.
|
|
119
|
+
options = {} if args.function is None else {"function": args.function}
|
|
99
120
|
if blocking_verified:
|
|
100
|
-
return serve(functions, args.codebase, secret, sys.stdin.buffer, writer, gate, app_check_verified, blocking_verified=True)
|
|
101
|
-
return serve(functions, args.codebase, secret, sys.stdin.buffer, writer, gate, app_check_verified)
|
|
121
|
+
return serve(functions, args.codebase, secret, sys.stdin.buffer, writer, gate, app_check_verified, blocking_verified=True, **options)
|
|
122
|
+
return serve(functions, args.codebase, secret, sys.stdin.buffer, writer, gate, app_check_verified, **options)
|
|
@@ -88,8 +88,17 @@ class _HeldBody:
|
|
|
88
88
|
class RunnerRouter:
|
|
89
89
|
"""Admission and routing in front of the Flask app."""
|
|
90
90
|
|
|
91
|
-
def __init__(
|
|
91
|
+
def __init__(
|
|
92
|
+
self,
|
|
93
|
+
functions: dict,
|
|
94
|
+
manifest: dict,
|
|
95
|
+
project: str,
|
|
96
|
+
secret: str,
|
|
97
|
+
gate: EnvironmentGate | None = None,
|
|
98
|
+
fixed_identity: bool = False,
|
|
99
|
+
):
|
|
92
100
|
self._app = _flask_app()
|
|
101
|
+
self._fixed_identity = fixed_identity
|
|
93
102
|
self._gate = gate if gate is not None else EnvironmentGate({})
|
|
94
103
|
self._project = project
|
|
95
104
|
self._secret = secret.encode()
|
|
@@ -137,11 +146,13 @@ class RunnerRouter:
|
|
|
137
146
|
held = contextlib.ExitStack()
|
|
138
147
|
held.enter_context(self._gate.hold(route[3]))
|
|
139
148
|
try:
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
149
|
+
if not self._fixed_identity:
|
|
150
|
+
# The variables a production instance has from its start name the function it serves. One process
|
|
151
|
+
# serves the whole codebase here, so they name the call that started most recently, as for events.
|
|
152
|
+
# A dedicated runner has them from its spawn.
|
|
153
|
+
os.environ["FUNCTION_TARGET"] = route[2]
|
|
154
|
+
os.environ["FUNCTION_SIGNATURE_TYPE"] = "http"
|
|
155
|
+
os.environ["K_SERVICE"] = name
|
|
145
156
|
body = self._app(environ, start_response)
|
|
146
157
|
except BaseException as error:
|
|
147
158
|
_log_failure(name, error)
|
|
@@ -155,9 +166,9 @@ class _QuietHandler(WSGIRequestHandler):
|
|
|
155
166
|
pass
|
|
156
167
|
|
|
157
168
|
|
|
158
|
-
def start_server(functions: dict, manifest: dict, secret: str, gate: EnvironmentGate | None = None):
|
|
169
|
+
def start_server(functions: dict, manifest: dict, secret: str, gate: EnvironmentGate | None = None, fixed_identity: bool = False):
|
|
159
170
|
"""Starts the server on a free loopback port; returns `(server, port)`."""
|
|
160
|
-
router = RunnerRouter(functions, manifest, os.environ.get("GCLOUD_PROJECT", ""), secret, gate)
|
|
171
|
+
router = RunnerRouter(functions, manifest, os.environ.get("GCLOUD_PROJECT", ""), secret, gate, fixed_identity)
|
|
161
172
|
server = make_server("127.0.0.1", 0, router, threaded=True, request_handler=_QuietHandler)
|
|
162
173
|
import threading
|
|
163
174
|
|