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

Make the pkcs11 config more generic #199

Merged

Conversation

vakwetu
Copy link
Contributor

@vakwetu vakwetu commented Jan 13, 2025

Made the pkcs11 more generic so that hopefully we will be able to support many HSMs and configurations without
too many changes.

Jira: https://issues.redhat.com/browse/OSPRH-12972

pkg/barbican/volumes.go Outdated Show resolved Hide resolved
pkg/barbican/p11_prep.go Outdated Show resolved Hide resolved
api/v1beta1/barbican_webhook.go Outdated Show resolved Hide resolved
controllers/barbican_controller.go Outdated Show resolved Hide resolved
api/v1beta1/common_types.go Show resolved Hide resolved
templates/barbican/config/barbican-api-config.json Outdated Show resolved Hide resolved
templates/barbican/config/barbican-api-config.json Outdated Show resolved Hide resolved
templates/barbican/config/barbican-p11-prep-config.json Outdated Show resolved Hide resolved
templates/barbican/config/barbican-p11-prep-config.json Outdated Show resolved Hide resolved
api/v1beta1/common_types.go Show resolved Hide resolved
@vakwetu vakwetu force-pushed the simplify_luna_deploy branch 2 times, most recently from 4f21104 to f3e693b Compare January 15, 2025 15:45
controllers/barbican_controller.go Outdated Show resolved Hide resolved
controllers/barbican_controller.go Outdated Show resolved Hide resolved
controllers/barbican_controller.go Outdated Show resolved Hide resolved
controllers/barbicanworker_controller.go Outdated Show resolved Hide resolved
@vakwetu vakwetu force-pushed the simplify_luna_deploy branch 2 times, most recently from 0e3b919 to 4cc913e Compare January 16, 2025 22:34
@vakwetu vakwetu force-pushed the simplify_luna_deploy branch from 4cc913e to 03e16f4 Compare January 20, 2025 21:06
@vakwetu vakwetu changed the title Initial change to simplify the config Make the pkcs11 config more generic Jan 20, 2025
@vakwetu vakwetu force-pushed the simplify_luna_deploy branch from 03e16f4 to a1fe6b5 Compare January 21, 2025 04:46
controllers/barbicanworker_controller.go Outdated Show resolved Hide resolved
controllers/barbicanapi_controller.go Outdated Show resolved Hide resolved
controllers/barbicankeystonelistener_controller.go Outdated Show resolved Hide resolved
controllers/barbicanapi_controller.go Outdated Show resolved Hide resolved
)

var (
commonWatchFields = []string{
workerWatchFields = []string{
Copy link
Contributor

Choose a reason for hiding this comment

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

adding it here as you can not comment on not changed parts in the file. since this barbican controller renders the main config, it should also index/reconcile when the p11 secrets change. otherwise the config won't get updated. Needs that added in SetupWithManager

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a larger question that this, I think.

The config that is generated in the top-level controller is passed down to the sub-component controllers (BarbicanAPI, BarbicanWorker, BarbicanKeystoneListener) - and the reconciliation that takes placed based on those watches is done in those components.

This is similar to what is done in cinder: https://github.com/search?q=repo%3Aopenstack-k8s-operators%2Fcinder-operator%20commonWatchFields&type=code

So, if there is a change in any of the watched things, then there will be a reconciliation triggered in the sub-components.

If there is something that is lacking here, then we need a separate change to reconcile all of the common secrets in the top-level controller. (not just pk11 secrets).

I'm not sure what effect that will have - and whether we'll end up with cascading reconciliations.
The top-level controller only initiates some setup jobs (dbsync, p11-prep). Not sure if we want to rerun these jobs when the config changes.

If something needs to change here, then we should open a Jira for this and address it separately. (And we'd probably need to fix it in cinder too!)

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, lets follow up on this. here in barbican it is, right now, not an issue, since all controller render the global config, due to the link used for the templates directory. if the components would just consume the global config ,rendered by the main controller, and this one does not index/watch properly the input secret, the component controllers would reconcile, but not getting an updated rendered global config of the updated secret since the main controller did not reconcile. so something to keep in mind when removing the link as mentioned bellow, since there could be a situation where the user updated the config secret, but still using the old config since it has not rendered again.

pkg/barbican/volumes.go Outdated Show resolved Hide resolved
templates/barbican/bin/generate_p11_keys.sh Outdated Show resolved Hide resolved
templates/barbican/config/barbican-p11-prep-config.json Outdated Show resolved Hide resolved

// BarbicanPKCS11Template - Includes common HSM properties
type BarbicanPKCS11Template struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need BarbicanPKCS11Template as part of the of the component api at all [11]. it would probably be enough to have it just on the barbican as we fetch the global config from there. But since this was done from beginning with other global parameters, I am not sure if you want to do such a change at this point for P11, we can not change it for the params which are there since GA.

[1] https://github.com/openstack-k8s-operators/barbican-operator/blob/main/api/v1beta1/common_types.go#L54C9-L54C15

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not entirely clear as to what you're proposing here, but yeah, I think we want to follow the pattern we've been using from the beginning.

Copy link
Contributor

Choose a reason for hiding this comment

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

just wanted to mention that the component controllers right now have parameters in their api which they probably won't need, since its a global thing would only required to be rendered in the main controller, where the sub components consume the global config for the generated secret.

if err != nil {
return err
}
customData[barbican.CustomConfigFileName] = string(barbicanSecret.Data[barbican.CustomConfigFileName])
Copy link
Contributor

Choose a reason for hiding this comment

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

since we render and get the main config from the secret the barbican controller renders, I think we might want to consider to no longer use links for the component template directories? similar how it is done in cinder

$ ll templates/
barbican
barbicanapi -> barbican
barbicankeystonelistener -> barbican
barbicanworker -> barbican

Otherwise we'd still render the configs and have the global one + the local rendered? if we make dedicated directories for each one and just have the component specific config as part of its directory, we won't have to check for the global secrets and set templateParameters.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agreed. We should do this. But I think we should do this as a separate change. That way we can focus on making sure that particular change doesn't break anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Lets open a separate Jira for this.

Copy link
Contributor

Choose a reason for hiding this comment

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

ack sounds good

api/v1beta1/common_types.go Outdated Show resolved Hide resolved
api/v1beta1/barbican_webhook.go Outdated Show resolved Hide resolved
api/v1beta1/common_types.go Outdated Show resolved Hide resolved
config/samples/pods_with_pkcs11-luna.yaml Outdated Show resolved Hide resolved
config/samples/pods_with_pkcs11-luna.yaml Outdated Show resolved Hide resolved
AlwaysSetCKASensitive bool `json:"alwaysSetCKASensitive"`
// +kubebuilder:validation:Required
// The OpenShift secret that stores the HSM client data.
// These will be mounted to /var/lib/config-data/hsm
Copy link
Contributor

Choose a reason for hiding this comment

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

Where does /var/lib/config-data/hsm come from?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Per design discussion, we will mount the data in a standard location and use kolla to move the data to the location designated by ClientDataPath.

The path we currently use for kolla stuff is /var/lib/config-data/default. This is just a branch close to this.

The reason for this is that if we mount the secret to ClientDataPath directly, then we end up overwriting whatever is already there. So, if we wanted to use /usr/local/luna is the client path, we'd end up deleting everything in that directory and only having the secrets there.

}

// check for PKCS11 secret holding the PKCS11 Crypto Login
if slices.Contains(instance.Spec.EnabledSecretStores, barbicanv1beta1.SecretStorePKCS11) && instance.Spec.PKCS11 != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we test here for len(instance.Spec.EnabledSecretStores) == 0 as above?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think so. If instance.Spec.EnabledSecretStores is [], then the first term here will fail without throwing any error - as we'd expect.

The length check above is so that we default to simple_crypto in case EnabledSecretStores is undefined.

controllers/barbican_controller.go Outdated Show resolved Hide resolved
controllers/barbican_controller.go Outdated Show resolved Hide resolved
config/samples/pods_with_pkcs11-luna.yaml Outdated Show resolved Hide resolved
config/samples/pods_with_pkcs11-luna.yaml Outdated Show resolved Hide resolved
@vakwetu vakwetu force-pushed the simplify_luna_deploy branch 2 times, most recently from 6c8fc91 to c16a257 Compare January 23, 2025 04:48
Modify the PKCS11 support to make it more generic and hopefully
make it easier to then support different HSM configurations.

Updated the PKCS11 functional tests.
Fix tls-e kuttl tests
@vakwetu vakwetu force-pushed the simplify_luna_deploy branch from c16a257 to 772d803 Compare January 23, 2025 20:59
@vakwetu
Copy link
Contributor Author

vakwetu commented Jan 23, 2025

Just merged all the changes into a single commit to trigger new kuttl test run now that openshift/release#60903 has merged.

@stuggi
Copy link
Contributor

stuggi commented Jan 27, 2025

/override ci/prow/precommit-check

Copy link

openshift-ci bot commented Jan 27, 2025

@stuggi: Overrode contexts on behalf of stuggi: ci/prow/precommit-check

In response to this:

/override ci/prow/precommit-check

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.

Copy link
Contributor

@stuggi stuggi left a comment

Choose a reason for hiding this comment

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

/lgtm lets address things we discussed in this PR and not yet in, in follow ups

Copy link

openshift-ci bot commented Jan 27, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: stuggi, vakwetu

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

The pull request process is described 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

@openshift-merge-bot openshift-merge-bot bot merged commit cf83ce8 into openstack-k8s-operators:main Jan 27, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants