From 6b6cbd5b0d89a9ed4bf032c307bc498713314d1e Mon Sep 17 00:00:00 2001 From: Mateusz Urbanek Date: Tue, 21 Nov 2023 17:13:47 +0100 Subject: [PATCH 1/4] feat(docker): added base dockerfile Signed-off-by: Mateusz Urbanek --- .dockerignore | 19 ++++++++++++++ Dockerfile | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..f08a380 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,19 @@ +# Binaries for programs and plugins +bin/ +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Go workspace file +go.work + +# Helm resources +helm/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c565830 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,70 @@ +# Copyright 2023 Linode, LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +ARG TOOLCHAIN_VERSION=1.21 + +######################################################################################### +# Build +######################################################################################### + +# First stage: building the driver executable. +FROM docker.io/library/golang:${TOOLCHAIN_VERSION} as builder + +WORKDIR /work + +# Copy the Go Modules manifests. +COPY go.mod go.mod +COPY go.sum go.sum + +# Cache dep before building and copying source so that we don't need to re-download as +# much and so that source changes don't invalidate our downloaded layer. +RUN go mod download + +# Copy the go source. +COPY cmd/ cmd/ +COPY internal/ internal/ +COPY pkg/ pkg/ +COPY Makefile Makefile + +# Explicitly set the version, so the make won't try to get it (and fail). +ENV VERSION="builder" + +# Build. +RUN make build + +######################################################################################### +# Runtime +######################################################################################### + +# Second stage: building final environment for running the executable. +FROM gcr.io/distroless/static-debian11:latest AS runtime + +COPY --from=builder /work/bin/linode-cosi-driver /usr/bin/linode-cosi-driver + +# Set volume mount point for app socket. +VOLUME [ "/var/lib/cosi" ] + +# Disable healthcheck. +HEALTHCHECK NONE + +# Add labels +LABEL name="linode-cosi-driver" +LABEL description="COSI Driver for Linode Object Storage" +LABEL vendor="Linode, LLC" +LABEL license="Apache-2.0" +LABEL maintainers="Linode COSI Driver Authors" + +# Set the entrypoint. +ENTRYPOINT [ "/usr/bin/linode-cosi-driver" ] +CMD [] From 0aba70da4c19e1906644b7fd63fee56e5abf4614 Mon Sep 17 00:00:00 2001 From: Mateusz Urbanek Date: Wed, 22 Nov 2023 14:14:50 +0100 Subject: [PATCH 2/4] feat(helm): added scaffolding Signed-off-by: Mateusz Urbanek --- helm/.kube-linter.yaml | 70 +++++++++++++ helm/linode-cosi-driver/.helmignore | 23 +++++ helm/linode-cosi-driver/Chart.yaml | 24 +++++ helm/linode-cosi-driver/README.md | 47 +++++++++ helm/linode-cosi-driver/templates/NOTES.txt | 22 +++++ .../linode-cosi-driver/templates/_helpers.tpl | 62 ++++++++++++ .../templates/tests/.gitkeep | 0 helm/linode-cosi-driver/values.yaml | 98 +++++++++++++++++++ 8 files changed, 346 insertions(+) create mode 100644 helm/.kube-linter.yaml create mode 100644 helm/linode-cosi-driver/.helmignore create mode 100644 helm/linode-cosi-driver/Chart.yaml create mode 100644 helm/linode-cosi-driver/README.md create mode 100644 helm/linode-cosi-driver/templates/NOTES.txt create mode 100644 helm/linode-cosi-driver/templates/_helpers.tpl create mode 100644 helm/linode-cosi-driver/templates/tests/.gitkeep create mode 100644 helm/linode-cosi-driver/values.yaml diff --git a/helm/.kube-linter.yaml b/helm/.kube-linter.yaml new file mode 100644 index 0000000..8c3bd3c --- /dev/null +++ b/helm/.kube-linter.yaml @@ -0,0 +1,70 @@ +checks: + include: + - "access-to-create-pods" + # - "access-to-secrets" + - "cluster-admin-role-binding" + - "dangling-horizontalpodautoscaler" + - "dangling-ingress" + - "dangling-networkpolicy" + - "dangling-networkpolicypeer-podselector" + - "dangling-service" + - "default-service-account" + - "deprecated-service-account-field" + # - "dnsconfig-options" + - "docker-sock" + - "drop-net-raw-capability" + - "duplicate-env-var" + - "env-var-secret" + - "exposed-services" + - "host-ipc" + - "host-network" + - "host-pid" + - "hpa-minimum-three-replicas" + - "invalid-target-ports" + - "latest-tag" + # - "minimum-three-replicas" + - "mismatching-selector" + - "no-anti-affinity" + - "no-extensions-v1beta" + # - "no-liveness-probe" + # - "no-node-affinity" + - "no-read-only-root-fs" + # - "no-readiness-probe" + # - "no-rolling-update-strategy" + - "non-existent-service-account" + # - "non-isolated-pod" + - "privilege-escalation-container" + - "privileged-container" + - "privileged-ports" + - "read-secret-from-env-var" + # - "required-annotation-email" + # - "required-label-owner" + - "run-as-non-root" + - "sensitive-host-mounts" + - "ssh-port" + - "unsafe-proc-mount" + - "unsafe-sysctls" + # - "unset-cpu-requirements" + # - "unset-memory-requirements" + # - "use-namespace" + - "wildcard-in-rules" + - "writable-host-mount" + + # NOTE: manually exclude failing for documentation, fix them in future or + # comment why are they disabled. + exclude: + - "access-to-secrets" # NOTE: COSI Provisioner Sidecar requires access to secrets + - "dnsconfig-options" + - "minimum-three-replicas" + - "no-liveness-probe" + - "no-node-affinity" + - "no-readiness-probe" + - "no-rolling-update-strategy" + - "non-isolated-pod" + - "pdb-max-unavailable" + - "pdb-min-available" + - "required-annotation-email" + - "required-label-owner" + - "unset-cpu-requirements" + - "unset-memory-requirements" + - "use-namespace" diff --git a/helm/linode-cosi-driver/.helmignore b/helm/linode-cosi-driver/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/helm/linode-cosi-driver/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/helm/linode-cosi-driver/Chart.yaml b/helm/linode-cosi-driver/Chart.yaml new file mode 100644 index 0000000..1a517cb --- /dev/null +++ b/helm/linode-cosi-driver/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: linode-cosi-driver +description: A Helm chart for Kubernetes + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.1.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "v0.1.0" diff --git a/helm/linode-cosi-driver/README.md b/helm/linode-cosi-driver/README.md new file mode 100644 index 0000000..a4b9b03 --- /dev/null +++ b/helm/linode-cosi-driver/README.md @@ -0,0 +1,47 @@ +# linode-cosi-driver + +![Version: 0.1.0](https://img.shields.io/badge/Version-0.1.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 1.16.0](https://img.shields.io/badge/AppVersion-1.16.0-informational?style=flat-square) + +A Helm chart for Kubernetes + +## Values + +| Key | Type | Default | Description | +|-----|------|---------|-------------| +| affinity | object | `{}` | | +| autoscaling.enabled | bool | `false` | | +| autoscaling.maxReplicas | int | `100` | | +| autoscaling.minReplicas | int | `1` | | +| autoscaling.targetCPUUtilizationPercentage | int | `80` | | +| fullnameOverride | string | `""` | | +| image.pullPolicy | string | `"IfNotPresent"` | | +| image.repository | string | `"nginx"` | | +| image.tag | string | `""` | | +| imagePullSecrets | list | `[]` | | +| ingress.annotations | object | `{}` | | +| ingress.className | string | `""` | | +| ingress.enabled | bool | `false` | | +| ingress.hosts[0].host | string | `"chart-example.local"` | | +| ingress.hosts[0].paths[0].path | string | `"/"` | | +| ingress.hosts[0].paths[0].pathType | string | `"ImplementationSpecific"` | | +| ingress.tls | list | `[]` | | +| nameOverride | string | `""` | | +| nodeSelector | object | `{}` | | +| podAnnotations | object | `{}` | | +| podLabels | object | `{}` | | +| podSecurityContext | object | `{}` | | +| replicaCount | int | `1` | | +| resources | object | `{}` | | +| securityContext | object | `{}` | | +| service.port | int | `80` | | +| service.type | string | `"ClusterIP"` | | +| serviceAccount.annotations | object | `{}` | | +| serviceAccount.automount | bool | `true` | | +| serviceAccount.create | bool | `true` | | +| serviceAccount.name | string | `""` | | +| tolerations | list | `[]` | | +| volumeMounts | list | `[]` | | +| volumes | list | `[]` | | + +---------------------------------------------- +Autogenerated from chart metadata using [helm-docs v1.11.3](https://github.com/norwoodj/helm-docs/releases/v1.11.3) diff --git a/helm/linode-cosi-driver/templates/NOTES.txt b/helm/linode-cosi-driver/templates/NOTES.txt new file mode 100644 index 0000000..eab4996 --- /dev/null +++ b/helm/linode-cosi-driver/templates/NOTES.txt @@ -0,0 +1,22 @@ +1. Get the application URL by running these commands: +{{- if .Values.ingress.enabled }} +{{- range $host := .Values.ingress.hosts }} + {{- range .paths }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }} + {{- end }} +{{- end }} +{{- else if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "linode-cosi-driver.fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo http://$NODE_IP:$NODE_PORT +{{- else if contains "LoadBalancer" .Values.service.type }} + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "linode-cosi-driver.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "linode-cosi-driver.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") + echo http://$SERVICE_IP:{{ .Values.service.port }} +{{- else if contains "ClusterIP" .Values.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "linode-cosi-driver.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT +{{- end }} diff --git a/helm/linode-cosi-driver/templates/_helpers.tpl b/helm/linode-cosi-driver/templates/_helpers.tpl new file mode 100644 index 0000000..6968ba8 --- /dev/null +++ b/helm/linode-cosi-driver/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "linode-cosi-driver.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "linode-cosi-driver.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "linode-cosi-driver.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "linode-cosi-driver.labels" -}} +helm.sh/chart: {{ include "linode-cosi-driver.chart" . }} +{{ include "linode-cosi-driver.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "linode-cosi-driver.selectorLabels" -}} +app.kubernetes.io/name: {{ include "linode-cosi-driver.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "linode-cosi-driver.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "linode-cosi-driver.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/helm/linode-cosi-driver/templates/tests/.gitkeep b/helm/linode-cosi-driver/templates/tests/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/helm/linode-cosi-driver/values.yaml b/helm/linode-cosi-driver/values.yaml new file mode 100644 index 0000000..434698d --- /dev/null +++ b/helm/linode-cosi-driver/values.yaml @@ -0,0 +1,98 @@ +# Default values for linode-cosi-driver. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: nginx + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "" + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + # Specifies whether a service account should be created + create: true + # Automatically mount a ServiceAccount's API credentials? + automount: true + # Annotations to add to the service account + annotations: {} + # The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template + name: "" + +podAnnotations: {} +podLabels: {} + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +service: + type: ClusterIP + port: 80 + +ingress: + enabled: false + className: "" + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: + - path: / + pathType: ImplementationSpecific + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +# Additional volumes on the output Deployment definition. +volumes: [] +# - name: foo +# secret: +# secretName: mysecret +# optional: false + +# Additional volumeMounts on the output Deployment definition. +volumeMounts: [] +# - name: foo +# mountPath: "/etc/foo" +# readOnly: true + +nodeSelector: {} + +tolerations: [] + +affinity: {} From cbe3db7255452b02b968ae4b71d9aeb3ecdc897e Mon Sep 17 00:00:00 2001 From: Mateusz Urbanek Date: Wed, 22 Nov 2023 15:00:19 +0100 Subject: [PATCH 3/4] fix(review/1): non-root user in runtime Signed-off-by: Mateusz Urbanek --- Dockerfile | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index c565830..bb236b5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,8 +21,12 @@ ARG TOOLCHAIN_VERSION=1.21 # First stage: building the driver executable. FROM docker.io/library/golang:${TOOLCHAIN_VERSION} as builder +# Set the working directory. WORKDIR /work +# Prepare dir so it can be copied over to runtime layer. +RUN mkdir -p /var/lib/cosi + # Copy the Go Modules manifests. COPY go.mod go.mod COPY go.sum go.sum @@ -50,11 +54,18 @@ RUN make build # Second stage: building final environment for running the executable. FROM gcr.io/distroless/static-debian11:latest AS runtime -COPY --from=builder /work/bin/linode-cosi-driver /usr/bin/linode-cosi-driver +# Copy the executable. +COPY --from=builder --chown=65532:65532 /work/bin/linode-cosi-driver /usr/bin/linode-cosi-driver + +# Copy the volume directory with correct permissions, so driver can bind a socket there. +COPY --from=builder --chown=65532:65532 /var/lib/cosi /var/lib/cosi # Set volume mount point for app socket. VOLUME [ "/var/lib/cosi" ] +# Set the final UID:GID to non-root user. +USER 65532:65532 + # Disable healthcheck. HEALTHCHECK NONE From f5996e0a5b85df68e5b48d1d93b80197969b48c3 Mon Sep 17 00:00:00 2001 From: Mateusz Urbanek Date: Thu, 23 Nov 2023 09:08:39 +0100 Subject: [PATCH 4/4] fix(license): correct license holder Signed-off-by: Mateusz Urbanek --- Dockerfile | 4 ++-- LICENSE | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index bb236b5..84d09e3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -# Copyright 2023 Linode, LLC +# Copyright 2023 Akamai Technologies, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -72,7 +72,7 @@ HEALTHCHECK NONE # Add labels LABEL name="linode-cosi-driver" LABEL description="COSI Driver for Linode Object Storage" -LABEL vendor="Linode, LLC" +LABEL vendor="Akamai Technologies, Inc." LABEL license="Apache-2.0" LABEL maintainers="Linode COSI Driver Authors" diff --git a/LICENSE b/LICENSE index 197b68c..e8d3405 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2023 Linode, LLC + Copyright 2023 Akamai Technologies, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.