Skip to content

feat: PEP-3172 update scripts to support KAS#31

Open
dillonthompson wants to merge 13 commits into
mainfrom
feature/PEP-3172-support-kas
Open

feat: PEP-3172 update scripts to support KAS#31
dillonthompson wants to merge 13 commits into
mainfrom
feature/PEP-3172-support-kas

Conversation

@dillonthompson
Copy link
Copy Markdown

No description provided.

@dillonthompson dillonthompson marked this pull request as draft March 10, 2026 18:09
@dillonthompson dillonthompson marked this pull request as ready for review March 20, 2026 20:20
@nwilliamsgit
Copy link
Copy Markdown
Contributor

nwilliamsgit commented May 6, 2026

Proposed script updates for KAS KEY_ID support, let me know your thoughts

  1. In setup-cks-latest.sh, add a default KEY_ID variable near the KAS defaults:
# KAS defaults
KAS_ENABLED=false
KEY_ID=""
  1. In setup-cks-latest.sh, when KAS is enabled, prompt for the Virtru SaaS DSP-provisioned 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
  1. In setup-cks-latest.sh, write KEY_ID into env/cks.env with the other KAS env vars:
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
  1. In setup-cks-latest.sh, keep PORT at 9000:
printf "PORT=9000\n" >> ./env/cks.env
  1. In update.sh, when enabling KAS, preserve an existing KEY_ID if present; otherwise require the user to enter it:
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
  1. In update.sh, write/preserve KEY_ID with the other KAS env vars:
updateEnvVariable "KAS_ROOT_KEY" "$KAS_ROOT_KEY"
updateEnvVariable "KEY_ID" "$KEY_ID"
updateEnvVariable "ORG_ID" "$EXISTING_ORG_ID"
  1. In update.sh, keep PORT at 9000:
updateEnvVariable "PORT" "9000"

Rationale: KEY_ID is required for KAS deployments because it is the key identifier provisioned in Virtru SaaS DSP. Without it, the generated KAS env file is incomplete. Current deployments use
PORT=9000, so the update path should preserve that expectation.

dillonthompson and others added 4 commits May 6, 2026 15:56
- 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>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.sh commands to use containers.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

  • STATUS is parsed as a number and then compared with -ne, but if curl fails (network error, DNS, TLS, etc.) STATUS can 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.

Comment thread update.sh
Comment on lines +133 to +141
# 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"
Comment thread update.sh
Comment on lines +173 to +194
# 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
Comment thread update.sh
# 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"
Comment thread update.sh
Comment on lines +205 to +209
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

Comment thread setup-cks-latest.sh
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
Comment thread setup-cks-latest.sh
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
Comment thread README.md
Comment on lines +47 to +51
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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants