Skip to content

Commit

Permalink
Convert cluster-secret-store url string creation from in-line to `_…
Browse files Browse the repository at this point in the history
…helpers.tpl` (#64)

* debug bweso issues

* jesse figured out the string creation

* add helpers for jsonpath

* add quotes to strings

* add login sub path ro jsonpath

* add the . for the jsonpath variables

* add fields clustersecretstore

* maybe fix quote issue for fiels CSS?

* Update charts/bitwarden-eso-provider/values.yaml

Co-authored-by: JesseBot <jessebot@linux.com>

* change the restart policy to OnFailure

* Bump chart to 0.4.0 and generate docs

* Update ci-helm-lint-test.yml - fix kind-chart-testing

---------

Co-authored-by: JesseBot <jessebot@linux.com>
  • Loading branch information
cloudymax and jessebot authored Aug 19, 2023
1 parent fd837bf commit a8fdd60
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-helm-lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
- name: Pull and side-load docker container
run: |
docker pull --platform=linux/amd64 docker.io/jessebot/bweso:v0.2.0 && \
kind load docker-image docker.io/jessebot/bweso:v0.2.0 --name kind
kind load docker-image docker.io/jessebot/bweso:v0.2.0 --name kind-chart-testing
shell: bash

- name: Run chart-testing (install)
Expand Down
2 changes: 1 addition & 1 deletion charts/bitwarden-eso-provider/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ 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.3.1
version: 0.4.0

# renovate: image=jessebot/bweso
appVersion: "v0.2.0"
Expand Down
4 changes: 2 additions & 2 deletions charts/bitwarden-eso-provider/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# bitwarden-eso-provider

![Version: 0.3.1](https://img.shields.io/badge/Version-0.3.1-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: v0.2.0](https://img.shields.io/badge/AppVersion-v0.2.0-informational?style=flat-square)
![Version: 0.4.0](https://img.shields.io/badge/Version-0.4.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: v0.2.0](https://img.shields.io/badge/AppVersion-v0.2.0-informational?style=flat-square)

Helm chart to use Bitwarden as a Provider for External Secrets Operator

Expand Down Expand Up @@ -44,7 +44,7 @@ Helm chart to use Bitwarden as a Provider for External Secrets Operator
| replicaCount | int | `1` | replicas to deploy of this pod |
| resources | object | `{}` | |
| securityContext | object | `{}` | |
| service.port | int | `80` | port to broadcast for k8s service internally on the cluster |
| service.port | int | `8087` | port to broadcast for k8s service internally on the cluster |
| service.targetPort | int | `8087` | port on the container to target for the k8s service |
| service.type | string | `"ClusterIP"` | |
| serviceAccount.annotations | object | `{}` | Annotations to add to the service account |
Expand Down
35 changes: 35 additions & 0 deletions charts/bitwarden-eso-provider/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,38 @@ Create the name of the service account to use
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}

{{/*
Create the url string that will be used to query Bitwarden:
- cluster-secret-store logins url
*/}}
{{- define "bitwarden-eso-provider.clusterSecretStore.loginUrl" -}}
{{- printf "http://%s.%s.svc.cluster.local:%s/list/object/items?search={{ .remoteRef.key }}" .Release.Name .Release.Namespace (.Values.service.port | toString) | quote }}
{{- end }}


{{/*
Create the url string that will be used to query bitwarden
- cluster-secret-store logins jsonpath
*/}}
{{- define "bitwarden-eso-provider.clusterSecretStore.loginJsonPath" -}}
{{- printf "$.data.data[0].login.{{ .remoteRef.property }}" | quote }}
{{- end }}


{{/*
Create the url string that will be used to query Bitwarden:
- cluster-secret-store fields url
*/}}
{{- define "bitwarden-eso-provider.clusterSecretStore.fieldsUrl" -}}
{{- printf "http://%s.%s.svc.cluster.local:%s/list/object/items?search={{ .remoteRef.key }}" .Release.Name .Release.Namespace (.Values.service.port | toString) | quote }}
{{- end }}


{{/*
Create the url string that will be used to query bitwarden
- cluster-secret-store fields jsonpath
*/}}
{{- define "bitwarden-eso-provider.clusterSecretStore.fieldsJsonPath" -}}
{{- printf "$.data.data[0].fields[?(@.name==\"{{ .remoteRef.property }}\")].value" | quote }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ metadata:
spec:
provider:
webhook:
url: "http://{{ .Release.Name }}.{{ .Release.Namespace }}.svc.cluster.local:{{ .Values.service.port }}/object/items"
url: {{ include "bitwarden-eso-provider.clusterSecretStore.loginUrl" . }}
headers:
Content-Type: application/json
result:
jsonPath: "$.data.data[?(@.name=={{`{{ .remoteRef.key }}`}})].login.{{`{{ .remoteRef.property }}`}}"
jsonPath: {{ include "bitwarden-eso-provider.clusterSecretStore.loginJsonPath" . }}
---
apiVersion: external-secrets.io/v1beta1
kind: ClusterSecretStore
Expand All @@ -20,7 +20,7 @@ metadata:
spec:
provider:
webhook:
url: "http://{{ .Release.Name }}.{{ .Release.Namespace }}.svc.cluster.local:{{ .Values.service.port }}/object/item/"
url: {{ include "bitwarden-eso-provider.clusterSecretStore.fieldsUrl" . }}
result:
jsonPath: "$.data.data[?(@.name==\"{{`{{ .remoteRef.key }}`}}\"].fields[?@.name==\"{{`{{ .remoteRef.property }}`}}\"].value"
jsonPath: {{ include "bitwarden-eso-provider.clusterSecretStore.fieldsJsonPath" . }}
{{- end }}
1 change: 1 addition & 0 deletions charts/bitwarden-eso-provider/templates/credentials.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apiVersion: v1
kind: Secret
metadata:
name: {{ .Release.Name }}
namespace: {{ .Release.Namespace }}
type: Opaque
data:
BW_HOST: {{ .Values.bitwarden_eso_provider.auth.host | b64enc | quote }}
Expand Down
7 changes: 4 additions & 3 deletions charts/bitwarden-eso-provider/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "bitwarden-eso-provider.fullname" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "bitwarden-eso-provider.labels" . | nindent 4 }}
spec:
Expand Down Expand Up @@ -63,18 +64,18 @@ spec:
command:
- wget
- -q
- http://127.0.0.1:{{ .Values.service.targetPort }}/sync
- http://127.0.0.1:{{ .Values.service.port }}/sync
- --post-data=''
readinessProbe:
tcpSocket:
port: {{ .Values.service.targetPort }}
port: {{ .Values.service.port }}
initialDelaySeconds: 20
failureThreshold: 3
timeoutSeconds: 1
periodSeconds: 10
startupProbe:
tcpSocket:
port: {{ .Values.service.targetPort }}
port: {{ .Values.service.port }}
initialDelaySeconds: 10
failureThreshold: 30
timeoutSeconds: 1
Expand Down
1 change: 1 addition & 0 deletions charts/bitwarden-eso-provider/templates/hpa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "bitwarden-eso-provider.fullname" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "bitwarden-eso-provider.labels" . | nindent 4 }}
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ kind: NetworkPolicy
apiVersion: networking.k8s.io/v1
metadata:
name: external-secret-2-{{ .Release.Name }}
namespace: {{ .Release.Namespace }}
spec:
podSelector:
matchLabels:
Expand Down
3 changes: 2 additions & 1 deletion charts/bitwarden-eso-provider/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "bitwarden-eso-provider.fullname" . }}
name: {{ .Release.Name }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "bitwarden-eso-provider.labels" . | nindent 4 }}
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: test-connection
namespace: {{ .Release.Namespace }}
data:
curl_script.sh: |
curl http://{{ include "bitwarden-eso-provider.fullname" . }}:{{ .Values.service.port }}/status
curl http://{{ .Release.Name }}.{{ .Release.Namespace }}.svc.cluster.local:{{ .Values.service.port }}/status
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: v1
kind: Pod
metadata:
name: "{{ include "bitwarden-eso-provider.fullname" . }}-test-connection"
namespace: {{ .Release.Namespace }}
labels:
{{- include "bitwarden-eso-provider.labels" . | nindent 4 }}
annotations:
Expand All @@ -23,4 +24,4 @@ spec:
configMap:
name: test-connection
defaultMode: 0777
restartPolicy: Never
restartPolicy: OnFailure
2 changes: 1 addition & 1 deletion charts/bitwarden-eso-provider/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ service:
# -- port on the container to target for the k8s service
targetPort: 8087
# -- port to broadcast for k8s service internally on the cluster
port: 80
port: 8087

resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious
Expand Down

0 comments on commit a8fdd60

Please sign in to comment.