Is there a way to run an action step without networking? #24975
-
I would like to run a particular step of my workflow without access to networking (well without Internet access specifically). This is a testing step and recently we had an issue where our tests were sometimes not being fully mocked and accidentally reached out to the Internet which is not ideal for reproducibility etc. I would like to make it so that the testing step of our action is somehow blocked from accessing the Internet so that this kind of mistake is caught during PR review. Does anyone have any recommendations of how to do that? Thanks, Daniel. |
Beta Was this translation helpful? Give feedback.
Replies: 9 comments
-
My first thought: Run it in a container with networking disabled, e.g.:
|
Beta Was this translation helpful? Give feedback.
-
Is there a way to run in a ‘container’ which is just the host OS? I’d rather not complicate matters with another “platform” if I can avoid it. |
Beta Was this translation helpful? Give feedback.
-
Also, will that kind of thing work on Windows and Mac runners too? |
Beta Was this translation helpful? Give feedback.
-
kinnison:
On Linux you could achieve that with I do something similar here, to run web server tests in separate network and IPC namespaces: github.jparrowsec.cnairtower-luna/mod_gnutls/blob/461fd384dbc08afc2fd1bd1b66cb357bfa074312/test/netns_py.bash#L21-L22
I don’t know if there’s anything similar for Windows or Mac. |
Beta Was this translation helpful? Give feedback.
-
Ooh |
Beta Was this translation helpful? Give feedback.
-
A container is going to be the only option here as that would be isolated from the host. Disabling networking on the host during a step would cause the runner to lose connection to github.com and your job would fail. |
Beta Was this translation helpful? Give feedback.
-
@chrispat Thanks for that input, it’s useful to prevent me trying down that route for sure. Is there any way that a container / generic solution could be worked out which the runner could enforce on the processes used in the step, without limiting the runner itself, across all the platforms? I figure this is getting into the realms of ‘not easy to make cross-platform’ but if anyone know what the runners are capable of, it’ll be someone like you :slight_smile: . |
Beta Was this translation helpful? Give feedback.
-
I don’t think it is possible in a cross platform way. The only model I can think of where this could be possible in a straight forward way would be using a container. Maybe there is something you can do with HyperKit or virtual box on MacOS. |
Beta Was this translation helpful? Give feedback.
-
Okay, thanks Chris. I’ll see what I can get up to with unshare in my Linux builds and trust that my other platform’s code won’t vary too much :slight_smile: |
Beta Was this translation helpful? Give feedback.
On Linux you could achieve that with
unshare --net ...
, to run a command in a network namespace of its own without starting a full container that’d also be separated in other ways (like file system).I do something similar here, to run web server tests in separate network and IPC namespaces:
github.jparrowsec.cnairtower-luna/mod_gnutls/blob/461fd384dbc08afc2fd1bd1b66cb357bfa074312/test/netns_py.bash#L21-L22