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

Added the Helm chart for the Secrets Manager operator #123

Merged
merged 44 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
64e0def
Added the Helm chart for the Secrets Manager operator
jhbeskow Mar 5, 2024
b1f81df
Some formatting changes requested by GitHub
jhbeskow Mar 5, 2024
459e7cf
Adding end-of-file carriage return suggested by GitHub
jhbeskow Mar 5, 2024
b6b4070
Removing the schema definition from the schema itself to match what w…
jhbeskow Mar 7, 2024
4b4732b
Merge branch 'main' into features/sm-operator-chart
jhbeskow Mar 7, 2024
7c400ed
Fixing an issue with the identity URL override
jhbeskow Mar 8, 2024
bdc13b0
README and CRD description updates.
jhbeskow Mar 14, 2024
3148bfb
Updating to use GHCR
jhbeskow Mar 26, 2024
51f2454
Adding optional image pull secrets
jhbeskow Mar 26, 2024
cc057d1
Adding missing properties to the values schema
jhbeskow Mar 26, 2024
3949495
Adding sm-operator to the build. Differentiating the versioning work…
jhbeskow Mar 29, 2024
1df830a
Fixing sed statement for appVersion lookup
jhbeskow Mar 29, 2024
72296b3
Adding the operator README to the root readme. Updating the .helmign…
jhbeskow Apr 1, 2024
958c15e
Adding Dev Container for testing purposes.
jhbeskow Apr 5, 2024
5c34fff
Locking down affinity to only the architectures we currently support.…
jhbeskow Apr 15, 2024
6c82963
First attempt to allow tests with the Helm chart
jhbeskow Apr 16, 2024
f5e2cfe
Adding conditional in self-install test
jhbeskow Apr 16, 2024
7fe2dbd
Adding SM-operator tests
jhbeskow Apr 16, 2024
faeb24b
Testing the auth token secret creation
jhbeskow Apr 17, 2024
2509511
Adding workflow to production environment
jhbeskow Apr 17, 2024
0a048b6
Testing secret creation
jhbeskow Apr 17, 2024
c93c653
Moving the test file to the workflows directory
jhbeskow Apr 17, 2024
7c31935
Checking logs and adding sleep
jhbeskow Apr 17, 2024
f4a7164
Adding tail so I can see the logs
jhbeskow Apr 17, 2024
819de22
Trying without the quotes on the auth secret for now
jhbeskow Apr 17, 2024
d57685c
Testing auth token length
jhbeskow Apr 17, 2024
770773a
Fixing auth token env variable setting
jhbeskow Apr 17, 2024
6b6c2e1
Adding some further tests
jhbeskow Apr 18, 2024
38b69ab
Adding a small wait
jhbeskow Apr 18, 2024
b1a593c
Fixing inverted logic
jhbeskow Apr 18, 2024
535ad72
Improving logging layout
jhbeskow Apr 18, 2024
b733b7e
Adding newlines requested by GitHub
jhbeskow Apr 30, 2024
a1dc5cb
Apply suggestions from code review
jhbeskow May 1, 2024
bb15337
Merge remote-tracking branch 'refs/remotes/origin/features/sm-operato…
jhbeskow Apr 30, 2024
f5f9176
Adding exectue permissions to postCreateCommand.sh
jhbeskow May 10, 2024
5cf8a27
Including a small testing message around Docker Desktop/DevContainers
jhbeskow May 10, 2024
ebcf400
Fixing capitalization in values.yaml
jhbeskow May 14, 2024
c1b5e98
Manually bumping the version to 0.1.0
jhbeskow Jun 5, 2024
eec09b1
Removing the image pull secret from the test files.
jhbeskow Jun 5, 2024
936965b
Merge branch 'main' into features/sm-operator-chart
jhbeskow Jun 5, 2024
991c0be
Fixing linter error for trailing spaces
jhbeskow Jun 5, 2024
1586345
Fixing the tag on the test values file
jhbeskow Jun 5, 2024
b83dbb7
Reverting the removal of imagePullSecrets for now to test
jhbeskow Jun 5, 2024
a628132
Updates requested from PR
jhbeskow Jun 6, 2024
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
43 changes: 43 additions & 0 deletions .devcontainer/common/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/kubernetes-helm
{
"name": "Bitwarden - Helm Charts Dev",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/base:bookworm",
"runArgs": ["--network=host"], // needed for kind
"postCreateCommand": "sudo .devcontainer/common/postCreateCommand.sh",
"customizations": {
"vscode": {
"extensions": [
"technosophos.vscode-helm",
"Tim-Koehler.helm-intellisense",
"ms-kubernetes-tools.vscode-kubernetes-tools",
"ms-azuretools.vscode-docker"
],
"settings": {}
}
},
"features": {
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {
"runArgs": [
"--privileged"
]
},
"ghcr.io/meaningful-ooo/devcontainer-features/fish:1": {
"fisher": true
},
"ghcr.io/devcontainers-contrib/features/kind:1": {}
},
// "initializeCommand": "cd .devcontainer && bash ensure-mount-sources",
"mounts": [
"source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind"
],
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "kubectl version",
// Configure tool-specific properties.
// "customizations": {},
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
"remoteUser": "root" // needed for kind: https://github.com/kubernetes-sigs/kind/issues/3196#issuecomment-1537260166
}
17 changes: 17 additions & 0 deletions .devcontainer/common/kind-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
kubeadmConfigPatches:
- |
kind: InitConfiguration
nodeRegistration:
kubeletExtraArgs:
node-labels: "ingress-ready=true"
extraPortMappings:
- containerPort: 80
hostPort: 80
protocol: TCP
- containerPort: 443
hostPort: 443
protocol: TCP
6 changes: 6 additions & 0 deletions .devcontainer/common/postCreateCommand.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
apt-get update
apt-get install -y kubernetes-client # kubectl
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
kind delete cluster --name helm-charts && kind create cluster --name helm-charts --config .devcontainer/common/kind-config.yaml

3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* text=auto eol=lf
*.{cmd,[cC][mM][dD]} text eol=crlf
*.{bat,[bB][aA][tT]} text eol=crlf
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
matrix:
include:
- chart_name: self-host
- chart_name: sm-operator
steps:
- name: Checkout repo
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/config/sample-bw-secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: k8s.bitwarden.com/v1
kind: BitwardenSecret
metadata:
labels:
app.kubernetes.io/name: bitwardensecret
app.kubernetes.io/instance: bitwardensecret-sample
app.kubernetes.io/part-of: sm-operator
name: bitwardensecret-sample
spec:
organizationId: "5a30c3dd-d7b9-4d32-8764-b06800c9e6ff"
secretName: bw-sample-secret
authToken:
secretName: bw-auth-token
secretKey: token
74 changes: 72 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
test:
name: Test Helm charts
runs-on: ubuntu-22.04
environment: Production
steps:
- name: Checkout repo
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
Expand All @@ -27,6 +28,18 @@ jobs:
with:
version: 'v3.13.1'

- name: Login to Azure - CI Subscription
uses: Azure/login@e15b166166a8746d1a47596803bd8c1b595455cf # v1.6.0
with:
creds: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }}

- name: Retrieve secrets
id: retrieve-secrets
uses: bitwarden/gh-actions/get-keyvault-secrets@main
with:
keyvault: "bitwarden-ci"
secrets: "helm-sm-operator-ci-test-access-token"

- name: Set up lynx
run: sudo apt install lynx

Expand All @@ -45,6 +58,7 @@ jobs:
CHANGED=$(ct list-changed --target-branch ${{ github.event.repository.default_branch }})
if [[ -n "$CHANGED" ]]; then
echo "changed=true" >> $GITHUB_OUTPUT
echo "changed-list=$CHANGED" >> $GITHUB_OUTPUT
fi

- name: Create kind cluster
Expand Down Expand Up @@ -107,12 +121,17 @@ jobs:

kubectl create secret tls tls-secret --cert=bitwarden.localhost.pem --key=bitwarden.localhost.key

#Setup image pull secret
kubectl create secret -n bitwarden docker-registry ghcr-login-secret --docker-server=ghcr.io --docker-username=bitwarden-devops-bot --docker-password=${{ secrets.GITHUB_TOKEN }} --docker-email=106330231+bitwarden-devops-bot@users.noreply.github.com



- name: Run chart-testing (install)
if: steps.list-changed.outputs.changed == 'true'
run: ct install --target-branch ${{ github.event.repository.default_branch }} --skip-clean-up --namespace bitwarden

- name: Test install
if: steps.list-changed.outputs.changed == 'true'
- name: Test install (self-host)
if: steps.list-changed.outputs.changed == 'true' && contains(steps.list-changed.outputs.changed-list,'self-host')
run: |
#For review purposes
echo "*****DEPLOYMENTS*****"
Expand Down Expand Up @@ -175,6 +194,57 @@ jobs:

echo "Admin OK."


- name: Test install (sm-operator)
if: steps.list-changed.outputs.changed == 'true' && contains(steps.list-changed.outputs.changed-list,'sm-operator')
run: |
#For review purposes
jhbeskow marked this conversation as resolved.
Show resolved Hide resolved
echo "*****DEPLOYMENTS*****"
kubectl get deployments

echo "*****PODS*****"
pods=$(kubectl get pods -l app.kubernetes.io/name=sm-operator | grep 2/2)
echo $pods

if [[ -z "$pods" ]]; then
echo "::error::No pods found."
exit 1
fi

echo "*****CREATING AUTH SECRET*****"
kubectl create secret generic bw-auth-token -n bitwarden --from-literal=token="$AUTH_TOKEN"
echo "*****CREATING BW SECRET*****"
kubectl apply -f .github/workflows/config/sample-bw-secret.yaml

# Sleeping while BitwardenSecret is being created and synced
sleep 2s
jhbeskow marked this conversation as resolved.
Show resolved Hide resolved

echo "*****LOGS*****"
logs=$(kubectl logs -l app.kubernetes.io/name=sm-operator -c manager)
echo "$logs"

completed=$(echo "$logs"| grep "Completed sync for bitwarden/bitwardensecret-sample")

if [[ -z "$completed" ]]; then
echo "::error::Secret did not sync."
exit 1
fi

echo "*****RESULTING SECRETS*****"
secrets=$(kubectl get secrets)
echo "$secrets"

secretCreated=$(echo "$secrets" | grep "bw-sample-secret Opaque 3")

if [[ -z "$secretCreated" ]]; then
echo "::error::Secret not created correctly."
exit 1
fi

echo "*****OPERATOR OK*****"
env:
AUTH_TOKEN: ${{ steps.retrieve-secrets.outputs.helm-sm-operator-ci-test-access-token }}

- name: Clean-up
if: steps.list-changed.outputs.changed == 'true'
run: |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
name: Update Versions
name: Update Versions - Self Host

on:
workflow_dispatch:
Expand Down Expand Up @@ -81,9 +81,9 @@ jobs:
WEBVERSION: ${{ steps.get-web.outputs.version }}
run: |
echo "Checking..."

coreimages=( "admin" "api" "attachments" "events" "icons" "identity" "notifications" "scim" "sso" "mssqlmigratorutility" )

test_image() {
image=$1
version=$2
Expand All @@ -98,15 +98,15 @@ jobs:
}

echo "Core Images ($COREVERSION)..."

for key in "${!coreimages[@]}"
do
image=${coreimages[$key]}
test_image $image $COREVERSION
done

echo "Web Image ($WEBVERSION)..."

test_image "web" $WEBVERSION

update-versions:
Expand Down
112 changes: 112 additions & 0 deletions .github/workflows/update-versions-sm-operator.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
---
name: Update Versions - SM Operator

on:
workflow_dispatch:

env:
_BRANCH: main

jobs:
setup:
name: Setup
runs-on: ubuntu-22.04
outputs:
operator_version: ${{ steps.operator-update.outputs.version }}
operator_version_update: ${{ steps.operator-update.outputs.update }}
steps:
- name: Checkout Branch
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
ref: ${{ env._BRANCH }}

- name: Get Latest Operator Version
id: get-operator-version
run: |
image="sm-operator"
json=$(curl -s "https://registry.hub.docker.com/v2/repositories/bitwarden/$image/tags/")
digest=$(echo $json |jq '."results"[] | select(.name=="latest")["digest"]')
latestTag=$(echo $json | jq --argjson DIGEST $digest '."results"[] | select(.digest==$DIGEST) | select(.name != "latest")["name"]' | head -n 1)

echo "Operator Image ($latestTag)..."

echo "version=$latestTag" >> $GITHUB_OUTPUT

- name: Check if operator needs updating
id: operator-update
env:
LATEST_OPERATOR_VERSION: ${{ steps.get-operator-version.outputs.version }}
run: |
OPERATOR_VERSION=$(sed -nE 's/^appVersion:\s+([^\s]+)/\1/p' Chart.yaml)

echo "Operator Version: $OPERATOR_VERSION"
echo "Latest Operator Version: $LATEST_OPERATOR_VERSION"
if [ "$OPERATOR_VERSION" != "$LATEST_OPERATOR_VERSION" ]; then
echo "Needs Operator update!"
echo "update=1" >> $GITHUB_OUTPUT
else
echo "update=0" >> $GITHUB_OUTPUT
fi
working-directory: charts/sm-operator

update-versions:
name: "Update Versions"
if: needs.setup.outputs.operator_version_update == 1
runs-on: ubuntu-22.04
needs: setup
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout Branch
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
ref: ${{ env._BRANCH }}

- name: Create Update Versions Branch
run: |
PR_BRANCH=update-versions-$GITHUB_RUN_ID
echo "PR_BRANCH=$PR_BRANCH" >> $GITHUB_ENV
git switch -c $PR_BRANCH
git push -u origin $PR_BRANCH

- name: Checkout Update Versions Branch
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
ref: ${{ env.PR_BRANCH }}

- name: Update Chart appVersion
env:
VERSION: ${{ needs.setup.outputs.operator_version }}
run: "sed -i -e 's/appVersion:.*/appVersion: '$VERSION'/' Chart.yaml"
working-directory: charts/sm-operator

- name: Commit updated files
run: |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git commit -m "Updated operator version" -a

- name: Push changes
run: git push -u origin $PR_BRANCH

- name: Create Update Versions PR
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BASE_BRANCH: ${{ github.ref_name }}
TITLE: "Update operator version"
run: |
gh pr create --title "$TITLE" \
--base "$BASE_BRANCH" \
--head "$PR_BRANCH" \
--label "automated pr" \
--body "
## Type of change
- [ ] Bug fix
- [ ] New feature development
- [ ] Tech debt (refactoring, code cleanup, dependency upgrades, etc)
- [ ] Build/deploy pipeline (DevOps)
- [X] Other

## Objective
Automated version update to appVersion in charts/sm-operator/Chart.yaml"
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
name: Version Bump
name: Version Bump - Self Host

on:
workflow_dispatch:
Expand Down
Loading
Loading