<#1016 Use non-root flyte user by default in built...
# flyte-github
a
#1016 Use non-root flyte user by default in built images Pull request opened by pingsutw Summary • Default base image now creates a non-root
flyte
user, chowns
/home/flyte
,
/root
, and
/opt/venv
to it, sets
WORKDIR /home/flyte
, and switches
USER flyte
at the end of the local Docker build. • Files added via
with_source_folder
,
with_source_file
, and
with_code_bundle
are copied with
--chown=flyte:flyte
so the runtime user can read them. • Refactored the user-creation layer from internal
_DockerLines
to
Commands
+
WorkDir
so the remote builder (whose protobuf IDL only understands proto-backed Layer types) also applies the user setup. Behavior notes • Local builds (including the published default base built via
maint_tools/build_default_image.py --builder=local
): runtime user is
flyte
. • Remote builds: the Union remote image builder backend currently hardcodes its own non-root user (
union
, uid 65532) and ignores SDK-side
USER
directives — the Layer IDL has no
USER
field. Verified by running a probe task on `dogfood.cloud-staging.union.ai`:
Copy code
user=union uid=65532 gid=65532  
home=/home/union cwd=/home/flyte  
/opt/venv owner=root:root
Making the remote builder also default to
flyte
will require a backend-side change (either adding a
USER
Layer to the IDL or aligning the backend's hardcoded user). Test plan import getpass import os import subprocess from pathlib import Path import flyte image = ( flyte.Image.from_debian_base() .with_source_file(Path("README.md")) ) env = flyte.TaskEnvironment(name="check_user_env", image=image) @env.task async def check_user() -> str: user = getpass.getuser() uid = os.getuid() gid = os.getgid() home = os.path.expanduser("~") cwd = os.getcwd() try: venv_owner = subprocess.check_output(["stat", "-c", "%U:%G", "/opt/venv"]).decode().strip() except Exception as e: venv_owner = f"<error: {e}>" readme = "/home/flyte/README.md" try: readme_owner = subprocess.check_output(["stat", "-c", "%U:%G", readme]).decode().strip() except Exception as e: readme_owner = f"<error: {e}>" try: with open(readme, "a") as f: f.write("\n# appended by check_user task\n") with open(readme) as f: tail = f.readlines()[-1].strip() modify_result = f"OK (last line: {tail!r})" except Exception as e: modify_result = f"FAILED: {e}" msg = ( f"user={user} uid={uid} gid={gid}\n" f"home={home} cwd={cwd}\n" f"/opt/venv owner={venv_owner}\n" f"{readme} owner={readme_owner}\n" f"modify {readme}: {modify_result}" ) print(msg) return msg if name == "__main__": flyte.init_from_config(".flyte/config.yaml") run = flyte.run(check_user) print(f"Run URL: {run.url}") run.wait(quiet=False) print(run.outputs()) • Built and ran a remote task on dogfood —
WorkDir
layer is honored, build succeeded. • Build the published default base locally with
python maint_tools/build_default_image.py --type flyte --builder local
and confirm the resulting image's default user is
flyte
and that
/opt/venv
is readable. • Run a task whose image extends the new default base and confirm files added via
with_source_folder
are accessible. • Existing image-builder unit tests pass. flyteorg/flyte-sdk