Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass OIDC config from .env to Backend and Frontend #458

Merged
merged 10 commits into from
Sep 1, 2023
6 changes: 6 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ HTTPS_PORT=443
# EMAIL_USER=
# EMAIL_PASSWORD=

# Optional: configure Single Sign-on with OpenID Connect
# OIDC_ENABLED=
matthew-white marked this conversation as resolved.
Show resolved Hide resolved
# OIDC_DISCOVERY_URL=
# OIDC_CLIENT_ID=
# OIDC_CLIENT_SECRET=

# Optional: configure error reporting
# SENTRY_ORG_SUBDOMAIN=
# SENTRY_KEY=
Expand Down
5 changes: 5 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ services:
- EMAIL_IGNORE_TLS=${EMAIL_IGNORE_TLS:-true}
- EMAIL_USER=${EMAIL_USER:-''}
- EMAIL_PASSWORD=${EMAIL_PASSWORD:-''}
- OIDC_ENABLED=${OIDC_ENABLED:-false}
- OIDC_DISCOVERY_URL=${OIDC_DISCOVERY_URL:-''}
- OIDC_CLIENT_ID=${OIDC_CLIENT_ID:-''}
- OIDC_CLIENT_SECRET=${OIDC_CLIENT_SECRET:-''}
- SENTRY_ORG_SUBDOMAIN=${SENTRY_ORG_SUBDOMAIN:-o130137}
- SENTRY_KEY=${SENTRY_KEY:-3cf75f54983e473da6bd07daddf0d2ee}
- SENTRY_PROJECT=${SENTRY_PROJECT:-1298632}
Expand All @@ -85,6 +89,7 @@ services:
- SENTRY_ORG_SUBDOMAIN=${SENTRY_ORG_SUBDOMAIN:-o130137}
- SENTRY_KEY=${SENTRY_KEY:-3cf75f54983e473da6bd07daddf0d2ee}
- SENTRY_PROJECT=${SENTRY_PROJECT:-1298632}
- OIDC_ENABLED=${OIDC_ENABLED:-false}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Vue build has access to environment variables via process.env, so I'm thinking that we can set oidcEnabled to process.env.OIDC_ENABLED in src/config.js. I don't remember the details of that mechanism (I'll look more into it later this week), I think we may need to add a Vue-specific prefix to the name of the environment variable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked, and it looks like the build mostly just has access to environment variables prefixed with VUE_APP_: https://cli.vuejs.org/guide/mode-and-env.html#environment-variables. I think I'm going to keep it named OIDC_ENABLED in docker-compose.yml, then add the prefix just when calling npm run build. It looks like the VUE_APP_ prefix may need to change to VITE_ once we move to Vite (getodk/central-frontend#671).

Also, I'm not sure, but for nginx, I think OIDC_ENABLED needs to be specified in docker-compose.yml under build.args rather than environment in order for it to make its way to build-frontend.sh. The variable journeys through a couple of layers before eventually reaching npm build.

ports:
- "${HTTP_PORT:-80}:80"
- "${HTTPS_PORT:-443}:443"
Expand Down
6 changes: 6 additions & 0 deletions files/service/config.json.template
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
"domain": "${BASE_URL}",
"sysadminAccount": "${SYSADMIN_EMAIL}"
},
"oidc": {
"enabled": ${OIDC_ENABLED},
"discoveryUrl": "${OIDC_DISCOVERY_URL}",
"clientId": "${OIDC_CLIENT_ID}",
"clientSecret": "${OIDC_CLIENT_SECRET}"
matthew-white marked this conversation as resolved.
Show resolved Hide resolved
},
"external": {
"sentry": {
"orgSubdomain": "${SENTRY_ORG_SUBDOMAIN}",
Expand Down
2 changes: 1 addition & 1 deletion files/service/scripts/start-odk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ echo "generating local service configuration.."

ENKETO_API_KEY=$(cat /etc/secrets/enketo-api-key) \
BASE_URL=$( [ "${HTTPS_PORT}" = 443 ] && echo https://"${DOMAIN}" || echo https://"${DOMAIN}":"${HTTPS_PORT}" ) \
envsubst '$DOMAIN $BASE_URL $SYSADMIN_EMAIL $ENKETO_API_KEY $DB_HOST $DB_USER $DB_PASSWORD $DB_NAME $DB_SSL $EMAIL_FROM $EMAIL_HOST $EMAIL_PORT $EMAIL_SECURE $EMAIL_IGNORE_TLS $EMAIL_USER $EMAIL_PASSWORD $SENTRY_ORG_SUBDOMAIN $SENTRY_KEY $SENTRY_PROJECT' \
envsubst '$DOMAIN $BASE_URL $SYSADMIN_EMAIL $ENKETO_API_KEY $DB_HOST $DB_USER $DB_PASSWORD $DB_NAME $DB_SSL $EMAIL_FROM $EMAIL_HOST $EMAIL_PORT $EMAIL_SECURE $EMAIL_IGNORE_TLS $EMAIL_USER $EMAIL_PASSWORD $OIDC_ENABLED $OIDC_DISCOVERY_URL $OIDC_CLIENT_ID $OIDC_CLIENT_SECRET $SENTRY_ORG_SUBDOMAIN $SENTRY_KEY $SENTRY_PROJECT' \
< /usr/share/odk/config.json.template \
> /usr/odk/config/local.json

Expand Down