Hybrid cloud recent solutions from Microsoft and VMWare – 2 different ends of the hybrid cloud spectrum

Public clouds have grown tremendously over the last few years and there are very few companies who do not use public cloud at this point. Even traditional enterprises with in-house data centers have some presence in the public cloud. I was looking at Amazon’s re:Invent conference details and I was amazed by the number of new services and enhancements that were announced this year.  It is very difficult for private clouds to keep up in pace with the new features of public cloud. There is no doubt that public clouds will overtake private clouds in the long term. Private clouds still have a wide deployment and there will be enough use cases for quite some time to deploy private cloud. The use cases includes regulated industries, compute needed in remote locations not having access to public cloud and some specialized requirements that public clouds cannot meet. For some enterprises, private cloud would make more sense from a costing perspective. Having hybrid cloud option is a safe bet for most companies as it provides the best of both worlds. I saw 2 recent announcements in hybrid cloud that captured my attention. One is Azure stack that allows running Azure stack in private cloud. Another is VMWare cloud on AWS that allows running entire VMware stack in AWS public cloud. I see these two services as 2 ends of the hybrid cloud spectrum. In 1 case, public cloud infrastructure software is made to run on private cloud(Azure stack) and in another case, private cloud infrastructure software is made to run on public cloud(Vmware cloud on AWS). In this blog, I have tried to capture more details on these 2 services.

Hybrid cloud

There are predominantly 2 options currently to run Private cloud. 1 option is to use vendor based cloud management software along with hardware from same vendor. Cisco UCS is an example in this category where customers get to use UCS servers integrated with networking and storage along with management software from Cisco. This provides a tightly integrated solution. Another option is to use Openstack as a cloud orchestration system and use server, networking and storage hardware from any vendor. Both these kinds of solutions works well in private cloud. For enterprises having private cloud, there always are use-cases where few services makes more sense in public cloud. A classic example is a development team using public cloud for 1 of their development projects for agility reasons. Once the development is complete, operations team has a choice to deploy the application in either private or public cloud. There is also the use case where current applications deployed in private cloud needs to be scaled by using public cloud for elasticity reasons. In either of the cases, we need a solution that allows easier migration of applications along with their policies between the private and public cloud.

Following are some important requirements of hybrid cloud:

  • Having a common management software to manage public and private clouds.
  • Ability to move applications seamlessly between the clouds.
  • Secure connectivity between the clouds.

Microsoft Azure stack

Azure stack is a hybrid cloud platform product from Microsoft that allows managing the private cloud with the same Azure public cloud software stack.

Following picture from Azure stack link shows the components of Azure stack:

privatecloud1

Following are some details on the solution:

  • Azure stack takes some of the components of Microsoft Azure public cloud to manage private cloud. To start with, Azure stack will support limited services in private cloud when compared to Azure public cloud.
  • Cloud infrastructure layer is hardware and basic system software for running compute, storage and networking. In the initial release, Azure stack will be provided as turnkey integrated solution with hardware integrated from Dell, HP and Lenovo. It looks like more vendors will be added in future. The reason to support limited vendors is to achieve tight integration and simplify the deployment solution.
  • Azure infrastruture layer sits on top of cloud infrastructure and the Azure services layer interacts with Azure infrastructure layer.
  • The first technical preview release was done in early 2016 and the second technical preview release was done in late 2016. GA release is planned middle of 2017.
  • The entire Azure stack runs currently on a single node. The plan is to make this distributed in future.

Following are some of my general thoughts on Azure stack:

  • Public cloud providers typically did not focus on private clouds since that would eat into their pie. This is a good move by Microsoft to facilitate hybrid cloud and the gradual move to public cloud.
  • The pricing and licensing model of Azure stack is not clear. Since the plan is to have a turnkey integrated solution with few vendors, there has to be some form of licensing agreement with multiple parties.
  • It is not clear how the OEM vendors providing cloud infrastructure can differentiate their solutions.
  • Having a restricted cloud infrastructure vendor list will make this solution not useful for private clouds using legacy hardware. It will be good if the cloud stack can provide common API that can allow any hardware vendor that supports the API to be managed by the Azure stack cloud software. To some extent, Openstack is following this model. It will be good if Azure stack can do the same so that there is no restriction on the vendor list.
  • AWS and Google cloud have not introduced private cloud management solutions till now. As mentioned earlier, there are use cases where access to public cloud is not possible and private cloud would be a better fit. AWS greengrass IoT solution is the closest private cloud like solution from AWS that I have seen where local IoT resources are used for compute when needed.

VMWare cloud on AWS

This solution allows the entire VMWare virtualization stack(including compute, storage and networking) to run in AWS public cloud. The solution is provided by VMWare and is a joint collaboration between VMWare and Amazon AWS. For enterprises using VMWare stack to manage their private cloud infrastructure, they can use the same software stack when moving some of their services to AWS public cloud.

Following picture from VMWare link shows the components of this solution:

privatecloud2

Following are some details on the solution:

  • All the core components of VMWare stack including Vsphere, Virtual SAN, NSX, ESX and Vcenter runs in AWS infrastructure.
  • AWS typically uses Xen hypervisor for virtualization and VMWare uses ESX for virtualization. To do this integrated solution, ESX runs in AWS baremetal. There is no Xen hypervisor in this integrated solution.
  • Vcenter is used for management across on-premise as well as in AWS. In 1 of the joint demos, VMWare shows seamless VM migration between on-premise cloud and AWS cloud.
  • VMs deployed in AWS public cloud can use all the AWS services like storage, database, analytics etc. This makes this solution very attractive.
  • This service will be operated and managed by VMWare. Both AWS and VMWare have made changes to their stack for this integrated solution.
  • The solution is currently in Technical preview phase and general availability is expected middle of 2017.

Following are some of my general thoughts on this VMware cloud on AWS solution:

  • VMWare has tried different strategies to get a foothold into public and hybrid cloud. vCloud hybrid service was 1 of their unsuccessful attempts earlier on this. This solution will benefit both VMWare and AWS, the bigger benefit lies for AWS.
  • AWS has not sold baremetal servers till now. There are companies like Packet that provides baremetal servers. There are use cases for baremetal like non-virtualized scenarios or pure container based solutions where baremetal servers would help. It will be interesting to see if AWS would sell these baremetal servers in future. It is not clear why AWS has not provided bare metal servers till now, 1 possible reason could be that it would take away some of its differentiators.
  • Microsoft has a private cloud enterprise solution with hyperv and public cloud solution with Azure public stack. Microsoft can provide a similar integrated solution that allows Microsoft’s private cloud stack to run on its Azure public cloud. It is not sure if Microsoft will venture into this.

Summary

Both solutions described above are good hybrid cloud solutions that eases movement to public cloud. Both these hybrid cloud solutions are favorable more for public cloud rather than private cloud. Even though these solutions helps private clouds temporarily, long term benefits lies with public cloud. It will be good to have cloud management software that is cloud agnostic so that multiple cloud vendors can be used and there is no vendor lock-in. Terraform and Cliqr are some solutions catered to this space.

References

Docker in Docker and play-with-docker

For folks who want to get started with Docker, there is the initial hurdle of installing Docker. Even though Docker has made it extremely simple to install Docker on different OS like Linux, Windows and Mac, the installation step prevents folks from getting started with Docker. With Play with Docker, that problem also goes away. Play with Docker provides a web based interface to create multiple Docker hosts and be able to run Containers. This project is started by Docker captain Marcos Nils and is an open source project. Users can run regular containers or build Swarm cluster between the Docker hosts and create container services on the Swarm cluster. The application can also be installed in the local machine. This project got me interested in trying to understand the internals of the Docker host used within the application. I understood that Docker hosts are implemented as Docker in Docker(Dind) containers. In this blog, I have tried to cover some details on Dind and Play with Docker.

Docker in Docker(Dind)

Docker in Docker(Dind) allows Docker engine to run as a Container inside Docker. This link is the official repository for Dind. When there is a new Docker version released, corresponding Dind version also gets released. This link from Jerome is an excellent reference on Docker in Docker that explains issues with Dind, cases where Dind can be used and cases where Dind should not be used.

Following are the two primary scenarios where Dind can be needed:

  1. Folks developing and testing Docker need Docker as a Container for faster turnaround time.
  2. Ability to create multiple Docker hosts with less overhead. “Play with Docker” falls in this scenario.

Following picture illustrates how Containers running in Dind are related to Containers running in host machine.

dind1

Dind, C1 and C2 are containers running in the host machine. Dind is a Docker container hosting Docker machine. C3 and C4 are containers running inside Dind Container.

Following example illustrates Dind:

I have Docker 1.13RC version as shown below:

$ docker version
Client:
 Version:      1.13.0-rc2
 API version:  1.25
 Go version:   go1.7.3
 Git commit:   1f9b3ef
 Built:        Wed Nov 23 06:24:33 2016
 OS/Arch:      linux/amd64

Server:
 Version:             1.13.0-rc2
 API version:         1.25
 Minimum API version: 1.12
 Go version:          go1.7.3
 Git commit:          1f9b3ef
 Built:               Wed Nov 23 06:24:33 2016
 OS/Arch:             linux/amd64
 Experimental:        false

Lets start Dind Container. Its needed to run this in privileged mode since its mounts system files from host system.

docker run --privileged --name dind1 -d docker:1.8-dind

We can look at Docker version inside Dind:

# docker version
Client:
 Version:      1.8.3
 API version:  1.20
 Go version:   go1.4.2
 Git commit:   f4bf5c7
 Built:        Mon Oct 12 18:01:15 UTC 2015
 OS/Arch:      linux/amd64

Server:
 Version:      1.8.3
 API version:  1.20
 Go version:   go1.4.2
 Git commit:   f4bf5c7
 Built:        Mon Oct 12 18:01:15 UTC 2015
 OS/Arch:      linux/amd64

Even though host machine is running Docker 1.13RC version, we can test Docker 1.8.3 inside the Container using above example.

For Continuous integration(CI) use cases, it is needed to build Containers from CI system. In case of Jenkins, it is needed to build Docker containers from Jenkins master or Jenkins slave. Jenkins master or slave run as Container themselves. For this scenario, it is not needed to have Docker engine running within Jenkins Container. It is needed to have Docker client in Jenkins container and use Docker engine from host machine. This can be achieved by mounting “/var/run/docker.sock” from host machine.

Following diagram illustrates this use-case:

dind2

Jenkins runs as a Container. C1 and C2 are containers started from host machine. C3 and C4 are Docker containers started from Docker client inside Jenkins. Since Docker engine on host is shared by Jenkins, C3 and C4 are created on same host and share same hierarchy as C1 and C2.

Following is an example of Jenkins Container that mounts /var/run/docker.sock from host machine.

docker run --rm --user root --name myjenkins -v /var/run/docker.sock:/var/run/docker.sock -p 8080:8080 -p 50000:50000 jenkins

Following command shows the Docker version inside Jenkins container:

# docker version
Client:
 Version:      1.13.0-rc4
 API version:  1.25
 Go version:   go1.7.3
 Git commit:   88862e7
 Built:        Sat Dec 17 01:34:17 2016
 OS/Arch:      linux/amd64

Server:
 Version:      1.13.0-rc2
 API version:  1.25 (minimum version 1.12)
 Go version:   go1.7.3
 Git commit:   1f9b3ef
 Built:        Wed Nov 23 06:24:33 2016
 OS/Arch:      linux/amd64
 Experimental: false

1.13RC4 is Docker client version installed inside Jenkins and 1.13RC2 is Docker server version installed in the Docker host.

“Play with Docker”

The application is hosted in public cloud and can be accessed as SaaS service using the following link. The application can also be run in the local machine. Following are some capabilities that I have tried:

  • Run traditional non-service based containers.
  • Create Swarm mode cluster and run services in the Swarm cluster.
  • Exposed ports in the services can either be accessed from localhost or can be accessed externally by tunneling with ngrok.
  • Create bridge and overlay networks.

Following is a screenshot of the application hosted in public cloud where I have created a 5 node Swarm cluster with 2 masters and 3 slaves.

dind3.PNG

To create a 5 node cluster, the typical approach would be to use 5 different hosts or VMs which is a huge burden on resources. Using
Play with Docker”, we create 5 node cluster with 5 Dind containers. For non-production testing scenarios, this saves lot of resources.

Following are some limitations in the SaaS version:

  • There is a limit of 5 nodes.
  • Sessions are active only for 4 hours.
  • The usual Dind limitations applies here.

Lets start a simple web server with 2 replicas:

docker service create --replicas 2 --name web -p 8080:80 nginx

Following output shows the service running:

$ docker service ps web
ID            NAME   IMAGE         NODE   DESIRED STATE  CURRENT STATE           ERROR  PORTS
dmflqoe67pr1  web.1  nginx:latest  node3  Running        Running 56 seconds ago
md47jcisfbeb  web.2  nginx:latest  node4  Running        Running 57 seconds ago

The service can either be accessed from Dind host using curl or by tunneling the application using ngrok and accessing using internet.
Following is an example of exposing the service to outside world using ngrok:

docker run --net host -ti jpetazzo/ngrok http 10.0.15.3:8080

This will return an URL which can be accessed from internet to access the nginx service that we started earlier.

“Play with Docker” can also be installed in local machine. The advantage here is that we can tweak the application according to our need. For example, we can install custom Docker version, increase the number of Docker hosts, keep the sessions always up etc.

Following are some internals on the application:

  • Base machine needs to have Docker 1.13RC2 running.
  • The application is written in GO and is run as a Container.
  • Dind Containers are not the official Docker Dind container. “franela/Dind” is used.
  • GO container that runs the main GO application does a volume mount of “/var/run/docker.sock”. This allows Dind Containers to run in the base machine.

Following picture shows the container hierarchy for this application.

dind4

“Golang” container is in the same hierarchy as Dind Containers. Dind containers simulate Docker hosts here. C1-C4 are user created containers created on the 2 Docker hosts.

To install “Play with Docker” in my localhost, I followed the steps below:

Installed docker 1.13.0-rc2
git clone https://github.com/franela/play-with-docker.git
installed go1.7
docker swarm init
docker pull franela/dind
cd play-with-docker
go get -v -d -t ./...
export GOPATH=~/play-with-docker
docker-compose up

My localhost is Ubuntu 14.04 VM running inside Windows machine.

Following is the 2 node Swarm cluster I created:

$ docker node ls
ID                           HOSTNAME  STATUS  AVAILABILITY  MANAGER STATUS
p6koe4bo8rn7hz3s4y7eddqwz *  node1     Ready   Active        Leader
yuk6u9r3o6o0nblqsiqjutoa0    node2     Ready   Active

Following are some problems I faced with local installation:

  • When I started docker-compose, the application crashed once in a while. I was able to work around this problem by restarting docker-compose.
  • For swarm mode services, I was not able to access exposed service using host port number. For regular containers, I was able to access exposed host port.

I did not face the above 2 problems when I accessed the application as SaaS.

Thanks to Marcos Nils for helping me with few issues faced during my local installation.

References

Vault – Use cases

This blog is a continuation of my previous blog on Vault. In the first blog, I have covered overview of Vault. In this blog, I will cover some Vault use cases that I tried out.

Pre-requisites:

Install and start Vault

I have used Vault 0.6 version for the examples here. Vault can be used either in development or production mode. In development mode, Vault is unsealed by default and secrets are stored only in memory. Vault in production mode needs manual unsealing and supports backends like Consul, S3.

Start Vault server:

Following command starts Vault server in development mode. We need to note down the root key that will be used later.

vault server -dev

As the name suggests, development mode is strictly for trying out Vault.

Enable authentication backends

Here, we enable authentication backends needed for this usecase. “Token” backend is enabled by default. We can enable backends by “vault auth-enable <backend name>”. Following command lists the enabled authentication backends for the use cases in this blog.

$ vault auth -methods
Path       Type      Default TTL  Max TTL  Description
approle/   approle   system       system   
github/    github    system       system   
token/     token     system       system   token based credentials
userpass/  userpass  system       system  

Enabling secret backends

Next, we enable secret backends needed for this use case. We have enabled “mysql”, other backends are enabled by default. Following command lists the enabled secret backends for the use cases in this blog.

$ vault mounts
Path        Type       Default TTL  Max TTL  Description
cubbyhole/  cubbyhole  n/a          n/a      per-token private secret storage
mysql/      mysql      system       system   
secret/     generic    system       system   generic secret storage
sys/        system     n/a          n/a      system endpoints used for control, policy and debugging

Use Cases

Use case 1 – AWS backend

This use case is for getting dynamic AWS IAM access keys. AWS Identity and Access Management (IAM) provides granular access to AWS account based on user and group. AWS allows creation of IAM policy to restrict access to specific AWS resources. AWS IAM credentials being present in configuration file exposes a security risk. Vault allows dynamic creation of AWS IAM credentials with specific lease period so that the application can either revoke the credential after use or Vault will automatically delete the IAM credential after lease expiry.

Following is the workflow:

  • Register AWS root credentials with Vault.
  • Create IAM policy based on the access needed.
  • Create AWS role in Vault with the IAM policy created before.
  • Get dynamic AWS IAM credentials using the role created in previous step.
Pre-requisite:

We need to have AWS account to try this. Creating new IAM account does not have AWS charges.

Example:

Following command configures the lease period for AWS IAM dynamic keys.

$ vault write aws/config/lease lease=1200s lease_max=3600s
Success! Data written to: aws/config/lease

In the above command, we have configured lease period as 1200 seconds, this causes secret deletion after 20 minutes.

Following AWS IAM policy allows the user to touch only EC2 resource in AWS.

policy.json:
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "Stmt1426528957000",
      "Effect": "Allow",
      "Action": [
        "ec2:*"
      ],
      "Resource": [
        "*"
      ]
    }
  ]
}

Register root AWS key:

vault write aws/config/root \
    access_key=xxx \
    secret_key=xxx

Replace access key and secret key with your own AWS root keys.

Register IAM policy for EC2 access with Vault:

vault write aws/roles/deploy policy=@policy.json

“policy.json” is the file specified in previous step.

Following command shows the dynamic key generation from Vault:

$ vault read aws/creds/deploy 
Key            	Value
---            	-----
lease_id       	aws/creds/deploy/c44fb09f-7465-d1e5-bbb1-59291013ac12
lease_duration 	20m0s
lease_renewable	true
access_key     	AKIAJQKLF72XDNV74SIQ
secret_key     	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
security_token 	

In the above command output, we can see that the lease duration is 20 minutes as we specified in AWS configuration. This key will become invalid after 20 minutes. Using above access and secret key, we can access only AWS EC2 services. We cannot access any other AWS service like S3 with this set of credentials.

If we list IAM users from aws IAM cli (“aws iam list-users”), we can see the new IAM user created by Vault:

    {
            "UserName": "vault-root-deploy-1475168892-6220", 
            "Path": "/", 
            "CreateDate": "2016-09-29T17:08:14Z", 
            "UserId": "AIDAJBH4XTDI3HU5HV5I4", 
            "Arn": "arn:aws:iam::173760706945:user/vault-root-deploy-1475168892-6220"
        }

Use case 2 – Passing secrets to Container

One approach to pass secret tokens to Container is by using environment variable. This approach is not secure as environment variables gets logged and this can easily get into the hands of malicious users. Vault provides a new backend called Cubbyhole to overcome this issue.

Following is the workflow for using Cubbyhole backend:

  • Enable Cubbyhole secret backend. Vault enables this by default.
  • Create temporary token with use count of 2. The use count specifies number of times the specific token can be used.
  • Create permanent token.
  • Store permanent token in temporary token’s cubbyhole.
  • Pass temporary token to container application using environment variable.
  • Application reads permanent token from cubbyhole using temporary token. Even if temporary token is read by malicious user later, there is no use for it since the use count for temporary token would have expired. Out of the specified initial use count of 2 for temporary token, first count is used when writing the permanent token and the second count is used when reading the permanent token.
Cubbyhole manual example

Create temporary token as shown below:

$ vault token-create --policy=policy1 --use-limit=4
Key            	Value
---            	-----
token          	a20119a5-7954-8045-e6df-01615adee8ab
token_accessor 	abd78995-788f-6158-a6b0-258b895ae870
token_duration 	720h0m0s
token_renewable	true
token_policies 	[default policy1]

In the above command, we have used use-limit of 4. This means this token would expire after 4 accesses. I have created “policy1″in Vault before-hand.

Create permanent token:

$ vault token-create
Key            	Value
---            	-----
token          	fc8576ef-0d7a-87d8-f2de-ef4ad37c6dd9
token_accessor 	1ea0240f-5512-e10d-645c-91993d860877
token_duration 	0s
token_renewable	false
token_policies 	[root]

Store permanent token in temporary token’s cubbyhole:

$ vault auth 27e83eeb-beef-cdd1-f406-92ba3fb229a7
Successfully authenticated! You are now logged in.
token: 27e83eeb-beef-cdd1-f406-92ba3fb229a7
token_duration: 2591989
token_policies: [default, policy1]
sreeni@ubuntu:~/vault$ vault write cubbyhole/app  app-token=fc8576ef-0d7a-87d8-f2de-ef4ad37c6dd9
Success! Data written to: cubbyhole/app

Retrieve permanent token using temporary token:

$ vault auth 27e83eeb-beef-cdd1-f406-92ba3fb229a7
Successfully authenticated! You are now logged in.
token: 27e83eeb-beef-cdd1-f406-92ba3fb229a7
token_duration: 2591951
token_policies: [default, policy1]
sreeni@ubuntu:~/vault$ vault read cubbyhole/app
Key      	Value
---      	-----
app-token	fc8576ef-0d7a-87d8-f2de-ef4ad37c6dd9

If we do the token read 1 more time, it will fail since token access count is exceeded:

$ vault read cubbyhole/app
Error reading cubbyhole/app: Error making API request.

URL: GET http://127.0.0.1:8200/v1/cubbyhole/app
Code: 403. Errors:

* permission denied

In the above example, I have used use count of 4 since Vault CLI does not allow 1 command to read and authenticate at the same time. First use count is used to authenticate, second is to write the permanent token, third is used to authenticate and fourth is used to read the permanent token.

Cubbyhole Programmatic example

Following example uses programmatic way to use cubbyhole using Ruby APIs. I found this complete example here.
Create temporary token with use count of 2:

temp = deployer_client.auth_token.create({ :ttl => '15s', :num_uses => 2 })[:auth][:client_token]

Create permanent token:

# permanent token can be used any number of times w/ no ttl.
perm = deployer_client.auth_token.create({})[:auth][:client_token]

Store permanent token in cubbyhole using tempoary token:

# using the first use of token #1, store the permanent token in cubbyhole
temp_client = Vault::Client.new(address: vault_address, token: temp)
temp_client.logical.write("cubbyhole/app-token", { :token => perm })

Fetch permanent token using temporary token:

# get the permanent token to use to grab real secrets
app_temp_client = Vault::Client.new(address: vault_address, token: temp)
puts "using temporary token #{temp} to access permanent token"
perm_token = app_temp_client.logical.read("cubbyhole/app-token")[:data][:token]
Cubbyhole wrap response

With Vault 0.6 version, there is a new capability called wrap response where any secret can be wrapped inside a Cubby hole.

Following is an example:

Wrap permanent token:

$ vault token-create --policy=policy1 --wrap-ttl=60s --use-limit=2
Key                          	Value
---                          	-----
wrapping_token:              	8c92f8d9-1035-d135-531e-e44396a560ec
wrapping_token_ttl:          	1m0s
wrapping_token_creation_time:	2016-09-29 09:14:52.462898166 -0700 PDT
wrapped_accessor:            	13cdb1d2-3c6c-6a36-fd19-2fab10d570b9

Unwrap permanent token:

$ vault unwrap 8c92f8d9-1035-d135-531e-e44396a560ec
Key            	Value
---            	-----
token          	1e474c4c-2f11-5c69-043d-473b218022e9
token_accessor 	13cdb1d2-3c6c-6a36-fd19-2fab10d570b9
token_duration 	720h0m0s
token_renewable	true
token_policies 	[default policy1]

In the above command, we have unwrapped using wrapping token. “8c92f8d9-1035-d135-531e-e44396a560ec” is the temporary token and “1e474c4c-2f11-5c69-043d-473b218022e9” is the permanent token.

Use case 3 – Mysql secret access

In this example, we will generate Mysql role based secrets dynamically. Following picture illustrates the flow.

vault1

Following are the goals of this use case:

  • The application will use Vault to generate username and password with specific roles to access Mysql database. “Readonly” role should be able to only read mysql database entries. “Superuser” role should be able to read and modify mysql database entries.
  • mysql user credentials will be generated dynamically with a specific lease time using Vault. The application can destroy the credentials after its use. In case the application does not destroy, Vault will automatically destroy credentials after the lease time expiry of the secret.
  • Different authentication backends like userpass, Token, Github and Approle will be used to achieve the same goal of dynamically generating mysql credentials. “mysql” secret backend will be used here.
Example

Start mysql server:

We will start mysql server as Docker container mapping the container port to host port.

docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=mysql -d mysql:latest

Port 3306 gets exposed on the host machine.

Add mysql credentials to Vault:
Following command sets up the connection to mysql server with username “root” and password “mysql”. The username and password here should match with the root credentials we used when starting mysql server.

vault write mysql/config/connection \
    connection_url="root:mysql@tcp(127.0.0.1:3306)/"

Configure mysql secrets lease duration to 1 hour:

vault write mysql/config/lease \
    lease=1h \
    lease_max=24h

Create roles for mysql access:

In this step, we will associate mysql roles for “readonly” and “modify” policy. “readonly” role is allowed only select access in mysql. “modify” role is allowed all access to the database. Following command creates roles in Vault.

vault write mysql/roles/readonly \
    sql="CREATE USER '{{name}}'@'%' IDENTIFIED BY '{{password}}';GRANT SELECT ON *.* TO '{{name}}'@'%';"
vault write mysql/roles/modify \
    sql="CREATE USER '{{name}}'@'%' IDENTIFIED BY '{{password}}';GRANT ALL ON *.* TO '{{name}}'@'%';"

Create policy for mysql:
Following is the mysql readonly policy “mysqlreadonly.json” that allows read access to “mysql/creds/readonly”.

path "mysql/creds/readonly" {
  policy = "read"
}

Following is the mysql modify policy “mysqlmodify.json” that provides read access to “mysql/creds/modify”.

path "mysql/creds/modify" {
  policy = "read"
}

Write the policy to Vault:

Following set of commands writes the JSON policy specified in previous section to Vault.

vault policy-write mysqlmodify mysqlmodify.json
vault policy-write mysqlreadonly mysqlreadonly.json
Using Token based authentication

In this section, we will use token based authentication scheme to access mysql secrets.

Following 2 commands creates tokens for the 2 types of users:

vault token-create --policy=mysqlmodify
vault token-create --policy=mysqlreadonly

Following output shows the results:

$ vault token-create --policy=mysqlmodify
Key            	Value
---            	-----
token          	92456126-c387-199b-fb51-306eb1eeb921
token_accessor 	e44602ad-397d-e4b4-826a-c540e0e16853
token_duration 	720h0m0s
token_renewable	true
token_policies 	[default mysqlmodify]

$ vault token-create --policy=mysqlreadonly
Key            	Value
---            	-----
token          	778455d8-08a9-6407-4b99-c039f503b377
token_accessor 	c266a977-279f-e12f-d5b5-d17ce9e5cd2b
token_duration 	720h0m0s
token_renewable	true
token_policies 	[default mysqlreadonly]

Lets authenticate using readonly token:

$ vault auth 778455d8-08a9-6407-4b99-c039f503b377
Successfully authenticated! You are now logged in.
token: 778455d8-08a9-6407-4b99-c039f503b377
token_duration: 2591649
token_policies: [default, mysqlreadonly]

Now that we have authenticated, lets get the mysql credentails for readonly user:

$ vault read mysql/creds/readonly
Key            	Value
---            	-----
lease_id       	mysql/creds/readonly/18bfe188-f36b-88d3-d61c-5ca4842265da
lease_duration 	1h0m0s
lease_renewable	true
password       	00ee87a7-a2e8-1959-b94a-56431e6e71cf
username       	read-toke-1e1806

If we try to access credentials for modify user, we wont be able to get it since this user has access to only the readonly credentails.

$ vault read mysql/creds/modify
Error reading mysql/creds/modify: Error making API request.

URL: GET http://127.0.0.1:8200/v1/mysql/creds/modify
Code: 403. Errors:

* permission denied

Now, we can access the mysql database using the mysql client with the above credentials. We can read the database, but we are not able to modify the database as shown below.

$ mysql -h127.0.0.1 -P3306 -uread-toke-1e1806 -p00ee87a7-a2e8-1959-b94a-56431e6e71cf
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 5.7.15 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| alpha              |
| alpha1             |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
6 rows in set (0.01 sec)

mysql> create database alpha2;
ERROR 1044 (42000): Access denied for user 'read-toke-1e1806'@'%' to database 'alpha2'

Now, lets authenticate as “modify” user using the appropriate token:

$ vault auth 92456126-c387-199b-fb51-306eb1eeb921
Successfully authenticated! You are now logged in.
token: 92456126-c387-199b-fb51-306eb1eeb921
token_duration: 2591261
token_policies: [default, mysqlmodify]

Now, lets try to get credentials to modify database.

$ vault read mysql/creds/modify
Key            	Value
---            	-----
lease_id       	mysql/creds/modify/85380045-5951-993c-ef3d-04f9c5b4bbed
lease_duration 	1h0m0s
lease_renewable	true
password       	5e73da55-df7b-ef04-0556-0674fc4c42f8
username       	modi-toke-42e9e3

Lets access the database and try to create a new database. Since we have used “modify” role, we are able to make changes to the database with this username and password.

$ mysql -h127.0.0.1 -P3306 -umodi-toke-42e9e3 -p5e73da55-df7b-ef04-0556-0674fc4c42f8
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 17
Server version: 5.7.15 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| alpha              |
| alpha1             |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
6 rows in set (0.00 sec)

mysql> create database alpha2;
Query OK, 1 row affected (0.01 sec)

Lease duration:

We can query the token and we can see that ttl is getting decremented. The “creation_ttl” reflects initial creation duration(720 hrs/2592000 seconds) and the “ttl” reflects pending time(2590930 seconds). The ttl for the token reflects the lease expiry of authentication token.

$ vault token-lookup 778455d8-08a9-6407-4b99-c039f503b377
Key             	Value
---             	-----
accessor        	c266a977-279f-e12f-d5b5-d17ce9e5cd2b
creation_time   	1474217534
creation_ttl    	2592000
display_name    	token
explicit_max_ttl	0
id              	778455d8-08a9-6407-4b99-c039f503b377
meta            	
num_uses        	0
orphan          	false
path            	auth/token/create
policies        	[default mysqlreadonly]
renewable       	true
ttl             	2590930

There is also a lease period for database authentication credentials. In this example, we have used 1 hour as the lease period. After this period, database credentials will be destroyed.

Destroy tokens and mysql credentials:

After we have accessed the database, we can revoke the secret as well as the token as shown below.

vault revoke mysql/creds/modify/85380045-5951-993c-ef3d-04f9c5b4bbed
vault revoke mysql/creds/readonly/18bfe188-f36b-88d3-d61c-5ca4842265da
vault token-revoke 778455d8-08a9-6407-4b99-c039f503b377
vault token-revoke 92456126-c387-199b-fb51-306eb1eeb921
Userpass authentication

In this approach, we will use Vault authentication using username and password.
Following 2 commands creates “readonlyuser” with “mysqlreadonly” policy and “superuser” with “mysqlmodify” policy:

vault write auth/userpass/users/readonlyuser \
    password=foo \
    policies=mysqlreadonly

vault write auth/userpass/users/superuser \
    password=foo \
    policies=mysqlmodify

Following command and the associated output shows authentication using the “readonlyuser”. We can see that the returned policy is “mysqlreadonly”.

$ vault auth -method=userpass \
>     username=readonlyuser \
>     password=foo
Successfully authenticated! You are now logged in.
The token below is already saved in the session. You do not
need to "vault auth" again with the token.
token: a6f5315a-1e97-fe03-b7e0-24505157b498
token_duration: 2591999
token_policies: [default, mysqlreadonly]

Following command and the associated output shows authentication using the “superuser”. We can see that the returned policy is “mysqlmodify”

$ vault auth -method=userpass \
>     username=superuser \
>     password=foo
Successfully authenticated! You are now logged in.
The token below is already saved in the session. You do not
need to "vault auth" again with the token.
token: 613ac80a-1fa8-7494-5212-182b4b5eadf2
token_duration: 2592000
token_policies: [default, mysqlmodify]
Using Approle authentication approach

In this approach, we will use Vault authentication using Approle.

This authentication approach is mainly used for machines where some machine property like mac address will be used to authenticate.
First step is to create the roles “readonlyuser” and “superuser” and associate with the respective policies.

vault write auth/approle/role/readonlyuser policies=mysqlreadonly
vault write auth/approle/role/superuser policies=mysqlmodify

Nest step is to create roleid for both type of roles:

$ vault read auth/approle/role/readonlyuser/role-id
Key    	Value
---    	-----
role_id	adebbe05-c929-107e-6164-e86e2dc563f7

$ vault read auth/approle/role/superuser/role-id
Key    	Value
---    	-----
role_id	6ec1966c-b00b-b37c-48db-16084bc57f64

We need to get secrets corresponding to the role as shown below.

$ vault write -f auth/approle/role/readonlyuser/secret-id
Key               	Value
---               	-----
secret_id         	ea99d1ec-ea78-cf4c-92ef-cb0964126960
secret_id_accessor	4253940a-235e-de26-ff94-0c6c1c7d339a

vault write -f auth/approle/role/superuser/secret-id
Key               	Value
---               	-----
secret_id         	1b87e79a-328d-9b10-6cd2-9b2e5e0e8dfa
secret_id_accessor	a71163ef-302b-71f4-8187-65f062d2a3e6

Now, we can authenticate using the above roleid and secretid. This will return the appropriate policies.

$ vault write auth/approle/login role_id=adebbe05-c929-107e-6164-e86e2dc563f7 secret_id=ea99d1ec-ea78-cf4c-92ef-cb0964126960
Key            	Value
---            	-----
token          	0634efb3-d630-2bcb-657a-db017873f7e6
token_accessor 	335a46dc-60ba-0973-b8f6-4e282da8bc30
token_duration 	20m0s
token_renewable	true
token_policies 	[default mysqlreadonly]

$ vault write auth/approle/login role_id=6ec1966c-b00b-b37c-48db-16084bc57f64 secret_id=1b87e79a-328d-9b10-6cd2-9b2e5e0e8dfa
Key            	Value
---            	-----
token          	2e958510-9f46-3b18-9022-45c2145edd8b
token_accessor 	c8c761d2-8264-0c86-124c-480da0b26f7a
token_duration 	20m0s
token_renewable	true
token_policies 	[default mysqlmodify]

Typically, roleid would be a property of the machine programmed into it by some configuration management system.

Using github authentication

In this approach, we will use Vault authentication using Github.

Github authentication scheme is used for user based authentication. Following are some internals on this scheme:

  • Github has concept of organizations, teams and members. Organization can have many teams and each team can have many members.
  • The first step in this scheme is generation of personal access token for the github user account. This token is needed while authenticating to Vault.
  • In this scheme, when user tries to authenticate to Vault, Vault contacts github server with specified username and authentication token. Github returns the teams that this specific user is part of. Vault will then return the policy associated with the specific team.

Following is the Org structure that I created in github along with policy returned by Vault.

vault2

When user “smakam” logs in, github returns team “local” to Vault. Vault would then identify policy associated with team “local”.

Following commands creates the organization, team and associates policy with the team.

vault write auth/github/config organization=sreeniorg
vault write auth/github/map/teams/local value=mysqlreadonly

Following command shows the output when we try to authenticate using token for user “smakam”. Here, we get policy returned as “mysqlreadonly”.

$ vault auth -method=github token=xxxx
Successfully authenticated! You are now logged in.
The token below is already saved in the session. You do not
need to "vault auth" again with the token.
token: 4803ddf8-e419-d1e5-7aae-8d2d42834966
token_duration: 2591999
token_policies: [default, mysqlreadonly]

References

Vault Overview

I have always loved Hashicorp’s Devops and cloud tools. I have used Vagrant, Consul, Terraform, Packer and Atlas before and I have written about few of them in my previous blogs. Vault is Hashicorp’s tool to manage secrets securely in a central location. Secret could be database credentials, AWS access keys, Consul api key, ssh private keys etc. It is necessary for secrets to be managed centrally and having strict control and audit policies. By having a separate tool to manage secrets, application developer don’t need to worry about security internals and leave it to Vault to manage secrets. In this blog, I will cover Vault overview and internals and in the next blog, I will cover some use cases that I tried out.

Vault Principles

Vault uses the following principles:

Continue reading Vault Overview

Docker for AWS – Deployment options

In this blog, I will cover 5 different options to deploy Docker Containers in AWS infrastructure. There are pros and cons of each option and the goal in this blog is not to suggest that some options are better than others, but to highlight the suitable option for a particular use case. I have taken a sample multi-container application and deployed in all the 5 different models to illustrate this. Following are the 5 options/models discussed in this blog:

  1. Docker Machine for AWS
  2. Docker for AWS
  3. Docker cloud for AWS
  4. Docker Datacenter for AWS
  5. AWS ECS

I have separate blog for each of the above deployment options which are linked to this blog.

Sample application

Following is the sample application used in this blog:

docker_aws10

“client” service has 1 client container task. “vote” service has multiple vote container tasks. Both these services are deployed on a multi-node cluster. “client” service is used to access multi-container “vote” service. “vote” service can also be accessed through external load balancer. The goal of the sample application is to illustrate multi-node cluster, multi-container application, orchestration, container networking across hosts, external load balancing, service discovery and internal load balancing.

Docker-machine for AWS

Docker-machine has EC2 driver for creating a Docker node out of AWS. Docker node in this context means a AWS VM instance with Docker pre-installed. Docker-machine also sets up secure ssh access to the EC2 instance. Once the basic node setup is done, the user can either use traditional Swarm or Swarm mode for orchestration. In terms of integration, this approach provides minimal integration with AWS. This option is very easy to start with and useful for developers who want to try out Docker Containers in the AWS cloud. For more details on Docker-machine for AWS, please refer here.

Docker for AWS

As part of Docker 1.12 announcement, Docker released AWS Docker integration as beta software. With this software, Docker is trying to  simplify AWS integration by better integrating Docker with AWS services like load balancer, security groups, cloudwatch etc. Compared to docker-machine, this option provides close integration with AWS services. System containers running in the EC2 instances provides tight integration between user containers and AWS services. These system containers are added by Docker. For example, 1 of the system container listens to host exposed ports and automatically adds it to the AWS ELB. Currently, there are limited options to change the configuration setup. Hopefully, this will be improved when this comes out of beta phase. This option is useful for developers and operations folks who are used to both Docker tools as well as AWS services.  For more details on Docker for AWS, please refer here.

Docker Cloud for AWS

Docker cloud is a paid hosted service from Docker to manage Containers. Docker cloud can be used to manage nodes in the cloud or in local data center. By providing AWS credentials, Docker cloud can create and manage AWS EC2 instances and Docker containers will be created on these EC2 instances. Since Docker cloud was an acquisition, it does not use some of the Docker ecosystem software. In terms of integration with AWS, Docker cloud provides minimal integration at this point. Docker cloud provides a lot of value in terms of simplifying infrastructure management and deployment of complex micro-services. This option is useful for folks who want a simple hosted solution with minimal integration around AWS services. For more details on Docker cloud for AWS, please refer here.

Docker Datacenter for AWS

Docker Datacenter is Docker’s enterprise grade CaaS(Container as a service) solution where they have integrated their open source software with some proprietary software and support to make it into a commercial product. Docker Datacenter is an application comprised of Universal control plane(UCP), Docker Trusted registry(DTR), Docker engine and supporting services running as Containers. Docker Datacenter for AWS means running these system services on AWS EC2 instances along with running the application containers which the system services manages. Docker Datacenter is an enterprise grade solution with multi-tenancy support and it provides nice integration with Light weight directory access protocol(LDAP) and Role based access control(RBAC). Docker Datacenter for AWS provides a secure solution with clear separation between private and public subnet. Docker Datacenter also provides high availability with multiple UCP controllers and DTR replicas. This option is useful for Enterprises who want a production grade Docker deployment with tight integration around AWS services. For more details on Docker Datacenter for AWS, please refer here.

AWS ECS

AWS has EC2 Container service(ECS) for folks who want to deploy Docker containers in AWS infrastructure. With ECS, Amazon provides its own scheduler to manage Docker containers. ECS integrates very well with other AWS services including load balancer, cloudwatch, cloudformation templates etc. The workflow is little different for folks used to Docker tools. For folks who want to use the Docker ecosystem tools, this option is not suitable.This option can be very powerful once ECS integrates with all AWS services, it can allow seamless movement between VMs and Containers.  The task and service definition file formats does not seem flexible.  The good thing with ECS is users are not charged for Containers or for ECS, but charged only for the EC2 instances. This option seems more suitable for folks who have been using AWS for a long time and want to try out Docker containers. For more details on AWS ECS, please refer here.

Following table is a brief comparison between the 5 solutions:

Property/Solution Docker Machine for AWS Docker for AWS Docker Cloud for AWS Docker Datacenter for AWS AWS ECS
Docker version Latest Docker version(1.12.1 in my case), no flexibility to select Docker version Latest Docker version(1.12 in my case), no flexibility to select Docker version Uses 1.11, no flexibility to select Docker version Uses 1.11, no flexibility to select Docker version Uses 1.11, no flexibility to select Docker version
Orchestration Traditional Swarm using external discovery or Swarm mode can be used. Needs to be setup manually. Swarm mode is integrated and available automatically. Uses proprietary scheduler. Traditional Swarm is used. KV store is automatically setup. Uses AWS proprietary scheduler. There is a plan to integrate external schedulers.
Networking Docker Libnetwork Docker Libnetwork Uses Weave. Docker Libnetwork AWS VPC based networking
Application definition Compose and DAB Compose and DAB Stackfile Compose Task and Service definition files
Integration with AWS Services Very minimal integration Good integration. VPC, ELB, Security groups, IAM roles gets automatically setup. Minimal integration. Good integration. Availability zones, VPC, ELB, Security groups, IAM roles gets automatically setup. Very good integration. Integration available with classic or application load balancer, Cloudwatch logs, autoscaling groups.
Cost (This is in addition to EC2 instance cost) Free Beta phase currently, not sure of the cost. 1 node and 1 private repository free, charges applicable after that. Paid service, free for 30 day trial period Free

Following are some things that I would like to see:

  • AWS ECS allowing an option to use Swarm scheduler.
  • Docker for AWS, Docker cloud and Docker Datacenter using a common networking and orchestration solution.
  • It will be good to have a common task definition format for applications or an option to automatically convert between the formats internally. This allows for users to easily move between these options and use the same task definition format.

References

AWS ECS – Docker Container service

In this blog, I will cover AWS ECS Docker Container service. ECS is an AWS product. This blog is part of my Docker for AWS series and uses the sample voting application for illustration.

AWS has EC2 Container service(ECS) for folks who want to deploy Docker containers in AWS infrastructure. For basics of AWS ECS, you can refer to my previous blog here. With ECS, Amazon provides its own scheduler to manage Docker containers. ECS integrates very well with other AWS services including load balancer, logging service, cloudformation templates etc. AWS recently introduced Application load balancer(ALB) that does L7 load balancing and this integrates well with ECS. Using ALB, we can load balance services directly across Containers. With ECS, users get charged for the EC2 instances and not for the Containers.

To demonstrate ECS usage, we will deploy voting service application in ECS cluster.

Continue reading AWS ECS – Docker Container service