Skip to content
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

Add support for a Kubernetes secret in Image Policy #1715

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

Conversation

harche
Copy link
Contributor

@harche harche commented Nov 12, 2024

Copy link
Contributor

openshift-ci bot commented Nov 12, 2024

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 Nov 12, 2024
Copy link
Contributor

openshift-ci bot commented Nov 12, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign tremes for approval. For more information see the Kubernetes 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

Copy link
Member

@saschagrunert saschagrunert left a comment

Choose a reason for hiding this comment

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

Generally LGTM, just a few nits and clarifications.

@@ -315,6 +338,69 @@ type ImagePolicyStatus struct {

### Implementation Details/Notes/Constraints [optional]

#### Populating PolicyType using a Kuberentes Secret

When the Machine Config Operator (MCO) detects a valid (non-nil) reference to a Kubernetes Secret, `ImagePolicySecretRef` in `PolicyRootOfTrust`, it will fetch the Secret and validate the keys within it according to the specified `PolicyType`. Based on this validation, the `MCO` will populate the corresponding `PolicyType` fields. For example, if the `PolicyType` is set to `PublicKey`, it will extract and validate the `public-key` and `rekor-key` from the Secret, populating the `PublicKey` struct appropriately. Similarly, for other types like `PKI` or `FulcioCAWithRekor`, the MCO will validate and populate fields from the Secret as needed.
Copy link
Member

Choose a reason for hiding this comment

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

Can we outline how the validation works? Which fields are optional and required.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Existing API already has very extensive validation for every field. Any invalidate input would get caught right at the time of populating those structs, we just have to ensure the error is bubbled up correctly while we implement this feature in MCO.

Comment on lines 180 to 183
SecretPKIRootsDataKey = "ca-roots" // ca-roots
SecretPKIIntermediatesDataKey = "ca-intermediates" // ca-intermediates
SecretPKICertificateEmailKey = "certificate-email" // certificate-email
SecretPKICertificateHostnameKey = "certificate-hostname" // certificate-hostname
Copy link
Member

Choose a reason for hiding this comment

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

Do we have use cases where the data would be provided by different users? For example, ca-roots could be provided by secret A and the rest of the data by secret B?

Copy link
Contributor Author

@harche harche Nov 13, 2024

Choose a reason for hiding this comment

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

I don't see a reason for having multiple secrets per image policy. All we are doing here is, replacing someone manually setting those fields with a kubernetes secret owned by the same user. Also IMO, it is a much simpler design for users to follow. All they have to make sure is to have their external key provider (such as Vault) store the certs with the keys defined in this API. When an external secret operator (or Vault operator) will try to create the kubernetes secret it will automatically set the keys of the secret data to match the keys stored in their custody.

Copy link
Contributor

Choose a reason for hiding this comment

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

It seems to me that this is just asking the same question in a different way: Does the external key provider always contain the complete set of keys for the policy?

  • Is it plausible that the keys could be maintained by different teams (e.g. one department maintaining Rekor, and another maintaining the actual signing mechanism), i.e. different KMS accounts, and perhaps even different KMS servers?
  • Are the KMS keys going to be maintained as a single unit in this sense? My first guess is that a KMS would contain, in one “managed item”, both the public+private key for Rekor; and in another “managed item”, both the public+private key for signing. Not that the KMS would store all policy keys for a single signing scope in one “managed item” — if nothing else, it is possible to use the same Rekor server for several scopes.

In both cases, the current design seems to assume that the controller syncing the KMS data into a Secret can extract data from KMS, and merge multiple KMS items, into one Secret. I don’t know what controller/operator is being used or planned to be used, and I’m perfectly happy to stay out of this, I’d just like to hear that yes, this has been tried once and such a syncing setup can be configured.

@harche harche marked this pull request as ready for review November 13, 2024 14:38
@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 Nov 13, 2024
Copy link
Contributor

openshift-ci bot commented Nov 13, 2024

@harche: all tests passed!

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.

@@ -315,6 +337,69 @@ type ImagePolicyStatus struct {

### Implementation Details/Notes/Constraints [optional]

#### Populating PolicyType using a Kuberentes Secret

When the Machine Config Operator (MCO) detects a valid (non-nil) reference to a Kubernetes Secret, `ImagePolicySecret` in `PolicyRootOfTrust`, it will fetch the Secret and validate the keys within it according to the specified `PolicyType`. Based on this validation, the `MCO` will populate the corresponding `PolicyType` fields. For example, if the `PolicyType` is set to `PublicKey`, it will extract and validate the `public-key` and `rekor-key` from the Secret, populating the `PublicKey` struct appropriately. Similarly, for other types like `PKI` or `FulcioCAWithRekor`, the MCO will validate and populate fields from the Secret as needed.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can the user still specify some values directly if a secret is used for other values?

If so, what happens if both the CR and the secret contain a value for an item?

Comment on lines +182 to +183
SecretPKICertificateEmailKey = "certificate-email"
SecretPKICertificateHostnameKey = "certificate-hostname"
Copy link
Contributor

Choose a reason for hiding this comment

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

Here and … (A)

Comment on lines +188 to +189
SecretFulcioOidcIssuerKey = "oidc-issuer"
SecretFulcioSignedEmailKey = "signed-email"
Copy link
Contributor

Choose a reason for hiding this comment

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

(A) … here we are storing non-cryptographic strings in the KMS. Is that (possible at all) and necessary?

E.g. I could well imagine that there would be quite a few policies within a company, all referencing the same Rekor keys and Fulcio/PKI CAs, but with a different certificate subject for each registry namespace (e.g. one certificate subject per a project team, signing builds of that project). It makes sense to manage the cryptographic keys in a specialized software, but the registry repo / certificate subject mapping is something a bit different.

This rather depends on the “Can the user still specify some values directly” question — if the answer to that is “yes”, and this is only an option to store these parts of the policy in a Secret, I don’t see a reason to object. If the data had to be only stored in a Secret, that intuitively feels unnatural to me.

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