Skip to content

Commit c8f22f7

Browse files
authored
[server] Load auth-pki into server config (#17214)
1 parent 92331d9 commit c8f22f7

File tree

6 files changed

+142
-26
lines changed

6 files changed

+142
-26
lines changed

components/server/src/config.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export type Config = Omit<
2929
| "linkedInSecretsFile"
3030
| "licenseFile"
3131
| "patSigningKeyFile"
32+
| "auth"
3233
> & {
3334
hostUrl: GitpodHostUrl;
3435
workspaceDefaults: WorkspaceDefaults;
@@ -44,6 +45,20 @@ export type Config = Omit<
4445
// Absolute file path pointing to a file which contains admin credentials, encoded as JSON.
4546
credentialsPath: string;
4647
};
48+
49+
auth: {
50+
// Public/Private key for signing authenticated sessions
51+
pki: {
52+
signing: {
53+
privateKey: string;
54+
publicKey: string;
55+
};
56+
validating: {
57+
privateKey: string;
58+
publicKey: string;
59+
}[];
60+
};
61+
};
4762
};
4863

4964
export interface WorkspaceDefaults {
@@ -244,6 +259,20 @@ export interface ConfigSerialized {
244259
* This is the same signing key used by Public API
245260
*/
246261
patSigningKeyFile?: string;
262+
263+
auth: {
264+
pki: AuthPKIConfig;
265+
};
266+
}
267+
268+
export interface AuthPKIConfig {
269+
signing: KeyPair;
270+
validating?: KeyPair[];
271+
}
272+
273+
export interface KeyPair {
274+
publicKeyPath: string;
275+
privateKeyPath: string;
247276
}
248277

249278
export namespace ConfigFile {
@@ -346,6 +375,18 @@ export namespace ConfigFile {
346375
}
347376
}
348377

378+
const authPKI: Config["auth"]["pki"] = {
379+
signing: {
380+
privateKey: fs.readFileSync(filePathTelepresenceAware(config.auth.pki.signing.privateKeyPath), "utf-8"),
381+
publicKey: fs.readFileSync(filePathTelepresenceAware(config.auth.pki.signing.publicKeyPath), "utf-8"),
382+
},
383+
validating:
384+
config.auth.pki.validating?.map((keypair) => ({
385+
privateKey: fs.readFileSync(filePathTelepresenceAware(keypair.privateKeyPath), "utf-8"),
386+
publicKey: fs.readFileSync(filePathTelepresenceAware(keypair.publicKeyPath), "utf-8"),
387+
})) || [],
388+
};
389+
349390
return {
350391
...config,
351392
hostUrl,
@@ -368,6 +409,9 @@ export namespace ConfigFile {
368409
...config.admin,
369410
credentialsPath: config.admin.credentialsPath,
370411
},
412+
auth: {
413+
pki: authPKI,
414+
},
371415
};
372416
}
373417
}

install/installer/pkg/components/server/authpki.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ package server
77
import (
88
"fmt"
99
"math"
10+
"path"
1011
"time"
1112

1213
"github.com/gitpod-io/gitpod/installer/pkg/common"
1314

1415
certmanagerv1 "github.com/jetstack/cert-manager/pkg/apis/certmanager/v1"
1516
cmmeta "github.com/jetstack/cert-manager/pkg/apis/meta/v1"
17+
corev1 "k8s.io/api/core/v1"
1618
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1719
"k8s.io/apimachinery/pkg/runtime"
1820
)
@@ -56,3 +58,36 @@ func authPKI(ctx *common.RenderContext) ([]runtime.Object, error) {
5658
},
5759
}, nil
5860
}
61+
62+
func getAuthPKI() ([]corev1.Volume, []corev1.VolumeMount, AuthPKIConfig) {
63+
64+
dir := "/secrets/auth-pki"
65+
signingDir := path.Join(dir, "signing")
66+
67+
volumes := []corev1.Volume{
68+
{
69+
Name: "auth-pki-signing",
70+
VolumeSource: corev1.VolumeSource{
71+
Secret: &corev1.SecretVolumeSource{
72+
SecretName: AuthPKISecretName,
73+
},
74+
},
75+
},
76+
}
77+
78+
mounts := []corev1.VolumeMount{
79+
{
80+
Name: "auth-pki-signing",
81+
MountPath: signingDir,
82+
ReadOnly: true,
83+
},
84+
}
85+
86+
cfg := AuthPKIConfig{
87+
Signing: KeyPair{
88+
PrivateKeyPath: path.Join(signingDir, "tls.key"),
89+
PublicKeyPath: path.Join(signingDir, "tls.crt"),
90+
},
91+
}
92+
return volumes, mounts, cfg
93+
}

install/installer/pkg/components/server/configmap.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ func configmap(ctx *common.RenderContext) ([]runtime.Object, error) {
196196

197197
_, _, adminCredentialsPath := getAdminCredentials()
198198

199+
_, _, authPKI := getAuthPKI()
200+
199201
// todo(sje): all these values are configurable
200202
scfg := ConfigSerialized{
201203
Version: ctx.VersionManifest.Version,
@@ -297,6 +299,9 @@ func configmap(ctx *common.RenderContext) ([]runtime.Object, error) {
297299
CredentialsPath: adminCredentialsPath,
298300
},
299301
ShowSetupModal: showSetupModal,
302+
Auth: AuthConfig{
303+
PKI: authPKI,
304+
},
300305
}
301306

302307
fc, err := common.ToJSONString(scfg)

install/installer/pkg/components/server/configmap_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func TestConfigMap(t *testing.T) {
3030
JWTSecret string
3131
SessionSecret string
3232
GitHubApp experimental.GithubApp
33+
Auth AuthConfig
3334
}
3435

3536
expectation := Expectation{
@@ -52,6 +53,14 @@ func TestConfigMap(t *testing.T) {
5253
WebhookSecret: "some-webhook-secret",
5354
CertSecretName: "some-cert-secret-name",
5455
},
56+
Auth: AuthConfig{
57+
PKI: AuthPKIConfig{
58+
Signing: KeyPair{
59+
PrivateKeyPath: "/secrets/auth-pki/signing/tls.key",
60+
PublicKeyPath: "/secrets/auth-pki/signing/tls.crt",
61+
},
62+
},
63+
},
5564
}
5665

5766
ctx, err := common.NewRenderContext(config.Config{
@@ -122,6 +131,7 @@ func TestConfigMap(t *testing.T) {
122131
WebhookSecret: config.GitHubApp.WebhookSecret,
123132
CertSecretName: config.GitHubApp.CertSecretName,
124133
},
134+
Auth: config.Auth,
125135
}
126136

127137
assert.Equal(t, expectation, actual)

install/installer/pkg/components/server/deployment.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,10 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
281281
volumes = append(volumes, adminCredentialsVolume)
282282
volumeMounts = append(volumeMounts, adminCredentialsMount)
283283

284+
authPKIVolumes, authPKIMounts, _ := getAuthPKI()
285+
volumes = append(volumes, authPKIVolumes...)
286+
volumeMounts = append(volumeMounts, authPKIMounts...)
287+
284288
return []runtime.Object{
285289
&appsv1.Deployment{
286290
TypeMeta: common.TypeMetaDeployment,

install/installer/pkg/components/server/types.go

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,33 @@ import (
1313

1414
// ConfigSerialized interface from components/server/src/config.ts
1515
type ConfigSerialized struct {
16-
Version string `json:"version"`
17-
HostURL string `json:"hostUrl"`
18-
InstallationShortname string `json:"installationShortname"`
19-
DevBranch string `json:"devBranch"`
20-
InsecureNoDomain bool `json:"insecureNoDomain"`
21-
License string `json:"license"`
22-
DefinitelyGpDisabled bool `json:"definitelyGpDisabled"`
23-
EnableLocalApp bool `json:"enableLocalApp"`
24-
DisableDynamicAuthProviderLogin bool `json:"disableDynamicAuthProviderLogin"`
25-
MaxEnvvarPerUserCount int32 `json:"maxEnvvarPerUserCount"`
26-
MaxConcurrentPrebuildsPerRef int32 `json:"maxConcurrentPrebuildsPerRef"`
27-
MakeNewUsersAdmin bool `json:"makeNewUsersAdmin"`
28-
DefaultBaseImageRegistryWhitelist []string `json:"defaultBaseImageRegistryWhitelist"`
29-
RunDbDeleter bool `json:"runDbDeleter"`
30-
ContentServiceAddr string `json:"contentServiceAddr"`
31-
UsageServiceAddr string `json:"usageServiceAddr"`
32-
IDEServiceAddr string `json:"ideServiceAddr"`
33-
MaximumEventLoopLag float64 `json:"maximumEventLoopLag"`
34-
VSXRegistryUrl string `json:"vsxRegistryUrl"`
35-
ChargebeeProviderOptionsFile string `json:"chargebeeProviderOptionsFile"`
36-
StripeSecretsFile string `json:"stripeSecretsFile"`
37-
StripeConfigFile string `json:"stripeConfigFile"`
38-
EnablePayment bool `json:"enablePayment"`
39-
LinkedInSecretsFile string `json:"linkedInSecretsFile"`
40-
PATSigningKeyFile string `json:"patSigningKeyFile"`
41-
ShowSetupModal bool `json:"showSetupModal"`
16+
Version string `json:"version"`
17+
HostURL string `json:"hostUrl"`
18+
InstallationShortname string `json:"installationShortname"`
19+
DevBranch string `json:"devBranch"`
20+
InsecureNoDomain bool `json:"insecureNoDomain"`
21+
License string `json:"license"`
22+
DefinitelyGpDisabled bool `json:"definitelyGpDisabled"`
23+
EnableLocalApp bool `json:"enableLocalApp"`
24+
DisableDynamicAuthProviderLogin bool `json:"disableDynamicAuthProviderLogin"`
25+
MaxEnvvarPerUserCount int32 `json:"maxEnvvarPerUserCount"`
26+
MaxConcurrentPrebuildsPerRef int32 `json:"maxConcurrentPrebuildsPerRef"`
27+
MakeNewUsersAdmin bool `json:"makeNewUsersAdmin"`
28+
DefaultBaseImageRegistryWhitelist []string `json:"defaultBaseImageRegistryWhitelist"`
29+
RunDbDeleter bool `json:"runDbDeleter"`
30+
ContentServiceAddr string `json:"contentServiceAddr"`
31+
UsageServiceAddr string `json:"usageServiceAddr"`
32+
IDEServiceAddr string `json:"ideServiceAddr"`
33+
MaximumEventLoopLag float64 `json:"maximumEventLoopLag"`
34+
VSXRegistryUrl string `json:"vsxRegistryUrl"`
35+
ChargebeeProviderOptionsFile string `json:"chargebeeProviderOptionsFile"`
36+
StripeSecretsFile string `json:"stripeSecretsFile"`
37+
StripeConfigFile string `json:"stripeConfigFile"`
38+
EnablePayment bool `json:"enablePayment"`
39+
LinkedInSecretsFile string `json:"linkedInSecretsFile"`
40+
PATSigningKeyFile string `json:"patSigningKeyFile"`
41+
ShowSetupModal bool `json:"showSetupModal"`
42+
Auth AuthConfig `json:"auth"`
4243

4344
WorkspaceHeartbeat WorkspaceHeartbeat `json:"workspaceHeartbeat"`
4445
WorkspaceDefaults WorkspaceDefaults `json:"workspaceDefaults"`
@@ -65,6 +66,23 @@ type CodeSyncResources struct {
6566
RevLimit int32 `json:"revLimit"`
6667
}
6768

69+
type AuthConfig struct {
70+
PKI AuthPKIConfig `json:"pki"`
71+
}
72+
73+
type AuthPKIConfig struct {
74+
// Signing KeyPair is always used to issue new auth tokens
75+
Signing KeyPair `json:"signing"`
76+
77+
// Validating KeyPairs are used for checking validity only
78+
Validating []KeyPair `json:"validating,omitempty"`
79+
}
80+
81+
type KeyPair struct {
82+
PrivateKeyPath string `json:"privateKeyPath"`
83+
PublicKeyPath string `json:"publicKeyPath"`
84+
}
85+
6886
type CodeSync struct {
6987
RevLimit int32 `json:"revLimit"`
7088
ContentLimit int32 `json:"contentLimit"`

0 commit comments

Comments
 (0)