feat: update entrypoint to autogenerate SAML certificate and private key
Signed-off-by: Thomas Stocker <thomas.stocker.pro@gmail.com>
This commit is contained in:
committed by
Bryan Frimin
parent
53965631c8
commit
9adc975369
@@ -129,11 +129,11 @@ This document provides a comprehensive reference for all environment variables u
|
|||||||
## SAML Authentication
|
## SAML Authentication
|
||||||
|
|
||||||
| Variable | Description | Default Value | Required |
|
| Variable | Description | Default Value | Required |
|
||||||
| ------------------------------- | ----------------------------------------------------------------- | ----------------------- | -------- |
|
| ------------------------------- | ----------------------------------------------------------------- |------------------| -------- |
|
||||||
| `SAML_SESSION_DURATION` | SAML session validity duration in seconds | `604800` (7 days) | No |
|
| `SAML_SESSION_DURATION` | SAML session validity duration in seconds | `604800` (7 days) | No |
|
||||||
| `SAML_CLEANUP_INTERVAL_SECONDS` | Interval in seconds for cleaning up expired SAML sessions (0=off) | `0` (disabled) | No |
|
| `SAML_CLEANUP_INTERVAL_SECONDS` | Interval in seconds for cleaning up expired SAML sessions (0=off) | `0` (disabled) | No |
|
||||||
| `SAML_CERTIFICATE` | SAML service provider certificate in PEM format | - | No |
|
| `SAML_CERTIFICATE` | SAML service provider certificate in PEM format | `autogenerated` | No |
|
||||||
| `SAML_PRIVATE_KEY` | SAML service provider private key in PEM format | - | No |
|
| `SAML_PRIVATE_KEY` | SAML service provider private key in PEM format | `autogenerated` | No |
|
||||||
|
|
||||||
## Custom Domains
|
## Custom Domains
|
||||||
|
|
||||||
|
|||||||
@@ -4,12 +4,38 @@ set -e
|
|||||||
# Configuration file path
|
# Configuration file path
|
||||||
CONFIG_FILE="${CONFIG_FILE:-/etc/probod/config.yml}"
|
CONFIG_FILE="${CONFIG_FILE:-/etc/probod/config.yml}"
|
||||||
|
|
||||||
|
# Function to generate default SAML certificate and private key if not provided
|
||||||
|
generate_saml_defaults() {
|
||||||
|
if [ -z "$SAML_CERTIFICATE" ] || [ -z "$SAML_PRIVATE_KEY" ]; then
|
||||||
|
echo "Generating default SAML certificate and private key..."
|
||||||
|
|
||||||
|
# Generate private key and certificate valid for 10 years
|
||||||
|
TEMP_KEY=$(mktemp)
|
||||||
|
TEMP_CERT=$(mktemp)
|
||||||
|
|
||||||
|
openssl req -x509 -newkey rsa:2048 -keyout "$TEMP_KEY" -out "$TEMP_CERT" \
|
||||||
|
-days 3650 -nodes -subj "/CN=probo-saml/O=Probo/C=US" 2>/dev/null
|
||||||
|
|
||||||
|
# Read generated files and export as environment variables
|
||||||
|
export SAML_PRIVATE_KEY=$(cat "$TEMP_KEY")
|
||||||
|
export SAML_CERTIFICATE=$(cat "$TEMP_CERT")
|
||||||
|
|
||||||
|
# Clean up temporary files
|
||||||
|
rm -f "$TEMP_KEY" "$TEMP_CERT"
|
||||||
|
|
||||||
|
echo "Default SAML certificate and private key generated successfully"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Check if config file already exists (e.g., mounted from ConfigMap)
|
# Check if config file already exists (e.g., mounted from ConfigMap)
|
||||||
if [ -f "$CONFIG_FILE" ]; then
|
if [ -f "$CONFIG_FILE" ]; then
|
||||||
echo "Using existing configuration file at: $CONFIG_FILE"
|
echo "Using existing configuration file at: $CONFIG_FILE"
|
||||||
else
|
else
|
||||||
echo "Generating configuration file from environment variables at: $CONFIG_FILE"
|
echo "Generating configuration file from environment variables at: $CONFIG_FILE"
|
||||||
|
|
||||||
|
# Generate default SAML credentials if not provided
|
||||||
|
generate_saml_defaults
|
||||||
|
|
||||||
# Create directory if it doesn't exist
|
# Create directory if it doesn't exist
|
||||||
mkdir -p "$(dirname "$CONFIG_FILE")"
|
mkdir -p "$(dirname "$CONFIG_FILE")"
|
||||||
|
|
||||||
@@ -121,7 +147,6 @@ EOF
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Add SAML config if any SAML variable is configured
|
# Add SAML config if any SAML variable is configured
|
||||||
if [ -n "$SAML_SESSION_DURATION" ] || [ -n "$SAML_CLEANUP_INTERVAL_SECONDS" ] || [ -n "$SAML_CERTIFICATE" ] || [ -n "$SAML_PRIVATE_KEY" ]; then
|
|
||||||
cat >> "$CONFIG_FILE" <<EOF
|
cat >> "$CONFIG_FILE" <<EOF
|
||||||
|
|
||||||
saml:
|
saml:
|
||||||
@@ -132,7 +157,6 @@ $(echo "${SAML_CERTIFICATE:-}" | sed 's/^/ /')
|
|||||||
private-key: |
|
private-key: |
|
||||||
$(echo "${SAML_PRIVATE_KEY:-}" | sed 's/^/ /')
|
$(echo "${SAML_PRIVATE_KEY:-}" | sed 's/^/ /')
|
||||||
EOF
|
EOF
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Configuration file generated at: $CONFIG_FILE"
|
echo "Configuration file generated at: $CONFIG_FILE"
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user