Skip to content

Create ApprovedImages based on MachineConfigs - #376

Merged
Jakob-Naucke merged 11 commits into
trusted-execution-clusters:mainfrom
Jakob-Naucke:mc
Nov 4, 2026
Merged

Jakob-Naucke merged 11 commits into
trusted-execution-clusters:mainfrom
Jakob-Naucke:mc

Conversation

@Jakob-Naucke

@Jakob-Naucke Jakob-Naucke commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

Gated behind an openshift feature, watch MachineConfigs and create and delete ApprovedImages based on their osImageURLs.
With the same feature, do not create ApprovedImages in tests.

Happy to resume this work, initial commit is over a year old 😅

Summary by Sourcery

Add feature-gated OpenShift support for automatically creating ApprovedImages from MachineConfig OS image URLs while keeping non-OpenShift behavior unchanged.

New Features:

  • Add an optional OpenShift integration that creates ApprovedImages from MachineConfigs selected by labelled MachineConfigPools.
  • Generate and register OpenShift MachineConfig and MachineConfigPool APIs and CRDs when the feature is enabled.

Bug Fixes:

  • Prevent OpenShift-enabled integration tests from creating or waiting for manually supplied ApprovedImages.

Enhancements:

  • Centralize RFC1035 resource naming and Kubernetes resource creation helpers for reuse across controllers.
  • Document the OpenShift MachineConfig-based ApprovedImage workflow and exclude external OpenShift CRDs from production bundles.

Build:

  • Add OpenShift feature-aware CRD generation and all-features build and test targets.

CI:

  • Run linting and Rust tests with generated OpenShift CRDs and all features enabled.

Documentation:

  • Document automatic ApprovedImage creation from eligible OpenShift MachineConfigs.

Tests:

  • Add unit coverage for MachineConfigPool selection, image creation, and reconciliation.

Chores:

  • Update OpenShift and related dependency metadata.

@sourcery-ai

sourcery-ai Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Introduces optional OpenShift integration that watches labeled MachineConfigPools and their selected MachineConfigs, creates deterministic ApprovedImages for eligible osImageURLs, and wires the feature through generated APIs, reconciliation, RBAC, CI, tests, packaging, and documentation while centralizing resource naming and creation utilities.

Sequence diagram for OpenShift MachineConfig ApprovedImage creation

sequenceDiagram
    participant MCP as MachineConfigPool
    participant MC as MachineConfig
    participant Controller as OpenShiftImageController
    participant Store as ApprovedImageStore
    participant API as KubernetesAPI

    MCP->>Controller: watch labeled MachineConfigPool
    Controller->>MC: select matching MachineConfigs
    MC-->>Controller: osImageURL
    Controller->>Store: check matching ApprovedImage
    alt eligible image is not stored
        Controller->>API: create ApprovedImage
        API-->>Controller: ApprovedImage created
    else image already exists
        Controller-->>Controller: requeue reconciliation
    end
Loading

Flow diagram for OpenShift MachineConfig eligibility

flowchart TD
    A[MachineConfigPool] --> B{Has autocreate label?}
    B -- No --> X[Ignore MachineConfigPool]
    B -- Yes --> C[Select MachineConfigs by labels]
    C --> D{MachineConfig has osImageURL?}
    D -- No --> Y[Skip image creation]
    D -- Yes --> E[Generate deterministic RFC1035 name]
    E --> F[Create ApprovedImage]
Loading

File-Level Changes

Change Details Files
Add feature-gated OpenShift reconciliation that discovers eligible MachineConfigs and creates deterministic ApprovedImages for their OS image URLs.
  • Add OpenShift MachineConfig and MachineConfigPool generated APIs and cluster reflectors.
  • Match labeled MachineConfigPools to MachineConfigs using Kubernetes label selectors.
  • Create idempotent ApprovedImages with source labels and RFC1035-compliant, hash-based names.
  • Register RBAC, controller startup, cache synchronization, and reconciliation wiring behind the openshift feature.
  • Add unit tests for selector matching, missing URLs, image creation, and reconciliation.
Cargo.toml
go.mod
Makefile
tools.go
api/v1alpha1/crds.go
lib/Cargo.toml
lib/src/kopium.rs
lib/src/lib.rs
lib/src/reference_values.rs
lib/src/machineconfigs.rs
lib/src/machineconfigpools.rs
operator/Cargo.toml
operator/src/lib.rs
operator/src/main.rs
operator/src/openshift_images.rs
Centralize deterministic resource naming and Kubernetes resource creation while preserving existing operator behavior.
  • Replace the create-or-ignore macro with a generic async helper for namespaced resources.
  • Move RFC1035 sanitization and SHA-1 disambiguation into shared library code.
  • Update compute-PCR Job and operator resource callers to use the shared helpers.
lib/src/reference_values.rs
operator/src/lib.rs
operator/src/reference_values.rs
operator/src/attestation_key_register.rs
operator/src/register_server.rs
operator/src/trustee.rs
Make OpenShift support and test behavior available through build, CI, deployment, and documentation changes.
  • Add openshift features to operator, library, and test utilities.
  • Generate OpenShift CRDs and run all-feature tests in CI and Make targets.
  • Exclude non-operator-owned MachineConfig CRDs from production bundles.
  • Prevent feature-enabled tests from applying or waiting for manually supplied ApprovedImages.
  • Document automatic ApprovedImage creation and its non-deletion behavior.
.github/workflows/lint.yml
.github/workflows/rust.yml
Makefile
scripts/generate-bundle-prod.sh
test_utils/Cargo.toml
test_utils/src/lib.rs
docs/design/reference-values.md

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

@Jakob-Naucke
Jakob-Naucke removed the request for review from SpaceFace02 September 28, 2026 15:27

@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 3 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="lib/src/reference_values.rs" line_range="23" />
<code_context>
+    let hash = hash(MessageDigest::sha1(), name.as_bytes())?;
+    let hashed = hex::encode(hash)[..10].to_string();
+    let formatted = format!("{prefix}-{hashed}-{replaced}");
+    Ok(formatted[..63].trim_end_matches('-').to_string())
+}

</code_context>
<issue_to_address>
**issue (bug_risk):** `formatted[..63]` panics when the generated name is shorter than 63 bytes, so `rfc1035("x", "prefix")` crashes instead of returning a valid truncated name.

**Triggers:** When a caller passes a short image reference or resource name.

**Suggested fix:** Use a bounded truncation operation such as `formatted.chars().take(63)` or slice only up to `formatted.len()`.

```suggestion
    Ok(formatted.chars().take(63).collect::<String>().trim_end_matches('-').to_string())
```
</issue_to_address>

### Comment 2
<location path="operator/src/mc_images.rs" line_range="37-48" />
<code_context>
+        return Ok(LONG_REQUEUE);
+    };
+
+    let image_name = rfc1035(&format!("{mcp_name}-{url}"), OSIMAGE_RESOURCE_PREFIX)?;
+    let labels = BTreeMap::from([(MCP_LABEL.to_string(), mcp_name.to_string())]);
+    let image = ApprovedImage {
+        metadata: ObjectMeta {
+            name: Some(image_name),
+            labels: Some(labels),
+            ..Default::default()
+        },
+        spec: ApprovedImageSpec { image: url },
+        status: None,
+    };
+    create_or_info_if_exists(ctx.client.clone(), &image).await?;
+    Ok(LONG_REQUEUE)
+}
</code_context>
<issue_to_address>
**issue (bug_risk):** When an MCP changes to reference a different MachineConfig or OS image, `add_approved_image` creates a new ApprovedImage but never deletes the previous one. On MCP deletion, `delete_approved_image` also deletes only the first matching image returned by the store, leaving any older images with the same MCP label behind.

**Triggers:** When an MCP configuration or its OS image changes, or when an MCP has accumulated more than one generated ApprovedImage.

**Suggested fix:** Track the current generated image identity and delete superseded images during apply; during cleanup, list and delete every ApprovedImage carrying the MCP label.
</issue_to_address>

### Comment 3
<location path="operator/Cargo.toml" line_range="39" />
<code_context>
 jsonwebtoken-openssl = "2.0.0"

+[features]
+openshift = ["trusted-cluster-operator-lib/openshift"]
+
 [dev-dependencies]
</code_context>
<issue_to_address>
**issue (testing):** Enabling the operator's `openshift` feature does not enable the separate `trusted-cluster-operator-test-utils/openshift` feature, so `#[cfg(not(feature = "openshift"))]` remains active in test_utils and tests still apply ApprovedImage manifests.

**Triggers:** When tests are run with the operator's `openshift` feature enabled.

**Suggested fix:** Forward the feature to test_utils in the relevant dependency feature definition, and define/propagate the feature for the integration-tests crate as well.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 3 findings to address first, and the operator now creates and deletes persisted ApprovedImage resources from cluster-wide MachineConfigPool state; a wrong association or image URL could cause PCR computation and attestation decisions to use the wrong image, while deletion can remove existing approval records. Reverting stops the new controller but does not automatically restore resources it created or deleted, so recovery requires reconciliation or manual repair.

Blocking findings: lib/src/reference_values.rs:23, operator/src/mc_images.rs:48, operator/Cargo.toml:39


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

Comment thread lib/src/reference_values.rs Resolved
Comment thread operator/src/mc_images.rs Outdated
Comment on lines +37 to +48
let image_name = rfc1035(&format!("{mcp_name}-{url}"), OSIMAGE_RESOURCE_PREFIX)?;
let labels = BTreeMap::from([(MCP_LABEL.to_string(), mcp_name.to_string())]);
let image = ApprovedImage {
metadata: ObjectMeta {
name: Some(image_name),
labels: Some(labels),
..Default::default()
},
spec: ApprovedImageSpec { image: url },
status: None,
};
create_or_info_if_exists(ctx.client.clone(), &image).await?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (bug_risk): When an MCP changes to reference a different MachineConfig or OS image, add_approved_image creates a new ApprovedImage but never deletes the previous one. On MCP deletion, delete_approved_image also deletes only the first matching image returned by the store, leaving any older images with the same MCP label behind.

Triggers: When an MCP configuration or its OS image changes, or when an MCP has accumulated more than one generated ApprovedImage.

Suggested fix: Track the current generated image identity and delete superseded images during apply; during cleanup, list and delete every ApprovedImage carrying the MCP label.

Comment thread operator/Cargo.toml Resolved

@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 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="operator/src/mc_images.rs" line_range="154-157" />
<code_context>
+    let mcp_ctx = ctx.clone();
+    tokio::spawn(
+        Controller::new(mcs, Default::default())
+            .watches(mcps, Default::default(), move |mcp| {
+                let mcs = mcp_ctx.mc_store.state_filter(|mc| is_live(&mcp, mc));
+                mcs.into_iter()
+                    .filter_map(|mc| mc.metadata.name.as_deref().map(ObjectRef::new))
+                    .collect::<Vec<_>>()
+            })
</code_context>
<issue_to_address>
**issue (broader_impact):** When a MachineConfigPool selector is narrowed or otherwise changed, the watch mapper enqueues only MachineConfigs matching the new selector. MachineConfigs that matched the old selector but no longer match are never reconciled, so their ApprovedImages remain after the MachineConfigPool stops selecting them.

**Triggers:** When an existing MachineConfigPool changes its selector to exclude previously selected MachineConfigs.

**Suggested fix:** Enqueue the union of MachineConfigs matching the old and new pool selectors, or reconcile all MachineConfigs affected by the pool event before applying the new scope.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 1 finding to address first, and the new controller automatically creates and deletes ApprovedImages from OpenShift MachineConfigPool selectors, changing which OS images are trusted for attestation and potentially revoking images through the downstream Trustee flow. Reverting the operator does not restore ApprovedImages or trust data that were already created or deleted, so a mistaken selector or cleanup decision requires separate repair.

Blocking findings: operator/src/mc_images.rs:157


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

Comment thread operator/src/mc_images.rs Outdated
Comment on lines +154 to +157
.watches(mcps, Default::default(), move |mcp| {
let mcs = mcp_ctx.mc_store.state_filter(|mc| is_live(&mcp, mc));
mcs.into_iter()
.filter_map(|mc| mc.metadata.name.as_deref().map(ObjectRef::new))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (broader_impact): When a MachineConfigPool selector is narrowed or otherwise changed, the watch mapper enqueues only MachineConfigs matching the new selector. MachineConfigs that matched the old selector but no longer match are never reconciled, so their ApprovedImages remain after the MachineConfigPool stops selecting them.

Triggers: When an existing MachineConfigPool changes its selector to exclude previously selected MachineConfigs.

Suggested fix: Enqueue the union of MachineConfigs matching the old and new pool selectors, or reconcile all MachineConfigs affected by the pool event before applying the new scope.

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.

I'm not sure the previous state of the MCP is really available here. I'm tempted to say LONG_REQUEUE will take care of it but I'm open to reviewers' opinions.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The previous MCP state is not available to this mapper, so the union-of-old-and-new approach is not practical without adding separate state. LONG_REQUEUE would eventually reconcile the MachineConfig—currently after one hour—but it leaves the ApprovedImage stale for up to that hour and is not a reliable event-driven cleanup mechanism.

I would avoid relying on it: on any MCP event, enqueue all cached MachineConfigs (or maintain the previous selector state separately), then let handle_machineconfig determine that previously selected objects are no longer live and delete their ApprovedImages.

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.

i.e.

            .watches(mcps, Default::default(), move |_| {
                let iter = mcp_ctx.mc_store.state().into_iter();
                iter.filter_map(|mc| mc.metadata.name.as_deref().map(ObjectRef::new))
                    .collect::<Vec<_>>()
            })

hmm. still open to comments from reviewers

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Yes, that is the right fix. The mapper should enqueue every cached MachineConfig for any MachineConfigPool event, because handle_machineconfig will then evaluate each one against the current MCP selectors and delete images for MCs that are no longer selected. The current head still uses state_filter(|mc| is_live(&mcp, mc)), so the stale-image case remains.

.watches(mcps, Default::default(), move |_| {
    mcp_ctx
        .mc_store
        .state()
        .into_iter()
        .filter_map(|mc| mc.metadata.name.as_deref().map(ObjectRef::new))
        .collect::<Vec<_>>()
})

This also handles selector widening and newly added MCPs; LONG_REQUEUE can remain only as a fallback for missed events.

Comment thread operator/src/lib.rs Resolved
Comment thread operator/src/mc_images.rs Outdated
let url = mc.spec.os_image_url.as_ref();
// Delete if moved out of scope or URL out of date
if !live || url.is_none_or(|url| *url != stored.spec.image) {
delete_approved_image(&stored, ctx.client.clone()).await?;

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.

The assumption here is that each TEC-machine can have only a single approved-image (which may be true).
What happens if a CoreOS of a node is upgraded and the node fails to boot with the new (CoreOS) approved-image -- does it fallback to the previously working still-installed CoreOS version (or just keep trying and failing the new version) ?

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.

As discussed off-GitHub, we don't currently know enough about the upgrade process to be certain about when deletion is safe, and are currently leaving deletion open.

The MachineConfigPools are now additionally filtered by a label.

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.

I think we should also add the image from baseOSContainerImage, WDYT?

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.

Currently I can not see this documentation, but why prefer the base over the custom-image itself ?
Is it for not updating the ApprovedImage when switching between several images with the same base-image ?

The base-image and the custom-image can have different PCRs' values -- depending on the Containerfile modifications.

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.

In the current draft, both the ControllerConfig's image and the MachineConfigs' images would be added, and they'd be equal ApprovedImages

however

the ControllerConfig watch as drafted here does not work because it contains nullable required fields, which (like non-nullable required fields) Kopium turns into T (not Option<T>). Many real-world ControllerConfigs have some of these fields as null so the watch fails.

I'm considering adding a case to Kopium that changes this, but as we're not yet sure if such images will be configured in the ControllerConfig in the near future, I'm more strongly considering to leave out ControllerConfigs here for now. WDYT?

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.

moved ControllerConfig to a shelved branch, only watching MachineConfigs as originally for now

@Jakob-Naucke
Jakob-Naucke force-pushed the mc branch 3 times, most recently from 519fe93 to 3552022 Compare October 16, 2026 13:48
@Jakob-Naucke Jakob-Naucke changed the title Create & remove ApprovedImages based on MachineConfigs Create ApprovedImages based on MachineConfigs Oct 20, 2026
@Jakob-Naucke
Jakob-Naucke force-pushed the mc branch 2 times, most recently from 15b51b8 to f0a64c8 Compare October 26, 2026 11:24
@Jakob-Naucke
Jakob-Naucke marked this pull request as draft October 26, 2026 13:27
@Jakob-Naucke
Jakob-Naucke marked this pull request as ready for review October 28, 2026 20:38

@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 8 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="api/v1alpha1/crds.go" line_range="38" />
<code_context>
 // +kubebuilder:rbac:groups=trusted-execution-clusters.io,resources=trustedexecutionclusters/finalizers;machines/finalizers;attestationkeys/finalizers;approvedimages/finalizers,verbs=update
 // +kubebuilder:rbac:groups=trusted-execution-clusters.io,resources=trustedexecutionclusters/status;machines/status;approvedimages/status;attestationkeys/status,verbs=get;patch;update
 // +kubebuilder:rbac:groups=events.k8s.io,resources=events,verbs=create;patch
+// +kubebuilder:rbac:groups=machineconfiguration.openshift.io,resources=machineconfigs;machineconfigpools,verbs=get;list;watch

 // TrustedExecutionClusterSpec defines the desired state of TrustedExecutionCluster
</code_context>
<issue_to_address>
**OpenShift watches are forbidden**

When the OpenShift feature is installed using the repository’s committed RBAC artifacts without regenerating them, the new controller and reflectors list and watch cluster-scoped MachineConfigs and MachineConfigPools, but the committed RBAC artifacts do not include the permissions added by this marker. The API server returns Forbidden, so automatic ApprovedImage creation never works for installations using those artifacts.

Regenerate and commit the operator’s RBAC artifacts and production CSV permissions with the new MachineConfig and MachineConfigPool access.
</issue_to_address>

### Comment 2
<location path="operator/Cargo.toml" line_range="39" />
<code_context>
 jsonwebtoken-openssl = "2.0.0"

+[features]
+openshift = ["trusted-cluster-operator-lib/openshift"]
+
 [dev-dependencies]
</code_context>
<issue_to_address>
**Released operator omits image approval**

When the operator is built through the repository's standard release path, the normal build omits `--features openshift`, so the published operator excludes `openshift_images` and its MachineConfig watcher; users therefore get no automatic ApprovedImages from MachineConfigs.

Enable the `openshift` feature in the standard operator release build.
</issue_to_address>

### Comment 3
<location path="operator/src/openshift_images.rs" line_range="28" />
<code_context>
+    if mcp_labels.is_none_or(|ls| !ls.contains_key(MCP_APPROVED_IMAGE_LABEL)) {
+        return false;
+    }
+    let Some(mc_labels) = mc.metadata.labels.as_ref() else {
+        return false;
+    };
</code_context>
<issue_to_address>
**Unlabeled configs are not selected**

When a labeled MachineConfigPool selects an unlabeled MachineConfig using a valid `DoesNotExist` or `NotIn` expression, `is_live` returns false before evaluating the pool selector when `mc.metadata.labels` is absent, so reconciliation never approves the selected MachineConfig's OS image.

Evaluate the selector against an empty label set when the MachineConfig has no labels.
</issue_to_address>

### Comment 4
<location path="lib/src/reference_values.rs" line_range="22" />
<code_context>
+    if prefix.len() > 52 {
+        return Err(anyhow::anyhow!("prefix too long"));
+    }
+    let replaced = name.replace(['.', ':', '/', '@', '_'], "-");
+    let hash = hash(MessageDigest::sha1(), name.as_bytes())?;
+    let hashed = hex::encode(hash)[..10].to_string();
</code_context>
<issue_to_address>
**Uppercase image tags block approval**

When a selected MachineConfig's valid `osImageURL` contains uppercase characters, such as in its tag, `rfc1035` preserves uppercase characters in the generated name, and `add_mc_image` uses that value as the ApprovedImage metadata name; Kubernetes rejects the create, so the image is never approved.

Convert the generated resource name to lowercase before creating the ApprovedImage.

Also at `operator/src/openshift_images.rs:90`.
</issue_to_address>

### Comment 5
<location path="api/v1alpha1/crds.go" line_range="38" />
<code_context>
 // +kubebuilder:rbac:groups=trusted-execution-clusters.io,resources=trustedexecutionclusters/finalizers;machines/finalizers;attestationkeys/finalizers;approvedimages/finalizers,verbs=update
 // +kubebuilder:rbac:groups=trusted-execution-clusters.io,resources=trustedexecutionclusters/status;machines/status;approvedimages/status;attestationkeys/status,verbs=get;patch;update
 // +kubebuilder:rbac:groups=events.k8s.io,resources=events,verbs=create;patch
+// +kubebuilder:rbac:groups=machineconfiguration.openshift.io,resources=machineconfigs;machineconfigpools,verbs=get;list;watch

 // TrustedExecutionClusterSpec defines the desired state of TrustedExecutionCluster
</code_context>
<issue_to_address>
**OpenShift read access is unconditional**

When the operator is installed on OpenShift with the `openshift` feature disabled, the RBAC generator includes cluster-wide `get`, `list`, and `watch` access to MachineConfigs and MachineConfigPools even when the operator is built without the `openshift` feature. On an OpenShift cluster, a compromised or misbehaving feature-disabled operator can still read those cluster configuration resources, exposing their contents.

Generate or distribute the MachineConfig permissions only for deployments built with the `openshift` feature.
</issue_to_address>

### Comment 6
<location path="operator/src/openshift_images.rs" line_range="91" />
<code_context>
+    };
+
+    let image_name = rfc1035(&format!("{mc_name}-{url}"), OSIMAGE_RESOURCE_PREFIX)?;
+    let labels = BTreeMap::from([(MC_LABEL.to_string(), mc_name.to_string())]);
+    add_approved_image(image_name, labels, url, ctx.client.clone()).await
+}
</code_context>
<issue_to_address>
**Long MachineConfig names block image creation**

When a selected MachineConfig has a valid name longer than 63 characters, `add_mc_image` copies the MachineConfig name into a Kubernetes label value, which is limited to 63 characters. A valid MachineConfig name longer than that makes the ApprovedImage create request fail validation, so the image is never approved.

Store the full MachineConfig name in an annotation or another field that permits longer values, or encode it into a valid bounded label value.
</issue_to_address>

### Comment 7
<location path="test_utils/src/lib.rs" line_range="1118" />
<code_context>
     test_namespace: String,
     manifests_dir: String,
     test_name: String,
+    #[cfg(not(feature = "openshift"))]
     delayed_approved_image: bool,
 }
</code_context>
<issue_to_address>
**Test image fixtures are missing**

When integration tests run with the `openshift` test-utils feature enabled, `TestContext` skips applying the generated ApprovedImage manifests, but tests still query, delete, and verify those named fixtures; they fail because the resources are absent.

Keep applying the test ApprovedImage manifests when the OpenShift test-utils feature is enabled.

Also at `test_utils/src/lib.rs:1119`, `test_utils/src/lib.rs:1188`.
</issue_to_address>

### Comment 8
<location path="operator/Cargo.toml" line_range="39" />
<code_context>
 jsonwebtoken-openssl = "2.0.0"

+[features]
+openshift = ["trusted-cluster-operator-lib/openshift"]
+
 [dev-dependencies]
</code_context>
<issue_to_address>
**OpenShift test behavior is not inherited**

When tests build the operator with `--features openshift` without separately enabling the test-utils feature, enabling the operator’s `openshift` feature enables only the library feature, not `trusted-cluster-operator-test-utils/openshift`; test utilities therefore still apply ApprovedImage manifests and wait for them to be committed in builds that enable OpenShift only on the operator.

Wire the OpenShift test behavior to the same build feature, or expose and document a test feature that enables both crates’ OpenShift features.

Also at `test_utils/src/lib.rs:506`.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 8 findings to address first, and a labeled MachineConfigPool causes its selected MachineConfigs' OS image URLs to become ApprovedImages, so an unintended match can make an image trusted without a separate approval step. Those ApprovedImages are not removed automatically; reverting this change stops future creation but does not undo existing approvals.

Blocking findings: api/v1alpha1/crds.go:38, operator/Cargo.toml:39, operator/src/openshift_images.rs:28, lib/src/reference_values.rs:22, api/v1alpha1/crds.go:38, and 3 more


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

Comment thread api/v1alpha1/crds.go Resolved
Comment thread operator/Cargo.toml Resolved
Comment thread operator/src/openshift_images.rs Resolved
Comment thread lib/src/reference_values.rs Resolved
Comment thread api/v1alpha1/crds.go Resolved
Comment thread operator/src/openshift_images.rs Resolved
Comment thread test_utils/src/lib.rs Resolved
Comment thread operator/Cargo.toml Resolved
#[cfg(feature = "openshift")]
pub const OSIMAGE_RESOURCE_PREFIX: &str = "osimage";
#[cfg(feature = "openshift")]
pub const MCP_APPROVED_IMAGE_LABEL: &str =

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.

It is worth having this value as an environment variable in case there is already an MCP that the administrator wants to be approved images

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.

admin can add labels, IMO that's overengineering

Comment thread operator/src/openshift_images.rs Resolved

@SpaceFace02 SpaceFace02 left a comment

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.

Looks good to me, Roy has a valid point regarding the cel's

Comment thread test_utils/src/lib.rs Resolved
for reuse

Signed-off-by: Jakob Naucke <jnaucke@redhat.com>
for reuse

Signed-off-by: Jakob Naucke <jnaucke@redhat.com>
Signed-off-by: Jakob Naucke <jnaucke@redhat.com>
for reuse

Signed-off-by: Jakob Naucke <jnaucke@redhat.com>
less indirection & can be used in non-anyhow contexts

Signed-off-by: Jakob Naucke <jnaucke@redhat.com>
instead of deriving Default, and then dropping it for unsupported
structs, kopium has a flag do only include it for structs without
multivalued enums which is enough for us.

Signed-off-by: Jakob Naucke <jnaucke@redhat.com>
Gated behind "openshift" feature

Signed-off-by: Jakob Naucke <jnaucke@redhat.com>
@Jakob-Naucke
Jakob-Naucke force-pushed the mc branch 2 times, most recently from 5ff0fba to 67fc4c8 Compare November 3, 2026 08:21
Insert osImageURLs of MachineConfigs as approved images.

Signed-off-by: Jakob Naucke <jnaucke@redhat.com>
Signed-off-by: Jakob Naucke <jnaucke@redhat.com>
for feature-gated MC detection. Move this to a separate section for
separation of particular downstreams.

Signed-off-by: Jakob Naucke <jnaucke@redhat.com>
When enabled, do not create ApprovedImages. Drop an `image_ready`
definition.

Signed-off-by: Jakob Naucke <jnaucke@redhat.com>
@openshift-ci

openshift-ci Bot commented Nov 4, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Jakob-Naucke, 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

@Jakob-Naucke
Jakob-Naucke merged commit fcc38a4 into trusted-execution-clusters:main Nov 4, 2026
15 checks passed
@Jakob-Naucke
Jakob-Naucke deleted the mc branch November 4, 2026 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants