Skip to content

Commit

Permalink
Check for required env variables on OIDC
Browse files Browse the repository at this point in the history
  • Loading branch information
arvchristos committed Dec 11, 2023
1 parent 526c47a commit edb3d2e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
13 changes: 4 additions & 9 deletions core/files/configure_misp.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
#!/bin/bash

source /rest_client.sh
source /utilities.sh

[ -z "$ADMIN_EMAIL" ] && ADMIN_EMAIL="admin@admin.test"
[ -z "$GPG_PASSPHRASE" ] && GPG_PASSPHRASE="passphrase"
[ -z "$REDIS_FQDN" ] && REDIS_FQDN="redis"
[ -z "$MISP_MODULES_FQDN" ] && MISP_MODULES_FQDN="http://misp-modules"
[ -z "$OIDC_PROVIDER_URL" ] && OIDC_PROVIDER_URL="test_provider"
[ -z "$OIDC_CLIENT_ID" ] && OIDC_CLIENT_ID="test_client_id"
[ -z "$OIDC_CLIENT_SECRET" ] && OIDC_CLIENT_SECRET="test_client_secret"
[ -z "$OIDC_ROLES_PROPERTY" ] && OIDC_ROLES_PROPERTY="roles"
[ -z "$OIDC_ROLES_MAPPING" ] && OIDC_ROLES_MAPPING="{
\"admin\": \"1\",
\"sync-user\": \"5\"
}"
[ -z "$OIDC_DEFAULT_ORG" ] && OIDC_DEFAULT_ORG="$ADMIN_ORG"

# Switches to selectively disable configuration logic
[ -z "$AUTOCONF_GPG" ] && AUTOCONF_GPG="true"
Expand Down Expand Up @@ -109,6 +101,9 @@ set_up_oidc() {
return
fi

# Check required variables
check_env_vars OIDC_PROVIDER_URL OIDC_CLIENT_ID OIDC_CLIENT_SECRET OIDC_ROLES_PROPERTY OIDC_ROLES_MAPPING OIDC_DEFAULT_ORG

sudo -u www-data php /var/www/MISP/tests/modify_config.php modify "{
\"Security\": {
\"auth\": [\"OidcAuth.Oidc\"]
Expand Down
18 changes: 18 additions & 0 deletions core/files/utilities.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

# Check whether passed env variables are defined
check_env_vars() {
local required_vars=("$@")

missing_vars=()
for i in "${required_vars[@]}"
do
test -n "${!i:+y}" || missing_vars+=("$i")
done
if [ ${#missing_vars[@]} -ne 0 ]
then
echo "The following env variables are not set:" >&2
printf ' %q\n' "${missing_vars[@]}" >&2
exit 1
fi
}
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ services:
- "OIDC_CLIENT_ID=${OIDC_CLIENT_ID}"
- "OIDC_CLIENT_SECRET=${OIDC_CLIENT_SECRET}"
- "OIDC_ROLES_PROPERTY=${OIDC_ROLES_PROPERTY}"
- "OIDC_ROLES_MAPPING=${OIDC_ROLES_MAPPING}"
- "OIDC_DEFAULT_ORG=${OIDC_DEFAULT_ORG}"
# sync server settings (see https://www.misp-project.org/openapi/#tag/Servers for more options)
- "SYNCSERVERS=${SYNCSERVERS}"
Expand Down
6 changes: 3 additions & 3 deletions template.env
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,6 @@ SYNCSERVERS_1_KEY=
# OIDC_PROVIDER_URL=
# OIDC_CLIENT_ID=
# OIDC_CLIENT_SECRET=
# OIDC_ROLES_PROPERTY=
# OIDC_ROLES_MAPPING=
# OIDC_DEFAULT_ORG=""
# OIDC_ROLES_PROPERTY="roles"
# OIDC_ROLES_MAPPING={"admin": "1","sync-user": "5"}
# OIDC_DEFAULT_ORG=

0 comments on commit edb3d2e

Please sign in to comment.