Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/install/installer/pkg/components/public-api-server/configmap.go
2501 views
1
// Copyright (c) 2021 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package public_api_server
6
7
import (
8
"fmt"
9
10
"github.com/gitpod-io/gitpod/installer/pkg/config/v1/experimental"
11
"k8s.io/utils/pointer"
12
13
"github.com/gitpod-io/gitpod/common-go/baseserver"
14
"github.com/gitpod-io/gitpod/components/public-api/go/config"
15
16
"github.com/gitpod-io/gitpod/installer/pkg/common"
17
"github.com/gitpod-io/gitpod/installer/pkg/components/auth"
18
"github.com/gitpod-io/gitpod/installer/pkg/components/redis"
19
"github.com/gitpod-io/gitpod/installer/pkg/components/server"
20
"github.com/gitpod-io/gitpod/installer/pkg/components/usage"
21
corev1 "k8s.io/api/core/v1"
22
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23
"k8s.io/apimachinery/pkg/runtime"
24
)
25
26
const (
27
configJSONFilename = "config.json"
28
)
29
30
func configmap(ctx *common.RenderContext) ([]runtime.Object, error) {
31
var stripeSecretPath string
32
var personalAccessTokenSigningKeyPath string
33
34
publicUrl := fmt.Sprintf("https://services.%s", ctx.Config.Domain)
35
36
_ = ctx.WithExperimental(func(cfg *experimental.Config) error {
37
_, _, stripeSecretPath, _ = getStripeConfig(cfg)
38
return nil
39
})
40
41
_ = ctx.WithExperimental(func(cfg *experimental.Config) error {
42
_, _, personalAccessTokenSigningKeyPath, _ = getPersonalAccessTokenSigningKey(cfg)
43
return nil
44
})
45
46
_ = ctx.WithExperimental(func(cfg *experimental.Config) error {
47
if cfg.WebApp != nil && cfg.WebApp.PublicURL != "" {
48
publicUrl = cfg.WebApp.PublicURL
49
}
50
return nil
51
})
52
53
_, _, databaseSecretMountPath := common.DatabaseEnvSecret(ctx.Config)
54
55
_, _, authCfg := auth.GetConfig(ctx)
56
redisCfg := redis.GetConfiguration(ctx)
57
58
cfg := config.Configuration{
59
PublicURL: publicUrl,
60
GitpodServiceURL: common.ClusterURL("ws", server.Component, ctx.Namespace, server.ContainerPort),
61
StripeWebhookSigningSecretPath: stripeSecretPath,
62
PersonalAccessTokenSigningKeyPath: personalAccessTokenSigningKeyPath,
63
BillingServiceAddress: common.ClusterAddress(usage.Component, ctx.Namespace, usage.GRPCServicePort),
64
SessionServiceAddress: common.ClusterAddress(common.ServerComponent, ctx.Namespace, common.ServerIAMSessionPort),
65
DatabaseConfigPath: databaseSecretMountPath,
66
Redis: config.RedisConfiguration{
67
Address: redisCfg.Address,
68
},
69
Auth: config.AuthConfiguration{
70
PKI: config.AuthPKIConfiguration{
71
Signing: config.KeyPair{
72
ID: authCfg.PKI.Signing.ID,
73
PublicKeyPath: authCfg.PKI.Signing.PublicKeyPath,
74
PrivateKeyPath: authCfg.PKI.Signing.PrivateKeyPath,
75
},
76
},
77
Session: config.SessionConfig{
78
LifetimeSeconds: authCfg.Session.LifetimeSeconds,
79
Issuer: authCfg.Session.Issuer,
80
Cookie: config.CookieConfig{
81
Name: authCfg.Session.Cookie.Name,
82
MaxAge: authCfg.Session.Cookie.MaxAge,
83
SameSite: authCfg.Session.Cookie.SameSite,
84
Secure: authCfg.Session.Cookie.Secure,
85
HTTPOnly: authCfg.Session.Cookie.HTTPOnly,
86
},
87
},
88
},
89
Server: &baseserver.Configuration{
90
Services: baseserver.ServicesConfiguration{
91
GRPC: &baseserver.ServerConfiguration{
92
Address: fmt.Sprintf("0.0.0.0:%d", GRPCContainerPort),
93
},
94
HTTP: &baseserver.ServerConfiguration{
95
Address: fmt.Sprintf("0.0.0.0:%d", HTTPContainerPort),
96
},
97
},
98
},
99
}
100
101
fc, err := common.ToJSONString(cfg)
102
if err != nil {
103
return nil, fmt.Errorf("failed to marshal config: %w", err)
104
}
105
106
return []runtime.Object{
107
&corev1.ConfigMap{
108
TypeMeta: common.TypeMetaConfigmap,
109
ObjectMeta: metav1.ObjectMeta{
110
Name: Component,
111
Namespace: ctx.Namespace,
112
Labels: common.CustomizeLabel(ctx, Component, common.TypeMetaConfigmap),
113
Annotations: common.CustomizeAnnotation(ctx, Component, common.TypeMetaConfigmap),
114
},
115
Data: map[string]string{
116
configJSONFilename: string(fc),
117
},
118
},
119
}, nil
120
}
121
122
func getStripeConfig(cfg *experimental.Config) (corev1.Volume, corev1.VolumeMount, string, bool) {
123
var volume corev1.Volume
124
var mount corev1.VolumeMount
125
var path string
126
127
if cfg == nil || cfg.WebApp == nil || cfg.WebApp.PublicAPI == nil || cfg.WebApp.PublicAPI.StripeSecretName == "" {
128
return volume, mount, path, false
129
}
130
131
stripeSecret := cfg.WebApp.PublicAPI.StripeSecretName
132
path = stripeSecretMountPath
133
134
volume = corev1.Volume{
135
Name: "stripe-secret",
136
VolumeSource: corev1.VolumeSource{
137
Secret: &corev1.SecretVolumeSource{
138
SecretName: stripeSecret,
139
Optional: pointer.Bool(true),
140
},
141
},
142
}
143
144
mount = corev1.VolumeMount{
145
Name: "stripe-secret",
146
MountPath: stripeSecretMountPath,
147
SubPath: "stripe-webhook-secret",
148
ReadOnly: true,
149
}
150
151
return volume, mount, path, true
152
}
153
154
func getPersonalAccessTokenSigningKey(cfg *experimental.Config) (corev1.Volume, corev1.VolumeMount, string, bool) {
155
var volume corev1.Volume
156
var mount corev1.VolumeMount
157
var path string
158
159
if cfg == nil || cfg.WebApp == nil || cfg.WebApp.PublicAPI == nil || cfg.WebApp.PublicAPI.PersonalAccessTokenSigningKeySecretName == "" {
160
return volume, mount, path, false
161
}
162
163
personalAccessTokenSecretname := cfg.WebApp.PublicAPI.PersonalAccessTokenSigningKeySecretName
164
path = personalAccessTokenSigningKeyMountPath
165
166
volume = corev1.Volume{
167
Name: "personal-access-token-signing-key",
168
VolumeSource: corev1.VolumeSource{
169
Secret: &corev1.SecretVolumeSource{
170
SecretName: personalAccessTokenSecretname,
171
Optional: pointer.Bool(true),
172
},
173
},
174
}
175
176
mount = corev1.VolumeMount{
177
Name: "personal-access-token-signing-key",
178
MountPath: personalAccessTokenSigningKeyMountPath,
179
SubPath: "personal-access-token-signing-key",
180
ReadOnly: true,
181
}
182
183
return volume, mount, path, true
184
}
185
186