-
Notifications
You must be signed in to change notification settings - Fork 222
kie-issues#1583: [sonataflow-operator] Add external built image integrity validation #3013
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
base: main
Are you sure you want to change the base?
kie-issues#1583: [sonataflow-operator] Add external built image integrity validation #3013
Conversation
@@ -40,6 +40,7 @@ COPY --from=builder --chown=185 /home/kogito/serverless-workflow-project/target/ | |||
COPY --from=builder --chown=185 /home/kogito/serverless-workflow-project/target/quarkus-app/*.jar /deployments/ | |||
COPY --from=builder --chown=185 /home/kogito/serverless-workflow-project/target/quarkus-app/app/ /deployments/app/ | |||
COPY --from=builder --chown=185 /home/kogito/serverless-workflow-project/target/quarkus-app/quarkus/ /deployments/quarkus/ | |||
COPY --from=builder --chown=185 /home/kogito/serverless-workflow-project/target/classes/workflow.sw.json /deployments/app/workflow.sw.json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, should the builder image add the workflow file to the /deployments/app
? Is there no other way to do it? This file can also be a YAML named anything (bananas.sw.yml
).
So, if we imagine a custom builder or an image built by users, they must know where to put the file in their environment.
Docs and migration from a previous version will be severely impacted. Can you also add a configuration to the manager to skip this validation? It will be needed in case of a migration from a previous version.
Currently, users may build their workflow images as they wish. To migrate to this new version, they might need to turn the validation off and turn it on once everything is migrated.
blocked by #3028 |
6713238
to
f4eaddc
Compare
…s-operator_405_fix_2 Incubator kie kogito serverless operator 405 fix 2
c51a1c9
to
c9f1816
Compare
@@ -0,0 +1,128 @@ | |||
// Copyright 2024 Apache Software Foundation (ASF) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong licence format, copyright not needed
@@ -118,6 +122,11 @@ func (r *SonataFlowReconciler) Reconcile(ctx context.Context, req ctrl.Request) | |||
return ctrl.Result{}, err | |||
} | |||
|
|||
if err := r.Validate(ctx, workflow, req); err != nil { | |||
klog.V(log.E).ErrorS(err, "Failed to validate SonataFlow") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the error message should include the name / namespace of the failing workflow. That information will be very helpful when we need to see the logs in case of failues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This invocation to the validator should go after the code below.
That if
indicates that the WF being deleted right now, so, we don't need to validate it.
if workflow.DeletionTimestamp != nil {
return r.applyFinalizers(ctx, workflow)
}
|
||
var validators = []Validator{ImageValidator{}} | ||
|
||
type Validator interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice approach!
Validate(ctx context.Context, client client.Client, sonataflow *operatorapi.SonataFlow, req ctrl.Request) error | ||
} | ||
|
||
// validate the SonataFlow object, right now it's only check if workflow is in deployment has image declared as that image |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick, validate here, goes with uppercase Validate instead.
|
||
func (v ImageValidator) Validate(ctx context.Context, client client.Client, sonataflow *operatorapi.SonataFlow, req ctrl.Request) error { | ||
if sonataflow.HasContainerSpecImage() { | ||
err := client.Get(ctx, req.NamespacedName, sonataflow) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are validating a `workflow' that was just read the instant before calling the Validators sequence, I don't believe we need to re-read it again.
But if you do, I don't believe we should read it and storing the value in the parameter sonataflow *operatorapi.SonataFlow paramter, I think this could make the validator has side effects on that variable value. When multiple validators are executed I think this code wont be clear.
Another nitpick, when we do reading of the resource as part of the reconciliation, we normally guard the code with something like this:
err := r.Client.Get(ctx, req.NamespacedName, workflow)
if err != nil {
if errors.IsNotFound(err) {
not good, return the error or whatever, but we know exactly that the given resource don't exist at this time.
}
not good, return the error or whatever, something went wrong, we don't know what.
}
func (v ImageValidator) Validate(ctx context.Context, client client.Client, sonataflow *operatorapi.SonataFlow, req ctrl.Request) error { | ||
if sonataflow.HasContainerSpecImage() { | ||
err := client.Get(ctx, req.NamespacedName, sonataflow) | ||
equals, err := validateImage(sonataflow, sonataflow.Spec.PodTemplate.Container.Image) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we don't do the consideration above, in case of error the sonataflow value is uncertain.
return err | ||
} | ||
if !equals { | ||
return fmt.Errorf("Workflow, defined in the image %s doesn't match deployment workflow", sonataflow.Spec.PodTemplate.Container.Image) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
workflow name/namepace would be nice to include in the message.
func jsonFromDockerImage(reader io.Reader) (operatorapi.Flow, error) { | ||
data, err := io.ReadAll(reader) | ||
workflow := &operatorapi.Flow{} | ||
if err = yaml.Unmarshal(data, workflow); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excuse me if I'm missing something, but do this Unmarshalling work both when the workflow inside the image is in json and yaml format? If so, maybe this function can be called workflowFromDockerImage.
@@ -0,0 +1,41 @@ | |||
// Copyright 2024 Apache Software Foundation (ASF) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, copyright we don't need
Hi @treblereel I had tried the feature in OpenShift 4.15.17 with the following scenario
`` It looks like it was not possible for the validator to read the image, |
@treblereel I'd recommend rebasing with main, since there has been some recent updates in sontaflow_controller.go |
@treblereel the docker api needs to authenticate with OpenShift internal registry |
Closes: apache/incubator-kie-kogito-serverless-operator#405