This repository has been archived by the owner on Feb 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 266
/
tls_etcd.tf
173 lines (129 loc) · 4.48 KB
/
tls_etcd.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// root CA
resource "tls_private_key" "etcd-ca" {
count = "${var.experimental_enabled || var.etcd_tls_enabled ? 1 : 0}"
algorithm = "RSA"
rsa_bits = "2048"
}
resource "tls_self_signed_cert" "etcd-ca" {
count = "${var.experimental_enabled || var.etcd_tls_enabled ? 1 : 0}"
key_algorithm = "${tls_private_key.etcd-ca.algorithm}"
private_key_pem = "${tls_private_key.etcd-ca.private_key_pem}"
subject {
common_name = "etcd-ca"
organization = "etcd"
}
is_ca_certificate = true
validity_period_hours = 8760
allowed_uses = [
"key_encipherment",
"digital_signature",
"cert_signing",
]
}
// (etcd) server keys
// These are used for etcd-to-etcd member communcation
resource "tls_private_key" "etcd_server" {
count = "${var.experimental_enabled || var.etcd_tls_enabled ? 1 : 0}"
algorithm = "RSA"
rsa_bits = "2048"
}
resource "tls_cert_request" "etcd_server" {
count = "${var.experimental_enabled || var.etcd_tls_enabled ? 1 : 0}"
key_algorithm = "${tls_private_key.etcd_server.algorithm}"
private_key_pem = "${tls_private_key.etcd_server.private_key_pem}"
subject {
common_name = "etcd"
organization = "etcd"
}
dns_names = "${concat(
var.etcd_cert_dns_names,
list(
"localhost",
"*.kube-etcd.kube-system.svc.cluster.local",
"kube-etcd-client.kube-system.svc.cluster.local",
))}"
ip_addresses = [
"127.0.0.1",
"${cidrhost(var.service_cidr, 15)}",
"${cidrhost(var.service_cidr, 20)}",
]
}
resource "tls_locally_signed_cert" "etcd_server" {
count = "${var.experimental_enabled || var.etcd_tls_enabled ? 1 : 0}"
cert_request_pem = "${tls_cert_request.etcd_server.cert_request_pem}"
ca_key_algorithm = "${join(" ", tls_self_signed_cert.etcd-ca.*.key_algorithm)}"
ca_private_key_pem = "${join(" ", tls_private_key.etcd-ca.*.private_key_pem)}"
ca_cert_pem = "${join(" ", tls_self_signed_cert.etcd-ca.*.cert_pem)}"
validity_period_hours = 8760
allowed_uses = [
"key_encipherment",
"server_auth",
]
}
// client keys
// These are used for "api server"-to-etcd and "etcd operator"-to-etcd client communication
resource "tls_private_key" "etcd_client" {
count = "${var.experimental_enabled || var.etcd_tls_enabled ? 1 : 0}"
algorithm = "RSA"
rsa_bits = "2048"
}
resource "tls_cert_request" "etcd_client" {
count = "${var.experimental_enabled || var.etcd_tls_enabled ? 1 : 0}"
key_algorithm = "${tls_private_key.etcd_client.algorithm}"
private_key_pem = "${tls_private_key.etcd_client.private_key_pem}"
subject {
common_name = "etcd"
organization = "etcd"
}
}
resource "tls_locally_signed_cert" "etcd_client" {
count = "${var.experimental_enabled || var.etcd_tls_enabled ? 1 : 0}"
cert_request_pem = "${tls_cert_request.etcd_client.cert_request_pem}"
ca_key_algorithm = "${join(" ", tls_self_signed_cert.etcd-ca.*.key_algorithm)}"
ca_private_key_pem = "${join(" ", tls_private_key.etcd-ca.*.private_key_pem)}"
ca_cert_pem = "${join(" ", tls_self_signed_cert.etcd-ca.*.cert_pem)}"
validity_period_hours = 8760
allowed_uses = [
"key_encipherment",
"client_auth",
]
}
// peer keys
// These are used for etcd-to-etcd member communcation
resource "tls_private_key" "etcd_peer" {
count = "${var.experimental_enabled || var.etcd_tls_enabled ? 1 : 0}"
algorithm = "RSA"
rsa_bits = "2048"
}
resource "tls_cert_request" "etcd_peer" {
count = "${var.experimental_enabled || var.etcd_tls_enabled ? 1 : 0}"
key_algorithm = "${tls_private_key.etcd_peer.algorithm}"
private_key_pem = "${tls_private_key.etcd_peer.private_key_pem}"
subject {
common_name = "etcd"
organization = "etcd"
}
dns_names = "${concat(
var.etcd_cert_dns_names,
list(
"*.kube-etcd.kube-system.svc.cluster.local",
"kube-etcd-client.kube-system.svc.cluster.local",
))}"
ip_addresses = [
"${cidrhost(var.service_cidr, 15)}",
"${cidrhost(var.service_cidr, 20)}",
]
}
resource "tls_locally_signed_cert" "etcd_peer" {
count = "${var.experimental_enabled || var.etcd_tls_enabled ? 1 : 0}"
cert_request_pem = "${tls_cert_request.etcd_peer.cert_request_pem}"
ca_key_algorithm = "${join(" ", tls_self_signed_cert.etcd-ca.*.key_algorithm)}"
ca_private_key_pem = "${join(" ", tls_private_key.etcd-ca.*.private_key_pem)}"
ca_cert_pem = "${join(" ", tls_self_signed_cert.etcd-ca.*.cert_pem)}"
validity_period_hours = 8760
allowed_uses = [
"key_encipherment",
"server_auth",
"client_auth",
]
}