Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

launch middleman process on macOS to workaround SIP limit #416

Merged
merged 1 commit into from
Apr 9, 2020

Conversation

TingluoHuang
Copy link
Member

@TingluoHuang TingluoHuang commented Apr 8, 2020

When DYLD_INSERT_LIBRARIES set on macOS, SIP will remove it when launch process that under /usr/bin, ex: bash

We will use node as a proxy process on macOS when DYLD_INSERT_LIBRARIES is set to execute runs script.

More detail:
https://github.com/github/c2c-actions-runtime/issues/447

Copy link

@aibaars aibaars left a comment

Choose a reason for hiding this comment

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

Thanks @TingluoHuang !

This looks like it would solve our problem assuming WellKnownDirectory.Externals is outside /usr, which is true on the current actions VMs.

src/Runner.Worker/Handlers/ScriptHandler.cs Outdated Show resolved Hide resolved
// launch `node macOSRunInvoker.js shell args` instead of `shell args` to avoid macOS SIP remove `DYLD_INSERT_LIBRARIES` when launch process
string node12 = Path.Combine(HostContext.GetDirectory(WellKnownDirectory.Externals), "node12", "bin", $"node{IOUtil.ExeExtension}");
string macOSRunInvoker = Path.Combine(HostContext.GetDirectory(WellKnownDirectory.Bin), "macOSRunInvoker.js");
arguments = $"\"{macOSRunInvoker.Replace("\"", "\\\"")}\" \"{fileName.Replace("\"", "\\\"")}\" {arguments}";
Copy link

Choose a reason for hiding this comment

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

Replace("\"", "\\\"") is not enough to escape an arbitrary string for the command line. For a unix-like OS, I think you should at least also escape \ , $ and ` .

Isn't there a utility function somewhere for escaping an argument string in an OS specific way?

Copy link
Member Author

Choose a reason for hiding this comment

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

we don't need to escape those since those are special character for bash/sh, the runner launch process directly, so we only need to worry about " and (space).

Copy link
Collaborator

@ericsciple ericsciple Apr 9, 2020

Choose a reason for hiding this comment

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

Should we pass the command line using an environment variable instead? Then we avoid escaping complexity

INPUT_FILENAME AND INPUT_ARGS

And delete the env vars (delete process.env.INPUT_FILENAME etc) before launching the child process from node.

Copy link

Choose a reason for hiding this comment

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

Alright, I see you have _proc.StartInfo.UseShellExecute = false in ProcessInvoker.cs.

In that case you probably still need to worry about \ . Otherwise an argument containing \" (a backslash and a quote) might cause some trouble. After the Replace you'd end-up with \\", which I think would be interpreted as an escaped backslash and an unescaped ".

Wouldn't it be easier to use ProcessStartInfo.ArgumentList instead of ProcessStartInfo.Arguments ? That looks more convenient.

Copy link
Member Author

Choose a reason for hiding this comment

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

we don't want to be in a business of parse customer's arg string into arg array. :)

src/Runner.Worker/Handlers/ScriptHandler.cs Outdated Show resolved Hide resolved
@TingluoHuang TingluoHuang force-pushed the users/tihuang/workaroundsip branch 2 times, most recently from d9a08df to 39bc519 Compare April 9, 2020 16:27
@TingluoHuang TingluoHuang merged commit 2bd0b1a into master Apr 9, 2020
@TingluoHuang TingluoHuang deleted the users/tihuang/workaroundsip branch April 9, 2020 20:13
AdamOlech pushed a commit to antmicro/runner that referenced this pull request Jan 28, 2021
adityasharad added a commit to github/codeql-action that referenced this pull request Jul 25, 2022
We do not need to prefix `$CODEQL_RUNNER` here on macOS to bypass SIP,
because we assume that the `init` step exported `DYLD_INSERT_LIBRARIES`
into the environment, which activates the Actions workaround for SIP.
See actions/runner#416.
adityasharad added a commit to github/codeql-action that referenced this pull request Jul 25, 2022
We do not need to prefix `$CODEQL_RUNNER` here on macOS to bypass SIP,
because we assume that the `init` step exported `DYLD_INSERT_LIBRARIES`
into the environment, which activates the Actions workaround for SIP.
See actions/runner#416.
Copy link

@Tombow916 Tombow916 left a comment

Choose a reason for hiding this comment

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

I fix the malfunction so stop bullying people

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants