-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
removing part_of_app_of_apps feature (#100)
* removing part_of_app_of_apps feature * fix vouch bitwarden id stuff... even though I thought I did that already * bump pyproject again * finish cleaning up the last of app_of_apps stuff in favor of using appsets more effeciently and directory recursion * Update smol_k8s_lab/k8s_apps/secrets_management/external_secrets_operator.py - fix typo Co-authored-by: Max! <[email protected]> --------- Co-authored-by: Max! <[email protected]>
- Loading branch information
Showing
7 changed files
with
62 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "smol_k8s_lab" | ||
version = "2.0.0a1" | ||
version = "2.0.0a2" | ||
description = "Bootstrap simple projects on Kubernetes with kind, k3d, and k3s. this is an alpha release" | ||
authors = ["Jesse Hitch <[email protected]>", | ||
"Max Roby <[email protected]>"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 22 additions & 44 deletions
66
smol_k8s_lab/k8s_apps/secrets_management/external_secrets_operator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,63 @@ | ||
#!/usr/bin/env python3.11 | ||
""" | ||
Name: external_secrets | ||
DESCRIPTION: configures external secrets, currently only with gitlab | ||
DESCRIPTION: configures external secrets, currently only with Bitwarden and GitLab | ||
hopefully with more supported providers in the future | ||
AUTHOR: @jessebot | ||
LICENSE: GNU AFFERO GENERAL PUBLIC LICENSE Version 3 | ||
""" | ||
import logging as log | ||
from smol_k8s_lab.bitwarden.bw_cli import BwCLI | ||
from smol_k8s_lab.k8s_tools.argocd_util import install_with_argocd, wait_for_argocd_app | ||
from smol_k8s_lab.k8s_tools.k8s_lib import K8s | ||
from smol_k8s_lab.utils.rich_cli.console_logging import sub_header | ||
from smol_k8s_lab.utils.subproc import subproc | ||
|
||
|
||
def configure_external_secrets(k8s_obj: K8s, | ||
eso_dict: dict, | ||
bweso_dict: dict = {}, | ||
eso_provider: str = "", | ||
distro: str = "", | ||
bitwarden: BwCLI = None) -> None: | ||
""" | ||
configure external secrets and provider. (and optionally bweso) | ||
configure external secrets and provider. (and optionally bweso or gitlab) | ||
""" | ||
k8s_obj.create_namespace("external-secrets") | ||
|
||
if eso_provider == "bitwarden": | ||
setup_bweso_provider(k8s_obj, distro, bitwarden) | ||
elif eso_provider == "gitlab": | ||
setup_gitlab_provider(k8s_obj, eso_dict['init']['values']['gitlab_access_token']) | ||
|
||
install_with_argocd(k8s_obj, 'external-secrets-operator', eso_dict['argo']) | ||
wait_for_argocd_app('external-secrets-operator') | ||
|
||
if bweso_dict['enabled']: | ||
setup_bweso(k8s_obj, distro, bweso_dict['argo'], bitwarden) | ||
# wait for bitwarden external secrets provider to be up | ||
wait_for_argocd_app('bitwarden-eso-provider') | ||
|
||
|
||
def setup_bweso(k8s_obj: K8s, | ||
distro: str, | ||
bweso_argo_dict: dict = {}, | ||
bitwarden: BwCLI = None) -> None: | ||
def setup_bweso_provider(k8s_obj: K8s, distro: str, bitwarden: BwCLI = None) -> None: | ||
""" | ||
Creates an initial secret for use with the bitwarden provider for ESO | ||
""" | ||
sub_header("Installing the Bitwarden External Secrets Provider...") | ||
|
||
# this is a standard k8s secrets yaml | ||
k8s_obj.create_secret('bweso-login', 'external-secrets', | ||
k8s_obj.create_secret('bweso-login', | ||
'external-secrets', | ||
{"BW_PASSWORD": bitwarden.password, | ||
"BW_CLIENTSECRET": bitwarden.client_secret, | ||
"BW_CLIENTID": bitwarden.client_id, | ||
"BW_HOST": bitwarden.host}) | ||
|
||
if distro == 'kind': | ||
image = "docker.io/jessebot/bweso:v0.2.0" | ||
image = "docker.io/jessebot/bweso:v0.5.0" | ||
cmds = [f"docker pull --platform=linux/amd64 {image}", | ||
f"kind load docker-image {image} --name smol-k8s-lab-kind"] | ||
subproc(cmds) | ||
|
||
if bweso_argo_dict.get('part_of_app_of_apps', None): | ||
log.debug("Looks like this app is actually part of an app of apps " | ||
"that will be deployed") | ||
return True | ||
|
||
install_with_argocd(k8s_obj, 'bitwarden-eso-provider', bweso_argo_dict) | ||
# wait for bitwarden external secrets provider to be up | ||
wait_for_argocd_app('bitwarden-eso-provider') | ||
|
||
|
||
def setup_gitlab_provider(k8s_obj: K8s, external_secrets_config: dict) -> None: | ||
def setup_gitlab_provider(k8s_obj: K8s, gitlab_access_token: str) -> None: | ||
""" | ||
setup the gitlab external secrets operator config | ||
Accepts dict as arg: | ||
dict = {'namespace': 'somenamespace', 'access_token': 'tokenhere'} | ||
setup the GitLab external secrets operator provider config by creating a | ||
secret with the GitLab access token | ||
""" | ||
gitlab_access_token = external_secrets_config['access_token'] | ||
gitlab_namespace = external_secrets_config['namespace'] | ||
|
||
# create the namespace if does not exist | ||
subproc([f'kubectl create namespace {gitlab_namespace}'], error_ok=True) | ||
|
||
# this currently only works with gitlab | ||
gitlab_secret = {'apiVersion': 'v1', | ||
'kind': 'Secret', | ||
'metadata': {'name': 'gitlab-secret', | ||
'namespace': gitlab_namespace, | ||
'labels': {'type': 'gitlab'}}, | ||
'type': 'Opaque', | ||
'stringData': {'token': gitlab_access_token}} | ||
|
||
k8s_obj.apply_custom_resources([gitlab_secret]) | ||
k8s_obj.create_secret('gitlab-secret', | ||
'external-secrets', | ||
{'token': gitlab_access_token}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters