Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Perelle committed Feb 9, 2021
1 parent 691cc32 commit b9e84c2
Show file tree
Hide file tree
Showing 32 changed files with 1,437 additions and 5 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,8 @@ env.sh

**/.temp/*kube_config

### SSH keys ###
.rsa
.rsa.pub

# End of https://www.gitignore.io/api/macos,terraform,terragrunt,virtualenv,intellij+all
77 changes: 73 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ This project contains sources to build an hub and spoke infrastructure on Azure

## Architecture overview

The archirecture is built on an [hub and spoke network topology](https://docs.microsoft.com/en-us/azure/architecture/reference-architectures/hybrid-networking/hub-spoke?tabs=cli).
The archirecture is built upon an [hub and spoke network topology](https://docs.microsoft.com/en-us/azure/architecture/reference-architectures/hybrid-networking/hub-spoke?tabs=cli).

![archi](docs/img/archi.png)

## Requirements

Expand All @@ -21,6 +23,13 @@ These tools must be present in your environment to execute the different stacks

> You can build a Docker base image including all these requirements in order to guarantee that all team members and your CI tool use exactly the same environment to work with the project.
## Deployment

In this example project each stack get its own dedicated Resource Group.

>Depends on your way of working, you may prefer having the backend Account Storage and Key Vault in a same `Common` resource group, or in the `hub` resource group.
Maybe you haven't enough permissions to create Resource Group in your subscription and someone else from IT team will provide them to you. In these different use cases you will have to adapt the code a little bit to feet your needs.

### Service principal for Terraform

[Setup Service Principal for Terraform](docs/tf_azure_authent.md)
Expand All @@ -32,13 +41,73 @@ In Azure, stores the state as a Blob with the given Key within the Blob Containe

[Create the terraform backend if it doesn't already exists](docs/tf_backend.md)

## Deployment
### Key vault

Infrastructure stacks often need a secret manager and this corresponds to good practices tu use one. So we will provision an Azure Key Vault before building the hub and spoke infrastructure.

This stack create the Key Vault itself but will also be responsible for maintaining permission delegations to users, groups and applications of the company to consume or manage secrets, keys and certificates.

[Deploy the Key Vault if it doesn't already exists](terraform/vault/README.md)

### Infrastructure

The infrastructure is divided in two different terraform stacks containing resources which will have different lifecycle:

- [`aks`](terraform/aks/README.md):
- `aks`
- implements an AKS environment
- use terraform workspace to manage multiple environments with their specificities
- [`hub`](terraform/hub/README.md): implements the hub containing cross environment components
- `hub`
- implements the hub containing cross environment components like:
- connectivity with Internet or DC
- eventually a Bastion
- DNS resources

#### Create a spoke AKS environment

[Follow these instruction to create an AKS environment](terraform/aks/README.md)

#### Create the hub

[Follow these instruction to create the hub](terraform/hub/README.md)

## End to end test

Get the public IP of the Application Gateway.
Access the demo app deployed in the dev environment from your host by requesting the public IP of the Application Gateway:

```bash
$ curl -H "Host: dev.linkbynet.com" 20.74.8.233
```

---
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
---

## Conclusion

You have built a first version of an hub and spoke infrastructure for your AKS environements.
Obviously there are still things to add and maybe some things need to be adapted to your specific context, but this is a first basis for work.
Binary file added docs/img/appgw_backend.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/img/archi.drawio
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<mxfile host="Chrome" modified="2021-02-09T09:59:41.412Z" agent="5.0 (Macintosh; Intel Mac OS X 11_2_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.146 Safari/537.36" etag="VXW6PYkiOWR9hrlSnSMn" version="14.2.9" type="device"><diagram id="8IBC5YIdZTFhsr8UUqcM" name="Page-1">7V1Zl6K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8bnnwXEZlu5tfoAX6bLc5NLveoF3b6zX8y6lca6mWisvBdOANfr9CqwXoQYMecgW3z+adIQdPMuSVLKn8QHo16t6OFn4b0trTqvlVrZqfDmYNU/Npx68bnT6pnbXsjVZAhVPbAcqMSO14fe9jPej8OrUdoFyN1A7T6JiTQU8+rR2gfEAvZjJk10sVuFHzuma/UzQHRm3ZNPoTvVoWg++vlsOquRj0KpsW9zweVE1zOHuNcwBqDKrdqRp7cvNHa65V12bzw4Qn8O4rPEXrvbpDrmUNftdc2fvFNUt5GnjsDDrx7xXHWnU0GkAvO50yV598rBrt1Vpu816jMx43Siu6LhUcubRa1TvyoiGpHjq+SK/sK8KX9Ar3o2NYT/pYyBOZq0sBzvz7HZXeHaN6r1Dvw6tLffj+AJ7Fcw3vlxMdgzoFF643qG7jo0zXJyO6Yayi4ypsi6lPyuu6VIYjIGUqw3NeBXQPrt06aIDGhgdZKqPz9UsP+jQpb+RpGb0H47fV3rYFfYLntPmV7D0X4dmrhvThRMewTw68xwK0AwPPXMMzmJeKBdplMB9WV/narLsZlkaT/kSbgJZhZa/gymxrDNqG7nsVs94ZMYBDkGOQ704NyrqThlde/2zvkNAMNBZw/SRz96wh+oBpdM4PTTO5pLePIaxBiYQ5rJjCHJY4euFbdZbB5PULrI6n+5Pgd3efM3gmuhsYsoTou4Q4HLEfPzOZjm50FYk26xXsSTaR6zOXdFtsA1rOzWeV4TkqG7dTk96s2OavIwmuCratbGLVwlnlZcYsGWPkTbYOEXk332X7qVikk7RCENPKUpHg9d7cNpVttETROiES94GS3x2fjeLMuk1SuyzL7e3mC3b3HNwZfapSIDR8vTR3RIjgLq9viPwJRBgufx2IEBpODSJwaVsoQG1XHayssWxpSJWX/w8=</diagram></mxfile>
Binary file added docs/img/archi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/lens.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions docs/tf_azure_authent.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ These values map to the Terraform variables like so:
- password is the client_secret defined above.
- tenant is the tenant_id defined above.

After that, to authenticate with the Terraform Service Principal:

```bash
$ az login --service-principal -u $ARM_CLIENT_ID -p $ARM_CLIENT_SECRET --tenant $ARM_TENANT_ID
```

> You can create your own `env.sh` script at the root of the project. Take example upon the model [env.sh.example](../env.sh.example).
## Add Azure AD permissions
Expand Down
54 changes: 54 additions & 0 deletions scripts/aks_key_pair.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash

VAULT_NAME=hub-and-spoke-vault
KEY_PREFIX=aks
TMP_DIR=./temp

function generate {
echo "generate..."
ssh-keygen -b 4096 \
-t rsa \
-f ${TMP_DIR}/${KEY_PREFIX}-${envCurrent}.rsa \
-N '' \
<<<y 2>&1 >/dev/null
}
function send {
echo "send..."
az keyvault secret set --vault-name $VAULT_NAME \
-n "aks-${envCurrent}-ssh-priv" \
-f "${TMP_DIR}/${KEY_PREFIX}-${envCurrent}.rsa"
az keyvault secret set --vault-name $VAULT_NAME \
-n "aks-${envCurrent}-ssh-pub" \
-f "${TMP_DIR}/${KEY_PREFIX}-${envCurrent}.rsa.pub"
}
function clean {
echo "clean..."
rm -f ${TMP_DIR}/*.rsa*
}

function process {
generate
send
clean
}

# Main
envList=( dev staging prod )
envCurrent=""
if [ ! -z "$1" ]; then
for item in "${envList[@]}"; do
if [ $1 == $item ]; then
echo "Current environment is $1"
envCurrent=$1
process
exit
fi
done
if [ "$envCurrent" == "" ]; then
echo "Environment name incorrect !"
echo "Use a value in the list: ${envList[@]}"
fi
else
echo "You must pass an environment name."
echo "Use a value in the list: ${envList[@]}"
fi
Empty file added scripts/temp/.gitkeep
Empty file.
Loading

0 comments on commit b9e84c2

Please sign in to comment.