Skip to content

Commit cb3fcd3

Browse files
authored
feat(operator): let the platform source trust a private registry CA (#5237)
## What this PR does The operator creates the `cozystack-platform` OCIRepository from its own command-line arguments and rewrites the whole object on every start; `cozystack-packages` copies that spec. When the platform source is a registry whose certificate is issued by a private CA (an internal pull-through cache in an air-gapped install, for example), there is no durable way to make Flux trust it: a `certSecretRef` patched onto the live object is dropped on the next operator restart, source-controller then fails TLS, and platform updates silently stop arriving. This adds `--platform-source-cert-secret` to the operator and `cozystackOperator.platformSourceCertSecret` to the installer chart. The named Secret in `cozy-system` is set as `spec.certSecretRef` on the generated OCIRepository, so it holds `ca.crt` for a private CA and/or `tls.crt`+`tls.key` for client certificate auth, with the Flux key layout. `cozystack-packages` inherits it through the existing spec copy. The flag is OCI only. `GitRepository` has no `certSecretRef` (Flux reads a Git CA from the `ca.crt` key of the `secretRef` Secret), so a Git platform source with the flag set is refused at startup instead of having its CA silently ignored. Tests: unit tests for the generated spec, a regression test that the CA survives the operator's update of an existing OCIRepository, a test that a Git source with the flag writes nothing, and a helm-unittest suite for the new chart value. ### Screenshots <!-- REQUIRED for UI changes: attach screenshots or screen recordings demonstrating the visual impact of your changes. PRs with UI changes without screenshots will not be merged. --> ### Downstream repositories <!-- Cozystack is upstream for repositories that are NOT kept in sync with it automatically, and nothing in CI compares the two sides, so a change here can break them silently. Which change forces what, and which file to touch, is the trigger map in docs/agents/contributing.md under "Downstream Repositories". Walk it before you tick anything. IF YOU ARE AN AI AGENT OR AN LLM, THIS IS PART OF THE TASK, NOT A FORM TO FILL IN: 1. Walk the trigger map against the actual diff of this PR, file by file. Do not decide from the PR title or from your memory of what you changed. 2. For every repository you tick, open the follow-up PR there and link it on the same line. A ticked box with no link claims work that does not exist, which is worse than an empty box. Search that repository for an open PR or issue covering it first, and link that instead of filing a duplicate. 3. When the follow-up is out of scope, or needs a decision that is not yours to make, open an issue in that repository instead, link that, and say so in the PR body. Do not push a speculative PR into another repository just to fill a line here. 4. Do not tick "No downstream repository is affected" to make the checklist go away. If you are unsure, leave every box empty and say so in the PR body, so a human decides. --> - [ ] No downstream repository is affected by this change - [x] [cozystack/website](https://github.com/cozystack/website) - follow-up: cozystack/website#791 - [ ] [cozystack/terraform-provider-cozystack](https://github.com/cozystack/terraform-provider-cozystack) - follow-up: - [ ] [cozystack/ansible-cozystack](https://github.com/cozystack/ansible-cozystack) - follow-up: - [ ] [cozystack/ccp](https://github.com/cozystack/ccp) - follow-up: - [ ] [cozystack/talm](https://github.com/cozystack/talm) - follow-up: - [ ] [cozystack/cozyhr](https://github.com/cozystack/cozyhr) - follow-up: - [ ] [cozystack/cozy-proxy](https://github.com/cozystack/cozy-proxy) - follow-up: - [ ] [cozystack/cozystack-telemetry-server](https://github.com/cozystack/cozystack-telemetry-server) - follow-up: - [ ] [cozystack/external-apps-example](https://github.com/cozystack/external-apps-example) - follow-up: - [ ] [cozystack/examples](https://github.com/cozystack/examples) - follow-up: - [ ] [cozystack/community](https://github.com/cozystack/community) - follow-up: The new installer value is optional, so `ansible-cozystack` is not reached. The website's air-gapped guide (`content/en/docs/next/install/kubernetes/air-gapped.md`) added the private CA to the nodes only, while Flux fetches the platform source itself; cozystack/website#791 adds a step for `platformSourceUrl`, `platformSourceSecret` and `platformSourceCertSecret`. ### Release note ```release-note feat(operator): the platform source can be served from a registry behind a private CA. Set `cozystackOperator.platformSourceCertSecret` in the installer to a Secret in `cozy-system` with `ca.crt` (and optionally `tls.crt`/`tls.key`); the operator sets it as `certSecretRef` on the `cozystack-platform` OCIRepository, so it survives operator restarts. ``` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **New Features** * Added the `platformSourceCertSecret` setting for OCI platform sources. It allows a Secret containing certificates for private CA trust or client authentication to be configured separately from registry credentials. * The configured certificate Secret is applied to the OCI source and inherited by its package source. * **Configuration** * The setting is empty by default. Git platform sources do not support a separate certificate Secret; use the existing platform source Secret for Git TLS certificates. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2 parents 970191d + 0a44896 commit cb3fcd3

5 files changed

Lines changed: 263 additions & 9 deletions

File tree

‎cmd/cozystack-operator/main.go‎

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ func main() {
9999
var platformSourceName string
100100
var platformSourceRef string
101101
var platformSourceSecret string
102+
var platformSourceCertSecret string
102103
var systemNamespaceMemoryLimit string
103104
var systemNamespaceMemoryRequest string
104105

@@ -145,6 +146,7 @@ func main() {
145146
flag.StringVar(&platformSourceName, "platform-source-name", "cozystack-platform", "Name for the generated platform source resource and PackageSource")
146147
flag.StringVar(&platformSourceRef, "platform-source-ref", "", "Reference specification as key=value pairs (e.g., 'branch=main' or 'digest=sha256:...,tag=v1.0'). For OCI: digest, semver, semverFilter, tag. For Git: branch, tag, semver, name, commit.")
147148
flag.StringVar(&platformSourceSecret, "platform-source-secret", "", "Name of the Secret in cozy-system namespace containing credentials for the platform source. Sets spec.secretRef on the generated OCIRepository or GitRepository. Secret type depends on the source kind: kubernetes.io/dockerconfigjson for OCI (oci://...); Opaque with username+password (or bearerToken) for Git over HTTPS; Opaque with identity (PEM private key) and known_hosts for Git over SSH.")
149+
flag.StringVar(&platformSourceCertSecret, "platform-source-cert-secret", "", "Name of the Secret in cozy-system namespace holding TLS material for an OCI platform source: ca.crt for a registry behind a private CA, and/or tls.crt+tls.key for client certificate auth. Sets spec.certSecretRef on the generated OCIRepository. Not supported for Git sources, where Flux reads ca.crt from the --platform-source-secret Secret.")
148150
flag.StringVar(&cozyValuesSecretName, "cozy-values-secret-name", "cozystack-values", "The name of the secret containing cluster-wide configuration values.")
149151
flag.StringVar(&cozyValuesSecretNamespace, "cozy-values-secret-namespace", "cozy-system", "The namespace of the secret containing cluster-wide configuration values.")
150152
flag.StringVar(&cozyValuesNamespaceSelector, "cozy-values-namespace-selector", "cozystack.io/system=true", "The label selector for namespaces where the cluster-wide configuration values must be replicated.")
@@ -189,6 +191,11 @@ func main() {
189191
os.Exit(1)
190192
}
191193

194+
if err := validatePlatformSourceCertSecret(platformSourceURL, platformSourceCertSecret); err != nil {
195+
setupLog.Error(err, "invalid platform source flags")
196+
os.Exit(1)
197+
}
198+
192199
config := ctrl.GetConfigOrDie()
193200

194201
// Create a direct client (without cache) for pre-start operations
@@ -278,12 +285,12 @@ func main() {
278285

279286
// Generate and install platform source resource if specified
280287
if platformSourceURL != "" {
281-
setupLog.Info("Generating platform source resource", "url", platformSourceURL, "name", platformSourceName, "ref", platformSourceRef, "secret", platformSourceSecret)
288+
setupLog.Info("Generating platform source resource", "url", platformSourceURL, "name", platformSourceName, "ref", platformSourceRef, "secret", platformSourceSecret, "certSecret", platformSourceCertSecret)
282289
installCtx, installCancel := context.WithTimeout(mgrCtx, 2*time.Minute)
283290
defer installCancel()
284291

285292
// Use direct client for pre-start operations (cache is not ready yet)
286-
if err := installPlatformSourceResource(installCtx, directClient, platformSourceURL, platformSourceName, platformSourceRef, platformSourceSecret); err != nil {
293+
if err := installPlatformSourceResource(installCtx, directClient, platformSourceURL, platformSourceName, platformSourceRef, platformSourceSecret, platformSourceCertSecret); err != nil {
287294
setupLog.Error(err, "failed to install platform source resource")
288295
os.Exit(1)
289296
} else {
@@ -414,7 +421,7 @@ func main() {
414421

415422
// installPlatformSourceResource generates and installs a Flux source resource (OCIRepository or GitRepository)
416423
// based on the platform source URL
417-
func installPlatformSourceResource(ctx context.Context, k8sClient client.Client, sourceURL, resourceName, refSpec, secretName string) error {
424+
func installPlatformSourceResource(ctx context.Context, k8sClient client.Client, sourceURL, resourceName, refSpec, secretName, certSecretName string) error {
418425
logger := log.FromContext(ctx)
419426

420427
// Parse the source URL to determine type
@@ -432,11 +439,14 @@ func installPlatformSourceResource(ctx context.Context, k8sClient client.Client,
432439
var obj client.Object
433440
switch sourceType {
434441
case "oci":
435-
obj, err = generateOCIRepository(resourceName, repoURL, refMap, secretName)
442+
obj, err = generateOCIRepository(resourceName, repoURL, refMap, secretName, certSecretName)
436443
if err != nil {
437444
return fmt.Errorf("failed to generate OCIRepository: %w", err)
438445
}
439446
case "git":
447+
if err := validatePlatformSourceCertSecret(sourceURL, certSecretName); err != nil {
448+
return err
449+
}
440450
obj, err = generateGitRepository(resourceName, repoURL, refMap, secretName)
441451
if err != nil {
442452
return fmt.Errorf("failed to generate GitRepository: %w", err)
@@ -532,6 +542,19 @@ func parseSystemNamespaceMemory(rawLimit, rawRequest string) (limit, request res
532542
return limit, request, nil
533543
}
534544

545+
// validatePlatformSourceCertSecret rejects --platform-source-cert-secret for a
546+
// Git source: GitRepository has no certSecretRef, and Flux reads a Git CA from
547+
// the ca.crt key of the --platform-source-secret Secret instead.
548+
func validatePlatformSourceCertSecret(sourceURL, certSecretName string) error {
549+
if certSecretName == "" {
550+
return nil
551+
}
552+
if sourceType, _, err := parsePlatformSourceURL(sourceURL); err == nil && sourceType == "git" {
553+
return fmt.Errorf("--platform-source-cert-secret is only supported for OCI sources; for a Git source put ca.crt into the --platform-source-secret Secret")
554+
}
555+
return nil
556+
}
557+
535558
// parsePlatformSourceURL parses the source URL and returns the source type and repository URL.
536559
// Supports formats:
537560
// - oci://registry.example.com/repo
@@ -650,7 +673,7 @@ func validateGitRef(refMap map[string]string) error {
650673
}
651674

652675
// generateOCIRepository creates an OCIRepository resource
653-
func generateOCIRepository(name, repoURL string, refMap map[string]string, secretName string) (*sourcev1.OCIRepository, error) {
676+
func generateOCIRepository(name, repoURL string, refMap map[string]string, secretName, certSecretName string) (*sourcev1.OCIRepository, error) {
654677
if err := validateOCIRef(refMap); err != nil {
655678
return nil, err
656679
}
@@ -687,6 +710,12 @@ func generateOCIRepository(name, repoURL string, refMap map[string]string, secre
687710
}
688711
}
689712

713+
if certSecretName != "" {
714+
obj.Spec.CertSecretRef = &fluxmeta.LocalObjectReference{
715+
Name: certSecretName,
716+
}
717+
}
718+
690719
return obj, nil
691720
}
692721

‎cmd/cozystack-operator/main_test.go‎

Lines changed: 149 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323

2424
cozyv1alpha1 "github.com/cozystack/cozystack/api/v1alpha1"
2525
"github.com/cozystack/cozystack/internal/marketplace/tapconst"
26+
sourcev1 "github.com/fluxcd/source-controller/api/v1"
2627
"k8s.io/apimachinery/pkg/api/resource"
2728
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2829
"k8s.io/apimachinery/pkg/runtime"
@@ -534,7 +535,7 @@ func TestValidateGitRef(t *testing.T) {
534535

535536
func TestGenerateOCIRepository(t *testing.T) {
536537
refMap := map[string]string{"tag": "v1.0", "digest": "sha256:abc123"}
537-
obj, err := generateOCIRepository("my-repo", "oci://registry.example.com/repo", refMap, "")
538+
obj, err := generateOCIRepository("my-repo", "oci://registry.example.com/repo", refMap, "", "")
538539
if err != nil {
539540
t.Fatalf("unexpected error: %v", err)
540541
}
@@ -560,10 +561,13 @@ func TestGenerateOCIRepository(t *testing.T) {
560561
if obj.Spec.SecretRef != nil {
561562
t.Errorf("expected SecretRef to be nil when secretName is empty, got %+v", obj.Spec.SecretRef)
562563
}
564+
if obj.Spec.CertSecretRef != nil {
565+
t.Errorf("expected CertSecretRef to be nil when certSecretName is empty, got %+v", obj.Spec.CertSecretRef)
566+
}
563567
}
564568

565569
func TestGenerateOCIRepository_NoRef(t *testing.T) {
566-
obj, err := generateOCIRepository("my-repo", "oci://registry.example.com/repo", map[string]string{}, "")
570+
obj, err := generateOCIRepository("my-repo", "oci://registry.example.com/repo", map[string]string{}, "", "")
567571
if err != nil {
568572
t.Fatalf("unexpected error: %v", err)
569573
}
@@ -573,14 +577,14 @@ func TestGenerateOCIRepository_NoRef(t *testing.T) {
573577
}
574578

575579
func TestGenerateOCIRepository_InvalidRef(t *testing.T) {
576-
_, err := generateOCIRepository("my-repo", "oci://registry.example.com/repo", map[string]string{"branch": "main"}, "")
580+
_, err := generateOCIRepository("my-repo", "oci://registry.example.com/repo", map[string]string{"branch": "main"}, "", "")
577581
if err == nil {
578582
t.Fatal("expected error for invalid OCI ref key, got nil")
579583
}
580584
}
581585

582586
func TestGenerateOCIRepository_WithSecret(t *testing.T) {
583-
obj, err := generateOCIRepository("my-repo", "oci://registry.example.com/repo", map[string]string{"tag": "v1.0"}, "my-registry-creds")
587+
obj, err := generateOCIRepository("my-repo", "oci://registry.example.com/repo", map[string]string{"tag": "v1.0"}, "my-registry-creds", "")
584588
if err != nil {
585589
t.Fatalf("unexpected error: %v", err)
586590
}
@@ -592,6 +596,147 @@ func TestGenerateOCIRepository_WithSecret(t *testing.T) {
592596
}
593597
}
594598

599+
func TestGenerateOCIRepository_WithCertSecret(t *testing.T) {
600+
obj, err := generateOCIRepository("my-repo", "oci://registry.example.com/repo", map[string]string{"tag": "v1.0"}, "", "registry-ca")
601+
if err != nil {
602+
t.Fatalf("unexpected error: %v", err)
603+
}
604+
if obj.Spec.CertSecretRef == nil {
605+
t.Fatal("expected CertSecretRef to be set when certSecretName is non-empty")
606+
}
607+
if obj.Spec.CertSecretRef.Name != "registry-ca" {
608+
t.Errorf("expected CertSecretRef.Name %q, got %q", "registry-ca", obj.Spec.CertSecretRef.Name)
609+
}
610+
if obj.Spec.SecretRef != nil {
611+
t.Errorf("expected SecretRef to stay nil when only certSecretName is set, got %+v", obj.Spec.SecretRef)
612+
}
613+
}
614+
615+
func newSourceTestClient(t *testing.T, objs ...client.Object) client.Client {
616+
t.Helper()
617+
scheme := newTestScheme()
618+
if err := sourcev1.AddToScheme(scheme); err != nil {
619+
t.Fatalf("add source scheme: %v", err)
620+
}
621+
return fake.NewClientBuilder().WithScheme(scheme).WithObjects(objs...).Build()
622+
}
623+
624+
// The operator rewrites the whole platform OCIRepository on every start, so a
625+
// certSecretRef patched onto the live object by hand is lost on the next
626+
// restart and source-controller then fails TLS against a registry behind a
627+
// private CA. The CA has to come from the operator's own arguments and survive
628+
// that update path, including a rename of the Secret when the CA is rotated.
629+
func TestInstallPlatformSourceResource_UpdateKeepsCertSecret(t *testing.T) {
630+
existing := &sourcev1.OCIRepository{
631+
ObjectMeta: metav1.ObjectMeta{Name: "cozystack-platform", Namespace: "cozy-system"},
632+
Spec: sourcev1.OCIRepositorySpec{URL: "oci://ghcr.io/cozystack/cozystack/cozystack-packages"},
633+
}
634+
k8sClient := newSourceTestClient(t, existing)
635+
636+
for _, certSecret := range []string{"registry-ca", "registry-ca-next"} {
637+
if err := installPlatformSourceResource(context.Background(), k8sClient,
638+
"oci://registry.internal:8083/cozystack/cozystack/cozystack-packages", "cozystack-platform",
639+
"digest=sha256:abc123", "registry-creds", certSecret); err != nil {
640+
t.Fatalf("installPlatformSourceResource: %v", err)
641+
}
642+
}
643+
644+
got := &sourcev1.OCIRepository{}
645+
if err := k8sClient.Get(context.Background(), client.ObjectKey{Namespace: "cozy-system", Name: "cozystack-platform"}, got); err != nil {
646+
t.Fatalf("get OCIRepository: %v", err)
647+
}
648+
if got.Spec.CertSecretRef == nil || got.Spec.CertSecretRef.Name != "registry-ca-next" {
649+
t.Errorf("expected CertSecretRef registry-ca-next after update, got %+v", got.Spec.CertSecretRef)
650+
}
651+
if got.Spec.SecretRef == nil || got.Spec.SecretRef.Name != "registry-creds" {
652+
t.Errorf("expected SecretRef registry-creds after update, got %+v", got.Spec.SecretRef)
653+
}
654+
if got.Spec.URL != "oci://registry.internal:8083/cozystack/cozystack/cozystack-packages" {
655+
t.Errorf("expected URL to be repointed, got %q", got.Spec.URL)
656+
}
657+
}
658+
659+
// GitRepository has no certSecretRef: Flux reads a Git CA from the ca.crt key
660+
// of the secretRef Secret. Accepting the flag for a Git source would silently
661+
// drop the CA, so it must fail before anything is written.
662+
func TestInstallPlatformSourceResource_GitRejectsCertSecret(t *testing.T) {
663+
k8sClient := newSourceTestClient(t)
664+
665+
err := installPlatformSourceResource(context.Background(), k8sClient,
666+
"https://git.internal/cozystack/cozystack", "cozystack-platform", "branch=main", "git-creds", "git-ca")
667+
if err == nil {
668+
t.Fatal("expected an error for a cert secret on a Git platform source, got nil")
669+
}
670+
if !strings.Contains(err.Error(), "ca.crt") {
671+
t.Errorf("expected the error to point at the ca.crt key of the source secret, got: %v", err)
672+
}
673+
674+
list := &sourcev1.GitRepositoryList{}
675+
if err := k8sClient.List(context.Background(), list); err != nil {
676+
t.Fatalf("list GitRepositories: %v", err)
677+
}
678+
if len(list.Items) != 0 {
679+
t.Errorf("expected no GitRepository to be written, got %d", len(list.Items))
680+
}
681+
}
682+
683+
// The Git guard runs on every start; one that misfires without a cert secret
684+
// would crash-loop the operator for every Git platform source.
685+
func TestInstallPlatformSourceResource_GitWithoutCertSecret(t *testing.T) {
686+
for _, sourceURL := range []string{
687+
"https://git.internal/cozystack/cozystack",
688+
"ssh://[email protected]/cozystack/cozystack",
689+
} {
690+
t.Run(sourceURL, func(t *testing.T) {
691+
k8sClient := newSourceTestClient(t)
692+
693+
if err := installPlatformSourceResource(context.Background(), k8sClient,
694+
sourceURL, "cozystack-platform", "branch=main", "git-creds", ""); err != nil {
695+
t.Fatalf("installPlatformSourceResource: %v", err)
696+
}
697+
698+
got := &sourcev1.GitRepository{}
699+
if err := k8sClient.Get(context.Background(), client.ObjectKey{Namespace: "cozy-system", Name: "cozystack-platform"}, got); err != nil {
700+
t.Fatalf("get GitRepository: %v", err)
701+
}
702+
if got.Spec.URL != sourceURL {
703+
t.Errorf("expected URL %q, got %q", sourceURL, got.Spec.URL)
704+
}
705+
if got.Spec.SecretRef == nil || got.Spec.SecretRef.Name != "git-creds" {
706+
t.Errorf("expected SecretRef git-creds, got %+v", got.Spec.SecretRef)
707+
}
708+
})
709+
}
710+
}
711+
712+
// Checked right after flag parsing: CRDs and Flux are installed before the
713+
// platform source, so a combination rejected only there would exit after a
714+
// partial install.
715+
func TestValidatePlatformSourceCertSecret(t *testing.T) {
716+
tests := []struct {
717+
name string
718+
sourceURL string
719+
certSecret string
720+
wantErr bool
721+
}{
722+
{name: "oci with cert secret", sourceURL: "oci://registry.internal:8083/cozystack-packages", certSecret: "registry-ca"},
723+
{name: "oci without cert secret", sourceURL: "oci://registry.internal:8083/cozystack-packages"},
724+
{name: "https git without cert secret", sourceURL: "https://git.internal/cozystack/cozystack"},
725+
{name: "ssh git without cert secret", sourceURL: "ssh://[email protected]/cozystack/cozystack"},
726+
{name: "no source url", certSecret: "registry-ca"},
727+
{name: "https git with cert secret", sourceURL: "https://git.internal/cozystack/cozystack", certSecret: "git-ca", wantErr: true},
728+
{name: "ssh git with cert secret", sourceURL: "ssh://[email protected]/cozystack/cozystack", certSecret: "git-ca", wantErr: true},
729+
}
730+
for _, tt := range tests {
731+
t.Run(tt.name, func(t *testing.T) {
732+
err := validatePlatformSourceCertSecret(tt.sourceURL, tt.certSecret)
733+
if (err != nil) != tt.wantErr {
734+
t.Errorf("validatePlatformSourceCertSecret(%q, %q) error = %v, wantErr %v", tt.sourceURL, tt.certSecret, err, tt.wantErr)
735+
}
736+
})
737+
}
738+
}
739+
595740
func TestGenerateGitRepository(t *testing.T) {
596741
refMap := map[string]string{"branch": "main", "commit": "abc1234def5678"}
597742
obj, err := generateGitRepository("my-repo", "https://github.com/user/repo", refMap, "")

‎packages/core/installer/templates/cozystack-operator.yaml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ spec:
200200
{{- if .Values.cozystackOperator.platformSourceSecret }}
201201
- --platform-source-secret={{ .Values.cozystackOperator.platformSourceSecret }}
202202
{{- end }}
203+
{{- if .Values.cozystackOperator.platformSourceCertSecret }}
204+
- --platform-source-cert-secret={{ .Values.cozystackOperator.platformSourceCertSecret }}
205+
{{- end }}
203206
{{- $hasEndpointEnv := or (eq .Values.cozystackOperator.variant "talos") (eq .Values.cozystackOperator.variant "generic") }}
204207
{{- if or .Values.cozystackOperator.platformVersion $hasEndpointEnv }}
205208
env:
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
suite: cozystack-operator platform source arguments
2+
3+
# Each flag must follow its own value: a pull-through cache behind a private CA
4+
# often needs the CA without credentials, so a cert flag keyed on the wrong
5+
# value would bring back the TLS failure while every other case stays green.
6+
7+
templates:
8+
- templates/cozystack-operator.yaml
9+
10+
tests:
11+
- it: passes platformSourceCertSecret alone, without credentials
12+
set:
13+
cozystackOperator.platformSourceCertSecret: registry-ca
14+
asserts:
15+
- contains:
16+
path: spec.template.spec.containers[0].args
17+
content: --platform-source-cert-secret=registry-ca
18+
documentSelector:
19+
path: kind
20+
value: Deployment
21+
- notExists:
22+
path: spec.template.spec.containers[0].args[?(@ =~ /^--platform-source-secret=/)]
23+
documentSelector:
24+
path: kind
25+
value: Deployment
26+
27+
- it: passes platformSourceSecret alone, without the cert flag
28+
set:
29+
cozystackOperator.platformSourceSecret: registry-creds
30+
asserts:
31+
- contains:
32+
path: spec.template.spec.containers[0].args
33+
content: --platform-source-secret=registry-creds
34+
documentSelector:
35+
path: kind
36+
value: Deployment
37+
- notExists:
38+
path: spec.template.spec.containers[0].args[?(@ =~ /^--platform-source-cert-secret=/)]
39+
documentSelector:
40+
path: kind
41+
value: Deployment
42+
43+
- it: passes both secrets together
44+
set:
45+
cozystackOperator.platformSourceSecret: registry-creds
46+
cozystackOperator.platformSourceCertSecret: registry-ca
47+
asserts:
48+
- contains:
49+
path: spec.template.spec.containers[0].args
50+
content: --platform-source-cert-secret=registry-ca
51+
documentSelector:
52+
path: kind
53+
value: Deployment
54+
- contains:
55+
path: spec.template.spec.containers[0].args
56+
content: --platform-source-secret=registry-creds
57+
documentSelector:
58+
path: kind
59+
value: Deployment
60+
61+
- it: omits the cert secret flag by default
62+
asserts:
63+
- notExists:
64+
path: spec.template.spec.containers[0].args[?(@ =~ /^--platform-source-cert-secret=/)]
65+
documentSelector:
66+
path: kind
67+
value: Deployment

0 commit comments

Comments
 (0)