Skip to content
Snippets Groups Projects
Verified Commit 5ace6a95 authored by Maarten de Waard's avatar Maarten de Waard :angel:
Browse files

remove usage of secrets dir

parent c91ecdcd
No related branches found
No related tags found
No related merge requests found
...@@ -250,7 +250,7 @@ def secrets(clus, args): ...@@ -250,7 +250,7 @@ def secrets(clus, args):
:param cluster.Cluster clus: cluster to show information about :param cluster.Cluster clus: cluster to show information about
""" """
clus.load_data() clus.load_data()
clus.dump_secrets(args) clus.dump_secrets()
def create(clus, args): # pylint: disable=too-many-branches def create(clus, args): # pylint: disable=too-many-branches
...@@ -310,10 +310,13 @@ def create(clus, args): # pylint: disable=too-many-branches ...@@ -310,10 +310,13 @@ def create(clus, args): # pylint: disable=too-many-branches
elif args.droplet_id: elif args.droplet_id:
clus.set_info_by_droplet_id(args.droplet_id) clus.set_info_by_droplet_id(args.droplet_id)
elif args.ip_address: elif args.ip_address:
if not args.create_hostname: if args.create_hostname:
log.error('--create-hostname required when using --ip-address') create_hostname = args.create_hostname
sys.exit(2) else:
clus.set_info_by_ip_and_hostname(args.ip_address, args.create_hostname) log.info('No --create-hostname provided, using cluster name "%s"',
args.cluster_name)
create_hostname = args.cluster_name
clus.set_info_by_ip_and_hostname(args.ip_address, create_hostname)
elif args.droplet_hostname: elif args.droplet_hostname:
clus.set_info_by_hostname(args.droplet_hostname) clus.set_info_by_hostname(args.droplet_hostname)
......
"""Contains code for managing the files related to an OpenAppStack cluster.""" """Contains code for managing the files related to an OpenAppStack cluster."""
import base64 import base64
import configparser
import logging import logging
import os import os
import sys import sys
...@@ -162,7 +161,7 @@ CLUSTER_DIR={cluster_dir} ...@@ -162,7 +161,7 @@ CLUSTER_DIR={cluster_dir}
IP_ADDRESS={ip_address} IP_ADDRESS={ip_address}
HOSTNAME={hostname} HOSTNAME={hostname}
FQDN={domain} FQDN={domain}
KUBECONFIG={secret_dir}/kube_config_cluster.yml KUBECONFIG={cluster_dir}/kube_config_cluster.yml
""" """
with open(self.dotenv_file, 'w') as stream: with open(self.dotenv_file, 'w') as stream:
...@@ -172,7 +171,6 @@ KUBECONFIG={secret_dir}/kube_config_cluster.yml ...@@ -172,7 +171,6 @@ KUBECONFIG={secret_dir}/kube_config_cluster.yml
ip_address=self.ip_address, ip_address=self.ip_address,
hostname=self.hostname, hostname=self.hostname,
domain=self.domain, domain=self.domain,
secret_dir=self.secret_dir
)) ))
log.info("Created %s", self.dotenv_file) log.info("Created %s", self.dotenv_file)
...@@ -183,7 +181,6 @@ KUBECONFIG={secret_dir}/kube_config_cluster.yml ...@@ -183,7 +181,6 @@ KUBECONFIG={secret_dir}/kube_config_cluster.yml
def make_cluster_directories(self): def make_cluster_directories(self):
"""Make sure the cluster's file directory exists""" """Make sure the cluster's file directory exists"""
os.makedirs(self.cluster_dir, exist_ok=True) os.makedirs(self.cluster_dir, exist_ok=True)
os.makedirs(self.secret_dir, exist_ok=True)
@property @property
def inventory_file(self): def inventory_file(self):
...@@ -196,16 +193,10 @@ KUBECONFIG={secret_dir}/kube_config_cluster.yml ...@@ -196,16 +193,10 @@ KUBECONFIG={secret_dir}/kube_config_cluster.yml
return os.path.join(self.cluster_dir, '.cluster.env') return os.path.join(self.cluster_dir, '.cluster.env')
@property def dump_secrets(self):
def secret_dir(self):
"""Path where all the passwords for cluster admins are saved"""
return os.path.join(self.cluster_dir, 'secrets')
def dump_secrets(self, args):
""" """
Shows all OAS cluster secrets. Shows all OAS cluster secrets.
""" """
all_secrets = { all_secrets = {
'flux-system': { 'flux-system': {
'oas-kube-prometheus-stack-variables': ['grafana_admin_password'], 'oas-kube-prometheus-stack-variables': ['grafana_admin_password'],
...@@ -219,16 +210,16 @@ KUBECONFIG={secret_dir}/kube_config_cluster.yml ...@@ -219,16 +210,16 @@ KUBECONFIG={secret_dir}/kube_config_cluster.yml
'oas-rocketchat-variables': [ 'oas-rocketchat-variables': [
'rocketchat_admin_password', 'rocketchat_admin_password',
'mongodb_root_password', 'mongodb_root_password',
'mongodb_password' ], 'mongodb_password'],
'oas-single-sign-on-variables': [ 'oas-single-sign-on-variables': [
'userbackend_admin_username', 'userbackend_admin_username',
'userbackend_admin_password', 'userbackend_admin_password',
'userbackend_postgres_password', 'userbackend_postgres_password',
'hydra_system_secret' ], 'hydra_system_secret'],
'oas-wordpress-variables': [ 'oas-wordpress-variables': [
'wordpress_admin_password', 'wordpress_admin_password',
'wordpress_mariadb_password', 'wordpress_mariadb_password',
'wordpress_mariadb_root_password' ] 'wordpress_mariadb_root_password']
} }
} }
...@@ -239,8 +230,8 @@ KUBECONFIG={secret_dir}/kube_config_cluster.yml ...@@ -239,8 +230,8 @@ KUBECONFIG={secret_dir}/kube_config_cluster.yml
secret = self.get_password_from_kubernetes( secret = self.get_password_from_kubernetes(
app, app,
app_secret, app_secret,
namespace) 'flux-system')
print(app_secret + '=' + secret ) print(app_secret + '=' + secret)
def get_password_from_kubernetes(self, secret, key, namespace): def get_password_from_kubernetes(self, secret, key, namespace):
""" """
...@@ -252,19 +243,19 @@ KUBECONFIG={secret_dir}/kube_config_cluster.yml ...@@ -252,19 +243,19 @@ KUBECONFIG={secret_dir}/kube_config_cluster.yml
encoded password encoded password
:param string namespace: The namespace the secret is in :param string namespace: The namespace the secret is in
""" """
kubeconfig = os.path.join(self.secret_dir, 'kube_config_cluster.yml') kubeconfig = os.path.join(self.cluster_dir, 'kube_config_cluster.yml')
config.load_kube_config(config_file=kubeconfig) config.load_kube_config(config_file=kubeconfig)
api = client.CoreV1Api() api = client.CoreV1Api()
try: try:
secret_data = api.read_namespaced_secret(secret, namespace) secret_data = api.read_namespaced_secret(secret, namespace)
except client.exceptions.ApiException: except client.rest.ApiException:
print(f"Secret {secret} not found in namespace '{namespace}'") print(f"Secret {secret} not found in namespace '{namespace}'")
return "password not found" return "password not found"
try: try:
password = secret_data.data[key] password = secret_data.data[key]
except KeyError: except KeyError:
print(f"Could not get password from secret '{secret}' in namespace" print(f"Could not get password from secret '{secret}' in namespace"
" '{namespace}' with key '{key}'") " '{namespace}' with key '{key}'")
return "password not found" return "password not found"
return base64.b64decode(password).decode('utf-8') return base64.b64decode(password).decode('utf-8')
...@@ -292,11 +283,11 @@ KUBECONFIG={secret_dir}/kube_config_cluster.yml ...@@ -292,11 +283,11 @@ KUBECONFIG={secret_dir}/kube_config_cluster.yml
To use kubectl with this cluster, copy-paste this in your terminal: To use kubectl with this cluster, copy-paste this in your terminal:
export KUBECONFIG={secret_dir}/kube_config_cluster.yml""" export KUBECONFIG={cluster_dir}/kube_config_cluster.yml"""
print(info_string.format( print(info_string.format(
name=self.name, name=self.name,
ip_address=self.ip_address, ip_address=self.ip_address,
hostname=self.hostname, hostname=self.hostname,
domain=self.domain, domain=self.domain,
inventory_file=self.inventory_file, inventory_file=self.inventory_file,
secret_dir=self.secret_dir)) cluster_dir=self.cluster_dir))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment