Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ on:
env:
# ---- Language Versions ----

GO_VERSION: "1.17"
GO_VERSION: "1.19"
PYTHON_VERSION: "3.8.10"
NODE_VERSION: "16"
NPM_VERSION: "7"
Expand Down
2 changes: 1 addition & 1 deletion auto-discovery/kubernetes/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: Apache-2.0

# Build the manager binary
FROM golang:1.17 as builder
FROM golang:1.19 as builder

WORKDIR /workspace
# Copy the Go Modules manifests
Expand Down
95 changes: 64 additions & 31 deletions auto-discovery/kubernetes/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ IMG ?= auto-discovery-kubernetes
# Tag used for the image
IMG_TAG ?= sha-$$(git rev-parse --short HEAD)

# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
Expand All @@ -26,6 +23,7 @@ endif
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec

.PHONY: all
all: build

##@ General
Expand All @@ -41,96 +39,131 @@ all: build
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php

.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

##@ Development

.PHONY: manifests
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases

.PHONY: generate
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."

.PHONY: fmt
fmt: ## Run go fmt against code.
go fmt ./...

.PHONY: vet
vet: ## Run go vet against code.
go vet ./...

ENVTEST_ASSETS_DIR=$(shell pwd)/testbin

.PHONY: test-setup
test-setup: manifests generate fmt vet ## Run tests.
mkdir -p ${ENVTEST_ASSETS_DIR}
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.7.2/hack/setup-envtest.sh


.PHONY: test
test: test-setup
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out

.PHONY: ginko
ginkgo:
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); ginkgo test ./... -coverprofile cover.out -v --progress

##@ Build

.PHONY: build
build: generate fmt vet ## Build manager binary.
go build -o bin/manager main.go

.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
go run ./main.go --config auto-discovery-config.yaml

.PHONY: docker-build
docker-build: test ## Build docker image with the manager.
@echo ".: ⚙️ Build Container Images"
docker build -t ${IMG_NS}/${IMG}:${IMG_TAG} .

.PHONY: docker-push
docker-push: ## Push docker image with the manager.
docker push ${IMG_NS}/${IMG}:${IMG_TAG}

.PHONY: docker-export
docker-export:
@echo ".: 💾 Export Container Images"
docker save $(IMG_NS)/$(IMG):$(IMG_TAG) > $(IMG).tar

##@ Deployment

.PHONY: kind-import
kind-import:
@echo ".: 💾 Importing the image archive to local kind cluster."
kind load image-archive ./$(IMG).tar

.PHONY: helm-deploy
helm-deploy:
@echo ".: ⚙️ Deploying auto-discovery with the Image tag '$(IMG_TAG)' into kind."
helm upgrade --install auto-discovery ./ --wait \
--set="image.repository=docker.io/$(IMG_NS)/$(IMG)" \
--set="image.tag=$(IMG_TAG)" \
--set="image.repository=docker.io/$(IMG_NS)/$(IMG)" \
--set="image.tag=$(IMG_TAG)" \
--set="image.pullPolicy=IfNotPresent" \

ifndef ignore-not-found
ignore-not-found = false
endif

.PHONY: install
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | kubectl apply -f -

uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | kubectl delete -f -
.PHONY: uninstall
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -

.PHONY: deploy
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/default | kubectl apply -f -

undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/default | kubectl delete -f -


CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
controller-gen: ## Download controller-gen locally if necessary.
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.4.1)

KUSTOMIZE = $(shell pwd)/bin/kustomize
kustomize: ## Download kustomize locally if necessary.
$(call go-install-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v3@v3.8.7)

# go-install-tool will 'go install' any package $2 and install it to $1.
# GOBIN needs to be an absolute path so an additional absolute path project dir variable is used
ABS_PROJECT_DIR=$(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-install-tool
@[ -f $(1) ] || { \
set -e ;\
echo "Downloading $(2)" ;\
GOBIN=$(ABS_PROJECT_DIR)/bin go install $(2) ;\
}
endef
.PHONY: undeploy
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -

##@ Build Dependencies

## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)

## Tool Binaries
KUSTOMIZE ?= $(LOCALBIN)/kustomize
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest

## Tool Versions
KUSTOMIZE_VERSION ?= v3.8.7
CONTROLLER_TOOLS_VERSION ?= v0.9.2

KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
$(KUSTOMIZE): $(LOCALBIN)
test -s $(LOCALBIN)/kustomize || { curl -s $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN); }

.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
$(CONTROLLER_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/controller-gen || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)

.PHONY: envtest
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
cfg "sigs.k8s.io/controller-runtime/pkg/config/v1alpha1"
)

//+kubebuilder:object:root=true
// +kubebuilder:object:root=true
type AutoDiscoveryConfig struct {
metav1.TypeMeta `json:",inline"`

Expand Down
4 changes: 2 additions & 2 deletions auto-discovery/kubernetes/api/v1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// SPDX-License-Identifier: Apache-2.0

// Package v1 contains API Schema definitions for the config v1 API group
//+kubebuilder:object:generate=true
//+groupName=config.securecodebox.io
// +kubebuilder:object:generate=true
// +groupName=config.securecodebox.io
package v1

import (
Expand Down
27 changes: 14 additions & 13 deletions auto-discovery/kubernetes/controllers/service_scan_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,19 +337,20 @@ func getShaHashesForPod(pod corev1.Pod) map[string]string {

// Takes a list of pods and returns a two tiered map to lookup pod digests per container
// The map returned look like this:
// {
// // container name
// container1: {
// // digest
// ab2dkbsjdha3kshdasjdbalsjdbaljsbd: true
// iuzaksbd2kabsdk4abksdbaksjbdak12a: true
// },
// container2: {
// // digest
// sjdha3kshdasjdbalsjdbaljsbdab2dkb: true
// d2kabsdk4abksdbaksjbdak12aiuzaksb: true
// },
// }
//
// {
// // container name
// container1: {
// // digest
// ab2dkbsjdha3kshdasjdbalsjdbaljsbd: true
// iuzaksbd2kabsdk4abksdbaksjbdak12a: true
// },
// container2: {
// // digest
// sjdha3kshdasjdbalsjdbaljsbdab2dkb: true
// d2kabsdk4abksdbaksjbdak12aiuzaksb: true
// },
// }
func gatherPodDigests(pods *corev1.PodList) map[string]map[string]bool {
podDigests := map[string]map[string]bool{}

Expand Down
14 changes: 7 additions & 7 deletions auto-discovery/kubernetes/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@

module github.com/secureCodeBox/secureCodeBox/auto-discovery/kubernetes

go 1.17
go 1.19

require (
github.com/Masterminds/sprig v2.22.0+incompatible
github.com/go-logr/logr v1.2.3
github.com/onsi/ginkgo v1.16.5
github.com/onsi/gomega v1.19.0
github.com/secureCodeBox/secureCodeBox/operator v0.0.0-20220516151324-e6d879a9eb4f
k8s.io/api v0.24.0
k8s.io/apimachinery v0.24.0
k8s.io/client-go v0.24.0
sigs.k8s.io/controller-runtime v0.11.0
k8s.io/api v0.24.2
k8s.io/apimachinery v0.24.2
k8s.io/client-go v0.24.2
sigs.k8s.io/controller-runtime v0.12.2
)

require (
Expand Down Expand Up @@ -83,8 +83,8 @@ require (
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
k8s.io/apiextensions-apiserver v0.24.0 // indirect
k8s.io/component-base v0.24.0 // indirect
k8s.io/apiextensions-apiserver v0.24.2 // indirect
k8s.io/component-base v0.24.2 // indirect
k8s.io/klog/v2 v2.60.1 // indirect
k8s.io/kube-openapi v0.0.0-20220328201542-3ee0da9b0b42 // indirect
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9 // indirect
Expand Down
Loading