Skip to content

Commit d330542

Browse files
committed
Implement TLS overlay for Catalogd TLS
Signed-off-by: Tayler Geiger <[email protected]>
1 parent ab2e1c6 commit d330542

38 files changed

+74
-29
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ install.sh
3939
site
4040

4141
.tiltbuild/
42+
.vscode

.vscode/launch.json

Lines changed: 0 additions & 18 deletions
This file was deleted.

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ else
5454
$(warning Could not find docker or podman in path! This may result in targets requiring a container runtime failing!)
5555
endif
5656

57-
KUSTOMIZE_BUILD_DIR := config/default
57+
KUSTOMIZE_BUILD_DIR := config/overlays/tls
5858

5959
# Disable -j flag for make
6060
.NOTPARALLEL:
@@ -148,7 +148,7 @@ build-push-e2e-catalog: ## Build the testdata catalog used for e2e tests and pus
148148
# for example: ARTIFACT_PATH=/tmp/artifacts make test-e2e
149149
.PHONY: test-e2e
150150
test-e2e: KIND_CLUSTER_NAME := operator-controller-e2e
151-
test-e2e: KUSTOMIZE_BUILD_DIR := config/e2e
151+
test-e2e: KUSTOMIZE_BUILD_DIR := config/base/e2e
152152
test-e2e: GO_BUILD_FLAGS := -cover
153153
test-e2e: run image-registry build-push-e2e-catalog kind-load-test-artifacts e2e e2e-coverage kind-clean #HELP Run e2e test suite on local kind cluster
154154

Tiltfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ repos = cfg.get('repos', ['operator-controller', 'catalogd'])
99

1010
repo = {
1111
'image': 'quay.io/operator-framework/operator-controller',
12-
'yaml': 'config/default',
12+
'yaml': 'config/overlays/tls',
1313
'binaries': {
1414
'manager': 'operator-controller-controller-manager',
1515
},

cmd/manager/main.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ limitations under the License.
1717
package main
1818

1919
import (
20+
"crypto/tls"
2021
"crypto/x509"
2122
"flag"
2223
"fmt"
24+
"log"
2325
"net/http"
2426
"net/url"
2527
"os"
@@ -80,9 +82,11 @@ func main() {
8082
systemNamespace string
8183
unpackImage string
8284
provisionerStorageDirectory string
85+
tlsCert string
8386
)
8487
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
8588
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
89+
flag.StringVar(&tlsCert, "tls-cert", "", "The TLS certificate to use for verifying HTTPS connections to the Catalogd web server.")
8690
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
8791
"Enable leader election for controller manager. "+
8892
"Enabling this will ensure there is only one active controller manager.")
@@ -152,8 +156,27 @@ func main() {
152156
os.Exit(1)
153157
}
154158

159+
httpClient := &http.Client{Timeout: 10 * time.Second}
160+
161+
if tlsCert != "" {
162+
cert, err := os.ReadFile(tlsCert)
163+
if err != nil {
164+
log.Fatalf("Failed to read certificate file: %v", err)
165+
}
166+
caCertPool := x509.NewCertPool()
167+
caCertPool.AppendCertsFromPEM(cert)
168+
tlsConfig := &tls.Config{
169+
RootCAs: caCertPool,
170+
MinVersion: tls.VersionTLS12,
171+
}
172+
tlsTransport := &http.Transport{
173+
TLSClientConfig: tlsConfig,
174+
}
175+
httpClient.Transport = tlsTransport
176+
}
177+
155178
cl := mgr.GetClient()
156-
catalogClient := catalogclient.New(cl, cache.NewFilesystemCache(cachePath, &http.Client{Timeout: 10 * time.Second}))
179+
catalogClient := catalogclient.New(cl, cache.NewFilesystemCache(cachePath, httpClient))
157180

158181
cfgGetter, err := helmclient.NewActionConfigGetter(mgr.GetConfig(), mgr.GetRESTMapper(), helmclient.StorageNamespaceMapper(func(o client.Object) (string, error) {
159182
return systemNamespace, nil
File renamed without changes.
File renamed without changes.

config/manager/manager.yaml renamed to config/base/manager/manager.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,6 @@ spec:
114114
terminationGracePeriodSeconds: 10
115115
volumes:
116116
- name: cache
117-
emptyDir: {}
117+
emptyDir: {}
118118
- name: bundle-cache
119-
emptyDir: {}
119+
emptyDir: {}
File renamed without changes.
File renamed without changes.

config/rbac/role.yaml renamed to config/base/rbac/role.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ rules:
2020
- apiGroups:
2121
- catalogd.operatorframework.io
2222
resources:
23-
- catalogs
23+
- clustercatalogs
2424
verbs:
2525
- list
2626
- watch
File renamed without changes.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Adds namespace to all resources.
2+
namespace: operator-controller-system
3+
4+
# Value of this field is prepended to the
5+
# names of all resources, e.g. a deployment named
6+
# "wordpress" becomes "alices-wordpress".
7+
# Note that it should also match with the prefix (text before '-') of the namespace
8+
# field above.
9+
namePrefix: operator-controller-
10+
11+
# the following config is for teaching kustomize how to do var substitution
12+
apiVersion: kustomize.config.k8s.io/v1beta1
13+
kind: Kustomization
14+
resources:
15+
- ../../base/crd
16+
- ../../base/rbac
17+
- ../../base/manager
18+
19+
patches:
20+
- target:
21+
kind: Deployment
22+
name: controller-manager
23+
path: patches/manager_deployment_cert.yaml
24+
- target:
25+
kind: Namespace
26+
name: system
27+
path: patches/manager_namespace_label.yaml
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
- op: add
2+
path: /spec/template/spec/volumes/-
3+
value: {"name":"ca-certificate", "secret":{"secretName":"catalogd-catalogserver-cert", "optional": false, "items": [{"key": "tls.crt", "path": "tls.crt"}]}}
4+
- op: add
5+
path: /spec/template/spec/containers/0/volumeMounts/-
6+
value: {"name":"ca-certificate", "readOnly": true, "mountPath":"/var/certs"}
7+
- op: add
8+
path: /spec/template/spec/containers/0/args/-
9+
value: "--tls-cert=/var/certs/tls.crt"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- op: add
2+
path: /metadata/labels/trust
3+
value: "enabled"

config/samples/catalogd_operatorcatalog.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
apiVersion: catalogd.operatorframework.io/v1alpha1
2-
kind: Catalog
2+
kind: ClusterCatalog
33
metadata:
44
name: operatorhubio
55
spec:

internal/controllers/clusterextension_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ type InstalledBundleGetter interface {
108108
//+kubebuilder:rbac:groups=core,resources=pods/log,verbs=get
109109
//+kubebuilder:rbac:groups=*,resources=*,verbs=*
110110

111-
//+kubebuilder:rbac:groups=catalogd.operatorframework.io,resources=catalogs,verbs=list;watch
111+
//+kubebuilder:rbac:groups=catalogd.operatorframework.io,resources=clustercatalogs,verbs=list;watch
112112
//+kubebuilder:rbac:groups=catalogd.operatorframework.io,resources=catalogmetadata,verbs=list;watch
113113

114114
// The operator controller needs to watch all the bundle objects and reconcile accordingly. Though not ideal, but these permissions are required.

scripts/install.tpl.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ function kubectl_wait() {
3535
kubectl apply -f "https://github.com/cert-manager/cert-manager/releases/download/${cert_mgr_version}/cert-manager.yaml"
3636
kubectl_wait "cert-manager" "deployment/cert-manager-webhook" "60s"
3737

38-
kubectl apply -f "https://github.com/operator-framework/catalogd/releases/download/${catalogd_version}/catalogd.yaml"
39-
kubectl_wait "catalogd-system" "deployment/catalogd-controller-manager" "60s"
38+
curl -L https://github.com/operator-framework/catalogd/releases/download/${catalogd_version}/catalogd.yaml | sed s/catalogd-system/operator-controller-system/g | kubectl apply -f -
39+
kubectl_wait "operator-controller-system" "deployment/catalogd-controller-manager" "60s"
4040

4141
kubectl apply -f "${operator_controller_manifest}"
4242
kubectl_wait "operator-controller-system" "deployment/operator-controller-controller-manager" "60s"

0 commit comments

Comments
 (0)