Skip to content

attestation key QoL improvements - #362

Open
SpaceFace02 wants to merge 1 commit into
trusted-execution-clusters:mainfrom
SpaceFace02:qol_changes
Open

attestation key QoL improvements#362
SpaceFace02 wants to merge 1 commit into
trusted-execution-clusters:mainfrom
SpaceFace02:qol_changes

Conversation

@SpaceFace02

@SpaceFace02 SpaceFace02 commented Sep 8, 2026

Copy link
Copy Markdown
Member
  • Backfill the kind label onto AttestationKey secrets created by older operator versions that watched all secrets without a label filter, so the secret controller picks them up after an upgrade.
  • 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.

Summary by Sourcery

Ensure legacy AttestationKey secrets remain discoverable and streamline cleanup during TrustedExecutionCluster deletion.

Bug Fixes:

  • Backfill the AttestationKey kind label on existing secrets so they continue to be reconciled after upgrading the operator.
  • Skip trustee updates while the TrustedExecutionCluster is being deleted.

@sourcery-ai

sourcery-ai Bot commented Sep 8, 2026

Copy link
Copy Markdown

Reviewer's Guide

The 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 backfill

sequenceDiagram
    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
Loading

Sequence diagram for TEC deletion cleanup optimization

sequenceDiagram
    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
Loading

File-Level Changes

Change Details Files
Backfill the AttestationKey kind label on existing secrets so upgraded secret watchers can reconcile them.
  • Create a namespaced Secret API client during attestation key approval.
  • Check existing AttestationKey secrets and merge the expected kind label when it is missing or incorrect.
  • Leave newly created secrets on the existing labeled creation path.
operator/src/attestation_key_register.rs
Avoid unnecessary trustee updates while the TrustedExecutionCluster is being deleted.
  • Detect TEC deletion or absence during AttestationKey secret finalizer cleanup.
  • Skip trustee reconciliation and allow cleanup to proceed when TEC teardown is already underway.
  • Preserve trustee updates and cleanup error handling for normal secret deletion.
operator/src/attestation_key_register.rs

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@openshift-ci

openshift-ci Bot commented Sep 8, 2026

Copy link
Copy Markdown

[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.

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

@SpaceFace02
SpaceFace02 requested review from Jakob-Naucke, iroykaufman and yairpod and removed request for iroykaufman September 8, 2026 06:14

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread operator/src/attestation_key_register.rs
Comment thread operator/src/attestation_key_register.rs Outdated
    - 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>
}

// 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<()> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I know we wanted to avoid migration jobs, but I honestly prefer a migration job over carrying this around forever. WDYT @alicefr?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

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.

3 participants