attestation key QoL improvements - #362
Conversation
Reviewer's GuideThe operator now repairs labels on pre-upgrade AttestationKey secrets so the label-filtered secret controller can discover them, and skips trustee updates during TEC deletion because trustee is being torn down with the cluster. Sequence diagram for AttestationKey secret label backfillsequenceDiagram
participant AK as AttestationKey
participant Operator
participant Kubernetes as Kubernetes API
participant SecretController
AK->>Operator: approve_ak
Operator->>Kubernetes: get_opt(secret_name)
alt Secret exists
Operator->>Operator: ensure_secret_label
Operator->>Kubernetes: patch(secret_name, metadata.labels)
Kubernetes-->>SecretController: Label-filtered secret becomes discoverable
else Secret does not exist
Operator->>Kubernetes: create Secret with kind label
end
Sequence diagram for TEC deletion cleanup optimizationsequenceDiagram
participant Kubernetes as Kubernetes API
participant Operator
participant Trustee
Kubernetes->>Operator: secret_reconcile Cleanup
Operator->>Kubernetes: get_opt_tec
alt TEC is being deleted or absent
Operator-->>Kubernetes: return LONG_REQUEUE
else TEC remains active
Operator->>Trustee: update_attestation_keys
Trustee-->>Operator: update result
Operator-->>Kubernetes: return LONG_REQUEUE
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: SpaceFace02 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="operator/src/attestation_key_register.rs" line_range="300-303" />
<code_context>
info!("Created secret {secret_name} for attestation key {name} with finalizer");
+ } else {
+ // Ensures the AttestationKey secret has the label the secret controller watches on.
+ ensure_secret_label(&secrets, &secret_name).await?;
}
</code_context>
<issue_to_address>
**issue (broader_impact):** When `secret_store` does not yet contain an existing Secret, `approve_ak` takes the creation branch; if the API already contains an unlabeled legacy Secret, `create_or_info_if_exists!` receives a 409 and only logs it, so `ensure_secret_label` is never called and the Secret remains invisible to the label-filtered secret controller.
**Triggers:** When the reflector cache is stale or has not yet observed an existing legacy Secret.
**Suggested fix:** On an already-existing Secret (including a create 409), fetch it from the API and call `ensure_secret_label` instead of relying on the cache-only existence check.
```suggestion
}
// Ensures the AttestationKey secret has the label the secret controller watches on.
ensure_secret_label(&secrets, &secret_name).await?;
```
</issue_to_address>
### Comment 2
<location path="operator/src/attestation_key_register.rs" line_range="379-383" />
<code_context>
+
+ // If TEC is already being deleted, trustee will be deleted too, so no need to update it.
+ let tec_deleting = ctx
+ .get_opt_tec()
+ .ok()
+ .flatten()
+ .is_none_or(|tec| tec.metadata.deletion_timestamp.is_some());
+
+ if tec_deleting {
+ info!(
</code_context>
<issue_to_address>
**issue (bug_risk):** `get_opt_tec().ok().flatten()` treats both an empty TEC cache and a `get_opt_tec` error as evidence that the TEC is being deleted, so Cleanup returns success without calling `update_attestation_keys`; the AttestationKey finalizer is then removed while trustee can retain the deleted key.
**Triggers:** When the TEC reflector cache is temporarily empty or when more than one TEC causes `get_opt_tec` to return an error.
**Suggested fix:** Only skip trustee cleanup when a successfully retrieved TEC has a non-None `deletion_timestamp`; propagate cache/invariant errors and handle a genuinely missing TEC according to the intended teardown state.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 2 findings to address first, and existing attestation secrets are persistently relabeled so the secret controller will process them and update Trustee's mounted keys; if that classification is wrong, Trustee could use or expose an unintended secret before it is corrected. Reverting the code does not remove the label or undo reconciliation that has already changed the deployment, and skipping cleanup could also leave stale Trustee state during deletion.
Blocking findings: operator/src/attestation_key_register.rs:303, operator/src/attestation_key_register.rs:383
- Backfill the kind label onto AttestationKey secrets created by older
operator versions that watched all secrets without a label filter
- AttestationKey secret finalizers return immediately when the
TrustedExecutionCluster is being deleted; trustee is torn down with the
TEC, so there is no need to update it during cleanup.
Signed-off-by: Chirag Rao <crao@redhat.com>
06a6931 to
d3df772
Compare
| } | ||
|
|
||
| // Secrets created by older operator versions lack the label, as older operator versions watched all secrets, without label filters. | ||
| async fn ensure_secret_label(secrets: &Api<Secret>, name: &str) -> Result<()> { |
There was a problem hiding this comment.
I know we wanted to avoid migration jobs, but I honestly prefer a migration job over carrying this around forever. WDYT @alicefr?
There was a problem hiding this comment.
You mean a migration job that the operator spins up which ensures all secrets have labels?
I'm not sure its worth the added complexity, this change is only really needed when we upgrade from versions < 0.2.3. Later versions will have the label present anyways.
There was a problem hiding this comment.
I am with Jakob, if only versions < 0.2.3 will need this for upgrade, and considering such versions have are per-upgrade support, I would prefer a migration job that the admin will have to run to add the missing label rather then a permanent part of the reconciliation loop.
Summary by Sourcery
Ensure legacy AttestationKey secrets remain discoverable and streamline cleanup during TrustedExecutionCluster deletion.
Bug Fixes: