Path: blob/main/install/installer/pkg/components/auth/keypair.go
2501 views
// Copyright (c) 2023 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34package auth56import (7"fmt"8"math"9"path"10"time"1112"github.com/gitpod-io/gitpod/installer/pkg/common"1314certmanagerv1 "github.com/jetstack/cert-manager/pkg/apis/certmanager/v1"15cmmeta "github.com/jetstack/cert-manager/pkg/apis/meta/v1"16corev1 "k8s.io/api/core/v1"17metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"18"k8s.io/apimachinery/pkg/runtime"19)2021func keypair(ctx *common.RenderContext) ([]runtime.Object, error) {22serverAltNames := []string{23fmt.Sprintf("gitpod.%s", ctx.Namespace),24fmt.Sprintf("%s.%s.svc", Component, ctx.Namespace),25Component,26fmt.Sprintf("%s-dev", Component),27}2829return []runtime.Object{30&certmanagerv1.Certificate{31TypeMeta: common.TypeMetaCertificate,32ObjectMeta: metav1.ObjectMeta{33Name: common.AuthPKISecretName,34Namespace: ctx.Namespace,35Labels: common.DefaultLabels(Component),36},37Spec: certmanagerv1.CertificateSpec{38Duration: &metav1.Duration{39Duration: time.Duration(math.MaxInt64), // never expire automatically40},41SecretName: common.AuthPKISecretName,42DNSNames: serverAltNames,43IssuerRef: cmmeta.ObjectReference{44Name: common.CertManagerCAIssuer,45Kind: certmanagerv1.ClusterIssuerKind,46Group: "cert-manager.io",47},48PrivateKey: &certmanagerv1.CertificatePrivateKey{49Encoding: certmanagerv1.PKCS8,50Size: 4096,51Algorithm: certmanagerv1.RSAKeyAlgorithm,52},53SecretTemplate: &certmanagerv1.CertificateSecretTemplate{54Labels: common.DefaultLabels(Component),55},56},57},58}, nil59}6061func getPKI() ([]corev1.Volume, []corev1.VolumeMount, PKIConfig) {62dir := "/secrets/auth-pki"63signingDir := path.Join(dir, "signing")6465volumes := []corev1.Volume{66{67Name: "auth-pki-signing",68VolumeSource: corev1.VolumeSource{69Secret: &corev1.SecretVolumeSource{70SecretName: common.AuthPKISecretName,71},72},73},74}7576mounts := []corev1.VolumeMount{77{78Name: "auth-pki-signing",79MountPath: signingDir,80ReadOnly: true,81},82}8384cfg := PKIConfig{85Signing: KeyPair{86ID: "0001",87PrivateKeyPath: path.Join(signingDir, "tls.key"),88PublicKeyPath: path.Join(signingDir, "tls.crt"),89},90}91return volumes, mounts, cfg92}9394type PKIConfig struct {95// Signing KeyPair is always used to issue new auth tokens96Signing KeyPair `json:"signing"`9798// Validating KeyPairs are used for checking validity only99Validating []KeyPair `json:"validating,omitempty"`100}101102type KeyPair struct {103ID string `json:"id"`104PrivateKeyPath string `json:"privateKeyPath"`105PublicKeyPath string `json:"publicKeyPath"`106}107108109