DEV Community

Cover image for Firebase & PowerShell Execution Policy
whybe
whybe

Posted on

Firebase & PowerShell Execution Policy

when you install the Firebase via npm:

npm i -g firebase firebase-tools
Enter fullscreen mode Exit fullscreen mode

and try to run:

firebase login
Enter fullscreen mode Exit fullscreen mode

it throws an error into your terminal that says that the execution policy of Powershell is preventing you from running this script or any unsigned script certificate, which is quite fair making your system secure from malicious scripts. Still, why is Firebase not a signed and white-listed script 🤷‍♂️?

will I get you covered, instead of dropping the security layer of your ExecutionPolicy in Powershell by this command ⛔?

Set-ExecutionPolicy -ExecutionPolicy Unrestricted
Enter fullscreen mode Exit fullscreen mode

which will make your machine vulnerable to malicious scripts,
we will create a signed certificate for the firebase.psl script and we will install it.

Create A Signed Certificate

first, make sure your terminal is in elevated privileges (Run as Administrator)

Then let's make our certificate for our firebase script using this command:

New-SelfSignedCertificate -CertStoreLocation Cert:\CurrentUser\My -Subject "CN=Firebase" -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.3") -FriendlyName "Firebase Script"
Enter fullscreen mode Exit fullscreen mode

screenshot of runnig the Script in the terminal

this will generate our certificate in the directory C:\Users\{username}\AppData\Roaming\Microsoft\SystemCertificates\My\Certificates script using New-SelfSignedCertificate, you will see the Thumbprint which is the also the name of the certificate file in the listed directory, you can always verified using this command:

Get-ChildItem -Path Cert:\CurrentUser\My -CodeSigningCert
Enter fullscreen mode Exit fullscreen mode

will now the certificate is been initialized now we need to install it.

Install Certificate

follow these steps to install the certificate:

click: win+R and write control, or open the control panel

Window Screenshot

the search for certificates in the control panel:

Window Screenshot

the Click Manage User Certificates Link and you will see a window like this:

Window Screenshot

then click on Trusted Root Certification Authorities and then click on certificates:

Window Screenshot

what you have to do is click on actions => all tasks => import, and you will see this window:

Window Screenshot

Window Screenshot

then click next and the brows

Window Screenshot

and head to this path: C:\Users\{username}\AppData\Roaming\Microsoft\SystemCertificates\My\Certificates, replace the {username} with your account username folder. then click All files

Window Screenshot

what is left is to choose the created certificate earlier,
verified the name of the file using this command:

Get-ChildItem -Path Cert:\CurrentUser\My -CodeSigningCert
Enter fullscreen mode Exit fullscreen mode

you will see the Thumbprint which is also the name of the certificate file in the listed directory, click it and click next then you will see this screen just click next:

Window Screenshot

then click finish and the created certificate will be installed and ready to use:

Window Screenshot

then what's left is to sign the firebase.psl certificate with the installed certificate using this command:

first, we store the certificate in a variable called $cert

$cert = Get-ChildItem -Path Cert:\CurrentUser\My -CodeSigningCert
Enter fullscreen mode Exit fullscreen mode

then we proceed in the process:

Set-AuthenticodeSignature -Certificate:$cert -FilePath:"C:\Users\{user}\AppData\Roaming\npm\firebase.ps1"
Enter fullscreen mode Exit fullscreen mode

replace the {user} with your account username and the firebase.psl is now white-listed and ready to use without any errors

firebase login
Enter fullscreen mode Exit fullscreen mode

Top comments (0)