Skip to content

Commit c122c3d

Browse files
authored
Merge pull request #1 from cruxstack/dev
feat: add initial project source
2 parents 721eeba + 1ff18fe commit c122c3d

23 files changed

+2374
-22
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ following tools:
3434
1. Clone and open this repository:
3535

3636
```bash
37-
git clone https://github.com/sgtoj/terraform-aws-teleport-cluster.git
37+
git clone https://github.com/cruxstack/terraform-aws-teleport-cluster.git
3838
code terraform-aws-teleport-cluster
3939
```
4040

README.md

Lines changed: 53 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,78 @@
1-
# Terraform Module: AWS Teleport Cluster
1+
# Terraform Module: Teleport Cluster
22

3-
This project is under development. See `dev` branch for latest activity.
3+
This Terraform module deploys a Teleport cluster in high availability (HA)
4+
configuration. [Teleport](https://github.com/gravitational/teleport) is a modern
5+
zero-trust solution by Gravitational.
46

5-
## Prerequisites
7+
### Features
68

7-
- Terraform v0.13.0 or newer
8-
- An AWS account
9+
- **High Availability**: Deploys Teleport in a highly available configuration to
10+
ensure uninterrupted access.
11+
- **Managed Upgrades**: Supports controlled upgrades to new versions of
12+
Teleport.
13+
- **Secure**: Uses AWS Key Management Service (KMS) to secure sensitive data.
14+
- **Scalable**: Can handle growth in your user base and infrastructure without a
15+
corresponding increase in complexity.
16+
- **Integrated**: Works well with your existing infrastructure by following
17+
CloudPosse's context and labeling patterns.
918

1019
## Usage
1120

21+
Deploy it using the block below. For the first time deployments, it make take 10
22+
minutes before the web portal is available.
23+
24+
```hcl
25+
1226
```hcl
1327
module "teleport_cluster" {
1428
source = "cruxstack/teleport-cluster/aws"
1529
version = "x.x.x"
1630
17-
# TBD
31+
teleport_letsencrypt_email = "[email protected]"
32+
teleport_runtime_version = "10.3.15"
33+
dns_parent_zone_id = Z0000000000000000000
34+
dns_parent_zone_name = demo.example.com
35+
vpc_id = "vpc-00000000000000"
36+
vpc_subnet_ids = ["subnet-00000000000000", "subnet-11111111111111111", "subnet-22222222222222222"]
37+
vpc_public_subnet_ids = ["subnet-33333333333333", "subnet-44444444444444444", "subnet-55555555555555555"]
38+
teleport_setup_mode = false
1839
}
1940
```
2041

21-
## Requirements
22-
23-
- Terraform 0.13.0 or later
24-
- AWS provider
25-
2642
## Inputs
2743

2844
In addition to the variables documented below, this module includes several
2945
other optional variables (e.g., `name`, `tags`, etc.) provided by the
3046
`cloudposse/label/null` module. Please refer to the [`cloudposse/label` documentation](https://registry.terraform.io/modules/cloudposse/label/null/latest) for more details on these variables.
3147

32-
| Name | Description | Type | Default | Required |
33-
|-------------|-------------|:------:|:-------:|:--------:|
34-
| `placehold` | N/A | string | null | No |
48+
| Name | Description | Type | Default | Required |
49+
|------------------------------|-------------------------------------------------------------------------------------------------------------------|----------------|---------|:--------:|
50+
| `teleport_runtime_version` | The runtime version of Teleport. | `string` | n/a | yes |
51+
| `teleport_letsencrypt_email` | The email address to use for Let's Encrypt. | `string` | n/a | yes |
52+
| `teleport_setup_mode` | Toggle Teleport setup mode. | `bool` | `true` | no |
53+
| `teleport_experimental_mode` | Toggle Teleport experimental mode. | `bool` | `false` | no |
54+
| `instance_config` | Configuration for the instances. Each type (`auth`, `node`, `proxy`) contains an object with `count` and `sizes`. | `object` | `{}` | no |
55+
| `artifacts_bucket_name` | The name of the S3 bucket for artifacts. | `string` | `""` | no |
56+
| `logs_bucket_name` | The name of the S3 bucket for logs. | `string` | `""` | no |
57+
| `dns_parent_zone_id` | The ID of the parent DNS zone. | `string` | n/a | yes |
58+
| `dns_parent_zone_name` | The name of the parent DNS zone. | `string` | n/a | yes |
59+
| `vpc_id` | The ID of the VPC to deploy resources into. | `string` | n/a | yes |
60+
| `vpc_private_subnet_ids` | The IDs of the private subnets in the VPC to deploy resources into. | `list(string)` | n/a | yes |
61+
| `vpc_public_subnet_ids` | The IDs of the public subnets in the VPC to deploy resources into. | `list(string)` | n/a | yes |
62+
| `aws_region_name` | The name of the AWS region. | `string` | `""` | no |
63+
| `aws_account_id` | The ID of the AWS account. | `string` | `""` | no |
64+
| `aws_kv_namespace` | The namespace or prefix for AWS SSM parameters and similar resources. | `string` | `""` | no |
3565

36-
## Outputs
66+
### Outputs
3767

38-
| Name | Description |
39-
|-------------|-------------|
40-
| `placehold` | N/A |
68+
| Name | Description |
69+
|-------------------------|------------------------------------------------------------------|
70+
| `teleport_dns_name` | The DNS name of the Teleport service. |
71+
| `teleport_auth_config` | The configuration details for the Teleport auth service. |
72+
| `teleport_node_config` | The configuration details for the Teleport node service. |
73+
| `teleport_proxy_config` | The configuration details for the Teleport proxy service. |
74+
| `security_group_id` | The ID of the security group created for the Teleport service. |
75+
| `security_group_name` | The name of the security group created for the Teleport service. |
4176

4277
## Contributing
4378

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
# shellcheck disable=SC1091
3+
set -e -x
4+
5+
source "/etc/teleport.d/conf"
6+
7+
# copy certificates into place
8+
/bin/aws s3 sync "s3://${TELEPORT_S3_BUCKET}/live/${TELEPORT_DOMAIN_NAME}" /var/lib/teleport
9+
10+
# disable influxdb
11+
systemctl stop telegraf
12+
systemctl stop influxdb
13+
systemctl disable telegraf
14+
systemctl disable influxdb
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/bash
2+
# shellcheck disable=SC1091,SC2002
3+
set -e -o pipefail
4+
5+
TELEPORT_CONFIG_TEMPLATE_PATH=/etc/teleport.d/teleport.tmpl.yaml
6+
TELEPORT_CONFIG_PATH=/etc/teleport.yaml
7+
8+
# ================================================================= function ===
9+
10+
get_aws_metadata() {
11+
REQUEST_PATH="${1}"
12+
IMDS_TOKEN=$(curl -m5 -sS -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 300")
13+
curl -m5 -sS -H "\"X-aws-ec2-metadata-token: ${IMDS_TOKEN}\"" "http://169.254.169.254/latest/${REQUEST_PATH}" 2>/dev/null
14+
}
15+
16+
# =================================================================== script ===
17+
18+
# ------------------------------------------------------------------- config ---
19+
20+
if getent passwd teleport >/dev/null 2>&1 && getent group adm >/dev/null 2>&1; then
21+
if [ ! -d /var/lib/teleport ]; then
22+
mkdir -p /var/lib/teleport
23+
fi
24+
chown -R teleport:adm /var/lib/teleport
25+
fi
26+
27+
source "/etc/teleport.d/conf"
28+
29+
echo "${TELEPORT_ROLE}" >> "/etc/teleport.d/role.${TELEPORT_ROLE}"
30+
31+
INSTANCE_HOSTNAME=$(get_aws_metadata "meta-data/local-hostname")
32+
INSTANCE_PRIVATE_IP=$(get_aws_metadata "meta-data/local-ipv4")
33+
34+
export TELEPORT_NODENAME=${INSTANCE_HOSTNAME}
35+
export TELEPORT_ADVERTISE_IP=${INSTANCE_PRIVATE_IP}
36+
37+
cat "$TELEPORT_CONFIG_TEMPLATE_PATH" | envsubst > "${TELEPORT_CONFIG_PATH}"
38+
39+
chmod 664 "${TELEPORT_CONFIG_PATH}"
40+
if getent passwd teleport >/dev/null 2>&1 && getent group adm >/dev/null 2>&1; then
41+
chown teleport:adm ${TELEPORT_CONFIG_PATH}
42+
fi
43+
44+
# ----------------------------------------------------------------- services ---
45+
46+
if [[ "${TELEPORT_ROLE}" == "auth" ]]; then
47+
48+
systemctl enable teleport-ssm-publish-tokens.service teleport-ssm-publish-tokens.timer
49+
systemctl start teleport-ssm-publish-tokens.timer
50+
51+
systemctl enable teleport-get-cert.service teleport-get-cert.timer
52+
systemctl enable teleport-renew-cert.service teleport-renew-cert.timer
53+
systemctl start --no-block teleport-get-cert.timer
54+
systemctl start --no-block teleport-renew-cert.timer
55+
56+
systemctl disable teleport.service
57+
systemctl enable teleport-auth.service
58+
systemctl start --no-block teleport-auth.service
59+
60+
elif [[ "${TELEPORT_ROLE}" == "proxy" ]]; then
61+
62+
systemctl enable teleport-check-cert.service teleport-check-cert.timer
63+
systemctl start --no-block teleport-check-cert.timer
64+
65+
systemctl disable teleport.service
66+
systemctl enable teleport-proxy.service
67+
systemctl start --no-block teleport-proxy.service
68+
69+
elif [[ "${TELEPORT_ROLE}" == "node" ]]; then
70+
71+
systemctl disable teleport.service
72+
systemctl enable teleport-node.service
73+
systemctl start --no-block teleport-node.service
74+
75+
fi
76+
77+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
# shellcheck disable=SC1091,SC2002
3+
set -e -o pipefail
4+
5+
source /etc/teleport.d/conf
6+
7+
TCTL=/usr/local/bin/tctl
8+
9+
PROXY_TOKEN=$(uuid -v4)
10+
${TCTL} nodes add --roles=proxy --ttl=4h --token="${PROXY_TOKEN}"
11+
aws ssm put-parameter --name "/teleport/${TELEPORT_CLUSTER_NAME}/tokens/proxy" --region "${EC2_REGION}" --type="SecureString" --value="${PROXY_TOKEN}" --overwrite
12+
13+
NODE_TOKEN=$(uuid -v4)
14+
${TCTL} nodes add --roles=node,app,db --ttl=4h --token="${NODE_TOKEN}"
15+
aws ssm put-parameter --name "/teleport/${TELEPORT_CLUSTER_NAME}/tokens/node" --region "${EC2_REGION}" --type="SecureString" --value="${NODE_TOKEN}" --overwrite
16+
17+
KUBE_TOKEN=$(uuid -v4)
18+
${TCTL} nodes add --roles=kube --ttl=4h --token="${KUBE_TOKEN}"
19+
aws ssm put-parameter --name "/teleport/${TELEPORT_CLUSTER_NAME}/tokens/kube" --region "${EC2_REGION}" --type="SecureString" --value="${KUBE_TOKEN}" --overwrite
20+
21+
APP_TOKEN=$(uuid -v4)
22+
${TCTL} nodes add --roles=app --ttl=4h --token="${APP_TOKEN}"
23+
aws ssm put-parameter --name "/teleport/${TELEPORT_CLUSTER_NAME}/tokens/app" --region "${EC2_REGION}" --type="SecureString" --value="${APP_TOKEN}" --overwrite
24+
25+
DATABASE_TOKEN=$(uuid -v4)
26+
${TCTL} nodes add --roles=db --ttl=4h --token="${DATABASE_TOKEN}"
27+
aws ssm put-parameter --name "/teleport/${TELEPORT_CLUSTER_NAME}/tokens/db" --region "${EC2_REGION}" --type="SecureString" --value="${DATABASE_TOKEN}" --overwrite
28+
29+
CA_PIN_HASH=$(tctl status | grep "CA pin" | awk '{print $3}')
30+
aws ssm put-parameter --name "/teleport/${TELEPORT_CLUSTER_NAME}/ca-pin-hash" --region "${EC2_REGION}" --type="String" --value="${CA_PIN_HASH}" --overwrite

examples/complete/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,45 @@
11
# Example: Complete
2+
3+
This directory contains a complete example of how to use the Teleport Cluster
4+
Terraform module in a real-world scenario.
5+
6+
## Overview
7+
8+
This example deploys a Teleport cluster with the following configuration:
9+
10+
- Teleport auth, node, and proxy services deployed in a high-availability (HA)
11+
configuration.
12+
- Deployment into a specified AWS VPC and subnets.
13+
14+
## Usage
15+
16+
To run this example, provide your own values for the following variables in a
17+
`.terraform.tfvars` file:
18+
19+
```hcl
20+
teleport_letsencrypt_email = "[email protected]"
21+
dns_parent_zone_id = "your-dns-zone-id"
22+
dns_parent_zone_name = "your-dns-zone-name"
23+
vpc_id = "your-vpc-id"
24+
vpc_private_subnet_ids = ["your-private-subnet-id"]
25+
vpc_public_subnet_ids = ["your-public-subnet-id"]
26+
```
27+
28+
## Inputs
29+
30+
| Name | Description | Type | Default | Required |
31+
|----------------------------|---------------------------------------------------------------------|----------------|---------|:--------:|
32+
| teleport_letsencrypt_email | The email address to use for Let's Encrypt. | `string` | n/a | yes |
33+
| dns_parent_zone_id | The ID of the parent DNS zone. | `string` | n/a | yes |
34+
| dns_parent_zone_name | The name of the parent DNS zone. | `string` | n/a | yes |
35+
| vpc_id | The ID of the VPC to deploy resources into. | `string` | n/a | yes |
36+
| vpc_private_subnet_ids | The IDs of the private subnets in the VPC to deploy resources into. | `list(string)` | n/a | yes |
37+
| vpc_public_subnet_ids | The IDs of the public subnets in the VPC to deploy resources into. | `list(string)` | n/a | yes |
38+
39+
## Outputs
40+
41+
| Name | Description |
42+
|-------------------------|---------------------------------------|
43+
| teleport_dns_name | The DNS name of the Teleport service. |
44+
| teleport_web_portal_url | The URL of the Teleport web portal. |
45+
```

examples/complete/main.tf

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
locals {}
2+
3+
# ================================================================== example ===
4+
5+
module "teleport_cluster" {
6+
source = "../.."
7+
8+
teleport_experimental_mode = true
9+
teleport_letsencrypt_email = var.teleport_letsencrypt_email
10+
teleport_runtime_version = var.teleport_runtime_version
11+
dns_parent_zone_id = var.dns_parent_zone_id
12+
dns_parent_zone_name = var.dns_parent_zone_name
13+
vpc_id = var.vpc_id
14+
vpc_private_subnet_ids = var.vpc_private_subnet_ids
15+
vpc_public_subnet_ids = var.vpc_public_subnet_ids
16+
teleport_setup_mode = false
17+
18+
context = module.example_label.context # not required
19+
}
20+
21+
# ===================================================== supporting-resources ===
22+
23+
module "example_label" {
24+
source = "cloudposse/label/null"
25+
version = "0.25.0"
26+
27+
name = "tf-example-complete-${random_string.example_random_suffix.result}"
28+
environment = "use1" # us-east-1
29+
}
30+
31+
resource "random_string" "example_random_suffix" {
32+
length = 6
33+
special = false
34+
upper = false
35+
}

examples/complete/output.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
output "teleport_dns_name" {
2+
value = module.teleport_cluster.teleport_dns_name
3+
description = "The DNS name of the Teleport service."
4+
}
5+
6+
output "teleport_web_portal_url" {
7+
value = "https://${module.teleport_cluster.teleport_dns_name}/web"
8+
description = "The URL of the Teleport web portal."
9+
}

examples/complete/variables.tf

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
variable "teleport_runtime_version" {
2+
type = string
3+
description = "The runtime version of Teleport."
4+
default = "10.3.15"
5+
}
6+
7+
variable "teleport_letsencrypt_email" {
8+
type = string
9+
description = "The email address to use for Let's Encrypt."
10+
}
11+
12+
variable "dns_parent_zone_id" {
13+
type = string
14+
description = "The ID of the parent DNS zone."
15+
}
16+
17+
variable "dns_parent_zone_name" {
18+
type = string
19+
description = "The name of the parent DNS zone."
20+
}
21+
22+
variable "vpc_id" {
23+
type = string
24+
description = "The ID of the VPC to deploy resources into."
25+
}
26+
27+
variable "vpc_private_subnet_ids" {
28+
type = list(string)
29+
description = "The IDs of the private subnets in the VPC to deploy resources into."
30+
}
31+
32+
variable "vpc_public_subnet_ids" {
33+
type = list(string)
34+
description = "The IDs of the public subnets in the VPC to deploy resources into."
35+
}

0 commit comments

Comments
 (0)