Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ jobs:
default: true
override: true

- name: install bwrap
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get -y install bubblewrap

- name: Install dependencies
run: python -m pip install tox

Expand Down
2 changes: 1 addition & 1 deletion src/fromager/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
@click.option(
"--network-isolation/--no-network-isolation",
default=SUPPORTS_NETWORK_ISOLATION,
help="Build sdist and wheen with network isolation (unshare -cn)",
help="Build sdist and wheen with network isolation (bwrap, unshare -nr)",
show_default=True,
)
@click.pass_context
Expand Down
17 changes: 10 additions & 7 deletions src/fromager/external_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@

logger = logging.getLogger(__name__)

NETWORK_ISOLATION: list[str] | None
NETWORK_ISOLATION: list[list[str]] | None
if sys.platform == "linux":
NETWORK_ISOLATION = ["unshare", "--net", "--map-current-user"]
NETWORK_ISOLATION = [
["bwrap", "--unshare-network", "--dev-bind", "/", "/", "--"],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--unshare-network doesn't appear to be valid? Is this supposed to be --unshare-net ?

@prarit prarit Oct 10, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: this needs docker to specify --privileged in builder's bin/boostrap.sh o/w you get an error

bwrap: Creating new namespace failed: Operation not permitted

["unshare", "--net", "--map-current-user"],
]
else:
NETWORK_ISOLATION = None

Expand All @@ -22,11 +25,11 @@ def network_isolation_cmd() -> typing.Sequence[str]:
Raises ValueError when network isolation is not supported
Returns: command list to run a process with network isolation
"""
if sys.platform == "linux":
unshare = shutil.which("unshare")
if unshare is not None:
return [unshare, "--net", "--map-current-user"]
raise ValueError("Linux system without 'unshare' command")
if NETWORK_ISOLATION is not None:
for cmd in NETWORK_ISOLATION:
if shutil.which(cmd[0]):
return cmd
raise ValueError("Linux system without network isolation support")
raise ValueError(f"unsupported platform {sys.platform}")


Expand Down