-
Notifications
You must be signed in to change notification settings - Fork 13
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
[Issue #2809] Handle parsing the jwt we created, and connect to a user #2959
Changes from all commits
4271713
b5e8ff4
f83f0d1
638d332
8eff255
8a38474
6be928a
6f588d0
4d2e229
ddef681
7942476
f2c0e75
970e54d
c74d1e8
9756844
f2ef7cf
3883512
1e53074
020521c
99660a8
25635ce
844b0f0
bbbb65a
6691783
09f0528
92664ed
3dc50ad
5b8dab5
f40f286
76cd414
c0e77c1
039bf15
c4631ae
da76c75
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
#!/usr/bin/env bash | ||
# setup-env-override-file.sh | ||
# | ||
# Generate an override.env file | ||
# with secrets pre-populated for local development. | ||
# | ||
# Examples: | ||
# ./setup-env-override-file.sh | ||
# ./setup-env-override-file.sh --recreate | ||
# | ||
|
||
set -o errexit -o pipefail | ||
|
||
PROGRAM_NAME=$(basename "$0") | ||
|
||
CYAN='\033[96m' | ||
GREEN='\033[92m' | ||
RED='\033[01;31m' | ||
END='\033[0m' | ||
|
||
USAGE="Usage: $PROGRAM_NAME [OPTION] | ||
|
||
--recreate Recreate the override.env file, fully overwriting any existing file | ||
" | ||
|
||
main() { | ||
print_log "Running $PROGRAM_NAME" | ||
|
||
for arg in "$@" | ||
do | ||
if [ "$arg" == "--recreate" ]; then | ||
recreate=1 | ||
else | ||
echo "$USAGE" | ||
exit 1 | ||
fi | ||
done | ||
|
||
OVERRIDE_FILE="override.env" | ||
|
||
if [ -f "$OVERRIDE_FILE" ] ; then | ||
if [ $recreate ] ; then | ||
print_log "Recreating existing override.env file" | ||
else | ||
print_log "override.env already exists, not recreating" | ||
exit 0 | ||
fi | ||
fi | ||
|
||
# Delete any key files that may be leftover from a prior run | ||
cleanup_files | ||
|
||
# Generate RSA keys | ||
# note ssh-keygen generates a different format for | ||
# the public key so we run it through openssl to fix it | ||
ssh-keygen -t rsa -b 2048 -m PEM -N '' -f tmp_jwk.key 2>&1 >/dev/null | ||
openssl rsa -in tmp_jwk.key -pubout -outform PEM -out tmp_jwk.pub | ||
|
||
PUBLIC_KEY=`cat tmp_jwk.pub` | ||
PRIVATE_KEY=`cat tmp_jwk.key` | ||
|
||
cat > $OVERRIDE_FILE <<EOF | ||
# override.env | ||
# | ||
# Any environment variables written to this file | ||
# will take precedence over those defined in local.env | ||
# | ||
# This file will not be checked into github and it is safe | ||
# to store secrets here, however you should still follow caution | ||
# with using any secrets locally if they cause the app to interact | ||
# with external systems. | ||
# | ||
# This file was generated by running: | ||
# make setup-env-override-file | ||
# | ||
# Which runs as part of our "make init" flow. | ||
# | ||
# If you would like to re-generate this file, please run: | ||
# make setup-env-override-file args="--recreate" | ||
# | ||
# Note that this will completely erase any existing configuration you may have | ||
|
||
############################ | ||
# Authentication | ||
############################ | ||
|
||
API_JWT_PRIVATE_KEY="$PRIVATE_KEY" | ||
|
||
API_JWT_PUBLIC_KEY="$PUBLIC_KEY" | ||
EOF | ||
|
||
|
||
print_log "Created new override.env" | ||
|
||
# Cleanup all keys generated in this run | ||
cleanup_files | ||
} | ||
|
||
# Cleanup a single file if it exists | ||
cleanup_file() | ||
{ | ||
FILE=$1 | ||
shift; | ||
|
||
if [ -f "$FILE" ] ; then | ||
rm "$FILE" | ||
fi | ||
} | ||
|
||
# Cleanup all miscellaneous keys generated | ||
cleanup_files() | ||
{ | ||
cleanup_file tmp_jwk.key | ||
cleanup_file tmp_jwk.pub | ||
cleanup_file tmp_jwk.key.pub | ||
} | ||
|
||
print_log() { | ||
printf "$CYAN%s $GREEN%s: $END%s\\n" "$(date "+%Y-%m-%d %H:%M:%S")" "$PROGRAM_NAME" "$*" | ||
} | ||
|
||
# Entry point | ||
main "$@" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,7 +90,11 @@ services: | |
"--reload", | ||
] | ||
container_name: grants-api | ||
env_file: ./local.env | ||
env_file: | ||
- path: ./local.env | ||
required: true | ||
- path: ./override.env | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool! It's just a list so lower ones override, nice There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, when I came across it in the docs I realized it was exactly what I'd been looking for in env var management from Docker for years |
||
required: false | ||
ports: | ||
- 8080:8080 | ||
volumes: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1423,4 +1423,8 @@ components: | |
type: apiKey | ||
in: header | ||
name: X-Auth | ||
ApiJwtAuth: | ||
type: apiKey | ||
in: header | ||
name: X-SGG-Token | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fancy docs!