Skip to content

OCPNODE-3008: Add v1 type ClusterImagePolicy and ImagePolicy #2310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

QiWang19
Copy link
Member

@QiWang19 QiWang19 commented May 6, 2025

Upgrade ClusterImagePolicy and ImagePolicy under SigstoreVerification featuregate to v1. will workon upgrade controller code to use v1 API and promote the featuregate to default as next step.

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label May 6, 2025
@openshift-ci-robot
Copy link

openshift-ci-robot commented May 6, 2025

@QiWang19: This pull request references OCPNODE-3008 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.20.0" version, but no target version was set.

In response to this:

Upgrade ClusterImagePolicy and ImagePolicy under SigstoreVerification featuregate to v1. will workon upgrade controller code to use v1 API and promote the featuregate to default as next step.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

Copy link
Contributor

openshift-ci bot commented May 6, 2025

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 6, 2025
Copy link
Contributor

openshift-ci bot commented May 6, 2025

Hello @QiWang19! Some important instructions when contributing to openshift/api:
API design plays an important part in the user experience of OpenShift and as such API PRs are subject to a high level of scrutiny to ensure they follow our best practices. If you haven't already done so, please review the OpenShift API Conventions and ensure that your proposed changes are compliant. Following these conventions will help expedite the api review process for your PR.

@openshift-ci openshift-ci bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label May 6, 2025
Copy link
Contributor

openshift-ci bot commented May 6, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

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

@QiWang19 QiWang19 force-pushed the sigstoreverification branch from bc22659 to c277fe2 Compare May 6, 2025 10:27
@QiWang19
Copy link
Member Author

QiWang19 commented May 6, 2025

/test all

@QiWang19 QiWang19 force-pushed the sigstoreverification branch 4 times, most recently from 28cc792 to c96787f Compare May 14, 2025 17:54
@QiWang19
Copy link
Member Author

/test lint
/test verify

@QiWang19
Copy link
Member Author

/test all

@QiWang19 QiWang19 force-pushed the sigstoreverification branch from c96787f to a184848 Compare May 21, 2025 21:05
@QiWang19
Copy link
Member Author

/test all

@QiWang19 QiWang19 force-pushed the sigstoreverification branch from a184848 to 5886a58 Compare May 22, 2025 15:24
@QiWang19
Copy link
Member Author

/test all

@QiWang19 QiWang19 marked this pull request as ready for review May 22, 2025 16:25
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 22, 2025
@openshift-ci openshift-ci bot requested review from deads2k and everettraven May 22, 2025 16:25
@QiWang19 QiWang19 changed the title OCPNODE-3008: Upgrade ClusterImagePolicy and ImagePolicy to v1 OCPNODE-3008: Add v1 type ClusterImagePolicy and ImagePolicy May 22, 2025
@QiWang19
Copy link
Member Author

@JoelSpeed Could you review?

Spec ClusterImagePolicySpec `json:"spec"`
// status contains the observed state of the resource.
// +optional
Status ClusterImagePolicyStatus `json:"status,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Omitempty doesn't work on non-pointer structs, you can drop the omitempty tag


// +k8s:deepcopy-gen=true
type ClusterImagePolicyStatus struct {
// conditions provide details on the status of this API Resource.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we provide further detail on the types of conditions that should be expected to be set here? I suspect we have a complete list for the feature now?

Copy link
Member Author

Choose a reason for hiding this comment

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

For ImagePolicy, we have Pending conditions suggesting some configs from this object would be overwritten since they conflict with existing cluster-wide objects.
We don't have other conditions for ClusterImagePolicy/ImagePolicy since there is no mechanism for MCO to give rollout feedback of a machine config.

// +k8s:deepcopy-gen=true
type ClusterImagePolicyStatus struct {
// conditions provide details on the status of this API Resource.
// +kubebuilder:validation:MaxItems=100
Copy link
Contributor

Choose a reason for hiding this comment

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

100 seems high, do you know how many conditions the feature actually uses right now? Would say 8 or 16 be a more sensible limit?

// +listType=map
// +listMapKey=type
// +optional
Conditions []metav1.Condition `json:"conditions,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

You should add a minimum length marker of 1 to this, so that [] is not a valid persisted object

Suggested change
Conditions []metav1.Condition `json:"conditions,omitempty"`
// +kubebuilder:validation:MinItems=1
Conditions []metav1.Condition `json:"conditions,omitempty"`

@@ -4,7 +4,6 @@ source "$(dirname "${BASH_SOURCE}")/lib/init.sh"

crd_globs="\
authorization/v1/zz_generated.crd-manifests/*_config-operator_*.crd*yaml\
config/v1/zz_generated.crd-manifests/*_config-operator_*.crd*yaml\
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this change required?

Copy link
Member Author

Choose a reason for hiding this comment

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

Add this change so the v1 manifests will not be included in the payload at this time https://github.com/openshift/api/tree/master/payload-manifests/crds. From our previous discussion, we will include the manifests later when MCO controller implementation is ready to use v1 APIs.

Spec ImagePolicySpec `json:"spec"`
// status contains the observed state of the resource.
// +optional
Status ImagePolicyStatus `json:"status,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Omitempty here is not doing anything


// Policy defines the verification policy for the items in the scopes list.
type Policy struct {
// rootOfTrust specifies the root of trust for the policy.
Copy link
Contributor

Choose a reason for hiding this comment

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

This godoc is a little light, can we expand at all on what a root of trust is, and/or why someone might want to configure this option

}

// PKI defines the root of trust based on Root CA(s) and corresponding intermediate certificates.
type PKI struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should add minimum lengths to each of the slices in this example

Copy link
Contributor

@everettraven everettraven left a comment

Choose a reason for hiding this comment

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

An initial pass. Structure of the API looks good. Most of my comments are suggestions to improve the API documentation and a couple validations that appear to need some updating

Comment on lines +48 to +49
// +required
// +kubebuilder:validation:MaxItems=256
Copy link
Contributor

Choose a reason for hiding this comment

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

Explicitly state these constraints in the GoDoc for the field. Users will not be able to see the markers when looking at the generated documentation so stating these validations explicitly, in plain english, helps us convey constraints to user reading the generated documentation.

Scopes []ImageScope `json:"scopes"`
// policy contains configuration to allow scopes to be verified, and defines how
// images not matching the verification policy will be treated.
// +required
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto on explicit inclusion in the GoDoc that this field is required.

RootOfTrust PolicyRootOfTrust `json:"rootOfTrust"`
// signedIdentity specifies what image identity the signature claims about the image. The required matchPolicy field specifies the approach used in the verification process to verify the identity in the signature and the actual image identity, the default matchPolicy is "MatchRepoDigestOrExact".
// +optional
SignedIdentity PolicyIdentity `json:"signedIdentity,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

As Joel has mentioned previously, omitempty doesn't do anything on a non-pointer struct. It can be dropped here.

// Policy defines the verification policy for the items in the scopes list.
type Policy struct {
// rootOfTrust specifies the root of trust for the policy.
// +required
Copy link
Contributor

Choose a reason for hiding this comment

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

Explicitly mention in the GoDoc that this field is required.

// +required
RootOfTrust PolicyRootOfTrust `json:"rootOfTrust"`
// signedIdentity specifies what image identity the signature claims about the image. The required matchPolicy field specifies the approach used in the verification process to verify the identity in the signature and the actual image identity, the default matchPolicy is "MatchRepoDigestOrExact".
// +optional
Copy link
Contributor

Choose a reason for hiding this comment

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

Explicitly mention that this field is optional in the GoDoc. It looks like you do appropriately state what the default behavior is if this field is omitted.

type PolicyMatchExactRepository struct {
// repository is the reference of the image identity to be matched.
// The value should be a repository name (by omitting the tag or digest) in a registry implementing the "Docker Registry HTTP API V2". For example, docker.io/library/busybox
// +required
Copy link
Contributor

Choose a reason for hiding this comment

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

Explicit mention of being required.

type PolicyMatchRemapIdentity struct {
// prefix is the prefix of the image identity to be matched.
// If the image identity matches the specified prefix, that prefix is replaced by the specified “signedPrefix” (otherwise it is used as unchanged and no remapping takes place).
// This useful when verifying signatures for a mirror of some other repository namespace that preserves the vendor’s repository structure.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// This useful when verifying signatures for a mirror of some other repository namespace that preserves the vendor’s repository structure.
// This is useful when verifying signatures for a mirror of some other repository namespace that preserves the vendor’s repository structure.

// The prefix and signedPrefix values can be either host[:port] values (matching exactly the same host[:port], string), repository namespaces,
// or repositories (i.e. they must not contain tags/digests), and match as prefixes of the fully expanded form.
// For example, docker.io/library/busybox (not busybox) to specify that single repository, or docker.io/library (not an empty string) to specify the parent namespace of docker.io/library/busybox.
// +required
Copy link
Contributor

Choose a reason for hiding this comment

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

Explicitly mention that the field is required in the GoDoc.

// signedPrefix is the prefix of the image identity to be matched in the signature. The format is the same as "prefix". The values can be either host[:port] values (matching exactly the same host[:port], string), repository namespaces,
// or repositories (i.e. they must not contain tags/digests), and match as prefixes of the fully expanded form.
// For example, docker.io/library/busybox (not busybox) to specify that single repository, or docker.io/library (not an empty string) to specify the parent namespace of docker.io/library/busybox.
// +required
Copy link
Contributor

Choose a reason for hiding this comment

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

Explicitly mention that the field is required in the GoDoc.

}

// IdentityMatchPolicy defines the type of matching for "matchPolicy".
// +kubebuilder:validation:Enum=MatchRepoDigestOrExact;MatchRepository;ExactRepository;RemapIdentity
Copy link
Contributor

Choose a reason for hiding this comment

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

From my understanding, this should allow the omitted value ("") - which is missing in this enum.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should it? The enum is used in a required field context, I would expect in this case that not allowing the empty string is probably correct.

I see there is a "When omitted" description though, which does imply that "" is a valid value.

Looking at the shape here, I think we have a case of "optional struct that has a required field within, where the required fields do not accept the zero value"

In this case, the appropriate action is to make the struct field a pointer, so that it can be correctly omitted.

Unless we are deliberately going for discoverability, in which case we need to make sure that all of the fields within the struct accept their zero value

Copy link
Contributor

@everettraven everettraven May 30, 2025

Choose a reason for hiding this comment

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

Unless we are deliberately going for discoverability, in which case we need to make sure that all of the fields within the struct accept their zero value

This is the case I was assuming we would have as this is a configuration API and our general stance is to have discoverability in these types of APIs.

I should have been a bit more clear as to why I understood this as needing to allow the omitted value, my apologies

Copy link
Contributor

Choose a reason for hiding this comment

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

Generally, when looking at discoverability comments we should start at the top as it were.

Given currently, https://github.com/openshift/api/pull/2310/files#diff-efbd815aeb2fd3f182852b1c6ec8317d546d44813792bfe7da5e253394f5ff18R72, the usage of the struct containing this is a DU that is optional, pointer, omitempty, we don't need to look at discoverability of fields within there until we have discussed if the signedIdentity field should be discoverable.

If the top level field isn't going to marshal down to {"matchPolicy":""} (which it won't currently) then we don't need "" to be valid here.

So, should signedIdentity be discoverable? Well, who is expected to create these objects? Are we ever likely to be producing these via a go client for the end user? Are we expecting 1 of these objects? Are we expecting many?

I don't think we originally aimed for discoverability on this API because there is no valid object for spec: {}, we need at least some config from an end user for this object to make sense (also, I expect there to be many of these rather than 1)

@QiWang19 QiWang19 force-pushed the sigstoreverification branch 2 times, most recently from c64bcf8 to e04c9af Compare June 2, 2025 21:09
Upgrade ClusterImagePolicy and ImagePolicy under SigstoreVerification featuregate to v1.
will workon upgrade controller code to use v1 API and promote the featuregate to default as next step.

Signed-off-by: Qi Wang <[email protected]>
@QiWang19 QiWang19 force-pushed the sigstoreverification branch from e04c9af to db83887 Compare June 2, 2025 22:12
Copy link
Contributor

openshift-ci bot commented Jun 2, 2025

@QiWang19: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/lint db83887 link true /test lint

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants