Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 3 additions & 8 deletions logging/bin/deploy_logging_azmonitor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@
# Copyright © 2020, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

cd "$(dirname $BASH_SOURCE)/../.."
cd "$(dirname "$BASH_SOURCE")/../.." || exit 1
source logging/bin/common.sh

# temp file used to capture command output
tmpfile=$TMP_DIR/output.txt
rm -f tmpfile

if [ "$(kubectl get ns $LOG_NS -o name 2>/dev/null)" == "" ]; then
kubectl create ns $LOG_NS
if [ "$(kubectl get ns "$LOG_NS" -o name 2> /dev/null)" == "" ]; then
kubectl create ns "$LOG_NS"
fi

set -e
Expand All @@ -25,6 +21,5 @@ log_notice "Deploying logging components to the [$LOG_NS] namespace [$(date)]"
log_info "STEP 1: Deploying Fluent Bit"
logging/bin/deploy_fluentbit_azmonitor.sh


log_notice "The deployment of logging components has completed [$(date)]"
echo ""
20 changes: 10 additions & 10 deletions logging/bin/deploy_servicemonitors_openshift.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,37 @@
# Copyright © 2021, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

cd "$(dirname $BASH_SOURCE)/../.."
cd "$(dirname "$BASH_SOURCE")/../.." || exit
source logging/bin/common.sh

this_script=`basename "$0"`
this_script=$(basename "$0")

log_debug "Script [$this_script] has started [$(date)]"

# Deploy ServiceMonitors?
DEPLOY_SERVICEMONITORS=${DEPLOY_SERVICEMONITORS:-false}

if [ "$DEPLOY_SERVICEMONITORS" != "true" ]; then
log_info "Environment variable [DEPLOY_SERVICEMONITORS] is not set to 'true'; exiting WITHOUT deploying ServiceMonitors"
exit
log_info "Environment variable [DEPLOY_SERVICEMONITORS] is not set to 'true'; exiting WITHOUT deploying ServiceMonitors"
exit
fi

EVENTROUTER_ENABLE=${EVENTROUTER_ENABLE:-true}
if [ "$EVENTROUTER_ENABLE" == "true" ]; then
# Eventrouter ServiceMonitor
kubectl apply -n $LOG_NS -f monitoring/monitors/kube/podMonitor-eventrouter.yaml
# Eventrouter ServiceMonitor
kubectl apply -n "$LOG_NS" -f monitoring/monitors/kube/podMonitor-eventrouter.yaml
fi

ELASTICSEARCH_ENABLE=${ELASTICSEARCH_ENABLE:-true}
if [ "$ELASTICSEARCH_ENABLE" == "true" ]; then
# Elasticsearch ServiceMonitor
kubectl apply -n $LOG_NS -f monitoring/monitors/logging/serviceMonitor-elasticsearch.yaml
# Elasticsearch ServiceMonitor
kubectl apply -n "$LOG_NS" -f monitoring/monitors/logging/serviceMonitor-elasticsearch.yaml
fi

FLUENT_BIT_ENABLED=${FLUENT_BIT_ENABLED:-true}
if [ "$FLUENT_BIT_ENABLED" == "true" ]; then
# Fluent Bit ServiceMonitors
kubectl apply -n $LOG_NS -f monitoring/monitors/logging/serviceMonitor-fluent-bit-v2.yaml
# Fluent Bit ServiceMonitors
kubectl apply -n "$LOG_NS" -f monitoring/monitors/logging/serviceMonitor-fluent-bit-v2.yaml
fi

log_info "ServiceMonitors have been deployed."
Expand Down
177 changes: 87 additions & 90 deletions logging/bin/offboard.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,82 +3,78 @@
# Copyright © 2021, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

cd "$(dirname $BASH_SOURCE)/../.."
cd "$(dirname "$BASH_SOURCE")/../.." || exit
source logging/bin/common.sh

source logging/bin/apiaccess-include.sh
source logging/bin/secrets-include.sh
source logging/bin/rbac-include.sh

this_script=`basename "$0"`

this_script=$(basename "$0")

function show_usage {
log_message "Usage: $this_script --namespace NAMESPACE [--tenant TENANT] [OPTIONS]"
log_message ""
log_message "'Offboards' either the specified SAS Viya deployment (namespace) or the specified tenant within that deployment. This removes the ability to limit admins to the SAS Viya deployment (or a single tenant within a given deployment)."
log_message "The offboarding process deletes the security access controls and the associated OpenSearch Dashboards tenant space (including any saved OpenSearch Dashboards content (e.g. visualizations, dashboards, etc.)."
log_message ""
log_message " Arguments:"
log_message " -ns, --namespace NAMESPACE - (Required) The SAS Viya deployment/Kubernetes Namespace to which access should be removed."
log_message " -t, --tenant TENANT - (Optional) The tenant within the specific SAS Viya deployment/Kubernetes Namespace to which access should be removed."
log_message ""
#log_message " Options:"
#log_message ""
log_message "Usage: $this_script --namespace NAMESPACE [--tenant TENANT] [OPTIONS]"
log_message ""
log_message "'Offboards' either the specified SAS Viya deployment (namespace) or the specified tenant within that deployment. This removes the ability to limit admins to the SAS Viya deployment (or a single tenant within a given deployment)."
log_message "The offboarding process deletes the security access controls and the associated OpenSearch Dashboards tenant space (including any saved OpenSearch Dashboards content (e.g. visualizations, dashboards, etc.)."
log_message ""
log_message " Arguments:"
log_message " -ns, --namespace NAMESPACE - (Required) The SAS Viya deployment/Kubernetes Namespace to which access should be removed."
log_message " -t, --tenant TENANT - (Optional) The tenant within the specific SAS Viya deployment/Kubernetes Namespace to which access should be removed."
log_message ""
#log_message " Options:"
#log_message ""
}


# set flag indicating wrapper/driver script being run
export LOGGING_DRIVER=true


#
#Handle arguments and parameters
#
POS_PARMS=""

while (( "$#" )); do
case "$1" in
-ns|--namespace)
if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
namespace=$2
shift 2
else
log_error "A value for parameter [NAMESPACE] has not been provided." >&2
while (("$#")); do
case "$1" in
-ns | --namespace)
if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then
namespace=$2
shift 2
else
log_error "A value for parameter [NAMESPACE] has not been provided." >&2
show_usage
exit 2
fi
;;
-t | --tenant)
if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then
tenant=$2
shift 2
else
log_error "A value for parameter [TENANT] has not been provided." >&2
show_usage
exit 2
fi
;;
-h | --help)
show_usage
exit 2
fi
;;
-t|--tenant)
if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
tenant=$2
shift 2
else
log_error "A value for parameter [TENANT] has not been provided." >&2
exit
;;
--*= | -*) # unsupported flags
log_error "Unsupported flag $1" >&2
show_usage
exit 2
fi
;;
-h|--help)
show_usage
exit
;;
-*|--*=) # unsupported flags
log_error "Unsupported flag $1" >&2
show_usage
exit 1
;;
exit 1
;;
*) # preserve positional arguments
POS_PARMS="$POS_PARMS $1"
shift
;;
esac
POS_PARMS="$POS_PARMS $1"
shift
;;
esac
done

# set positional arguments in their proper place
eval set -- "$POS_PARMS"


# No positional parameters are supported
if [ "$#" -ge 1 ]; then
log_error "Unexpected additional arguments were found; exiting."
Expand All @@ -87,36 +83,38 @@ if [ "$#" -ge 1 ]; then
fi

# Convert namespace and tenant to all lower-case
namespace=$(echo "$namespace"| tr '[:upper:]' '[:lower:]')
tenant=$(echo "$tenant"| tr '[:upper:]' '[:lower:]')
namespace=$(echo "$namespace" | tr '[:upper:]' '[:lower:]')
tenant=$(echo "$tenant" | tr '[:upper:]' '[:lower:]')

# validation of input args
if [ "$namespace" == "global" ]; then
log_error "Invalid namespace value specified; you can NOT offboard the [global] namespace."
exit 1
log_error "Invalid namespace value specified; you can NOT offboard the [global] namespace."
exit 1
fi

validateNamespace $namespace
validateNamespace "$namespace"

if [ -n "$tenant" ]; then
validateTenantID $tenant
validateTenantID "$tenant"

nst="${namespace}_${tenant}"
index_nst="${namespace}-__${tenant}__"
nst="${namespace}_${tenant}"
index_nst="${namespace}-__${tenant}__"
else
nst="$namespace"
index_nst="${namespace}"
nst="$namespace"
# shellcheck disable=SC2034
index_nst="${namespace}"
fi

# OpenSearch Dashboards tenant space
ktenant=$nst

if [ -n "$tenant" ]; then
tenant_description="An OpenSearch Dashboards tenant space for tenant [$tenant] within SAS Viya deployment (namespace) [$namespace]."
log_notice "Offboarding tenant [$tenant] within namespace [$namespace] [$(date)]"
tenant_description="An OpenSearch Dashboards tenant space for tenant [$tenant] within SAS Viya deployment (namespace) [$namespace]."
log_notice "Offboarding tenant [$tenant] within namespace [$namespace] [$(date)]"
else
tenant_description="An OpenSearch Dashboards tenant space for SAS Viya deployment (namespace) [$namespace]."
log_notice "Offboarding namespace [$namespace] [$(date)]"
# shellcheck disable=SC2034
tenant_description="An OpenSearch Dashboards tenant space for SAS Viya deployment (namespace) [$namespace]."
log_notice "Offboarding namespace [$namespace] [$(date)]"
fi

#
Expand All @@ -134,53 +132,52 @@ get_sec_api_url

# Delete OpenSearch Dashboards tenant space (if it exists)
if kibana_tenant_exists "$ktenant"; then
delete_kibana_tenant "$ktenant"
rc=$?
if [ "$rc" == "0" ]; then
add_notice " "
add_notice " The OpenSearch Dashboards tenant space [$ktenant] has been deleted. "
add_notice " "
else
log_error "Problems were encountered while attempting to delete tenant space [$ktenant]."
exit 1
fi
delete_kibana_tenant "$ktenant"
rc=$?
if [ "$rc" == "0" ]; then
add_notice " "
add_notice " The OpenSearch Dashboards tenant space [$ktenant] has been deleted. "
add_notice " "
else
log_error "Problems were encountered while attempting to delete tenant space [$ktenant]."
exit 1
fi
else
log_warn "The OpenSearch Dashboards tenant space [$ktenant] does not exist and, therefore, could not be deleted."
log_warn "The OpenSearch Dashboards tenant space [$ktenant] does not exist and, therefore, could not be deleted."
fi

# Delete ES index containing tenant content
kibana_index_name=".kibana_*_$(echo "$ktenant"|tr -d _)"
response=$(curl -s -o /dev/null -w "%{http_code}" -XDELETE "${es_api_url}/$kibana_index_name" --user $ES_ADMIN_USER:$ES_ADMIN_PASSWD --insecure)
kibana_index_name=".kibana_*_$(echo "$ktenant" | tr -d _)"
response=$(curl -s -o /dev/null -w "%{http_code}" -XDELETE "${es_api_url}/$kibana_index_name" --user "$ES_ADMIN_USER":"$ES_ADMIN_PASSWD" --insecure)
if [[ $response == 2* ]]; then
log_info "Deleted index [$kibana_index_name]. [$response]"
log_info "Deleted index [$kibana_index_name]. [$response]"
else
log_warn "There was an issue deleting the index [$kibana_index_name] holding content related to OpenSearch Dashboards tenant space [$ktenant]. You may need to manually delete this index. [$response]"
log_warn "There was an issue deleting the index [$kibana_index_name] holding content related to OpenSearch Dashboards tenant space [$ktenant]. You may need to manually delete this index. [$response]"
fi

response=$(curl -s -o /dev/null -w "%{http_code}" -XDELETE "${es_api_url}/${kibana_index_name}_*" --user $ES_ADMIN_USER:$ES_ADMIN_PASSWD --insecure)
response=$(curl -s -o /dev/null -w "%{http_code}" -XDELETE "${es_api_url}/${kibana_index_name}_*" --user "$ES_ADMIN_USER":"$ES_ADMIN_PASSWD" --insecure)
if [[ $response == 2* ]]; then
log_info "Deleted index [${kibana_index_name}_*]. [$response]"
log_info "Deleted index [${kibana_index_name}_*]. [$response]"
else
log_warn "There was an issue deleting the index [${kibana_index_name}_*] holding content related to OpenSearch Dashboards tenant space [$ktenant]. You may need to manually delete this index. [$response]"
log_warn "There was an issue deleting the index [${kibana_index_name}_*] holding content related to OpenSearch Dashboards tenant space [$ktenant]. You may need to manually delete this index. [$response]"
fi


# Delete access controls
./logging/bin/security_delete_rbac.sh $namespace $tenant
./logging/bin/security_delete_rbac.sh "$namespace" "$tenant"

# Delete Grafana Datasource utility user (if exists)
grfds_user="${nst}_grafana_ds"
if user_exists $grfds_user; then
log_verbose "Removing the [$grfds_user] utility account."
delete_user $grfds_user
if user_exists "$grfds_user"; then
log_verbose "Removing the [$grfds_user] utility account."
delete_user "$grfds_user"
fi

# Reminder that users are not deleted
add_notice " "
add_notice " The off-boarding process does NOT remove any users. If there "
add_notice " are users which are no longer needed after off-boarding the "
if [ -n "$tenant" ]; then
add_notice " tenant [$tenant] within the "
add_notice " tenant [$tenant] within the "
fi
add_notice " SAS Viya deployment/namespace of [$namespace] "
add_notice " you must delete those users manually, either through the "
Expand All @@ -197,7 +194,7 @@ echo ""

# Exit with an overall success/failure message
if [ -n "$tenant" ]; then
log_notice "Successfully offboarded tenant [$tenant] within namespace [$namespace] [$(date)]"
log_notice "Successfully offboarded tenant [$tenant] within namespace [$namespace] [$(date)]"
else
log_notice "Successfully offboarded namespace [$namespace] [$(date)]"
log_notice "Successfully offboarded namespace [$namespace] [$(date)]"
fi
Loading