forked from PelicanPlatform/pelican
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add the ability to proxy prometheus requests to an active service for real data - Works by running a cron to get a new jwt and add it to the proxy auth headers every 30 minutes
- Loading branch information
1 parent
836f84f
commit bb08cf9
Showing
8 changed files
with
122 additions
and
4 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,2 @@ | ||
API_URL=https://origin.test.org | ||
API_PASSWORD=password |
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,28 @@ | ||
FROM nginx:1.27 | ||
|
||
ENV NGINX_ENVSUBST_OUTPUT_DIR=/etc/nginx | ||
|
||
# Set some default environment variables so we can check them later | ||
ENV API_URL=https://host.docker.internal:8444 | ||
|
||
# Install cron | ||
RUN apt-get update && apt-get install -y cron | ||
|
||
# Update the entrypoint | ||
COPY ./entrypoint.sh /opt/bin/entrypoint.sh | ||
RUN chmod +x /opt/bin/entrypoint.sh | ||
ENTRYPOINT ["/opt/bin/entrypoint.sh"] | ||
|
||
# Copy the NGINX configuration file | ||
COPY ./nginx.conf /etc/nginx/templates/nginx.conf.template | ||
|
||
# Copy the login script | ||
COPY ./login.sh /opt/bin/login.sh | ||
RUN chmod +x /opt/bin/login.sh | ||
|
||
# Copy the crontab file and set up cron job | ||
COPY ./crontab /etc/cron.d/login_cron | ||
RUN chmod 0644 /etc/cron.d/login_cron | ||
RUN crontab /etc/cron.d/login_cron | ||
|
||
CMD ["nginx", "-g", "daemon off;"] |
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 @@ | ||
*/28 * * * * /opt/bin/login.sh > /proc/1/fd/1 |
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,17 @@ | ||
#!/bin/bash | ||
|
||
# Append environment variables to /etc/environment, excluding "no_proxy" | ||
echo "Appending environment variables to /etc/environment" | ||
printenv | grep -v "no_proxy" >> /etc/environment | ||
|
||
# Run the login script | ||
echo "Running login script" | ||
/opt/bin/login.sh | ||
|
||
# Start cron | ||
echo "Starting cron" | ||
cron | ||
|
||
# Run the original Docker entrypoint script with any passed arguments | ||
echo "Running original Docker entrypoint script with arguments: $@" | ||
/docker-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,26 @@ | ||
#!/bin/bash | ||
|
||
# Check if API_PASSWORD and API_URL are set in env | ||
if [ -z "$API_PASSWORD" ] || [ -z "$API_URL" ]; then | ||
echo "API_PASSWORD or API_URL not set. Skipping login." | ||
exit 0 | ||
fi | ||
|
||
# Prepend /api/v1.0/auth/login to the API_URL | ||
LOGIN_URL="${API_URL%/}/api/v1.0/auth/login" | ||
|
||
# Login and store the cookie | ||
curl -s -c /etc/nginx/conf.d/login_cookie.txt -X POST -H "Content-Type: application/json" -d "{\"user\": \"admin\", \"password\": \"$API_PASSWORD\"}" "$LOGIN_URL" | ||
|
||
# Extract the JWT from the cookie file | ||
jwt=$(grep 'login' /etc/nginx/conf.d/login_cookie.txt | awk '{print $7}') | ||
|
||
# Create a file with the Authorization header | ||
echo "proxy_set_header Authorization \"Bearer $jwt\";" > /etc/nginx/conf.d/login_header.txt | ||
|
||
# Reload Nginx to apply the new configuration if process exists | ||
if [ -e /var/run/nginx.pid ]; then | ||
nginx -s reload | ||
fi | ||
|
||
echo "\n Successfully Updated the Authorization Header" |
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 was deleted.
Oops, something went wrong.