Skip to content

feat(runtime): Validate cross-namespace secret refs in SecretValueFromReference#254

Open
sapphirew wants to merge 1 commit into
aws-controllers-k8s:mainfrom
sapphirew:secret-cross-namespace-validation
Open

feat(runtime): Validate cross-namespace secret refs in SecretValueFromReference#254
sapphirew wants to merge 1 commit into
aws-controllers-k8s:mainfrom
sapphirew:secret-cross-namespace-validation

Conversation

@sapphirew
Copy link
Copy Markdown
Contributor

Issue #, if available:

Description of changes:

Move cross-namespace validation for secret references into SecretValueFromReference so every caller is covered, including custom update functions (e.g. RDS db_cluster/custom_update.go) and hooks that call it directly rather than going through generated sdk.go code.

  • When --enable-cross-namespace is false and the secret targets a different namespace, return a terminal error (wrapping the ResourceReferenceCrossNamespaceNotAllowed sentinel). The caller's existing condition machinery sets ACK.Terminal from the message.
  • When the flag is true, log a deprecation warning and resolve the secret from the target namespace (Phase 1 behavior).
  • Same-namespace and empty-namespace refs are unaffected.

This lets the code-generator drop the per-call secret validation block it currently emits in set_sdk.go, which only covered generated sdk.go call sites.

Addresses review feedback on aws-controllers-k8s/code-generator#699.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@ack-prow ack-prow Bot requested review from a-hilaly and jlbutler June 5, 2026 00:05
@ack-prow
Copy link
Copy Markdown

ack-prow Bot commented Jun 5, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: sapphirew
Once this PR has been reviewed and has the lgtm label, please assign a-hilaly for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Comment thread pkg/runtime/reconciler.go
return "", ackerr.NewTerminalError(err)
}
if isCrossNamespace {
r.log.V(0).Info(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to also apply a condition to the resource similar to FieldExports and ResourceReferences? If yes, we may need to change the function signature. We'd still need to manually update the SecretValueFromReference calls in custom code, but at least they'd fail loudly.

…mReference

Move cross-namespace validation for secret references into
SecretValueFromReference so every caller is covered, including custom
update functions (e.g. RDS db_cluster/custom_update.go) and hooks that
call it directly rather than going through generated sdk.go code.

- When --enable-cross-namespace is false and the secret targets a
  different namespace, return a terminal error (wrapping the
  ResourceReferenceCrossNamespaceNotAllowed sentinel). The caller's
  existing condition machinery sets ACK.Terminal from the message.
- When the flag is true, log a deprecation warning, resolve the secret
  from the target namespace, and set the ACK.CrossNamespaceOptInRequired
  condition on the resource being reconciled.

Because SecretValueFromReference does not receive the resource handle,
the reconciler stashes the resource (a ConditionManager) in the context
via WithConditionManager; SecretValueFromReference retrieves it with
ConditionManagerFromContext and sets the condition through
SetCrossNamespaceOptInRequiredOnSubject. The condition is set on the
desired resource before sdkCreate/sdkUpdate deep-copies it into the
returned object, so it persists to the status patch. Passing no
ConditionManager is safe (the condition is simply skipped).

This lets the code-generator drop the per-call secret validation block
it currently emits in set_sdk.go, which only covered generated sdk.go
call sites.

Addresses review feedback on aws-controllers-k8s/code-generator#699.
@sapphirew sapphirew force-pushed the secret-cross-namespace-validation branch from c78f739 to a8e6efc Compare June 5, 2026 01:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants