|
| 1 | +# Connecting to SRDE |
| 2 | + |
| 3 | +Remote access to the secure environment workspace via the Command Line Interface. The SRDE consists of two separate servers: |
| 4 | +- The Workspace Host is where you access and analyze data |
| 5 | +- The Bastion Host acts as a proxy that allows your laptop/workstation to connect securely via the internet to the Workspace Host. |
| 6 | + |
| 7 | +Accessing the Secure environment Workspace Host remotely via the Command Line Interface (CLI) is a two-step process: First you must connect to the Bastion Host and then from the Bastion Host access your Workspace Host. The two-step process is demonstrated below: |
| 8 | + |
| 9 | + |
| 10 | +This two-step process is enabled with the use of SSH keys and SSH Agent Forwarding and is described in detail for some of the common Operating Systems (MacOS/Linux and Windows) in the following sections of the User Guide. For more general information about using SSH keys and the use of Bastion Host [see here](https://medium.com/devops-dudes/setting-up-an-ssh-agent-to-access-the-bastion-in-vpc-532918577949). |
| 11 | + |
| 12 | +User access to the secure environment is controlled by [Identity-Aware Proxy (IAP)](https://cloud.google.com/security/products/iap?hl=en) Google Cloud service. IAP provides a central way of managing user access and enforcing access control policies, without requiring external/public IP addresses on the Bastion Host and the Workspace Host. |
| 13 | + |
| 14 | +::::tip[Prerequisites] |
| 15 | +In order to be able to access your Secure Environment Workspace Host, you will need the following information, provided by the Secure Research Data Admins: |
| 16 | +- **Project Id** for the Bastion Host (ex. test-dev1-bastion-1234) |
| 17 | +- **Zone Name** (ex. us-east4-a) |
| 18 | + |
| 19 | +:::note |
| 20 | +At this time you are not required to be on the NYU Network (or VPN into the NYU Network) in order to access the Secure Environment workspace. |
| 21 | + |
| 22 | +::: |
| 23 | + |
| 24 | +:::: |
| 25 | + |
| 26 | + |
| 27 | +## Connecting through Google Cloud Console |
| 28 | +Navigate to Google Cloud Console https://console.cloud.google.com/welcome and login with your NetID. Click the Select a project drop-down list at the top left corner of the page. In the Select a project window that appears, search and select the bastion project using the provided project ID (ex. test-dev1-bastion-1234). |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | +Once selected, navigate to the VM Instances page via the Navigation menu (Menu in the top left corner of the page ) > Compute Engine > VM Instances. A running Bastion instance will be visible in the page as shown below: |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | +ssh to the Bastion instance by clicking on the SSH button, a new SSH-in-browser tab will appear with a restricted CLI ( Command line interface ) connected to the instance. We are now inside the Bastion Host. |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | +Now we can ssh to our workspace host by using the workspace internal IP address `10.0.0.2`: |
| 41 | +```sh |
| 42 | +ssh 10.0.0.2 |
| 43 | +``` |
| 44 | +This will open the workspace CLI, with access to the workspace host having the computing needs to work on our data. |
| 45 | + |
| 46 | +## Connecting through Google Cloud Shell |
| 47 | + |
| 48 | +Navigate to https://shell.cloud.google.com/ while logged in using your NetID. |
| 49 | + |
| 50 | +### Setting project and zone |
| 51 | + |
| 52 | +Note - Ask your SRDE administrator for the appropriate GCP PROJECT_ID and ZONE_NAME. Replace the values in the two commands below and run them |
| 53 | + |
| 54 | + |
| 55 | +```sh |
| 56 | +gcloud config set project PROJECT_ID |
| 57 | +gcloud config set compute/zone ZONE_NAME |
| 58 | +``` |
| 59 | + |
| 60 | +### Confirm settings |
| 61 | + |
| 62 | +Before proceeding, confirm that the project and zone match your GCP project ID and zone: |
| 63 | + |
| 64 | + |
| 65 | +```sh |
| 66 | +gcloud config list |
| 67 | + |
| 68 | + |
| 69 | +[compute] |
| 70 | +region = us-east4 |
| 71 | +zone = us-east4-a |
| 72 | +[core] |
| 73 | + |
| 74 | +disable_usage_reporting = False |
| 75 | +project = test-dev1-bastion-1234 |
| 76 | + |
| 77 | + |
| 78 | +Your active configuration is: [default] |
| 79 | +``` |
| 80 | + |
| 81 | + |
| 82 | +### Generate SSH keys |
| 83 | + |
| 84 | +:::tip[Unused keys expire!] |
| 85 | +Google Cloud Shell will delete your files, including generated SSH keys, if they are not accessed for 120 days. If this happens you will need to generate them again. |
| 86 | + |
| 87 | +::: |
| 88 | + |
| 89 | +The simplest way to generate SSH keys is to delegate the key generation to gcloud. In order to trigger key creation, run the following command. |
| 90 | + |
| 91 | +:::note |
| 92 | +Ignore the result of this command. It will most likely print errors to the output console. |
| 93 | + |
| 94 | +::: |
| 95 | + |
| 96 | +```sh |
| 97 | +gcloud compute ssh bastion-vm |
| 98 | +``` |
| 99 | + |
| 100 | +You will be prompted to enter an SSH passphrase. This is optional, however it is recommended for additional user security. |
| 101 | + |
| 102 | + |
| 103 | +The above command should log you into the bastion VM. You will see a prompt like: |
| 104 | +```sh |
| 105 | +-bash-4.4$” |
| 106 | +``` |
| 107 | +Before proceeding, exit back to your local machine |
| 108 | + |
| 109 | +```sh |
| 110 | +exit |
| 111 | +``` |
| 112 | + |
| 113 | +Then make sure the above step created two keys in your ssh home directory (`~/.ssh`) as shown below: |
| 114 | + |
| 115 | +```sh |
| 116 | +ls ~/.ssh |
| 117 | +``` |
| 118 | + |
| 119 | + |
| 120 | + |
| 121 | +Start the ssh-agent on your local machine |
| 122 | + |
| 123 | +```sh |
| 124 | +eval `ssh-agent -s` |
| 125 | +``` |
| 126 | +Add the google_compute_engine key to your ssh session |
| 127 | + |
| 128 | +```sh |
| 129 | +ssh-add ~/.ssh/google_compute_engine |
| 130 | +``` |
| 131 | +Connect to the instance with gcloud using the –ssh-flag-”-A” flag |
| 132 | +:::note |
| 133 | +This command uses the default project and zone set above. |
| 134 | + |
| 135 | +::: |
| 136 | + |
| 137 | +```sh |
| 138 | +gcloud compute ssh bastion-vm --ssh-flag="-A" --tunnel-through-iap |
| 139 | +``` |
| 140 | + |
| 141 | +### Add SSH key to session |
| 142 | +Run the following command to add the google_compute_engine key to the current session:ssh |
| 143 | +```sh |
| 144 | +ssh-add -L |
| 145 | +``` |
| 146 | +Connect to the workstation-vm |
| 147 | + |
| 148 | +```sh |
| 149 | +ssh 10.0.0.2 |
| 150 | +``` |
| 151 | + |
| 152 | +### Future logins |
| 153 | +After the initial login, you will not need to regenerate the SSH keys, but you will need the rest of the command sequence from “Start the SSH agent”. On your local machine: |
| 154 | +```sh |
| 155 | +eval `ssh-agent -s` |
| 156 | +ssh-add ~/.ssh/google_compute_engine |
| 157 | +gcloud compute ssh bastion-vm --ssh-flag="-A" --tunnel-through-iap --project=PROJECT_ID |
| 158 | +``` |
| 159 | + |
| 160 | +And then on the bastion VM: |
| 161 | + |
| 162 | +```sh |
| 163 | +ssh 10.0.0.2 |
| 164 | +``` |
| 165 | + |
| 166 | + |
| 167 | +## Connecting on MacOS/Linux |
| 168 | + |
| 169 | +### Install gcloud CLI |
| 170 | +Follow the [official guidelines](https://cloud.google.com/sdk/docs/install-sdk#installing_the_latest_version) to install the latest version of gcloud CLI locally on your computer. |
| 171 | + |
| 172 | +:::note |
| 173 | +After completing the gcloud installation, verify that the `gcloud` binary is in your $PATH environment variable. |
| 174 | + |
| 175 | +::: |
| 176 | + |
| 177 | +### Configure local gcloud settings |
| 178 | +Run the following command. It generates a link as shown below |
| 179 | + |
| 180 | +```sh |
| 181 | +gcloud auth login --no-launch-browser |
| 182 | +``` |
| 183 | + |
| 184 | + |
| 185 | + |
| 186 | +Copy the link and open your chrome browser in incognito mode to perform user sign in.Username is your NYU NetID email address. For e.g. [email protected] |
| 187 | + |
| 188 | + |
| 189 | +You will be redirected to the NYU SSO page and MFA verification through Duo Push. After successfully logging in, you will be asked to allow google SDK to access your account as shown below |
| 190 | + |
| 191 | + |
| 192 | + |
| 193 | +Pressing the “Allow” button on this page will present the authorization code. Copy the code and paste it in the terminal. If this step is successful, you should see this text printed to the console. **You are now logged in as [[email protected]]. ** |
| 194 | + |
| 195 | +### Connect to the workspace |
| 196 | +Follow the same instructions for connecting with Google Cloud Shell above, starting from section on setting project and zone above. |
| 197 | + |
| 198 | +## Connecting on Windows 10/11 |
| 199 | + |
| 200 | +### Start and Configure SSH-Agent Service |
| 201 | +Using an elevated PowerShell window (run as admin), execute the following command to install the SSH-Agent service and configure it to start automatically when you log into your machine: |
| 202 | +```ps |
| 203 | +Get-Service ssh-agent | Set-Service -StartupType Automatic -PassThru | Start-Service |
| 204 | +
|
| 205 | +``` |
| 206 | + |
| 207 | + |
| 208 | +### Install gcloud CLI |
| 209 | +Download the [Google Cloud CLI installer] (https://dl.google.com/dl/cloudsdk/channels/rapid/GoogleCloudSDKInstaller.exe) and run the installer |
| 210 | + |
| 211 | + |
| 212 | + |
| 213 | +Alternatively, run the following command to download and install: |
| 214 | +```ps |
| 215 | +(New-Object Net.WebClient).DownloadFile("https://dl.google.com/dl/cloudsdk/channels/rapid/GoogleCloudSDKInstaller.exe", "$env:Temp\GoogleCloudSDKInstaller.exe") |
| 216 | +
|
| 217 | +& $env:Temp\GoogleCloudSDKInstaller.exe |
| 218 | +
|
| 219 | +``` |
| 220 | + |
| 221 | +### Install Git |
| 222 | +Download the Git Bash setup from the official website: https://git-scm.com/ and run the installer |
| 223 | + |
| 224 | + |
| 225 | +### Install Putty |
| 226 | +Download and install Putty from this link https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html |
| 227 | + |
| 228 | +Post installation verify that the Putty authentication agent is installed and available |
| 229 | + |
| 230 | +For 64-bit installer, you will find this executable at `C:/Program Files/PuTTY/pageant.exe` |
| 231 | + |
| 232 | + |
| 233 | +### Install Python (>version 3.0) |
| 234 | +Install Python from the official website:https://www.python.org/downloads/ |
| 235 | + |
| 236 | +Remember to check “Add python to the environment path.” ***add screenshot |
| 237 | + |
| 238 | +Make sure it's installed and available on PATH. On many systems Python comes pre-installed, you can try running the python command to start the Python interpreter to check and see if it is already installed. |
| 239 | + |
| 240 | + |
| 241 | + |
| 242 | +On windows you can also try the py command which is a launcher which is more likely to work. If it is installed you will see a response which will include the version number, for example: |
| 243 | + |
| 244 | + |
| 245 | + |
| 246 | + |
| 247 | +### Logging in: |
| 248 | +Authenticate gcloud by starting a new session of command line or powershell. initialize and login to gcloud with your account (you will be redirected to the browser for authentication) |
| 249 | +```ps |
| 250 | +gcloud auth login |
| 251 | +``` |
| 252 | + |
| 253 | + |
| 254 | + |
| 255 | + |
| 256 | + |
| 257 | +Run Git Bash and start the ssh-agent on your local machine |
| 258 | + |
| 259 | +```ps |
| 260 | +eval `ssh-agent -s` |
| 261 | +``` |
| 262 | + |
| 263 | + |
| 264 | +Add the SSH key to agent by running |
| 265 | + |
| 266 | +```ps |
| 267 | +pageant.exe |
| 268 | +``` |
| 269 | + |
| 270 | + |
| 271 | +The app runs in the background. you can find it in the tray. |
| 272 | + |
| 273 | + |
| 274 | +Right click the icon and select "Add Key". Add the google_compute_engine key with the PPK extension (~/.ssh/google_compute_engine) to your agent: |
| 275 | + |
| 276 | + |
| 277 | + |
| 278 | +:::Skip this step in the future |
| 279 | +Go to the Pageant shortcut icon from the Windows Start Menu or your desktop. |
| 280 | + |
| 281 | +Right click on the icon, and click on Properties. (If Properties is not an option on the menu, click on Open file location, then right click on the Pageant icon, and click on Properties) |
| 282 | + |
| 283 | +::: |
| 284 | + |
| 285 | + |
| 286 | + |
| 287 | +From the Shortcut tab, edit the Target field. Leave the path to pageant.exe intact. After that path, add the path to your Google .ppk key file. |
| 288 | + |
| 289 | +:::warning[Critical] |
| 290 | +The key path should be outside the quotation marks. i |
| 291 | + |
| 292 | +::: |
| 293 | + |
| 294 | +Here’s an example: |
| 295 | +```ps |
| 296 | +"C:\Program Files\PuTTY\pageant.exe" C:\Users\Sam\.ssh\google_compute_engine.ppk |
| 297 | +``` |
| 298 | + |
| 299 | + |
| 300 | + |
| 301 | +### SSH into the bastion VM from Git Bash |
| 302 | +:::tip |
| 303 | +Ask your SRDE administrator for the appropriate GCP project ID. |
| 304 | + |
| 305 | +::: |
| 306 | + |
| 307 | +Replace gcp-project-id with that information in the below command: |
| 308 | +```ps |
| 309 | +export PROJECT_ID=gcp-project-id; |
| 310 | +
|
| 311 | +gcloud compute ssh bastion-vm --ssh-flag="-A" --zone=us-east4-a --tunnel-through-iap --project=${PROJECT_ID} |
| 312 | +
|
| 313 | +``` |
| 314 | + |
| 315 | + |
| 316 | +When SSHing to bastion in the git bash window, a new terminal in putty appears with the bastion connection |
| 317 | + |
| 318 | + |
| 319 | +A PuTTY security alert window may pop up to accept the host key, click on Accept |
| 320 | + |
| 321 | + |
| 322 | +### Add SSH key to session |
| 323 | + |
| 324 | +Run ssh-add to add the google_compute_engine key to the current session |
| 325 | +```ps |
| 326 | +ssh-add -L |
| 327 | +``` |
| 328 | + |
| 329 | +Connect to the workstation-vm |
| 330 | + |
| 331 | +```ps |
| 332 | +ssh 10.0.0.2 |
| 333 | +``` |
| 334 | + |
| 335 | + |
0 commit comments