feat: PEP-3172 update scripts to support KAS#31
Conversation
|
Proposed script updates for KAS
# KAS defaults
KAS_ENABLED=false
KEY_ID=""
if prompt "Do you want to enable KAS [yes/no]?"; then
KAS_ENABLED=true
KAS_AUTH_ISSUER="https://login.virtru.com/oauth2/default"
KAS_AUTH_AUDIENCE="https://api.virtru.com"
KAS_URI="https://${CKS_FQDN}"
while [ -z "$KEY_ID" ]; do
read -p "Enter the Virtru SaaS DSP Key ID for this KAS deployment: " KEY_ID
if [ -z "$KEY_ID" ]; then
printf "KEY_ID is required for KAS deployments.\n"
fi
done
fi
printf "KAS_ROOT_KEY=%s\n" "$KAS_ROOT_KEY" >> ./env/cks.env
printf "KEY_ID=%s\n" "$KEY_ID" >> ./env/cks.env
printf "ORG_ID=%s\n" "$JWT_AUTH_AUDIENCE" >> ./env/cks.env
printf "PORT=9000\n" >> ./env/cks.env
EXISTING_KEY_ID=$(grep '^KEY_ID=' "$WORKING_DIR"/env/cks.env 2>/dev/null | cut -d "=" -f2-)
if [ -z "$EXISTING_KEY_ID" ]; then
KEY_ID=""
while [ -z "$KEY_ID" ]; do
read -p "Enter the Virtru SaaS DSP Key ID for this KAS deployment: " KEY_ID
if [ -z "$KEY_ID" ]; then
printf "KEY_ID is required for KAS deployments.\n"
fi
done
else
KEY_ID="$EXISTING_KEY_ID"
fi
updateEnvVariable "KAS_ROOT_KEY" "$KAS_ROOT_KEY"
updateEnvVariable "KEY_ID" "$KEY_ID"
updateEnvVariable "ORG_ID" "$EXISTING_ORG_ID"
updateEnvVariable "PORT" "9000"Rationale: |
- setup-cks-latest.sh: hoist KEY_ID="" to the KAS defaults block; clarify the prompt to "Virtru SaaS DSP Key ID for this KAS deployment" and emit an explicit "KEY_ID is required" message inside the input loop. - setup-cks-latest.sh: write PORT=9000 to cks.env instead of PORT=3000 so the on-prem env file mirrors the Helm chart's configmap. (supervisord pins CKS Node to 3000 internally regardless; this just keeps the two config surfaces aligned.) - update.sh: refactor KEY_ID handling to read EXISTING_KEY_ID first and fall back to the same required-prompt; write via updateEnvVariable so reruns are idempotent. - update.sh: PORT=9000 for the same alignment rationale. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This reverts commit 2b3f3bf.
There was a problem hiding this comment.
Pull request overview
This PR updates the CKS setup/update scripts to support optionally enabling Key Access Service (KAS) for DSP integration, and aligns the generated runtime configuration with the new container/image/port assumptions (Caddy on 9000, supervisord-managed processes).
Changes:
- Add KAS enablement flow (new prompts + environment variables) to both initial setup and updates.
- Update image/tag validation and generated
run.shcommands to usecontainers.virtru.com/cks:v{VERSION}and fixed port behavior. - Expand README documentation with KAS enablement guidance and architecture/troubleshooting details.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| update.sh | Adds KAS migration/enablement during update, switches image validation and generated run.sh to the new registry/image and port model. |
| setup-cks-latest.sh | Adds KAS enablement during initial setup, writes KAS env vars, and updates generated run.sh and PORT handling. |
| README.md | Documents KAS support, enablement steps, and architecture/troubleshooting. |
Comments suppressed due to low confidence (1)
update.sh:63
STATUSis parsed as a number and then compared with-ne, but ifcurlfails (network error, DNS, TLS, etc.)STATUScan be empty, causing[ $STATUS -ne 200 ]to emit "unary operator expected" and the script may continue as if the version is valid. Consider using a string comparison (e.g.,!= "200") and explicitly handling an empty/failed response as invalid (or exiting with a clearer error).
STATUS=$(curl -sI https://containers.virtru.com/v2/cks/manifests/"v$CKS_VERSION" | head -n 1 | cut -d$' ' -f2)
if [ $STATUS -ne 200 ]; then
echo "Invalid CKS Version"
exit
fi
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # Get existing Org ID from JWT_AUTH_AUDIENCE | ||
| EXISTING_ORG_ID=$(cat "$WORKING_DIR"/env/cks.env | grep JWT_AUTH_AUDIENCE | cut -d "=" -f2) | ||
|
|
||
| # Add KAS environment variables | ||
| updateEnvVariable "KAS_ROOT_KEY" "$KAS_ROOT_KEY" | ||
| updateEnvVariable "ORG_ID" "$EXISTING_ORG_ID" | ||
| updateEnvVariable "KAS_AUTH_ISSUER" "$KAS_AUTH_ISSUER" | ||
| updateEnvVariable "KAS_AUTH_AUDIENCE" "$KAS_AUTH_AUDIENCE" | ||
| updateEnvVariable "KAS_URI" "$KAS_URI" |
| # Ensure KAS deployments have a KEY_ID set in cks.env. | ||
| # Preserve the existing value when present (covers KAS deployments that were | ||
| # already provisioned); otherwise prompt the operator for the SaaS-provisioned | ||
| # Key ID. Anchored grep avoids a false match on WRAPPING_KEY_ID. | ||
| if [ "$KAS_ENABLED" = true ]; then | ||
| EXISTING_KEY_ID=$(grep '^KEY_ID=' "$WORKING_DIR"/env/cks.env 2>/dev/null | cut -d "=" -f2-) | ||
|
|
||
| if [ -z "$EXISTING_KEY_ID" ]; then | ||
| KEY_ID="" | ||
| while [ -z "$KEY_ID" ]; do | ||
| read -p "Enter the Virtru SaaS DSP Key ID for this KAS deployment: " KEY_ID | ||
|
|
||
| if [ -z "$KEY_ID" ]; then | ||
| printf "KEY_ID is required for KAS deployments.\n" | ||
| fi | ||
| done | ||
| else | ||
| KEY_ID="$EXISTING_KEY_ID" | ||
| fi | ||
|
|
||
| updateEnvVariable "KEY_ID" "$KEY_ID" | ||
| fi |
| # Generate Docker run command (always uses port 9000 via Caddy, no "serve" arg) | ||
| DOCKER_IMAGE="containers.virtru.com/cks:v$CKS_VERSION" | ||
| CONTAINER_NAME="Virtru_CKS" | ||
| OLD_CONTAINER_NAME="Virtru_CKS" |
| echo "docker run --name $CONTAINER_NAME --interactive --tty --detach --restart unless-stopped --env-file "$WORKING_DIR"/env/cks.env -p 443:$EXTERNAL_PORT --mount type=bind,source="$WORKING_DIR"/keys,target="$KEY_PROVIDER_PATH" --mount type=bind,source="$WORKING_DIR"/ssl,target=/app/ssl --mount type=bind,source="$WORKING_DIR"/hsm-config/customerCA.crt,target=/opt/cloudhsm/etc/customerCA.crt $DOCKER_IMAGE" > "$WORKING_DIR/run.sh" | ||
| else | ||
| echo "docker run --name $CONTAINER_NAME --interactive --tty --detach --restart unless-stopped --env-file "$WORKING_DIR"/env/cks.env -p 443:$EXTERNAL_PORT --mount type=bind,source="$WORKING_DIR"/keys,target="$KEY_PROVIDER_PATH" --mount type=bind,source="$WORKING_DIR"/ssl,target=/app/ssl $DOCKER_IMAGE" > "$WORKING_DIR/run.sh" | ||
| fi | ||
|
|
| printf "PORT=%s\n" $PORT >> ./env/cks.env | ||
| # Caddy fronts traffic on 9000; supervisord pins CKS Node to 3000 internally. | ||
| # PORT here mirrors the chart's configmap value so cks.env stays aligned. | ||
| printf "PORT=9000\n" >> ./env/cks.env |
| chmod +x ./run.sh | ||
|
|
||
| # Generate run.sh (always uses port 9000 via Caddy, no "serve" arg - supervisord manages processes) | ||
| echo "docker run --name Virtru_CKS --interactive --tty --detach --restart unless-stopped --env-file "$WORKING_DIR"/env/cks.env -p 443:9000 --mount type=bind,source="$WORKING_DIR"/keys,target="$KEY_PROVIDER_PATH" --mount type=bind,source="$WORKING_DIR"/ssl,target=/app/ssl containers.virtru.com/cks:v"$CKS_VERSION"" > ./run.sh |
| Answer **yes** to enable KAS. The setup will automatically configure KAS with standard settings: | ||
| - OAuth Issuer: `https://login.virtru.com/oauth2/default` | ||
| - OAuth Audience: `https://api.virtru.com` | ||
| - KAS URI: Same as your CKS URL (derived from SSL certificate) | ||
|
|
No description provided.