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

feat: DSPO handle db tls connections and configs #575

Merged

Conversation

HumairAK
Copy link
Collaborator

@HumairAK HumairAK commented Feb 20, 2024

The issue resolved by this Pull Request:

Resolves for v1.6:

Description of your changes:

This change allows the DSPO to perform health checks against a tls
secured database. If the database is behind a self-signed cert, end user
can provide a ca-bundle either as a global cert (configmap named
"odh-trust-bundle" or via the ".caBundle" config option via the DSPA.

This change also exposes the "ExtraParams" field for DSP, meaning users
can now add ny DSN parameters when configuring a DB connection for DSP.
These params are utilized in the same manner by the DSPO when conducting
the health check to keep the behavior consistent.

NOTE that before external connections made a connection via tls:false, now it's enforced by default. To disable it, users will need to set customExtraParams to: {"tls":"true"} string.

Testing instructions

Deploy a secure/tls enabled s3/mariadb behind a self-signed cert (for example in a self-signed ocp cluster), provide these configs to the DSAP as external configs. Ensure they only accept tls based connections.

Deploy a cabundle as a configmap in the DSPA namespace:

kind: ConfigMap
apiVersion: v1
metadata:
  name: odh-trusted-ca-bundle
data:
  ca-bundle.crt: | 
      <your-bundle>

Deploy DSPA configured to leverage these connections via external db/object store connections.

Confirm DSPO is able conduct successfull health checks (if it deploys the DSPA pods then health checks worked), if it didn't, log the error here.

Confirm DSPA comes up successfully, in this change DSPO willl udpate the DSP server's configs to enable "tls" for db connections. Confirm this behavior by running a successful pipeline.

Confirm DSPA "simple" v1 still works (no external db/s3 configured).

Confirm setting "customExtraParams" in the DSPA's ".spec.database.customExtraParams". Provide wrong ca bundle, confirm it fails to deploy dspa, then set ".spec.database.customExtraParams" to {"tls":"true"}, it should work. Because the value is a json string, you should use | or >- to format the yaml value, example:

spec:
  dspVersion: v2
  database:
    customExtraParams: |                           
      {"tls": "skip-verify"} 

Checklist

  • The commits are squashed in a cohesive manner and have meaningful messages.
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has manually tested the changes and verified that the changes work

Signed-off-by: Humair Khan <HumairAK@users.noreply.github.com>
Signed-off-by: Humair Khan <HumairAK@users.noreply.github.com>
Signed-off-by: Humair Khan <HumairAK@users.noreply.github.com>
Signed-off-by: Humair Khan <HumairAK@users.noreply.github.com>
Signed-off-by: Humair Khan <HumairAK@users.noreply.github.com>
This change allows the DSPO to perform heatlh checks against a tls
secured database. If the database is behind a self-signed cert, end user
can provide a ca-bundle either as a global cert (configmap named
"odh-trust-bundle" or via the ".caBundle" config option via the DSPA.

This change also exposes the "ExtraParams" field for DSP, meaning users
can now add ny DSN parameters when configuring a DB connection for DSP.
These params are utilized in the same manner by the DSPO when conducting
the health check to keep the behavior consistent.

Signed-off-by: Humair Khan <HumairAK@users.noreply.github.com>
@HumairAK HumairAK force-pushed the v1.6.x-RHOAIENG-1690-and-2385-2 branch from 703f618 to 32d3e01 Compare February 20, 2024 14:28
@dsp-developers
Copy link
Collaborator

Change to PR detected. A new PR build was completed.
A new image has been built to help with testing out this PR: quay.io/opendatahub/data-science-pipelines-operator:pr-575

@HumairAK HumairAK changed the title V1.6.x rhoaieng 1690 and 2385 2 Feat: DSPO handls db tls connections and configs Feb 20, 2024
@HumairAK HumairAK changed the title Feat: DSPO handls db tls connections and configs feat: DSPO handls db tls connections and configs Feb 20, 2024
@gregsheremeta gregsheremeta changed the title feat: DSPO handls db tls connections and configs feat: DSPO handle db tls connections and configs Feb 20, 2024
Copy link
Contributor

@amadhusu amadhusu left a comment

Choose a reason for hiding this comment

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

I was able to test and verify the first two test cases but not the last one with the new field "customExtraParams".

Confirm setting "customExtraParams" in the DSPA's ".spec.database.customExtraParams". Provide wrong ca bundle, confirm it fails to deploy dspa, then set ".spec.database.customExtraParams" to {"tls":"true"}, it should work.

Copy link
Contributor

@amadhusu amadhusu left a comment

Choose a reason for hiding this comment

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

Tested the customExtraParams after Humair's suggestion about the format. It works as expected.

Copy link
Contributor

@gregsheremeta gregsheremeta left a comment

Choose a reason for hiding this comment

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

i have some thoughts and nitpicks ... all of which we can deal with in a follow up

/lgtm

controllers/util/util.go Outdated Show resolved Hide resolved
@@ -1,6 +1,6 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: odh-applications
namespace: opendatahub
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick, not related, should extract

// Watch for global ca bundle, if one is added to this namespace
// we need to reconcile on all the dspa's in this namespace
// so they may mount this cert in the appropriate containers
Watches(&source.Kind{Type: &corev1.ConfigMap{}},
Copy link
Contributor

Choose a reason for hiding this comment

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

watching ConfigMap gobbles up memory doesn't it? Do we need to check for that and mitigate, possibly by increasing limits and or requests?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We added a similar watcher for a pod, and didn't notice a major uptick (a lot of this is internally cached and heavily optimized in k8s I believe), and pod events work queue is likely to be insanely longer than the configmap events

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

buut if it does cause issues, we will probably catch it in our perf testing and adjust accordingly

@@ -149,6 +151,9 @@ func (p *DSPAParams) SetupDBParams(ctx context.Context, dsp *dspa.DataSciencePip
p.DBConnection.Port = dsp.Spec.Database.ExternalDB.Port
p.DBConnection.Username = dsp.Spec.Database.ExternalDB.Username
p.DBConnection.DBName = dsp.Spec.Database.ExternalDB.DBName
// Assume default external connection is tls enabled
// user can override this via CustomExtraParams field
p.DBConnection.ExtraParams = fmt.Sprintf(config.DBDefaultExtraParams, true)
Copy link
Contributor

Choose a reason for hiding this comment

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

The extra params should be a struct that gets serialized to json when it needs to be. I guess it needs to by dynamic though, because you don't want to chase the mysql API. Hmm. Sprintf'ing the 'true' or 'false' specifically for tls feels weird when the field is named "DBDefaultExtraParams" and not "tlsEnabled". Not sure what the solution is but wanted to call out that it feels weird to me.

Copy link
Collaborator Author

@HumairAK HumairAK Feb 22, 2024

Choose a reason for hiding this comment

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

I actually did it that way at first, i.e. Extraparams was of type map[string]string but in our configmap template we need to render it as a string, the thing is we need to pass it in as a string anyways to render it in our go template configmap, I was torn on it, this method resulted in a lot less lines of code so I did it this way instead

log.Info(fmt.Sprintf("Encountered error when attempting to fetch ConfigMap: [%s], Error: %v", globalCABundleCFGMapKey, err))
return err
} else {
// Found a global cert, consume this cert, takes precedence over "cABundle" provided via DSPA
Copy link
Contributor

Choose a reason for hiding this comment

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

local usually overrides global ... pinged you in slack about it

Signed-off-by: Humair Khan <HumairAK@users.noreply.github.com>
@openshift-ci openshift-ci bot removed the lgtm label Feb 22, 2024
@gregsheremeta
Copy link
Contributor

/lgtm

@openshift-ci openshift-ci bot added the lgtm label Feb 22, 2024
@gregsheremeta
Copy link
Contributor

/approve

Copy link
Contributor

openshift-ci bot commented Feb 22, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: amadhusu, gregsheremeta

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

@dsp-developers
Copy link
Collaborator

Change to PR detected. A new PR build was completed.
A new image has been built to help with testing out this PR: quay.io/opendatahub/data-science-pipelines-operator:pr-575

@HumairAK HumairAK merged commit 782777c into opendatahub-io:v1.6.x Feb 22, 2024
5 of 7 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.

None yet

4 participants