Chocolatey and Powershell

공부의 기록·2022년 1월 25일
0

Dev Computer Science

목록 보기
16/18
post-thumbnail

Introduce

이 문서는 2022년 1월 25일 에 작성되었습니다.

HTTP 프로토콜 를 문서를 작성 함에 앞서 curl 설치 가 필요했습니다.
이때, 패지키 매니저 Chocolatey 를 설치하라고 안내를 받았습니다.
노드 패키지 매니저인 npm 사이트에서도 curl 이 있었지만, 버전이 매우 다르고 동일한 curl 인지 확신할 수 없었습니다.

따라서 다음의 과정을 통해서 Chocolatey 를 설치하고
그 과정에서 짚고 넘어갈 간단한 것들을 작성해보았습니다.

✅ PowerShell -> Chocolatey

https://chocolatey.org/install
위 링크로 Chocolatey 사이트에 들어가보면 Chocolaty 설치 방법이 나와있습니다.
주의할 점은 cmd, 명령 프롬포트 창으로는 아래의 명령어를 실행할 수 없다는 점입니다.

따라서 컴퓨터에 설치된 Microsoft Store 에서 PowerShell 을 다운로드 받아야 합니다.
다운로드를 받고 나면 꼭 관리자 모드로 실행 하여야 합니다.

✅ Before...

사실 관리자 권한으로 실행한 PowerShell 의 보안 정책을 무지성으로 바꿔도 되는가? 에 대한 고민이 있어서, 조금 더 검색하여 다음의 내용을 완성했습니다.
참고한 자료는 about_Exceution_policiesMachinePolicy 또는 UserPolicy Exchange Server 2013~~~ 의 두 포스트를 참고하였습니다.
Ref 의 1,3을 참고해주세요.

✅ 실행 정책 확인

PowerShell 을 관리자모드로 실행한 다음, 실행 정책을 확인해 볼 것입니다.

// 실행 정책 확인
Get-ExecutionPolicy.

PowerShell 의 기본값은 Restricted 이며,
이는 외부 스크립트 실행을 종류를 불문하고 전면적으로 차단한다는 의미입니다.

따라서, 이러한 제한을 AllSigned 나 ByPass 로 변경해줘야 합니다.
Chocolatey Install 에도 Set-ExecutionPolicy ~~~ 등이 있습니다.
민감한 설정값이므로 정확한 문서를 찾아보니 about_Excecution_Policies 라는 2021년 9월 28일의 Micorosft Post 를 찾았습니다.

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.2

AllSigned, 서명이 된 스크립트만 실행
Scripts can run.
Requires that all scripts and configuration files be signed by a trusted publisher, including scripts that you write on the local computer.
Prompts you before running scripts from publishers that you haven't yet classified as trusted or untrusted.
Risks running signed, but malicious, scripts.

ByPass, 모든 스크립트를 실행 (자체적인 보안 모델이 있는 서비스를 위해)
Nothing is blocked and there are no warnings or prompts.
This execution policy is designed for configurations in which a PowerShell script is built in to a larger application or for configurations in which PowerShell is the foundation for a program that has its own security model.

✅ 실행 정책 설정

따라서 우리는 다음의 스크립트로 실행 정책을 바꿀 수 있습니다.
꼭 다음 문장도 읽어주세요!!!

// 설치 전
Set-ExecutionPolicy ByPass

// 설치 후
Set-ExecutionPolicy Restricted

// 설정 확인
Get-ExecutionPolicy

하지만, Chocolatey 의 스크립트 구문에 있는 -Scope process 를 추가하면 해당 PowerShell 을 종료하기 전까지만 설치 정책을 ByPass 등 으로 유지 하게 할 수 있습니다.

다음의 스크립트로 깔끔하게 설치 정책을 변경하고
Chocolaety 사이트의 install 명령어를 사용하여 해당 프로그램을 설치합시다.

// 설치 전
Set-ExecutionPolicy ByPass -Scope process

✅ 실행 정책 설정 후

바로 직전에서 언급한 스크립트로 설치 정책을 변경하였다고 하더라도
꼭 다시 한번 Get-ExcetutionPolicy 로 설치 정책을 확인해줍시다.

🤔 발생 가능한 에러

물론 설정 시에 다음과 같은 에러가 발생할 수도 있습니다.

이러한 에러가 뜨면 꼭 PowerShell 을 관리자 권한으로 실행하자.
자세한 내용은 아래 Ref 의 MachinePolicy 또는 UserPolicy Exchange Server 2013 ~~~ 의 포스트를 참고하자.

⚡ 만약 당신이 수동으로 PowerShell 을 깔았다면, ...

Get-ExecutionPolicy -List

위 커멘드로 설정값들을 확인해보자.
undefined 로 되어있을 확률이 높은데, 아래의 Ref 의 내용을 참고해보면 Restricted 로 설정하는 것이 더욱 안전함을 알 수 있다.

따라서, LocalMachine, CurrentUser 정도는 다음의 커멘드를 이용해서 Restricted 로 설정하자.

Set-ExecutionPolicy Restricted -Scope LocalMachine
Set-ExecutionPolicy Restricted -Scope CurrentUser

🤔 Unrestricted 로 설정한 당신?

구글링을 하다보니 다음과 같은 포스트를 발견했다. (????)

Set-ExecutionPolicy Unrestricted

위 명령어를 치면 이제 스크립트와 설정파일을 묻지도 따지지도 않고 쓸 수 있습니다.

앞서 언급한 about_Execution_Policies 에 따르면,

Unrestricted
There is no execution policy set in the current scope

오우쉣, ...

Ref

about_Execution_Policies in Microsoft Post(2021.09.28)

PowerShell 파워셸 실행정책(2019.12.10)

MachinePolicy 또는 UserPolicy Exchange Server 2013에 정의 되 면 누적 업데이트 또는 서비스 팩을 설치할 수 없습니다.

profile
2022년 12월 9일 부터 노션 페이지에서 작성을 이어가고 있습니다.

0개의 댓글