Skip to content

Commit 9ea4a96

Browse files
committed
fix(cacert): make the comments match the reconciler
Comments in the CA-extraction package described guards the code does not have. ManagedLabel: the anti-clobber decision is made by isOurProjection, from the Secret type and an owner reference back to the sentinel, not from the marker, which no decision keys on beyond the drift check. managedByCozystackLabel: the reconciler does mutate it. It deletes the label on a selectors-digest change, which is what hands the projection back to the lineage webhook for a fresh verdict. projectionSuffix: the projection name is kept clear of engine CA Secrets by a dot, and a release name cannot carry one, but the suffix an operator appends can and nothing validates it. A suffix ending in ".tenant-ca" is the only one that reaches a canonical name. TestProjectionNameCannotCollideWithADotFreeEngineSuffix: both its doc and its name claimed the property for any engine suffix while the loop samples only dot-free ones, which is the same overstatement one file over. Assisted-by: LLM Signed-off-by: Aleksei Sviridkin <[email protected]>
1 parent e94fcf8 commit 9ea4a96

2 files changed

Lines changed: 37 additions & 20 deletions

File tree

‎internal/controller/cacert/reconciler.go‎

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,11 @@ const (
114114
// per-release name templating.
115115
TenantCALabel = "internal.cozystack.io/tenant-ca"
116116

117-
// ManagedLabel marks a projection as controller-created. The reconciler
118-
// only ever writes over a Secret bearing this label, so a Secret that
119-
// merely shares the name — an engine's own key-bearing CA, for one — is
120-
// never clobbered.
117+
// ManagedLabel marks a projection as controller-created. It is part of the
118+
// drift check, so stripping it produces a write that puts it back, but no
119+
// decision keys on it beyond that: whether a Secret at the canonical name may
120+
// be overwritten is isOurProjection's call, and it does not look at this
121+
// label.
121122
ManagedLabel = "internal.cozystack.io/ca-cert-copy"
122123

123124
// SourceRefAnnotation records the "<namespace>/<name>" of the source on the
@@ -165,7 +166,9 @@ const (
165166
SelectorsDigestAnnotation = "internal.cozystack.io/ca-cert-selectors"
166167

167168
// managedByCozystackLabel is stamped by the lineage admission webhook. The
168-
// reconciler never writes it; it only takes care not to strip it.
169+
// reconciler removes it on exactly one occasion — a change to the selectors
170+
// digest, which is what hands the projection back for re-admission (see
171+
// upsertProjection) — and preserves it on every other write.
169172
managedByCozystackLabel = "internal.cozystack.io/managed-by-cozystack"
170173

171174
// helmNameLabel is the Helm ownership label Flux stamps on every rendered
@@ -185,12 +188,18 @@ const (
185188

186189
// projectionSuffix completes the canonical name "<release>.tenant-ca".
187190
//
188-
// The DOT is load-bearing. Engine CA Secrets are named <prefix><app><suffix>,
189-
// and app names are validated as DNS-1035 labels, which cannot contain a dot
190-
// (pkg/apis/apps/validation); Secret names are DNS-1123 subdomains, which can.
191-
// So no engine can generate this name for any application, and the projection
192-
// cannot collide with an operator-owned object — in either direction, and both
193-
// are unrecoverable. Do not "tidy" the dot into a dash.
191+
// The DOT is what separates the projection from engine CA Secrets, named
192+
// <prefix><app><suffix>; Secret names are DNS-1123 subdomains, so a dot in one
193+
// is legal. A release the apps API created carries none: application names are
194+
// DNS-1035 labels (pkg/apis/apps/validation) and release.prefix is restricted
195+
// to ^[a-z0-9-]*$ (api/v1alpha1). That guarantee stops at the API, because the
196+
// release here comes from the helm.toolkit.fluxcd.io/name LABEL and a label
197+
// value may carry a dot, so a hand-written HelmRelease is outside it. On the
198+
// validated path the dot can only come from the <suffix> an operator or chart
199+
// appends, which nothing validates at all, and a canonical name ends in
200+
// ".tenant-ca" carrying that one dot, so only a suffix ending in ".tenant-ca"
201+
// reaches one. A Secret there this controller does not recognise as its own is
202+
// never overwritten; see isOurProjection. Do not "tidy" the dot into a dash.
194203
projectionSuffix = ".tenant-ca"
195204

196205
// appsGroup is the API group of the aggregated application kinds, as it
@@ -598,9 +607,13 @@ func (r *Reconciler) anotherSentinelForRelease(ctx context.Context, tp *internal
598607
// over itself.
599608
//
600609
// The canonical name is chosen so that no operator the platform ships claims
601-
// it, so this is not reachable through any of them today; it is reachable
602-
// through a misconfiguration (a sentinel pointing sourceSecretName at
603-
// "<release>.tenant-ca" itself), and the answer depends entirely on content.
610+
// it, so this is not reachable through any of them today. One way in is a
611+
// misconfiguration: a sentinel pointing sourceSecretName at
612+
// "<release>.tenant-ca" itself. The other is legitimate, and is why the
613+
// key-free branch below is a success rather than a refusal: an operator whose
614+
// own CA Secret is named with an appended ".tenant-ca", declared as the source
615+
// by its chart. Nothing validates that suffix; see projectionSuffix. The answer
616+
// depends entirely on content.
604617
//
605618
// A key-FREE Secret there is already the trust anchor the tenant needs: there
606619
// is nothing to extract, it is not the controller's to adopt, and that is a

‎internal/controller/cacert/reconciler_test.go‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,10 +1488,14 @@ func TestOwnedSolelyBy(t *testing.T) {
14881488
}
14891489
}
14901490

1491-
// TestProjectionNameCannotCollideWithAnEngineCASecret pins the property the
1492-
// canonical name exists to have: no engine CA Secret, for any release, can ever
1493-
// produce the dotted "<release>.tenant-ca" name.
1494-
func TestProjectionNameCannotCollideWithAnEngineCASecret(t *testing.T) {
1491+
// TestProjectionNameCannotCollideWithADotFreeEngineSuffix pins the property the
1492+
// canonical name exists to have, over the dot-free engine suffixes it samples:
1493+
// no engine CA Secret takes the dotted "<release>.tenant-ca" name. Validation
1494+
// elsewhere generalises this over the releases the apps API created and no
1495+
// further, a hand-written HelmRelease being free to carry a dot in its name;
1496+
// over suffixes nothing validates anything, so there the fixtures are the whole
1497+
// coverage. See projectionSuffix.
1498+
func TestProjectionNameCannotCollideWithADotFreeEngineSuffix(t *testing.T) {
14951499
engineSuffixes := []string{"-ca", "-ca-cert", "-cluster-ca-cert", "-clients-ca-cert", "-ssl", "-tls"}
14961500
prefixes := []string{"", "postgres-", "kafka-", "clickhouse-", "http-cache-"}
14971501
appNames := []string{
@@ -1500,8 +1504,8 @@ func TestProjectionNameCannotCollideWithAnEngineCASecret(t *testing.T) {
15001504
}
15011505

15021506
if !strings.HasPrefix(projectionSuffix, ".") {
1503-
t.Fatalf("the canonical suffix must start with a dot; it is what makes the name "+
1504-
"unreachable by any engine. Got %q", projectionSuffix)
1507+
t.Fatalf("the canonical suffix must start with a dot; it is what keeps the name "+
1508+
"out of reach of a dot-free engine suffix. Got %q", projectionSuffix)
15051509
}
15061510

15071511
for _, prefix := range prefixes {

0 commit comments

Comments
 (0)