Skip to content

Commit 688e53e

Browse files
feat: PEP-3172 update scripts to support KAS (#31)
* feat: PEP-3172 update scripts to support KAS * updates env vars * cleanup unused env vars now that we're using bootstrapping * update readme * update readme * update readme * fix version check * cleanup * name fixes * update to prompt for kas key id * feat: PEP-3172 address nwilliamsgit review feedback - 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> * fix: drop /v2 from containers.virtru.com manifest check URL Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Revert "fix: drop /v2 from containers.virtru.com manifest check URL" This reverts commit 2b3f3bf. * fix: PEP-3172 address Copilot review feedback - Anchor awk patterns in updateEnvVariable and envVariableNotSet to ^VARIABLE= so KEY_ID no longer substring-matches WRAPPING_KEY_ID - Guard EXISTING_ORG_ID: prompt for Org ID if JWT_AUTH_AUDIENCE is missing from cks.env, instead of writing a blank ORG_ID - Remove unused OLD_CONTAINER_NAME variable - Remove unused PORT default from setup-cks-latest.sh (hardcoded in the printf below) - Fix README: KAS URI comes from user-provided FQDN during setup, inferred from SSL cert during update Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 159da7f commit 688e53e

3 files changed

Lines changed: 377 additions & 13 deletions

File tree

README.md

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,142 @@ bash ./cks-setup-scripts/setup-cks-latest.sh
2929
```
3030
bash ./cks-setup-scripts/update.sh
3131
```
32+
33+
---
34+
35+
## KAS Support
36+
37+
The setup scripts support deploying CKS with integrated Key Access Service (KAS) for Data Security Platform (DSP) integration. KAS enables advanced features like attribute-based access control and integration with Virtru's Data Security Platform.
38+
39+
### Enabling KAS During Initial Setup
40+
41+
When running `setup-cks-latest.sh`, you'll be prompted:
42+
43+
```
44+
Do you want to enable KAS [yes/no]?
45+
```
46+
47+
Answer **yes** to enable KAS. The setup will automatically configure KAS with standard settings:
48+
- OAuth Issuer: `https://login.virtru.com/oauth2/default`
49+
- OAuth Audience: `https://api.virtru.com`
50+
- KAS URI: Same as your CKS URL (set from the FQDN you provide during setup; the update script infers it from your existing SSL certificate)
51+
52+
KAS will automatically bootstrap itself on startup — it registers with the DSP platform, creates the necessary namespace, attributes, and imports keys. No manual provisioning steps or OAuth client credentials are required.
53+
54+
### Adding KAS to Existing CKS Deployment
55+
56+
To add KAS to an existing CKS-only deployment:
57+
58+
1. Run the update script:
59+
```bash
60+
bash ./cks-setup-scripts/update.sh
61+
```
62+
63+
2. When prompted, answer **yes** to enable KAS
64+
65+
3. The script will automatically:
66+
- Create a backup of your existing configuration
67+
- Configure KAS with standard settings (no manual input needed)
68+
- Add KAS environment variables to `env/cks.env`
69+
- Update `run.sh` with KAS-enabled configuration
70+
- Preserve all existing CKS keys and configuration
71+
72+
4. Apply the changes:
73+
```bash
74+
docker stop Virtru_CKS
75+
docker rm Virtru_CKS
76+
bash /path/to/working-dir/run.sh
77+
```
78+
79+
**Important:** Migration is safe and preserves your existing CKS keys and configuration. Your CKS data remains accessible after enabling KAS.
80+
81+
### Architecture
82+
83+
Both CKS-only and CKS+KAS deployments use the same Docker image: `containers.virtru.com/cks:v{VERSION}`
84+
85+
KAS is conditionally enabled based on the presence of `KAS_ROOT_KEY` in the environment configuration. If `KAS_ROOT_KEY` is not set, the KAS process remains dormant with no error logs.
86+
87+
#### CKS-Only Deployment
88+
- **Services:** Orchestrated by supervisord:
89+
- CKS (Node.js application on internal port 3000)
90+
- Caddy (reverse proxy on external port 9000)
91+
- **Port:** External port 443 → Internal port 9000 (Caddy) → Port 3000 (CKS)
92+
- **Database:** None required
93+
94+
#### CKS+KAS Deployment
95+
- **Services:** Multiple services orchestrated by supervisord:
96+
- PostgreSQL (internal database on port 5432)
97+
- CKS (Node.js application on internal port 3000)
98+
- KAS (Go service on internal port 8080)
99+
- Caddy (reverse proxy on external port 9000)
100+
- **Port:** External port 443 → Internal port 9000 (Caddy) → Port 3000 (CKS) or 8080 (KAS)
101+
- **Database:** PostgreSQL included in container
102+
- **Bootstrap:** KAS automatically registers with DSP, creates namespace/attributes, and imports keys on startup
103+
104+
#### Traffic Routing
105+
106+
Caddy reverse proxy routes incoming traffic:
107+
- **CKS Endpoints** → Port 3000 (CKS service)
108+
- `/rewrap`
109+
- `/bulk-rewrap`
110+
- `/public-keys`
111+
- `/key-pairs`
112+
- `/status`
113+
- `/healthz`
114+
- `/docs`
115+
- **All Other Traffic** → Port 8080 (KAS service)
116+
117+
### Troubleshooting
118+
119+
#### KAS Not Starting
120+
121+
**Symptom:** KAS service shows as "sleeping" in logs
122+
123+
**Solution:**
124+
- Verify `KAS_ROOT_KEY` is set in `env/cks.env`
125+
- Check that all required KAS environment variables are present
126+
- Review logs: `docker logs Virtru_CKS`
127+
128+
#### Bootstrap Failures
129+
130+
**Symptom:** Errors in KAS logs during startup
131+
132+
**Common Causes & Solutions:**
133+
1. **Auth Configuration**
134+
- Verify `KAS_AUTH_ISSUER` matches your OIDC provider
135+
- Check that `KAS_AUTH_AUDIENCE` matches the expected audience
136+
137+
2. **Key Files Missing**
138+
- Verify `KAS_PUBLIC_KEY_FILE` and `KAS_PRIVATE_KEY_FILE` paths point to existing keys
139+
- Check key file permissions
140+
141+
#### CKS Endpoints Not Working
142+
143+
**Symptom:** CKS endpoints return errors or timeout
144+
145+
**Solution:**
146+
- Review container logs: `docker logs Virtru_CKS`
147+
- Verify SSL certificates are valid and properly mounted
148+
149+
#### Viewing Service Logs
150+
151+
```bash
152+
# All logs
153+
docker logs Virtru_CKS
154+
155+
# Follow logs in real-time
156+
docker logs -f Virtru_CKS
157+
158+
# View supervisor logs
159+
docker exec Virtru_CKS cat /var/log/supervisor/supervisord.log
160+
```
161+
162+
---
163+
164+
## Version Compatibility
165+
166+
Both CKS-only and CKS+KAS deployments use the same Docker image:
167+
- **Image:** `containers.virtru.com/cks:v{VERSION}`
168+
- **Example:** `containers.virtru.com/cks:v1.29.0`
169+
170+
KAS is conditionally enabled within the same image based on environment configuration. When updating, both deployment types use the same VERSION file and Docker image.

setup-cks-latest.sh

Lines changed: 91 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ RESET="\033[0m"
1111
CLEAR="\033c"
1212

1313
# Defaults
14-
PORT=9000
1514
LOG_RSYS_ENABLED=false
1615
LOG_CONSOLE_ENABLED=true
1716
AUTH_TOKEN_STORAGE_TYPE="in-memory"
@@ -21,6 +20,10 @@ HMAC_AUTH_ENABLED=false
2120
JWT_AUTH_ENABLED=true
2221
JWT_AUTH_AUDIENCE=""
2322

23+
# KAS defaults
24+
KAS_ENABLED=false
25+
KEY_ID=""
26+
2427
# Yes or No Prompt
2528
prompt () {
2629
while true; do
@@ -109,6 +112,27 @@ while [ $l -ne 36 ]; do
109112
fi
110113
done
111114

115+
printf "\n${GREEN}Key Access Service (KAS) Support${RESET}\n"
116+
printf "KAS enables integration with Virtru's Data Security Platform (DSP).\n"
117+
printf "This allows advanced features like attribute-based access control.\n\n"
118+
119+
if prompt "Do you want to enable KAS [yes/no]?"; then
120+
KAS_ENABLED=true
121+
122+
# Set KAS configuration (no prompts needed - use standard values)
123+
KAS_AUTH_ISSUER="https://login.virtru.com/oauth2/default"
124+
KAS_AUTH_AUDIENCE="https://api.virtru.com"
125+
KAS_URI="https://${CKS_FQDN}"
126+
127+
while [ -z "$KEY_ID" ]; do
128+
read -p "Enter the Virtru SaaS DSP Key ID for this KAS deployment: " KEY_ID
129+
130+
if [ -z "$KEY_ID" ]; then
131+
printf "KEY_ID is required for KAS deployments.\n"
132+
fi
133+
done
134+
fi
135+
112136
printf "\nRequests from Virtru to your CKS are authenticated with JWTs.\n"
113137
printf "Authentication via HMACs may be enabled to support requests from CSE to CKS.\n\n"
114138

@@ -164,6 +188,13 @@ else
164188
chmod 644 $PUB_KEY_PATH
165189
fi
166190

191+
# Generate KAS root key if KAS is enabled
192+
KAS_ROOT_KEY=""
193+
if [ "$KAS_ENABLED" = true ]; then
194+
KAS_ROOT_KEY=$(openssl rand -hex 32)
195+
printf "\n${GREEN}KAS root key generated.${RESET}\n"
196+
fi
197+
167198
SECRET_B64_FINAL=""
168199
TOKEN_ID=""
169200
TOKEN_JSON=""
@@ -191,7 +222,10 @@ fi
191222
touch ./env/cks.env
192223

193224
# Write the Environment File
194-
printf "PORT=%s\n" $PORT >> ./env/cks.env
225+
# Caddy fronts traffic on 9000; supervisord pins CKS Node to 3000 internally.
226+
# PORT here mirrors the chart's configmap value so cks.env stays aligned.
227+
printf "PORT=9000\n" >> ./env/cks.env
228+
195229
printf "LOG_RSYSLOG_ENABLED=%s\n" $LOG_RSYS_ENABLED >> ./env/cks.env
196230
printf "LOG_CONSOLE_ENABLED=%s\n" $LOG_CONSOLE_ENABLED >> ./env/cks.env
197231
printf "KEY_PROVIDER_TYPE=%s\n" $KEY_PROVIDER_TYPE >> ./env/cks.env
@@ -210,6 +244,48 @@ if [ "$JWT_AUTH_ENABLED" = true ]; then
210244
printf "JWT_AUTH_AUDIENCE=%s\n" $JWT_AUTH_AUDIENCE >> ./env/cks.env
211245
fi
212246

247+
# Write KAS environment variables if enabled
248+
if [ "$KAS_ENABLED" = true ]; then
249+
# KAS Core Configuration
250+
printf "KAS_ROOT_KEY=%s\n" "$KAS_ROOT_KEY" >> ./env/cks.env
251+
printf "ORG_ID=%s\n" "$JWT_AUTH_AUDIENCE" >> ./env/cks.env
252+
printf "KAS_AUTH_ISSUER=%s\n" "$KAS_AUTH_ISSUER" >> ./env/cks.env
253+
printf "KAS_AUTH_AUDIENCE=%s\n" "$KAS_AUTH_AUDIENCE" >> ./env/cks.env
254+
printf "KAS_URI=%s\n" "$KAS_URI" >> ./env/cks.env
255+
printf "ACM_ENDPOINT=%s\n" "https://api.virtru.com/acm/api" >> ./env/cks.env
256+
printf "DATA_HARBOR_ENDPOINT=%s\n" "https://api.virtru.com/data-harbor/api" >> ./env/cks.env
257+
printf "WRAPPING_KEY_ID=%s\n" "kas-root-key" >> ./env/cks.env
258+
printf "KEY_ID=%s\n" "$KEY_ID" >> ./env/cks.env
259+
260+
# KAS Logging Configuration
261+
printf "KAS_LOG_LEVEL=%s\n" "debug" >> ./env/cks.env
262+
printf "KAS_LOG_TYPE=%s\n" "text" >> ./env/cks.env
263+
printf "KAS_LOG_OUTPUT=%s\n" "stdout" >> ./env/cks.env
264+
265+
# Database Configuration
266+
printf "DSP_DB_HOST=%s\n" "localhost" >> ./env/cks.env
267+
printf "DSP_DB_PORT=%s\n" "5432" >> ./env/cks.env
268+
printf "DSP_DB_DATABASE=%s\n" "opentdf" >> ./env/cks.env
269+
printf "DSP_DB_USER=%s\n" "postgres" >> ./env/cks.env
270+
printf "DSP_DB_PASSWORD=%s\n" "$(openssl rand -hex 16)" >> ./env/cks.env
271+
printf "DSP_DB_SSLMODE=%s\n" "prefer" >> ./env/cks.env
272+
printf "DSP_DB_SCHEMA=%s\n" "dsp" >> ./env/cks.env
273+
274+
# Key Configuration
275+
if [ "$KEY_TYPE" = "ECC" ]; then
276+
printf "KEY_ALGORITHM=%s\n" "ec:p256" >> ./env/cks.env
277+
printf "KAS_PUBLIC_KEY_FILE=/app/keys/ecc_p256_001.pub\n" >> ./env/cks.env
278+
printf "KAS_PRIVATE_KEY_FILE=/app/keys/ecc_p256_001.pem\n" >> ./env/cks.env
279+
else
280+
printf "KEY_ALGORITHM=%s\n" "rsa:2048" >> ./env/cks.env
281+
printf "KAS_PUBLIC_KEY_FILE=/app/keys/rsa_001.pub\n" >> ./env/cks.env
282+
printf "KAS_PRIVATE_KEY_FILE=/app/keys/rsa_001.pem\n" >> ./env/cks.env
283+
fi
284+
285+
# Update JWT_AUTH_ISSUER to match KAS_AUTH_ISSUER for consistency
286+
printf "JWT_AUTH_ISSUER=%s\n" "$KAS_AUTH_ISSUER" >> ./env/cks.env
287+
fi
288+
213289
# Print Summary
214290
printf "Summary:\n\n"
215291
printf "\tInstallation\n"
@@ -225,6 +301,15 @@ printf "\tAuth\n"
225301
printf "\tJWT Enabled: %s\n" "$JWT_AUTH_ENABLED"
226302
printf "\tHMAC Enabled: %s\n" "$HMAC_AUTH_ENABLED"
227303
printf "\tVirtru Org ID: %s\n\n" "$JWT_AUTH_AUDIENCE"
304+
305+
if [ "$KAS_ENABLED" = true ]; then
306+
printf "\t${GREEN}KAS Configuration${RESET}\n"
307+
printf "\tKAS Enabled: true\n"
308+
printf "\tKAS Auth Issuer: %s\n" "$KAS_AUTH_ISSUER"
309+
printf "\tKAS Auth Audience: %s\n" "$KAS_AUTH_AUDIENCE"
310+
printf "\tKAS URI: %s\n\n" "$KAS_URI"
311+
fi
312+
228313
printf "\tTroubleshooting\n"
229314
printf "\tSupport URL: %s\n" $SUPPORT_URL
230315
printf "\tSupport Email: %s\n" $SUPPORT_EMAIL
@@ -251,5 +336,8 @@ rm -rf ./cks_info
251336

252337
# Create the Run File
253338
touch ./run.sh
339+
chmod +x ./run.sh
340+
341+
# Generate run.sh (always uses port 9000 via Caddy, no "serve" arg - supervisord manages processes)
342+
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
254343

255-
echo "docker run --name Virtru_CKS --interactive --tty --detach --restart unless-stopped --env-file "$WORKING_DIR"/env/cks.env -p 443:$PORT --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" serve" > ./run.sh

0 commit comments

Comments
 (0)