|
| 1 | +# Safer Cluster Access with IAP Bastion Host |
| 2 | + |
| 3 | +This end to end example aims to showcase access patterns to a [Safer Cluster](../../modules/safer-cluster/README.md), which is a hardened GKE Private Cluster, through a bastion host utilizing [Identity Awareness Proxy](https://cloud.google.com/iap/) without an external ip address. Access to this cluster's control plane is restricted to the bastion host's internal IP using [authorized networks](https://cloud.google.com/kubernetes-engine/docs/how-to/authorized-networks#overview). |
| 4 | + |
| 5 | +Additionally we deploy a [tinyproxy](https://tinyproxy.github.io/) daemon which allows `kubectl` commands to be piped through the bastion host allowing ease of development from a local machine with the security of GKE Private Clusters. |
| 6 | + |
| 7 | +## Setup |
| 8 | + |
| 9 | +To deploy this example: |
| 10 | + |
| 11 | +1. Run `terraform init`. |
| 12 | + |
| 13 | +2. Create a `terraform.tfvars` to provide values for `project_id`, `bastion_members`. Optionally override any variables if necessary. |
| 14 | + |
| 15 | +3. Run `terraform apply`. |
| 16 | + |
| 17 | +4. After apply is complete, generate kubeconfig for the private cluster. _The command with the right parameters will displayed as the Terraform output `get_credentials_command`._ |
| 18 | + |
| 19 | + ```sh |
| 20 | + gcloud container clusters get-credentials --project $PROJECT_ID --zone $ZONE --internal-ip $CLUSTER_NAME |
| 21 | + ``` |
| 22 | + |
| 23 | +5. SSH to the Bastion Host while port forwarding to the bastion host through an IAP tunnel. _The command with the right parameters will displayed by running `terraform output bastion_ssh_command`._ |
| 24 | + |
| 25 | + ```sh |
| 26 | + gcloud beta compute ssh $BASTION_VM_NAME --tunnel-through-iap --project $PROJECT_ID --zone $ZONE -- -L8888:127.0.0.1:8888 |
| 27 | + ``` |
| 28 | + |
| 29 | +6. You can now run `kubectl` commands though the proxy. _An example command will displayed as the Terraform output `bastion_kubectl_command`._ |
| 30 | + |
| 31 | + ```sh |
| 32 | + HTTPS_PROXY=localhost:8888 kubectl get pods --all-namespaces |
| 33 | + ``` |
| 34 | + |
| 35 | + <!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> |
| 36 | +## Inputs |
| 37 | + |
| 38 | +| Name | Description | Type | Default | Required | |
| 39 | +|------|-------------|:----:|:-----:|:-----:| |
| 40 | +| bastion\_members | List of users, groups, SAs who need access to the bastion host | list(string) | `<list>` | no | |
| 41 | +| cluster\_name | The name of the cluster | string | `"safer-cluster-iap-bastion"` | no | |
| 42 | +| ip\_range\_pods\_name | The secondary ip range to use for pods | string | `"ip-range-pods"` | no | |
| 43 | +| ip\_range\_services\_name | The secondary ip range to use for pods | string | `"ip-range-svc"` | no | |
| 44 | +| ip\_source\_ranges\_ssh | Additional source ranges to allow for ssh to bastion host. 35.235.240.0/20 allowed by default for IAP tunnel. | list(string) | `<list>` | no | |
| 45 | +| network\_name | The name of the network being created to host the cluster in | string | `"safer-cluster-network"` | no | |
| 46 | +| project\_id | The project ID to host the cluster in | string | n/a | yes | |
| 47 | +| region | The region to host the cluster in | string | `"us-central1"` | no | |
| 48 | +| subnet\_ip | The cidr range of the subnet | string | `"10.10.10.0/24"` | no | |
| 49 | +| subnet\_name | The name of the subnet being created to host the cluster in | string | `"safer-cluster-subnet"` | no | |
| 50 | + |
| 51 | +## Outputs |
| 52 | + |
| 53 | +| Name | Description | |
| 54 | +|------|-------------| |
| 55 | +| bastion\_kubectl\_command | kubectl command using the local proxy once the bastion_ssh command is running | |
| 56 | +| bastion\_name | Name of the bastion host | |
| 57 | +| bastion\_ssh\_command | gcloud command to ssh and port forward to the bastion host command | |
| 58 | +| bastion\_zone | Location of bastion host | |
| 59 | +| ca\_certificate | Cluster ca certificate (base64 encoded) | |
| 60 | +| cluster\_name | Cluster name | |
| 61 | +| endpoint | Cluster endpoint | |
| 62 | +| get\_credentials\_command | gcloud get-credentials command to generate kubeconfig for the private cluster | |
| 63 | +| location | Cluster location (region if regional cluster, zone if zonal cluster) | |
| 64 | +| master\_authorized\_networks\_config | Networks from which access to master is permitted | |
| 65 | +| network\_name | The name of the VPC being created | |
| 66 | +| region | Subnet/Router/Bastion Host region | |
| 67 | +| router\_name | Name of the router that was created | |
| 68 | +| subnet\_name | The name of the VPC subnet being created | |
| 69 | + |
| 70 | + <!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> |
0 commit comments