Skip to content

About

Idira/CyberArk PSMP & SIA Connections using SSH from PowerShell

Topics

Resources

Code of conduct

Contributing

Stars

10 stars

Watchers

1 watching

Forks

Repository files navigation

PSMPSession

PSMPSession

Format an ssh connection command and connect to a target server, using a target account via CyberArk PSMP or SIA.

Main Branch Dev Branch CodeFactor Coverage PowerShell Gallery License
build dev codefactor codecov psgallery license
downloads

Usage

New-PSMPSession

Local Account Targets

Local

Domain Account Targets

Domain

Vault Usernames in UPN Format

VaultUPN

Target Usernames in UPN Format

TargetUPN

Vault Username and Target Username in UPN Format

UPN

Target Port & Tunnel Port

New-PSMPSession -VaultUser pspete -TargetAccount root -TargetAddress server -TargetPort 2222 -PSMPAddress psmp
# pspete@root@server#2222@psmp

New-PSMPSession -VaultUser pspete -TargetAccount root -TargetAddress server -TargetPort 22 -TunnelPort 5432 -PSMPAddress psmp -SSHArgument '-L', '5432:127.0.0.1:5432'
# ssh -L 5432:127.0.0.1:5432 pspete@root@server#22#5432@psmp

Additional ssh Arguments & Remote Command

New-PSMPSession -VaultUser pspete -TargetAccount root -TargetAddress server -PSMPAddress psmp -SSHArgument '-t' -Command 'uptime'
# ssh -t pspete@root@server@psmp uptime

New-PSMPSession -VaultUser pspete -TargetAccount root -TargetAddress server -PSMPAddress psmp -SSHArgument '-i', 'C:\keys\psmp_key'
# ssh -i C:\keys\psmp_key pspete@root@server@psmp

Specify each ssh switch and its value as separate array elements ('-i', 'C:\keys\psmp_key', not '-i C:\keys\psmp_key'). An SSH key supplied with -i authenticates you to PSMP / the SIA gateway (e.g. an MFA caching key), not to the target.

Pipeline Input

Import-Csv .\targets.csv | New-PSMPSession -VaultUser pspete -PSMPAddress psmp

Use -WhatIf or -Debug with either function to view the connection string without connecting.

New-SIASession

Connect through CyberArk Secure Infrastructure Access (SIA). Supplying -TargetAccount uses vaulted access; omitting it uses zero standing privileges (ZSP).

Zero Standing Privileges

New-SIASession -User pete@pspete.dev -Subdomain acme -TargetAddress 10.0.0.5
# pete@pspete.dev#acme@10.0.0.5@acme.ssh.cyberark.cloud

New-SIASession -User pete@pspete.dev -Subdomain acme -TargetAddress 10.0.0.5 -TargetPort 2222 -NetworkName Net1
# pete@pspete.dev#acme@10.0.0.5:2222#Net1@acme.ssh.cyberark.cloud

Vaulted Access

New-SIASession -User pete@pspete.dev -Subdomain acme -TargetAccount root -TargetAddress server.pspete.dev
# pete@pspete.dev#acme@root@server.pspete.dev@acme.ssh.cyberark.cloud

New-SIASession -User pete@pspete.dev -Subdomain acme -TargetAccount admin -TargetDomain pspete.dev -TargetAddress server.pspete.dev
# pete@pspete.dev#acme@admin#pspete.dev@server.pspete.dev@acme.ssh.cyberark.cloud

Gateway, ssh Arguments & Inline Commands

New-SIASession -User pete@pspete.dev -Subdomain acme -TargetAddress 10.0.0.5 -Gateway ssh.vanity.example.com
# pete@pspete.dev#acme@10.0.0.5@ssh.vanity.example.com

New-SIASession -User pete@pspete.dev -Subdomain acme -TargetAddress 10.0.0.5 -SSHArgument '-L', '8080:10.0.0.5:80' -Command 'touch tmp.txt; cat tmp.txt'
# ssh -L 8080:10.0.0.5:80 pete@pspete.dev#acme@10.0.0.5@acme.ssh.cyberark.cloud 'touch tmp.txt; cat tmp.txt'

New-SIASession -User pete@pspete.dev -Subdomain acme -TargetAddress 10.0.0.5 -SSHArgument '-i', 'C:\keys\sia_key'
# ssh -i C:\keys\sia_key pete@pspete.dev#acme@10.0.0.5@acme.ssh.cyberark.cloud

Save-SIASSHKey

Download an SIA MFA caching SSH key, then use it with New-SIASession to connect without repeating MFA until the key expires.

$Key = Save-SIASSHKey -User pete@pspete.dev -Subdomain acme -Path ~\.ssh\acme_pete
# sftp pete@pspete.dev#acme@key@acme.ssh.cyberark.cloud:/key C:\Users\pete\.ssh\acme_pete

New-SIASession -User pete@pspete.dev -Subdomain acme -TargetAddress 10.0.0.5 -SSHArgument '-i', $Key.FullName

Save-SIASSHKey -User pete@pspete.dev -Subdomain acme -Path ~\.ssh\acme_pete.ppk -Format PPK
# sftp pete@pspete.dev#acme@key_ppk@acme.ssh.cyberark.cloud:/key C:\Users\pete\.ssh\acme_pete.ppk

Access to the saved key is restricted to the current user. SIA only accepts the key from the IP address it was downloaded from.

Installation

Prerequisites

  • PowerShell Core or Powershell v5.1 (minimum).
  • SSH Client (and SFTP client for Save-SIASSHKey) installed and configured on your PATH
  • Target account to connect to a target server through CyberArk PSMP.

Install Options

Use one of the following methods:

Option 1: Install from PowerShell Gallery

PowerShell 5.0 or above must be used

This is the simplest & preferred method for installation of the module.

To install the module from the PowerShell Gallery,
from a PowerShell prompt, run:

Install-Module -Name PSMPSession -Scope CurrentUser

Option 2: Manual Install

You can manually copy the module files to one of your powershell module folders.

Find your PowerShell Module Paths with the following command:

$env:PSModulePath.split(';')

The module files should be placed in a folder named PSMPSession in one of the listed locations.

More: about_PSModulePath

There are multiple options for downloading the module files:

PowerShell Gallery
  • Download from the module PowerShell Gallery:
    • Run the PowerShell command Save-Module -Name PSMPSession -Path C:\temp
    • Copy the C:\temp\PSMPSession folder to your "Powershell Modules" directory of choice.
PSMPSession Release
  • Download the latest release
    • Unblock & Extract the archive
    • Rename the extracted PSMPSession-v#.#.# folder to PSMPSession
    • Copy the PSMPSession folder to your "Powershell Modules" directory of choice.
PSMPSession Branch
  • Download the main branch
    • Unblock & Extract the archive
    • Copy the PSMPSession (\<Archive Root>\PSMPSession-main\PSMPSession) folder to your "Powershell Modules" directory of choice.

About

Idira/CyberArk PSMP & SIA Connections using SSH from PowerShell

Topics

Resources

Code of conduct

Contributing

Stars

10 stars

Watchers

1 watching

Forks

Releases

Sponsor this project

Contributors

Languages