forked from HHS/TANF-app
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added basic security to Kibana/Elastic
- Added setup container to init elastic users, roles, and passwords
- Loading branch information
Showing
6 changed files
with
426 additions
and
6 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
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
ARG ELASTIC_VERSION | ||
|
||
FROM docker.elastic.co/elasticsearch/elasticsearch:${ELASTIC_VERSION} | ||
|
||
COPY . / | ||
|
||
RUN ["chmod", "+x", "/entrypoint.sh"] | ||
RUN ["chmod", "+x", "/util.sh"] | ||
|
||
ENTRYPOINT ["/entrypoint.sh"] |
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 |
---|---|---|
@@ -0,0 +1,118 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eu | ||
set -o pipefail | ||
|
||
source "${BASH_SOURCE[0]%/*}"/util.sh | ||
|
||
sleep 10 | ||
|
||
whoami | ||
|
||
sleep 10 | ||
|
||
|
||
# -------------------------------------------------------- | ||
# Users declarations | ||
|
||
declare -A users_passwords | ||
users_passwords=( | ||
[kibana_system]="${KIBANA_SYSTEM_PASSWORD:-}" | ||
[data_analyst]="${DATA_ANALYST_PASSWORD:-}" | ||
[ofa_sys_admin]="${OFA_SYS_ADMIN_PASSWORD:-}" | ||
) | ||
|
||
declare -A users_roles | ||
users_roles=( | ||
[kibana_system]='kibana_system' | ||
[data_analyst]='editor' | ||
[ofa_sys_admin]='kibana_admin' | ||
) | ||
|
||
# -------------------------------------------------------- | ||
# Roles declarations for custom roles | ||
|
||
declare -A roles_files | ||
roles_files=( | ||
|
||
) | ||
|
||
# -------------------------------------------------------- | ||
|
||
|
||
log 'Waiting for availability of Elasticsearch. This can take several minutes.' | ||
|
||
declare -i exit_code=0 | ||
wait_for_elasticsearch || exit_code=$? | ||
|
||
if ((exit_code)); then | ||
case $exit_code in | ||
6) | ||
suberr 'Could not resolve host. Is Elasticsearch running?' | ||
;; | ||
7) | ||
suberr 'Failed to connect to host. Is Elasticsearch healthy?' | ||
;; | ||
28) | ||
suberr 'Timeout connecting to host. Is Elasticsearch healthy?' | ||
;; | ||
*) | ||
suberr "Connection to Elasticsearch failed. Exit code: ${exit_code}" | ||
;; | ||
esac | ||
|
||
exit $exit_code | ||
fi | ||
|
||
sublog 'Elasticsearch is running' | ||
|
||
log 'Waiting for initialization of built-in users' | ||
|
||
wait_for_builtin_users || exit_code=$? | ||
|
||
if ((exit_code)); then | ||
suberr 'Timed out waiting for condition' | ||
exit $exit_code | ||
fi | ||
|
||
sublog 'Built-in users were initialized' | ||
|
||
for role in "${!roles_files[@]}"; do | ||
log "Role '$role'" | ||
|
||
declare body_file | ||
body_file="${BASH_SOURCE[0]%/*}/roles/${roles_files[$role]:-}" | ||
if [[ ! -f "${body_file:-}" ]]; then | ||
sublog "No role body found at '${body_file}', skipping" | ||
continue | ||
fi | ||
|
||
sublog 'Creating/updating' | ||
ensure_role "$role" "$(<"${body_file}")" | ||
done | ||
|
||
for user in "${!users_passwords[@]}"; do | ||
log "User '$user'" | ||
if [[ -z "${users_passwords[$user]:-}" ]]; then | ||
sublog 'No password defined, skipping' | ||
continue | ||
fi | ||
|
||
declare -i user_exists=0 | ||
user_exists="$(check_user_exists "$user")" | ||
|
||
if ((user_exists)); then | ||
sublog 'User exists, setting password' | ||
set_user_password "$user" "${users_passwords[$user]}" | ||
else | ||
if [[ -z "${users_roles[$user]:-}" ]]; then | ||
suberr ' No role defined, skipping creation' | ||
continue | ||
fi | ||
|
||
sublog 'User does not exist, creating' | ||
create_user "$user" "${users_passwords[$user]}" "${users_roles[$user]}" | ||
fi | ||
done | ||
|
||
log "Elastic setup completed. Exiting with code: $?" |
Oops, something went wrong.