Repository navigation
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
User-defined functions run on our servers and can call
fetch. That made it possible to reach internal-only addresses from a function, for example:169.254.169.254,metadata.google.internal), which returns instance credentials10.0.0.0/8,127.0.0.1,192.168.0.0/16, …) and internal service namesThis is a Server-Side Request Forgery (SSRF) risk. Apart from
fetch, there were other ways to reach the network:Denoglobal (Deno.connect,Deno.resolveDns,Deno.createHttpClient)import("http://169.254.169.254/")), which go through a separate loader, andfile://imports, which read local filesSolution
A new module,
crates/context_aware_config/src/function_sandbox.rs, sets up the function runtime. Everything goes through rustyscript's publicRuntimeOptions, so the rustyscript fork needs no changes.EgressPolicytrait,PublicInternetOnlyimpl)168.63.129.16, metadata hostnames, and internal suffixes (.internal,.local,.svc, …) and single-label names.fetchrequest before it is sent, including each redirect hop. Onlyhttp/httpsare allowed.169.254.169.254.nip.io).op_net_*,op_dns_*,op_tls_start,op_tls_handshake,op_fetch_custom_client). They throwop is disabledeven if user code finds a way to reach them.DenyImportsfunction.jsload is allowed.Denoglobal from the function scope (defense in depth). It throws if the removal fails.Normal functions are not affected:
fetchto public URLs,console,JSON, timers, etc. work as before. The execution timeout (1500ms) is unchanged; it is now a sharedFUNCTION_TIMEOUTconstant.Blocked requests fail with:
Network access to '<host>' is not allowed from functionsTesting
function_sandbox.rs:DenopresentDenoand keeps web APIsvalidation_functions::tests::functions_run_sandboxedchecks that real function execution goes through the sandbox.cargo test -p context_aware_config -- --ignored.Environment variable changes
None.
Pre-deployment activity
importorDeno.*. These will start failing after this change.Post-deployment activity
is not allowed from functions/op is disabled/Importing modulesmessages, to catch any legitimate use that is now blocked.API changes
None. The request and response formats are unchanged; only function runtime behaviour changes.
Possible Issues in the future
deno_fetchanddeno_errorare pinned to the versions rustyscript uses. They must be bumped together with rustyscript.fetch.