Skip to content

CMP-4521: Fix HyperShift Hosted Cluster detection using controlPlaneTopology - #15085

Open
yuumasato wants to merge 1 commit into
ComplianceAsCode:masterfrom
yuumasato:fix-hypershift-detection-using-controlplanetopology
Open

CMP-4521: Fix HyperShift Hosted Cluster detection using controlPlaneTopology#15085
yuumasato wants to merge 1 commit into
ComplianceAsCode:masterfrom
yuumasato:fix-hypershift-detection-using-controlplanetopology

Conversation

@yuumasato

Copy link
Copy Markdown
Member

Description:

This PR fixes the ocp4-on-hypershift-hosted CPE, which never fired. The
object_hypershift_hosted OVAL object matched ^--platform=HyperShift$ under
.spec.containers[:].command[:] of a hardcoded pod dump
(/kubernetes-api-resources/api/v1/namespaces/openshift-compliance/pods/api-checks-pod).
That path was wrong: the Compliance Operator names the pod <scan-name>-api-checks-pod,
and it places the --platform=HyperShift flag on the api-resource-collector
initContainer, not on a regular container. As a result the CPE was structurally
unreachable and never matched.

Instead of chasing the pod manifest, this PR detects HyperShift Hosted Clusters
from the infrastructure.config.openshift.io/cluster object, checking
.status.controlPlaneTopology == "External". This is the canonical signal for a
cluster whose control plane runs externally in the management cluster, and it is
independent of Compliance Operator pod naming.

Changes to shared/applicability/oval/installed_app_is_ocp4.xml:

  • Point object_hypershift_hosted at ocp4_infra_dump_location with yamlpath
    .status.controlPlaneTopology, matching ^External$.
  • Add a test_file_for_ocp4_infra criterion to the ocp4-on-hypershift-hosted
    definition so it only evaluates when the infrastructure/cluster file is present.
  • Remove the now-unused ocp4_operator_deployment_dump_location variable.

Rationale:

Every rule gated platform: not ocp4-on-hypershift-hosted (46 in ocp4-cis,
54 in ocp4-high, 4 in ocp4-stig) was executing inside hosted clusters against
control-plane namespaces that do not exist there (openshift-kube-apiserver,
openshift-etcd, ...), producing false FAILs (e.g. master_taint_noschedule).
With this fix those rules are correctly reported as NOT-APPLICABLE on HyperShift
Hosted Clusters.

Jira: https://issues.redhat.com/browse/CMP-4521

Review Hints:

To confirm the detection signal on a cluster:

oc get infrastructure cluster -o jsonpath='{.status.controlPlaneTopology}'
  • External -> HyperShift Hosted Cluster (control plane external)
  • HighlyAvailable / SingleReplica -> traditional OCP (control plane local)

The previous OVAL check for detecting HyperShift Hosted Clusters was
unreliable because it looked for a hardcoded pod name that didn't match
the actual pod naming pattern used by the Compliance Operator.

Old approach:
- Checked for file: /kubernetes-api-resources/.../pods/api-checks-pod
- Looked for --platform=HyperShift flag in pod command
- Failed because actual pod name is <scan-name>-api-checks-pod

New approach:
- Checks infrastructure.config.openshift.io/cluster object
- Looks for .status.controlPlaneTopology == "External"
- More reliable and independent of pod naming

This fix ensures that rules with "platform: not ocp4-on-hypershift-hosted"
are properly skipped on HyperShift Hosted Clusters, where control plane
components run externally in the management cluster.

Impact:
- API server, etcd, and other control plane checks will now correctly
  skip on HyperShift Hosted Clusters
- Fixes false failures like master_taint_noschedule on hosted clusters

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
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