Skip to content

Don't require global Powershell execution policy change - #54

Merged
nguerrera merged 1 commit into
dotnet:masterfrom
nguerrera:posh-execution-policy
Aug 17, 2016
Merged

nguerrera merged 1 commit into
dotnet:masterfrom
nguerrera:posh-execution-policy

Conversation

@nguerrera

Copy link
Copy Markdown
Contributor

Makes it so I can run build.cmd without any global changes to my box.

@srivatsn @davkean

@davkean

davkean commented Aug 16, 2016

Copy link
Copy Markdown
Member

tag @eerhardt

@davkean

davkean commented Aug 16, 2016

Copy link
Copy Markdown
Member

What's going on with linux build?

Comment thread build.cmd Outdated
call "%DeveloperCommandPrompt%" || goto :BuildFailed

powershell -NoProfile -NoLogo -Command "& \"%~dp0build.ps1\" %*; exit $LastExitCode;"
powershell -NoProfile -NoLogo -ExecutionPolicy RemoteSigned -Command "& \"%~dp0build.ps1\" %*; exit $LastExitCode;"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

-ExecutionPolicy Bypass is better, as it doesn't require the user to have explicitly set the execution policy to RemoteSigned first.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

My (possibly wrong) understanding is that this is slightly safer than because build.ps1 still couldn't pull a remote unsigned script.

I'm not understanding what user intervention is required with the way I have it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

build.ps1 does pull a remote script. See:

https://github.com/dotnet/sdk/blob/master/build.ps1#L39-L43

# Install a stage 0
$DOTNET_INSTALL_SCRIPT_URL="https://raw.githubusercontent.com/dotnet/cli/feature/msbuild/scripts/obtain/dotnet-install.ps1"
Invoke-WebRequest $DOTNET_INSTALL_SCRIPT_URL -OutFile "$env:DOTNET_INSTALL_DIR\dotnet-install.ps1"

& "$env:DOTNET_INSTALL_DIR\dotnet-install.ps1" -Version $DotnetCLIVersion -Verbose

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The user has to call Set-ExecutionPolicy RemoteSigned before they can run Build.cmd (most, but not all developers, seem to do this if they work with Powershell frequently).

@nguerrera nguerrera Aug 16, 2016 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The user has to call Set-ExecutionPolicy RemoteSigned

I don't think so. That's exactly what I'm trying to fix. I have not set anything on my machine. This is setting the policy to remotesigned for the execution of the script without affecting the global registry setting.

>powershell .\build.ps1
.\build.ps1 : File D:\Src\sdk\build.ps1 cannot be loaded because running scripts is disabled on this system. For more
information, see about_Execution_Policies at http://go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ .\build.ps1
+ ~~~~~~~~~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess
>powershell -ExecutionPolicy RemoteSigned .\build.ps1
VERBOSE: dotnet-install: Get-Azure-Channel-From-Channel -Channel "rel-1.0.0"
VERBOSE: dotnet-install: Get-CLIArchitecture-From-Architecture -Architecture "<auto>"
VERBOSE: dotnet-install: Get-Machine-Architecture
<snip>

build.ps1 does pull a remote script. See:

Lol. AFAICT, it does so by copying it to a local file and then executing it as a local script, so RemoteSigned doesn't impede it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If that's the case, then I am fine with RemoteSigned. @jaredpar might have some better knowledge, I know he recently changed one of our scripts to use Bypass due to a customer issue filed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hmm, I see dotnet/roslyn#13121. I guess I'll go ahead and use bypass because (1) like @jaredpar I've already spent too much time on this 😁 and (2) this particular script actually does download ps1 from the internet so any lesser privilege that happens to work is just cheating anyhow.

@eerhardt

Copy link
Copy Markdown
Member

What's going on with linux build?

It has never worked. @livarcocc is going to look into it.

@davkean

davkean commented Aug 16, 2016

Copy link
Copy Markdown
Member

Can we disable it until fixed?

@eerhardt

Copy link
Copy Markdown
Member

We had a similar PR in a separate repo: dotnet/core-setup#91, but it was rejected.

/cc @brthor

I'm not an expert in powershell. If this is common practice to run with this switch, I think it is fine.

@nguerrera

Copy link
Copy Markdown
Contributor Author

This is done quite a bit in other dotnet repos:

https://github.com/search?q=org%3Adotnet+RemoteSigned&type=Code

@tannergooding

Copy link
Copy Markdown
Member

@nguerrera

Copy link
Copy Markdown
Contributor Author

Bypass is done just as frequently (https://github.com/search?l=bat&q=org%3Adotnet+Bypass&ref=searchresults&type=Code&utf8=%E2%9C%93).

We should probably standardize on one or the other.

In general, I would favor a "least privilege" approach. Bypass just disables all checks, and I think it's best not to disable checks that you don't expect to trigger. Mind you, build.ps1 is getting script from the internet in a way that powershell can't spot so bypass might be more honest in this specific case. 😁 I do not think we should change RemoteSigned to Bypass everywhere.

@nguerrera

nguerrera commented Aug 16, 2016 •

Copy link
Copy Markdown
Contributor Author

Changed to bypass to be more honest about this specific script's required privileges.

@brthor

brthor commented Aug 17, 2016

Copy link
Copy Markdown
Contributor

I don't have a preference here. Anyone running the build has already opted into running the arbitrary code of the repo.

👍

@nguerrera
nguerrera merged commit f6f237a into dotnet:master Aug 17, 2016
@nguerrera
nguerrera deleted the posh-execution-policy branch August 17, 2016 00:19
@jaredpar

Copy link
Copy Markdown
Member

Bypass just disables all checks, and I think it's best not to disable checks that you don't expect to trigger.

Powershell's job is to run scripts. The fact that by default it's incapable of doing it's job by default is a rather confusing decision. I've spent all the time I care to figuring out what combination of switches will actually cause Powershell to run scripts. At the moment ByPass seems to be the way to go.

@jaredpar

Copy link
Copy Markdown
Member

For context when is the last time you had to make a change to enable a batch script to run? Or bash? The answer is never. Powershell though, hit this problem all the time. Insanely frustrating.

@nguerrera

nguerrera commented Aug 17, 2016 •

Copy link
Copy Markdown
Contributor Author

I'm persuaded by the fact that RemoteSigned mysteriously didn't work on a customer's box. This PR ended up using Bypass before being merged and I'm indifferent now if we want to go ahead and use bypass throughout. Never having seen RemoteSigned not do the trick myself, it seemed prudent to use the least privilege that scratched my itch, and it hadn't failed me before.

I agree that this probably shouldn't even be something that PowerShell tries to solve. I'm just always cautious when I'm disabling any check that someone, somewhere thought was worthwhile.

nguerrera added a commit that referenced this pull request Oct 10, 2016
Don't require global Powershell execution policy change
mmitche pushed a commit to mmitche/sdk that referenced this pull request Jun 5, 2020
Removing the call to dotnet restore3 from prepublish target
springmin added a commit to springmin/sdk-ohos that referenced this pull request Oct 11, 2026
Advance WORKLOAD_BUNDLE_SHA256 from 031ba342 (kit dotnet#53) to 09326398, the kit dotnet#54 repack of
openharmony-workload-1.0.0-preview.28: the Sdk pack carries the FINAL-BATCH shell (ui abc
623,784/58c5829b with the MEDIAELEMENT wave - ArkWeb media element service + child-window
media + vendored hls.js 1.7.3/MSE + the popup gesture opt-out and /__src__ single-range
Range/206 - the modal overlay visibility fix (OpenHarmonyOverlaySuspension) and the managed
subwindow default 2->4; headless 24,324/798b2477 unchanged), the media rawfile assets
(templates/resources/rawfile/media.html + hls.min.js + hls.LICENSE.txt), pages/Index.ets and
pages/SubWindow.ets at the merged sources, and the host at the same fingerprint
(367,520/ad7ab986, exports 164/164). The kit haps were rebuilt with the FINAL-BATCH MAUI
slice (36da77cba492) and the Ref/Runtime managed packs were rebuilt from the same sources
(PE metadata-only diffs). Installer tests: 43/43 + 10/10 + 5/5; fetch-nativeaot --local
content check OK.
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.

6 participants