Wednesday, June 28, 2017

PuTTY a telnet/SSH client for Windows (a.k.a how to access that Linux VM we just created from Windows)

Any OS/X, Linux or Unix system contains SSH which allows access to a remote system. Windows on the other hand does not support this natively which is where PuTTY comes in, a telnet/SSH client that runes on Windows. The download for PutTTY can be found at http://www.putty.org/.


From PuTTY's home page (above) it should be clear where to click to download "You can download PuTTY her." Navigating to the download page from the main page displays:


Those still using 32-bit Windows are getting rarer. Since I am using 64-bit Windows so I click on the putty-64bit-0.69-installer.msi link:


Save the MSI and then run it to install PuTTY:


Click "Run" to run the installer:


As in the case with any installer keep clicking the "Next" button:


Click "Next" unless you want to go rogue and change the default install location:


Pick the desired features and then click "Install:"


The status screen will churn away while PuTTY installs (hence Next is not enabled). Once install finishes the following is displayed:


On the final screen click "Finish."

Run PuTTY as you would any Windows application:


Under Port in the PuTTY screen the value is set to 22, the default for port for SSH. To access a machine such as our Ubuntu Virtual machine from Opening an inbound port for an Ubuntu Virtual Machine on Azure enter the machine IP address in the "Host Name (or IP address):"


Click on Open to access the machine specified which displays the following screen:


Enter the username and password for the remote host:


Click Enter and the user name and password will be used to authenticate SSH access to the host:


A Windows user now has access to a remote server.





Tuesday, June 27, 2017

Opening an inbound port for an Ubuntu Virtual Machine on Azure

In the post, "Creating an Ubuntu Server on Azure," an Ubuntu virtual machine (VM) was setup on Azure. The purpose of this machine was to expose a proxy server that will ultimately run on port 21777. The problem to be solved is that by default the only inbound port open on an Ubuntu virtual machine on Azure is port 22 -- SSH (Secure Shell). The proxy server to be configured will be listening on port 21777 which is not open.

To open the port sign to the Azure port and navigate to the blade used the manage the Ubuntu virtual machine:


The left hand tab contains a set of options including "Network interfaces" (see below):


Click on "Network interfaces" which displays a list IP address for the VM:


Clicking on the lone network interface listed in the table above navigates to a screen that is used to manage said network interface:


Along the tabs on the left is an entry named "Network security group:"


Clicking on "Network security group" displays the following blade:


From the list of one network security group, select the link associated wth the lone security group:


From the tabs along the left size under "SETTINGS" is an entry "Inbound security rules:"


Click on "Inbound security rules" which displays the following:


Along the top of the screen listing inbound security rules is an +Add button:


Click on the +Add button:


For name we entered TinyProxyAccess which is a hint, the proxy server we are going to setup is TinyProxy. Under "Port range" 21777 is entered as TinyProxy will be listening to a range of one ports, 21777. Once the desired information is set, click on "OK:"

The new inbound security role takes several seconds to create by one created it will be listed along with the rule associated with port 22:


The inbound port, 21777, to be used by TinyProxy, is not open.

Sunday, June 25, 2017

Creating an Ubuntu Server on Azure

I found myself in need of a proxy server for some development and Ubuntu was a logic choice. My MSDN subscription comes with a $150 Azure credit so this was the logical platform on which to create the virtual machine.

The first step in creating an Ubuntu Server on Azure is to login to the Azure portal (https://portal.azure.com). Upon login, the Dashboard for Azure is shown (see below):


Select the +New button at the top left of the management portal (see below):


There is a search box at the top of the categories displayed when +New is clicked,  In the search box type Ubuntu and click enter:


Clicking on enter to with ubuntu in the search box displays the following:


From the list of server options select the desired version by clicking on the name. For this project Ubuntu 17.04 was selected (note: the server cost will be selected later on in the process when the hardware is selected so don't worry about the cost just yet:


The previous screen allows a user to select between classic deployment and deployment using Resource Manager. This is basically say do you want to use the old way manage Azure resources (classic) or use the way everyone has moved to and Microsoft is advocating (Resource Manager). For this project, Resource Manager was selected. Once the desired value is selected click on Create:

\

The previous screen allows the core information for the virtual machine to be specified (machine name, administrator name, password or key-based authentication,  SSD or HDD drives, etc.). Below the information for this example is filled in:


Azure will warn of any mistakes, for example the user name must be in a lower case. I picked West US 2 because I'm in the Silicon Valley (which is western U.S.). Once the values are set click on OK which displays a choice of hardware and corresponding costs as follows:


The project this machine is being created for is to develop a client capable of going through a proxy. To run a proxy a A1 Standard ($37.94 a month) is fine which is well within my $150 Azure credit provided by MSDN. Notice to right of the above the screen the "View all" link. Microsoft has some monstrous machines. Once a machine is clicked on (selected) click on the Select button:


The previous screen allows storage, networking and various sundries to be set for the virtual machine. The defaults are acceptable so click on OK:



After clicking OK on the screen above, Azure will be the task of deploying the new virtual machine. In the previous screen the alert icon (the bell) contained a 2 indicating two alerts. After clicking on OK the alert icon contains a 3 indicating three alerts:


In order to see the alerts click on the alert icon (on the upper right side of the portal). Once clicked on the Alert icon will display notifications such as following:


Notice the first notification reads "Deployment in progress." This means the virtual machine is being deployed a process which can take several minutes.

Connecting to the Virtual Machine

Part of the deployment process performed by Azure is allocating an IP address for the virtual machine. One the virtual machine is deployed that the IP address can be determined by navigating to the management screen for the virtual machines. This is achieved by selecting "Virtual machines" from the Azure portal:



Selecting the "Virtual machines" link displays the "Virtual machines" blade (shown below):


To view the IP address and manage a virtual machine select the machine by name from the "Virtual machines" blade. The Ubuntu server created previously was named MugundaProxy so select the MugundaProxy link in the previous screen. Selecting a specif virtual machine display a screen such as the following:


The IP address for the MugundaProxy, Virtual Machine, is list in the right column of information of the previous screen. A closer look at the is section of the screen shows the IP address as follows:


The IP address above will be used with SSH in order to access the virtual machine.

Accessing the machine via SSH on Linux or OS/X

Any Linux or OS/X terminal can access SSH directly so logging into the virtual machine is a matter specifying the username and password created with the virtual machine.  The format of SSH is as follows:
SSH <username>@<ipaddress/hostname>

The following shows invoking SSH against our server (note the server was restarted so the IP differs from above)

When enter is hit a prompt is given for the password:

 After entering a correct password we can access our newly provisioned Ubuntu server:

Accessing the machine via Windows

Windows does not have a native SSH client. To access the virtual machine from Windows, download Putty (http://www.putty.org/). PuTTY is an open source SSH and telnet client. Installing and using Putty is the subject of a future blog. 

FYI by default only port 22 is open for Inbound Connections

Recall that this virtual machine is going to be used as a proxy server. This means that clients accessing the proxy will have to use a specific port. SSH uses port 22 and SSH was shown to allow access to the virtual machine. As it turns out, by default only port 22 is open for Inbound connections. Developers looking to open access to any other ports (like old favorites 20, 21, 25, 80, 443, etc.) will have to use the Azure portal (https://portal.azure.com) in order to configure additional inbound ports for the virtual machine. This is the subject of a future blog.

Tuesday, October 4, 2016

Azure: Web App Environment Variables

This posting will present a class that can be used to retrieve the environment variables associated with an Azure Web Application. A complete list of the pertinent environment variables for an Azure Web App can be found at Azure runtime environment | Environment | Website Environment Variables. An example of the environment variables associated with an Azure Web App are as follows

WEBSITE_SITE_NAME: SWPBlogAnotherWebApp01
WEBSITE_SKU: Shared
WEBSITE_COMPUTE_MODE: Shared
WEBSITE_INSTANCE_ID: Shared
WEBSITE_NODE_DEFAULT_VERSION: 4.4.7
WEBSOCKET_CONCURRENT_REQUEST_LIMIT: 35

The specific environment variable I was interested in was WEBSITE_SITE_NAME. The web site name was need in order to write a piece of code that read the web site's application log. For this particular web application the application log was written to a storage container of type blob (see below):


Navigating to the specific blob containing shows the following


Notice above that the blob container contains a folder with the same name as the Web App. The application log for the Web App, SWPBlogAnotherWebApp01, is contained in the folder of the same name. So in order to write code that read the logs for an Azure Web App, the underlying code needs to know the name of the Web App, e.g.:

string websiteName = 
           Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME");

A class the reads all the environment variables discussed is as follows:

using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;

using static System.Environment;

namespace SoftwarePronto.Azure.Utility.Master
{
    /*
     * https://github.com/projectkudu/kudu/wiki/Azure-runtime-environment
     * WEBSITE_SITE_NAME - The name of the site.
     * WEBSITE_SKU - The sku of the site 
     *   (Possible values: Free, Shared, Basic, Standard).
     * WEBSITE_COMPUTE_MODE - Specifies whether website is on a dedicated
     *   or shared VM/s (Possible values: Shared, Dedicated).
     * WEBSITE_HOSTNAME - The Azure Website's primary host name for the 
     *   site (For example: site.azurewebsites.net). Note that 
     *   custom hostnames are not accounted for here.
     * WEBSITE_INSTANCE_ID - The id representing the VM that the site 
     *   is running on (If site runs on multiple instances, 
     *   each instance will have a different id).
     * WEBSITE_NODE_DEFAULT_VERSION - The default node version this 
     *   website is using.
     * WEBSOCKET_CONCURRENT_REQUEST_LIMIT - The limit for websocket's 
     *   concurrent requests.
     */
    public static class WebAppEnviroment
    {
      public static string _envNameWEBSITE_SITE_NAME = 
        "WEBSITE_SITE_NAME";

      public static string _envNameWEBSITE_SKU = "WEBSITE_SKU";

      public static string _envNameWEBSITE_COMPUTE_MODE = 
        "WEBSITE_COMPUTE_MODE";

      public static string _envNameWEBSITE_INSTANCE_ID = 
        "WEBSITE_INSTANCE_ID";

      public static string _envNameWEBSITE_NODE_DEFAULT_VERSION = 
        "WEBSITE_NODE_DEFAULT_VERSION";

      public static string _envNameWEBSOCKET_CONCURRENT_REQUEST_LIMIT = 
        "WEBSOCKET_CONCURRENT_REQUEST_LIMIT";

      public static string WebSiteName =>
            GetEnvironmentVariable(_envNameWEBSITE_SITE_NAME);

      public static string WebSKU =>
            GetEnvironmentVariable(_envNameWEBSITE_SKU);

      public static string WebSitComputeMode =>
            GetEnvironmentVariable(_envNameWEBSITE_COMPUTE_MODE);

      public static string WebSiteInstanceId =>
            GetEnvironmentVariable(_envNameWEBSITE_INSTANCE_ID);

      public static string WebSiteNodeDefaultVersion =>
            GetEnvironmentVariable(_envNameWEBSITE_NODE_DEFAULT_VERSION);

      public static string WebSiteSocketConcurrentRequestLimit =>
            GetEnvironmentVariable(
              _envNameWEBSOCKET_CONCURRENT_REQUEST_LIMIT);

      public static Dictionary<string, string> Get() =>
        new Dictionary<string, string>
        {
          [_envNameWEBSITE_SITE_NAME] = WebSiteName,
          [_envNameWEBSITE_SKU] = WebSKU,
          [_envNameWEBSITE_COMPUTE_MODE] = WebSitComputeMode,
          [_envNameWEBSITE_INSTANCE_ID] = WebSitComputeMode,
          [_envNameWEBSITE_NODE_DEFAULT_VERSION] = 
                              WebSiteNodeDefaultVersion,
          [_envNameWEBSOCKET_CONCURRENT_REQUEST_LIMIT] = 
                   WebSiteSocketConcurrentRequestLimit
        };

      public static string GetAsText()
      {
        StringBuilder result = new StringBuilder();

        Get().ToList().ForEach(wsv =>
           result.AppendLine($"{wsv.Key}: {wsv.Value ?? String.Empty}"));

        return result.ToString();
      }
    }
 }

The source code can be found in github.com:
https://github.com/softwarepronto/Blog

The solution can be found in the SoftwarePronto.Azure.Utility.Master folder.




Monday, September 26, 2016

Azure Web App: Publishing Web Site/Service Forgot Deployment Password (getting Publish credentials through the Azure Portal)

In the previous positing, Azure Web App: Publishing Web Site/Service Forgot Deploy Password (introducing Cloud Explorer), it was shown how to find the publishing password for an Azure App Service using Cloud Explorer (an add-in for Visual Studio 2015). The impetus for this was to fix the web site/service deployment issue caused when Visual Studio's publishing wizard forgets the deployment password. Clearly a Visual Studio add-in, Cloud Explorer, is not the only way to determine the password used when publishing the Azure App Service. The same information can be retrieved using the Azure Portal, https://portal.azure.com/ which is precisely what this blog entry demonstrates.

An example of the screen shown when the Publishing wizard prompts for a password is as follows:


To find the publishing credentials in the Azure Portal navigate to the App Service for the which the credentials are to be retrieved. The initial blade displayed for an App Service is as follows:



Notice in the upper right corner the ...More menu which is shown below:


Clicking on this menu displays the Get publish profile menu item:



When the Get publish profile menu is clicked on the publishing profile is downloaded by default to a user's Downloads folder. The profile file takes the form of:
    <App Service Name>.PublishSettings

The profile file can be opened with a text editor such as Notepad++ which is shown below:


Within the profile the password can be found by searching for the letters PWD which are contained in the userPWD attribute which is shown below:


The userPWD attribute specifies the password used when publishing a web site/service using Visual Studio.