-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIMO] Move cluster certificate functionality to ClientHelper (#3736)
* move over TLS applying, as well as some clienthelper work
- Loading branch information
Showing
9 changed files
with
105 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package cluster | ||
|
||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the Apache License 2.0. | ||
|
||
import ( | ||
"context" | ||
"crypto/x509" | ||
"encoding/pem" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
|
||
"github.com/Azure/ARO-RP/pkg/util/clienthelper" | ||
"github.com/Azure/ARO-RP/pkg/util/keyvault" | ||
utilpem "github.com/Azure/ARO-RP/pkg/util/pem" | ||
) | ||
|
||
func EnsureTLSSecretFromKeyvault(ctx context.Context, kv keyvault.Manager, ch clienthelper.Writer, target types.NamespacedName, certificateName string) error { | ||
bundle, err := kv.GetSecret(ctx, certificateName) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
key, certs, err := utilpem.Parse([]byte(*bundle.Value)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
b, err := x509.MarshalPKCS8PrivateKey(key) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var cb []byte | ||
for _, cert := range certs { | ||
cb = append(cb, pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: cert.Raw})...) | ||
} | ||
|
||
privateKey := pem.EncodeToMemory(&pem.Block{Type: "PRIVATE KEY", Bytes: b}) | ||
|
||
secret := &corev1.Secret{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: target.Name, | ||
Namespace: target.Namespace, | ||
}, | ||
Data: map[string][]byte{ | ||
corev1.TLSCertKey: cb, | ||
corev1.TLSPrivateKeyKey: privateKey, | ||
}, | ||
Type: corev1.SecretTypeTLS, | ||
} | ||
|
||
return ch.Ensure(ctx, secret) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.