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

Fix vulnerabilities #165

Merged
merged 11 commits into from
Mar 7, 2022
Merged

Fix vulnerabilities #165

merged 11 commits into from
Mar 7, 2022

Conversation

roypaulin
Copy link
Collaborator

@roypaulin roypaulin commented Mar 2, 2022

This PR follows security vulnerabilities that have been detected inside operator pods.
the highlights are:

  • upgrade operator-sdk which leads to upgrade of go (v1.17), controller-gen (v0.8) and other packages as you can see here https://sdk.operatorframework.io/docs/upgrading-sdk-version/v1.17.0
  • In this version of controller-gen trivialVersions and preserveUnknownFields are not supported anymore
  • To install package we use go install instead of go get as using go get to build and install packages is deprecated and will not be possible from v1.18.
  • setup-envtest.sh does not exist anymore in recent releases and has been replaced by setup-envtest package.

Closes #30

Makefile Outdated
mkdir -p ${KUBEBUILDER_ASSETS}
$(SETUP_ENVTEST) use --bin-dir $(ENVTEST_ASSETS_BIN_DIR)
find $(ENVTEST_ASSETS_BIN_DIR)/ -exec cp {} $(KUBEBUILDER_ASSETS)/ \;
sudo rm -r $(ENVTEST_ASSETS_BIN_DIR)
Copy link
Collaborator Author

@roypaulin roypaulin Mar 2, 2022

Choose a reason for hiding this comment

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

I do not like this sudo. First I did not intend to add it but the github checks were failing. Using setup-envtest, the binaries are generated in <your-dir>/k8s/<version>. So I generated them in testbin/tmp/k8s/<version> them copy them to testbin/bin to then delete testbin/tmp.

Copy link
Collaborator

Choose a reason for hiding this comment

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

From the operator-sdk changelog, it looks like it is advising this change instead:

+# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
  +ENVTEST_K8S_VERSION = 1.21

  test: manifests generate fmt vet envtest ## Run tests.
  - go test ./... -coverprofile cover.out
  + KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out

From https://sdk.operatorframework.io/docs/upgrading-sdk-version/v1.11.0/

Did you try this approach instead?

There is also a separate target to download envtest. It might be easier to create a new project with operator-sdk then compare the Makefile it generates.

Copy link
Collaborator

@spilchen spilchen left a comment

Choose a reason for hiding this comment

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

I didn't see any evidence that we applied these upgrade steps. We should apply them:
https://sdk.operatorframework.io/docs/upgrading-sdk-version/v1.11.0/#gov3-ansiblev1-helmv1-add-containerport-protocol-field-in-manifests
https://sdk.operatorframework.io/docs/upgrading-sdk-version/v1.16.0/#add-annotation-to-specify-the-default-container
https://sdk.operatorframework.io/docs/upgrading-sdk-version/v1.18.0/#support-image-digests-instead-of-tags

This upgrade was partially done:
https://sdk.operatorframework.io/docs/upgrading-sdk-version/v1.14.0/#upgrade-k8s-versions-to-use-122-golangv3

I didn't see any evidence that these ones were added

  • ENVTEST_K8S_VERSION (although the version has been bumped since then)
  • Replace your admissionReviewVersions={v1,v1beta1} markers with admissionReviewVersions=v1

Makefile Outdated
mkdir -p ${KUBEBUILDER_ASSETS}
$(SETUP_ENVTEST) use --bin-dir $(ENVTEST_ASSETS_BIN_DIR)
find $(ENVTEST_ASSETS_BIN_DIR)/ -exec cp {} $(KUBEBUILDER_ASSETS)/ \;
sudo rm -r $(ENVTEST_ASSETS_BIN_DIR)
Copy link
Collaborator

Choose a reason for hiding this comment

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

From the operator-sdk changelog, it looks like it is advising this change instead:

+# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
  +ENVTEST_K8S_VERSION = 1.21

  test: manifests generate fmt vet envtest ## Run tests.
  - go test ./... -coverprofile cover.out
  + KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out

From https://sdk.operatorframework.io/docs/upgrading-sdk-version/v1.11.0/

Did you try this approach instead?

There is also a separate target to download envtest. It might be easier to create a new project with operator-sdk then compare the Makefile it generates.

Makefile Outdated
@@ -421,7 +427,11 @@ KUBERNETES_SPLIT_YAML = $(shell pwd)/bin/kubernetes-split-yaml
kubernetes-split-yaml: ## Download kubernetes-split-yaml locally if necessary.
$(call go-get-tool,$(KUBERNETES_SPLIT_YAML),github.com/mogensen/kubernetes-split-yaml@v0.3.0)

# go-get-tool will 'go get' any package $2 and install it to $1.
SETUP_ENVTEST = $(shell pwd)/bin/setup-envtest
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should follow what is done in the generated Makefile. So this becomes ENVTEST = and the make target below becomes envtest.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes it is definitely simpler like that. I will do that.

scripts/gen-csv.sh Show resolved Hide resolved
@spilchen
Copy link
Collaborator

spilchen commented Mar 2, 2022

We should add a changie entry too to indicate we moved to operator-sdk version 1.18.0

@roypaulin
Copy link
Collaborator Author

I didn't see any evidence that we applied these upgrade steps. We should apply them: https://sdk.operatorframework.io/docs/upgrading-sdk-version/v1.11.0/#gov3-ansiblev1-helmv1-add-containerport-protocol-field-in-manifests https://sdk.operatorframework.io/docs/upgrading-sdk-version/v1.16.0/#add-annotation-to-specify-the-default-container https://sdk.operatorframework.io/docs/upgrading-sdk-version/v1.18.0/#support-image-digests-instead-of-tags

This upgrade was partially done: https://sdk.operatorframework.io/docs/upgrading-sdk-version/v1.14.0/#upgrade-k8s-versions-to-use-122-golangv3

I didn't see any evidence that these ones were added

* ENVTEST_K8S_VERSION  (although the version has been bumped since then)

* Replace your admissionReviewVersions={v1,v1beta1} markers with admissionReviewVersions=v1

Yes I oversimplified this upgrade. With such a big jump in version it is clear that intermediary upgrades should not be skipped. I will change that.

@roypaulin
Copy link
Collaborator Author

We should add a changie entry too to indicate we moved to operator-sdk version 1.18.0

Yes I will do a last commit for that once the changes will be approved.

clientConfig:
service:
name: webhook-service
namespace: system
path: /mutate-vertica-com-v1beta1-verticadb
failurePolicy: Fail
name: mverticadb.kb.io
namespaceSelector:
Copy link
Collaborator

Choose a reason for hiding this comment

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

This file is no longer generated. So, I think we still need this. This allows the webhoook to work.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sorry what do you mean by is no longer generated? because with controller-gen crd webhook .... it automatically generates the file you see right now. Or do you mean we should still keep the part you highlighted and prevent this file to be re-generated each time?

Copy link
Collaborator

Choose a reason for hiding this comment

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

We changed this file to not be generated anymore. We did this because we needed to add the namespace selector to it in order to get the webhook to work. So, I think we still need that selector added.

Makefile Outdated
$(call go-get-tool,$(SETUP_ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)
ENVTEST = $(shell pwd)/bin/setup-envtest
.PHONY: envtest
envtest: ## Download envtest-setup locally if necessary.
Copy link
Collaborator

Choose a reason for hiding this comment

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

The comment should be "Download setup-envtest-setup locally if necessary."

Copy link
Collaborator

@spilchen spilchen left a comment

Choose a reason for hiding this comment

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

I think we can get rid of scripts/wait-for-webhook.sh. The update to controller-runtime should have fixed that as it adds a true health check that helm --wait can depend on.

config/webhook/manifests.yaml Show resolved Hide resolved
@spilchen
Copy link
Collaborator

spilchen commented Mar 4, 2022

The changes look good. Lets create the changie entry. And I will push it sometime next week once we have upgraded Go on our internal build machines.

@roypaulin
Copy link
Collaborator Author

I guess the Kind of changie is "Changed".

body: Move to operator-sdk v1.18.0
time: 2022-03-04T22:15:06.6959129+01:00
custom:
Issue: "30"
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should use 165 as the issue number. I typically try to link with the PR that pushed the change as that gives more context.

@spilchen spilchen merged commit 48650ea into vertica:main Mar 7, 2022
@roypaulin roypaulin deleted the fix-vulnerabilities branch March 23, 2022 15:32
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.

Webhook server could not answer in time
2 participants