15 Commits

Author SHA1 Message Date
886fe3783d fixed fields lookup
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
update libcrypte and libssl
2023-05-10 10:35:00 +02:00
18a47f8ad2 Merge pull request #24 from Lerentis/dependabot/pip/kopf-1.36.1
All checks were successful
continuous-integration/drone/push Build is passing
2023-05-10 10:00:36 +02:00
e405734e72 Bump kopf from 1.36.0 to 1.36.1
Bumps [kopf](https://github.com/nolar/kopf) from 1.36.0 to 1.36.1.
- [Release notes](https://github.com/nolar/kopf/releases)
- [Commits](https://github.com/nolar/kopf/compare/1.36.0...1.36.1)

---
updated-dependencies:
- dependency-name: kopf
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-05-08 07:00:31 +00:00
8bf4292991 bump chart version and image ref
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2023-04-26 16:39:00 +02:00
b149b26485 Merge pull request #19 from nicoangelo/feature/use-cli-json-mode
All checks were successful
continuous-integration/drone/push Build is passing
2023-04-26 16:35:02 +02:00
5263a811e1 add JSON output to changelog 2023-04-26 08:59:17 +02:00
4b59ff1aac fix 2023-04-26 08:54:36 +02:00
ad1cc9f646 switch to JSON mode of cli
pass around logger
2023-04-26 08:54:36 +02:00
0f518ab28d hopefully fix permissions
All checks were successful
continuous-integration/drone/push Build is passing
2023-04-22 15:37:14 +02:00
1bf2a24cf2 also setup builx for multiarch build
All checks were successful
continuous-integration/drone/push Build is passing
2023-04-22 15:25:10 +02:00
a73e8ff982 fix build and push 2023-04-22 15:22:35 +02:00
54a4ffa212 Merge pull request #20 from Lerentis/Lerentis/issue14 2023-04-22 15:17:55 +02:00
16040bf87a Push to more Registries
Fixes #14
2023-04-22 15:15:53 +02:00
9c1c7417e1 Merge pull request #18 from Lerentis/dependabot/github_actions/mikefarah/yq-4.33.3
All checks were successful
continuous-integration/drone/push Build is passing
Bump mikefarah/yq from 4.33.1 to 4.33.3
2023-04-21 16:01:23 +02:00
219c9d0413 Bump mikefarah/yq from 4.33.1 to 4.33.3
Bumps [mikefarah/yq](https://github.com/mikefarah/yq) from 4.33.1 to 4.33.3.
- [Release notes](https://github.com/mikefarah/yq/releases)
- [Changelog](https://github.com/mikefarah/yq/blob/master/release_notes.txt)
- [Commits](https://github.com/mikefarah/yq/compare/v4.33.1...v4.33.3)

---
updated-dependencies:
- dependency-name: mikefarah/yq
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-04-17 07:00:46 +00:00
11 changed files with 83 additions and 35 deletions

View File

@ -8,7 +8,9 @@ on:
jobs:
release:
permissions:
id-token: write
contents: write
packages: write
runs-on: ubuntu-latest
steps:
- name: Checkout
@ -34,15 +36,36 @@ jobs:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
- name: Get app version from chart
uses: mikefarah/yq@v4.33.1
uses: mikefarah/yq@v4.33.3
id: app_version
with:
cmd: yq '.appVersion' charts/bitwarden-crd-operator/Chart.yaml
- name: "GHCR Login"
uses: docker/login-action@v2
with:
registry: ghcr.io
username: lerentis
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: "GHCR Build and Push"
id: docker_build
uses: docker/build-push-action@v4
with:
push: true
platforms: linux/amd64,linux/arm64
tags: ghcr.io/lerentis/bitwarden-crd-operator:${{ steps.app_version.outputs.result }}
- name: Create SBOM
uses: anchore/sbom-action@v0
with:
image: lerentis/bitwarden-crd-operator:${{ steps.app_version.outputs.result }}
image: ghcr.io/lerentis/bitwarden-crd-operator:${{ steps.app_version.outputs.result }}
- name: Publish SBOM
uses: anchore/sbom-action/publish-sbom@v0

View File

@ -9,9 +9,14 @@ RUN cd /tmp && wget https://github.com/bitwarden/clients/releases/download/cli-v
FROM alpine:3.17.3
LABEL org.opencontainers.image.source=https://github.com/Lerentis/bitwarden-crd-operator
LABEL org.opencontainers.image.description="Kubernetes Operator to create k8s secrets from bitwarden"
LABEL org.opencontainers.image.licenses=MIT
ARG PYTHON_VERSION=3.10.11-r0
ARG PIP_VERSION=22.3.1-r1
ARG GCOMPAT_VERSION=1.1.0-r0
ARG LIBCRYPTO_VERSION=3.0.8-r4
COPY --from=builder /tmp/bw /usr/local/bin/bw
COPY requirements.txt requirements.txt
@ -22,7 +27,7 @@ RUN set -eux; \
mkdir -p /home/bw-operator; \
chown -R bw-operator /home/bw-operator; \
chmod +x /usr/local/bin/bw; \
apk add gcc musl-dev libstdc++ gcompat=${GCOMPAT_VERSION} python3=${PYTHON_VERSION} py3-pip=${PIP_VERSION}; \
apk add gcc musl-dev libstdc++ gcompat=${GCOMPAT_VERSION} python3=${PYTHON_VERSION} py3-pip=${PIP_VERSION} libcrypto3=${LIBCRYPTO_VERSION} libssl3=${LIBCRYPTO_VERSION}; \
pip install -r requirements.txt --no-warn-script-location; \
apk del --purge gcc musl-dev libstdc++;

View File

@ -4,9 +4,9 @@ description: Deploy the Bitwarden CRD Operator
type: application
version: "v0.5.4"
version: "v0.7.1"
appVersion: "0.5.4"
appVersion: "0.6.1"
keywords:
- operator
@ -93,9 +93,12 @@ annotations:
enabled: true
artifacthub.io/license: MIT
artifacthub.io/operator: "true"
artifacthub.io/containsSecurityUpdates: "true"
artifacthub.io/changes: |
- kind: changed
description: "Bump Alpine base image from 3.17.2 to 3.17.3"
- kind: fixed
description: "Fixed fields lookup"
- kind: fixed
description: "Fixed CVE-2023-1255 in base image"
artifacthub.io/images: |
- name: bitwarden-crd-operator
image: lerentis/bitwarden-crd-operator:0.5.4
image: ghcr.io/lerentis/bitwarden-crd-operator:0.6.1

View File

@ -5,7 +5,7 @@
replicaCount: 1
image:
repository: lerentis/bitwarden-crd-operator
repository: ghcr.io/lerentis/bitwarden-crd-operator
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
# tag: "0.1.0"

View File

@ -16,3 +16,17 @@ spec:
id: "88781348-c81c-4367-9801-550360c21295"
name: "test-secret"
namespace: "default"
---
apiVersion: "lerentis.uploadfilter24.eu/v1beta4"
kind: BitwardenSecret
metadata:
name: test-scope
spec:
content:
- element:
secretName: public_key
secretRef: pubKey
secretScope: fields
id: "466fc4b0-ffca-4444-8d88-b59d4de3d928"
name: "test-scope"
namespace: "default"

View File

@ -1,3 +1,3 @@
kopf==1.36.0
kopf==1.36.1
kubernetes==26.1.0
Jinja2==3.1.2

View File

@ -9,12 +9,12 @@ from utils.utils import command_wrapper, unlock_bw
def bitwarden_signin(logger, **kwargs):
if 'BW_HOST' in os.environ:
try:
command_wrapper(f"config server {os.getenv('BW_HOST')}")
command_wrapper(logger, f"config server {os.getenv('BW_HOST')}")
except BaseException:
logger.warn("Revieved none zero exit code from server config")
logger.warn("Received non-zero exit code from server config")
logger.warn("This is expected from startup")
pass
else:
logger.info("BW_HOST not set. Assuming SaaS installation")
command_wrapper("login --apikey")
command_wrapper(logger, "login --apikey")
unlock_bw(logger)

View File

@ -46,7 +46,7 @@ def create_managed_registry_secret(spec, name, namespace, logger, **kwargs):
unlock_bw(logger)
logger.info(f"Locking up secret with ID: {id}")
secret_json_object = json.loads(get_secret_from_bitwarden(id))
secret_json_object = get_secret_from_bitwarden(logger, id)
api = kubernetes.client.CoreV1Api()
@ -60,7 +60,7 @@ def create_managed_registry_secret(spec, name, namespace, logger, **kwargs):
secret = create_dockerlogin(
logger,
secret,
secret_json_object,
secret_json_object["data"],
username_ref,
password_ref,
registry)
@ -118,7 +118,7 @@ def update_managed_registry_secret(
unlock_bw(logger)
logger.info(f"Locking up secret with ID: {id}")
secret_json_object = json.loads(get_secret_from_bitwarden(id))
secret_json_object = get_secret_from_bitwarden(logger, id)
api = kubernetes.client.CoreV1Api()
@ -132,7 +132,7 @@ def update_managed_registry_secret(
secret = create_dockerlogin(
logger,
secret,
secret_json_object,
secret_json_object["data"],
username_ref,
password_ref,
registry)

View File

@ -45,7 +45,7 @@ def create_managed_secret(spec, name, namespace, logger, body, **kwargs):
unlock_bw(logger)
logger.info(f"Locking up secret with ID: {id}")
secret_json_object = json.loads(get_secret_from_bitwarden(id))
secret_json_object = get_secret_from_bitwarden(logger, id)
api = kubernetes.client.CoreV1Api()
@ -106,7 +106,7 @@ def update_managed_secret(
unlock_bw(logger)
logger.info(f"Locking up secret with ID: {id}")
secret_json_object = json.loads(get_secret_from_bitwarden(id))
secret_json_object = get_secret_from_bitwarden(logger, id)
api = kubernetes.client.CoreV1Api()

View File

@ -4,7 +4,7 @@ from utils.utils import get_secret_from_bitwarden, parse_fields_scope, parse_log
def bitwarden_lookup(id, scope, field):
_secret_json = json.loads(get_secret_from_bitwarden(id))
_secret_json = get_secret_from_bitwarden(None, id)
if scope == "login":
return parse_login_scope(_secret_json, field)
if scope == "fields":

View File

@ -7,44 +7,47 @@ class BitwardenCommandException(Exception):
pass
def get_secret_from_bitwarden(id):
return command_wrapper(command=f"get item {id}")
def get_secret_from_bitwarden(logger, id):
return command_wrapper(logger, command=f"get item {id}")
def unlock_bw(logger):
status_output = command_wrapper("status")
status = json.loads(status_output)['status']
status_output = command_wrapper(logger, "status", False)
status = status_output['data']['template']['status']
if status == 'unlocked':
logger.info("Already unlocked")
return
token_output = command_wrapper("unlock --passwordenv BW_PASSWORD")
tokens = token_output.split('"')[1::2]
os.environ["BW_SESSION"] = tokens[1]
token_output = command_wrapper(logger, "unlock --passwordenv BW_PASSWORD")
os.environ["BW_SESSION"] = token_output["data"]["raw"]
logger.info("Signin successful. Session exported")
def command_wrapper(command):
def command_wrapper(logger, command, use_success: bool = True):
system_env = dict(os.environ)
sp = subprocess.Popen(
[f"bw {command}"],
[f"bw --response {command}"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
close_fds=True,
shell=True,
env=system_env)
out, err = sp.communicate()
if err:
raise BitwardenCommandException(err)
return out.decode(encoding='UTF-8')
resp = json.loads(out.decode(encoding='UTF-8'))
if "DEBUG" in system_env:
logger.info(resp)
if resp["success"] != None and (not use_success or (use_success and resp["success"] == True)):
return resp
logger.warn(resp)
return None
def parse_login_scope(secret_json, key):
return secret_json["login"][key]
return secret_json["data"]["login"][key]
def parse_fields_scope(secret_json, key):
if "fields" not in secret_json:
if "fields" not in secret_json["data"]:
return None
for entry in secret_json["fields"]:
for entry in secret_json["data"]["fields"]:
if entry['name'] == key:
return entry['value']