-
Notifications
You must be signed in to change notification settings - Fork 2
/
tls.ts
120 lines (107 loc) · 2.72 KB
/
tls.ts
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
import * as gcp from '@pulumi/gcp';
import * as tls from '@pulumi/tls';
import * as provisioner from './provisioners';
interface TlsArgs {
loadBalancerIp: gcp.compute.Address;
}
/**
* Generate self-signed TLS certificates.
*/
export default function createTls(
args: TlsArgs
): {
selfSignedCa: tls.SelfSignedCert;
serverCa: tls.PrivateKey;
locallySignedCert: tls.LocallySignedCert;
} {
const ca = new tls.PrivateKey(
'vault-ca',
{
algorithm: 'RSA',
ecdsaCurve: '2048',
},
{
additionalSecretOutputs: ['privateKeyPem'],
}
);
const selfSignedCa = new tls.SelfSignedCert('vault-ca', {
keyAlgorithm: ca.algorithm,
privateKeyPem: ca.privateKeyPem,
subjects: [
{
commonName: 'vault-ca.local',
organization: 'HashiCorp Vault',
},
],
validityPeriodHours: 8760,
isCaCertificate: true,
allowedUses: ['cert_signing', 'digital_signature', 'key_encipherment'],
});
((): provisioner.SaveToFile =>
new provisioner.SaveToFile(
'vault-ca-stf',
{
path: './tls/vault-ca.pem',
content: selfSignedCa.certPem,
permission: '0600',
},
{ dependsOn: selfSignedCa }
))();
const serverCa = new tls.PrivateKey(
'vault-server',
{
algorithm: 'RSA',
ecdsaCurve: '2048',
},
{
additionalSecretOutputs: ['privateKeyPem'],
}
);
const certRequest = new tls.CertRequest('vault', {
keyAlgorithm: serverCa.algorithm,
privateKeyPem: serverCa.privateKeyPem,
subjects: [
{
commonName: 'vault.local',
organization: 'HashiCorp Vault',
},
],
dnsNames: ['vault', 'vault.local', 'vault.default.svc.cluster.local'],
ipAddresses: [args.loadBalancerIp.address],
});
const locallySignedCert = new tls.LocallySignedCert('vault', {
certRequestPem: certRequest.certRequestPem,
caKeyAlgorithm: ca.algorithm,
caPrivateKeyPem: ca.privateKeyPem,
caCertPem: selfSignedCa.certPem,
validityPeriodHours: 8760,
allowedUses: [
'cert_signing',
'client_auth',
'digital_signature',
'key_encipherment',
'server_auth',
],
});
((): provisioner.SaveToFile =>
new provisioner.SaveToFile(
'vault-signed-cert-stf',
{
path: './tls/vault.pem',
content: locallySignedCert.certPem,
},
{ dependsOn: locallySignedCert }
))();
((): provisioner.SaveToFile =>
new provisioner.SaveToFile(
'vault-self-signed-ca-stf',
{
path: './tls/vault.pem',
content: selfSignedCa.certPem,
append: true,
permission: '0600',
},
{ dependsOn: locallySignedCert }
))();
return { selfSignedCa, serverCa, locallySignedCert };
}