Skip to content

Commit 7c6da5a

Browse files
authored
Merge pull request #32 from mlbiam/main
add oci ca cert path
2 parents 78605a1 + 54cbac8 commit 7c6da5a

File tree

5 files changed

+64
-13
lines changed

5 files changed

+64
-13
lines changed

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
export VERSION="0.0.15"
3+
export VERSION="0.0.16"
44

55
rm -rf target
66
mkdir -p target

cmd/installAuthPortal.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var installAuthPortalCmd = &cobra.Command{
2828

2929
pathToValuesYaml = args[0]
3030

31-
openunisonDeployment, err := openunison.NewOpenUnisonDeployment(namespace, operatorChart, orchestraChart, orchestraLoginPortalChart, pathToValuesYaml, secretFile, clusterManagementChart, pathToDbPassword, pathToSmtpPassword, skipClusterManagement, parseChartSlices(&additionalCharts), parseChartSlices(&preCharts), parseNamespaceLabels(&namespaceLabels), skipCharts)
31+
openunisonDeployment, err := openunison.NewOpenUnisonDeployment(namespace, operatorChart, orchestraChart, orchestraLoginPortalChart, pathToValuesYaml, secretFile, clusterManagementChart, pathToDbPassword, pathToSmtpPassword, skipClusterManagement, parseChartSlices(&additionalCharts), parseChartSlices(&preCharts), parseNamespaceLabels(&namespaceLabels), skipCharts, ociCaCertPath)
3232

3333
if err != nil {
3434
panic(err)
@@ -87,6 +87,7 @@ func init() {
8787
installAuthPortalCmd.PersistentFlags().StringSliceVarP(&additionalCharts, "additional-helm-charts", "r", []string{}, "Comma separated list of chart=path to deploy additional charts after OpenUnison is deployed, adding '@version' installs the specific version")
8888

8989
installAuthPortalCmd.PersistentFlags().StringSliceVarP(&namespaceLabels, "namespace-labels", "j", []string{}, "Comma separated list of name=value of labels to add to the openunison namespace")
90+
installAuthPortalCmd.PersistentFlags().StringVarP(&ociCaCertPath, "oci-cacert-path", "p", "", "Path to a PEM file containing the CA certificate")
9091
// Cobra supports local flags which will only run when this command
9192
// is called directly, e.g.:
9293
// installAuthPortalCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")

cmd/installSatelite.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ var installSateliteCmd = &cobra.Command{
3232
controlPlaneCtxName := args[1]
3333
sateliteCtxName := args[2]
3434

35-
openunisonDeployment, err := openunison.NewSateliteDeployment(namespace, operatorChart, orchestraChart, orchestraLoginPortalChart, pathToValuesYaml, secretFile, controlPlaneCtxName, sateliteCtxName, addClusterChart, pathToSateliteYaml, parseChartSlices(&additionalCharts), parseChartSlices(&preCharts), parseNamespaceLabels(&namespaceLabels), controlPlaneOrchestraChartName, controlPlaneSecretName, skipCPIntegration, skipCharts)
35+
openunisonDeployment, err := openunison.NewSateliteDeployment(namespace, operatorChart, orchestraChart, orchestraLoginPortalChart, pathToValuesYaml, secretFile, controlPlaneCtxName, sateliteCtxName, addClusterChart, pathToSateliteYaml, parseChartSlices(&additionalCharts), parseChartSlices(&preCharts), parseNamespaceLabels(&namespaceLabels), controlPlaneOrchestraChartName, controlPlaneSecretName, skipCPIntegration, skipCharts, ociCaCertPath)
3636

3737
if err != nil {
3838
panic(err)
@@ -68,4 +68,6 @@ func init() {
6868

6969
installSateliteCmd.PersistentFlags().BoolVarP(&skipCPIntegration, "skip-controlplane-integration", "k", false, "Set to true if skipping the control plane integration step. Used when upgrading a satelite.")
7070
installSateliteCmd.PersistentFlags().StringSliceVarP(&skipCharts, "skip-charts", "i", []string{}, "Comma separated list of charts to skip during the deployment. May be used to run 'hot upgrades' that doesn't require restarts")
71+
72+
installSateliteCmd.PersistentFlags().StringVarP(&ociCaCertPath, "oci-cacert-path", "p", "", "Path to a PEM file containing the CA certificate")
7173
}

cmd/root.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ var controlPlaneSecretName string
5353
var skipCPIntegration bool
5454
var skipCharts []string
5555

56+
var ociCaCertPath string
57+
5658
// Execute adds all child commands to the root command and sets flags appropriately.
5759
// This is called by main.main(). It only needs to happen once to the rootCmd.
5860
func Execute() {

openunison/deployer.go

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package openunison
33
import (
44
"bytes"
55
"context"
6+
"crypto/tls"
7+
"crypto/x509"
68
"encoding/base64"
79
"encoding/json"
810
"flag"
@@ -11,6 +13,7 @@ import (
1113
"io/ioutil"
1214
"log"
1315
"math/rand"
16+
"net/http"
1417
"os"
1518
"path/filepath"
1619
"strings"
@@ -109,11 +112,13 @@ type OpenUnisonDeployment struct {
109112
approversGroup string
110113

111114
skipCharts map[string]bool
115+
116+
ociCaCertPath string
112117
}
113118

114119
// creates a new deployment structure
115-
func NewOpenUnisonDeployment(namespace string, operatorChart string, orchestraChart string, orchestraLoginPortalChart string, pathToValuesYaml string, secretFile string, clusterManagementChart string, pathToDbPassword string, pathToSmtpPassword string, skipClusterManagement bool, additionalCharts []HelmChartInfo, preCharts []HelmChartInfo, namespaceLabels map[string]string, skipCharts []string) (*OpenUnisonDeployment, error) {
116-
ou, err := NewSateliteDeployment(namespace, operatorChart, orchestraChart, orchestraLoginPortalChart, pathToValuesYaml, secretFile, "", "", "", "", additionalCharts, preCharts, namespaceLabels, "orchestra", "orchestra-secrets-source", false, skipCharts)
120+
func NewOpenUnisonDeployment(namespace string, operatorChart string, orchestraChart string, orchestraLoginPortalChart string, pathToValuesYaml string, secretFile string, clusterManagementChart string, pathToDbPassword string, pathToSmtpPassword string, skipClusterManagement bool, additionalCharts []HelmChartInfo, preCharts []HelmChartInfo, namespaceLabels map[string]string, skipCharts []string, ociCaCertPath string) (*OpenUnisonDeployment, error) {
121+
ou, err := NewSateliteDeployment(namespace, operatorChart, orchestraChart, orchestraLoginPortalChart, pathToValuesYaml, secretFile, "", "", "", "", additionalCharts, preCharts, namespaceLabels, "orchestra", "orchestra-secrets-source", false, skipCharts, ociCaCertPath)
117122

118123
if err != nil {
119124
return nil, err
@@ -128,7 +133,7 @@ func NewOpenUnisonDeployment(namespace string, operatorChart string, orchestraCh
128133
}
129134

130135
// creates a new deployment structure
131-
func NewSateliteDeployment(namespace string, operatorChart string, orchestraChart string, orchestraLoginPortalChart string, pathToValuesYaml string, secretFile string, controlPlanContextName string, sateliteContextName string, addClusterChart string, pathToSateliteYaml string, additionalCharts []HelmChartInfo, preCharts []HelmChartInfo, namespaceLabels map[string]string, cpOrchestraName string, cpSecretName string, skipCpIntegration bool, skipCharts []string) (*OpenUnisonDeployment, error) {
136+
func NewSateliteDeployment(namespace string, operatorChart string, orchestraChart string, orchestraLoginPortalChart string, pathToValuesYaml string, secretFile string, controlPlanContextName string, sateliteContextName string, addClusterChart string, pathToSateliteYaml string, additionalCharts []HelmChartInfo, preCharts []HelmChartInfo, namespaceLabels map[string]string, cpOrchestraName string, cpSecretName string, skipCpIntegration bool, skipCharts []string, ociCaCertPath string) (*OpenUnisonDeployment, error) {
132137
ou := &OpenUnisonDeployment{IsolatateRequestAccess: IsolateRequestAccess{Enabled: false, AzRules: make([]AzRule, 0)}}
133138

134139
ou.namespace = namespace
@@ -172,6 +177,8 @@ func NewSateliteDeployment(namespace string, operatorChart string, orchestraChar
172177
ou.skipCharts[skipCharts[chartToSkip]] = true
173178
}
174179

180+
ou.ociCaCertPath = ociCaCertPath
181+
175182
return ou, nil
176183
}
177184

@@ -1472,15 +1479,54 @@ func (ou *OpenUnisonDeployment) locateChart(configChartName string, chartPathOpt
14721479
if strings.HasPrefix(chartName, "oci://") {
14731480
fmt.Printf("OCI chart detected: %s\n", chartName)
14741481

1475-
// Step 1: Initialize OCI client
1476-
ociClient, err := registry.NewClient(
1477-
registry.ClientOptEnableCache(true),
1478-
registry.ClientOptDebug(true),
1479-
)
1480-
if err != nil {
1481-
return nil, fmt.Errorf("failed to initialize OCI client: %v", err)
1482+
var ociClient *registry.Client
1483+
1484+
if ou.ociCaCertPath != "" {
1485+
1486+
// there's a ca cert
1487+
var err error
1488+
caCert, err := os.ReadFile(ou.ociCaCertPath)
1489+
if err != nil {
1490+
panic(err)
1491+
}
1492+
1493+
caPool := x509.NewCertPool()
1494+
if ok := caPool.AppendCertsFromPEM(caCert); !ok {
1495+
panic("failed to append CA cert")
1496+
}
1497+
1498+
tlsConfig := &tls.Config{
1499+
RootCAs: caPool,
1500+
}
1501+
1502+
httpClient := &http.Client{
1503+
Transport: &http.Transport{
1504+
TLSClientConfig: tlsConfig,
1505+
},
1506+
}
1507+
1508+
ociClient, err = registry.NewClient(
1509+
registry.ClientOptEnableCache(true),
1510+
registry.ClientOptDebug(true),
1511+
registry.ClientOptHTTPClient(httpClient),
1512+
)
1513+
1514+
if err != nil {
1515+
return nil, fmt.Errorf("failed to initialize OCI client: %v", err)
1516+
}
1517+
} else {
1518+
var err error
1519+
ociClient, err = registry.NewClient(
1520+
registry.ClientOptEnableCache(true),
1521+
registry.ClientOptDebug(true),
1522+
)
1523+
if err != nil {
1524+
return nil, fmt.Errorf("failed to initialize OCI client: %v", err)
1525+
}
14821526
}
14831527

1528+
// Step 1: Initialize OCI client
1529+
14841530
// Step 2: Create a temporary directory
14851531
tempDir, err := os.MkdirTemp("", "helm-oci-*")
14861532
if err != nil {

0 commit comments

Comments
 (0)