Skip to content

Commit 17c0269

Browse files
authored
Merge pull request #208 from rootcodelabs/llm-469
Get update from llm-469
2 parents 45fbf7b + f5205f1 commit 17c0269

14 files changed

Lines changed: 552 additions & 161 deletions

DSL/CronManager/DSL/data_resync.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ agency_data_resync:
22
trigger: "0 0 0/1 * * ?"
33
# trigger: off
44
type: exec
5-
command: "../app/scripts/agency_data_resync.sh -s 10"
5+
command: "/app/scripts/agency_data_resync.sh -s 10"

DSL/CronManager/DSL/delete_from_vault.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ delete_secrets:
22
trigger: off
33
type: exec
44
command: "/app/scripts/delete_secrets_from_vault.sh"
5-
allowedEnvs: ['cookie','vaultUuid','llmPlatform', 'llmModel','embeddingModel','embeddingPlatform']
5+
allowedEnvs: ['cookie','vaultUuid','llmPlatform', 'llmModel','embeddingModel','embeddingPlatform', 'vaultAgentUrl']

DSL/CronManager/DSL/store_in_vault.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ store_secrets:
22
trigger: off
33
type: exec
44
command: "/app/scripts/store_secrets_in_vault.sh"
5-
allowedEnvs: ['cookie','vaultUuid','llmPlatform', 'llmModel','secretKey','accessKey','deploymentName','targetUrl','apiKey','embeddingModel','embeddingPlatform','embeddingAccessKey','embeddingSecretKey','embeddingDeploymentName','embeddingTargetUri','embeddingAzureApiKey','deploymentEnvironment']
5+
allowedEnvs: ['cookie','vaultUuid','llmPlatform', 'llmModel','secretKey','accessKey','deploymentName','targetUrl','apiKey','embeddingModel','embeddingPlatform','embeddingAccessKey','embeddingSecretKey','embeddingDeploymentName','embeddingTargetUri','embeddingAzureApiKey','deploymentEnvironment', 'vaultAgentUrl']

DSL/CronManager/script/delete_secrets_from_vault.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
set -e # Exit on any error
77

88
# Configuration
9-
# Use VAULT_AGENT_URL which points to vault-agent-cron proxy
9+
# Use vaultAgentUrl which points to vault-agent-cron proxy
1010
# The agent automatically injects the authentication token
11-
VAULT_ADDR="${VAULT_AGENT_URL:-http://vault-agent-cron:8203}"
11+
VAULT_ADDR="${vaultAgentUrl:-http://vault-agent-cron:8203}"
1212

1313
# Logging function
1414
log() {

DSL/CronManager/script/store_secrets_in_vault.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
set -e # Exit on any error
77

88
# Configuration
9-
# Use VAULT_AGENT_URL which points to vault-agent-cron proxy
9+
# Use vaultAgentUrl which points to vault-agent-cron proxy
1010
# The agent automatically injects the authentication token
11-
VAULT_ADDR="${VAULT_AGENT_URL:-http://vault-agent-cron:8203}"
11+
VAULT_ADDR="${vaultAgentUrl:-http://vault-agent-cron:8203}"
1212

1313
# Decryption Configuration
1414
PRIVATE_KEY_CACHE=""

docker-compose-ec2.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,11 @@ services:
502502
- ./vault/config:/vault/config:ro
503503
- ./vault/logs:/vault/logs
504504
networks:
505-
- vault-network # Only on vault-network for security
505+
vault-network: # Only on vault-network for security
506+
# Local testing: bare "vault" collides with the ckb stack on the shared
507+
# bykstack network, so expose this Vault under a unique alias instead.
508+
aliases:
509+
- rag-vault
506510
restart: unless-stopped
507511
healthcheck:
508512
test: ["CMD", "sh", "-c", "wget -q -O- http://127.0.0.1:8200/v1/sys/health || exit 0"]
@@ -519,7 +523,7 @@ services:
519523
vault:
520524
condition: service_healthy
521525
environment:
522-
VAULT_ADDR: http://vault:8200
526+
VAULT_ADDR: http://rag-vault:8200
523527
volumes:
524528
- vault-data:/vault/data
525529
- vault-agent-creds:/agent/credentials
@@ -528,8 +532,8 @@ services:
528532
- vault-agent-llm-token:/agent/llm-token
529533
- ./vault-init.sh:/vault-init.sh:ro
530534
networks:
531-
- vault-network # Access vault
532-
- bykstack # Access to write agent tokens
535+
# vault-network only: tokens/creds go via shared volumes, not the network.
536+
- vault-network
533537
entrypoint: ["/bin/sh"]
534538
command:
535539
- -c

docker-compose.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ services:
191191
environment:
192192
- server.port=9010
193193
- PYTHONPATH=/app:/app/src/vector_indexer:/app/src/intent_data_enrichment:/app/src/api_tool_indexer
194-
- VAULT_AGENT_URL=http://vault-agent-cron:8203
194+
- vaultAgentUrl=http://vault-agent-cron:8203
195195
ports:
196196
- 9010:8080
197197
depends_on:
@@ -449,7 +449,11 @@ services:
449449
- ./vault/config:/vault/config:ro
450450
- ./vault/logs:/vault/logs
451451
networks:
452-
- vault-network # Only on vault-network for security
452+
vault-network: # Only on vault-network for security
453+
# Local testing: bare "vault" collides with the ckb stack on the shared
454+
# bykstack network, so expose this Vault under a unique alias instead.
455+
aliases:
456+
- rag-vault
453457
restart: unless-stopped
454458
healthcheck:
455459
test: ["CMD", "sh", "-c", "wget -q -O- http://127.0.0.1:8200/v1/sys/health || exit 0"]
@@ -466,7 +470,7 @@ services:
466470
vault:
467471
condition: service_healthy
468472
environment:
469-
VAULT_ADDR: http://vault:8200
473+
VAULT_ADDR: http://rag-vault:8200
470474
volumes:
471475
- vault-data:/vault/data
472476
- vault-agent-creds:/agent/credentials
@@ -475,8 +479,8 @@ services:
475479
- vault-agent-llm-token:/agent/llm-token
476480
- ./vault-init.sh:/vault-init.sh:ro
477481
networks:
478-
- vault-network # Access vault
479-
- bykstack # Access to write agent tokens
482+
# vault-network only: tokens/creds go via shared volumes, not the network.
483+
- vault-network
480484
entrypoint: ["/bin/sh"]
481485
command:
482486
- -c

docs/VAULT_SECURITY_ARCHITECTURE.md

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,12 @@ Day 0+: Automatic Token Renewal:
197197
Container Restart:
198198
vault-init: Check if Vault is sealed
199199
200-
If unsealed: Regenerate secret_id only
200+
If unsealed: Validate existing secret_ids
201201
202-
vault-agent: Re-authenticate with new secret_id
202+
If valid: Reuse existing secret_id (no churn)
203+
If invalid: Mint new secret_id and write to disk
204+
205+
vault-agent: Re-authenticate with secret_id
203206
204207
New token issued and cached
205208
```
@@ -413,8 +416,9 @@ Connected Services:
413416
- GUI (React Frontend)
414417
415418
Token Lifecycle:
416-
- Default Lease: 768h (32 days)
417-
- Auto-renewal: Before expiration
419+
- Token type: periodic (token_period 20m, no max-TTL)
420+
- Auto-renewal: Every ~13 minutes (~2/3 of period)
421+
- Re-auth: only on agent restart (never in steady state)
418422
```
419423

420424
#### Agent 2: vault-agent-cron
@@ -429,8 +433,9 @@ Connected Services:
429433
- CronManager (Python worker)
430434
431435
Token Lifecycle:
432-
- Default Lease: 768h (32 days)
433-
- Auto-renewal: Before expiration
436+
- Token type: periodic (token_period 30m, no max-TTL)
437+
- Auto-renewal: Every ~20 minutes (~2/3 of period)
438+
- Re-auth: only on agent restart (never in steady state)
434439
```
435440

436441
#### Agent 3: vault-agent-llm
@@ -445,8 +450,9 @@ Connected Services:
445450
- LLM Orchestration Service (FastAPI)
446451
447452
Token Lifecycle:
448-
- Default Lease: 1h (shorter for higher security)
449-
- Auto-renewal: Every ~45 minutes
453+
- Token type: periodic (token_period 1h, no max-TTL)
454+
- Auto-renewal: Every ~40 minutes (~2/3 of period)
455+
- Re-auth: only on agent restart (never in steady state)
450456
```
451457

452458
### Token Caching and Auto-Renewal
@@ -464,29 +470,31 @@ T=0: Initial Authentication
464470
├─► POST /v1/auth/approle/login
465471
│ Body: { role_id, secret_id }
466472
467-
└─► Receives: { token, ttl: 3600s, renewable: true }
473+
└─► Receives: { token, period: 3600s, renewable: true } ← periodic token, no max-TTL
468474
469475
└─► Cache token in: /agent/llm-token/token
470476
471477
472-
T=45min: Proactive Renewal (75% of TTL)
478+
T≈40min: Proactive Renewal (~2/3 of period)
473479
vault-agent monitors expiration
474480
475481
├─► POST /v1/auth/token/renew-self
476482
│ Header: X-Vault-Token: <current_token>
477483
478-
└─► Receives: { token, ttl: 3600s } (same token, extended)
484+
└─► Receives: { token, period: 3600s } (same token, period reset)
479485
480486
└─► Update cache: /agent/llm-token/token
487+
488+
└─► Repeats forever — a periodic token never hits a max-TTL,
489+
so steady-state operation never needs approle/login again.
481490
482491
483-
T=59min: Renewal Failed (fallback)
484-
If renewal fails:
492+
On agent restart only:
493+
vault-agent re-reads role_id + secret_id from disk
485494
486-
├─► Re-authenticate from scratch
487-
│ POST /v1/auth/approle/login
495+
├─► POST /v1/auth/approle/login (secret_id must still be valid)
488496
489-
└─► New token issued and cached
497+
└─► New periodic token issued and cached
490498
491499
492500
Application Request (anytime):
@@ -856,15 +864,16 @@ Step 12: Check Vault Seal Status
856864
└─► GET /v1/sys/seal-status
857865
└─► If unsealed: Skip unseal steps
858866
859-
Step 13: Regenerate Secret IDs Only
860-
└─► POST /v1/auth/approle/role/gui-service/secret-id
861-
─► POST /v1/auth/approle/role/cron-manager-service/secret-id
862-
─► POST /v1/auth/approle/role/llm-orchestration-service/secret-id
863-
└─► Write new secret_ids to /agent/credentials/
867+
Step 13: Validate and Reconcile Secret IDs
868+
└─► For each role (gui, cron-manager, llm-orchestration):
869+
─► Test existing on-disk secret_id via AppRole login
870+
─► If valid: Reuse (no change to credential file)
871+
└─► If invalid/missing: Mint new secret_id and write to disk
864872
865873
Note: role_ids remain unchanged (static identifiers)
866874
Note: Existing secrets and policies preserved
867875
Note: RSA keypair NOT regenerated (preserved)
876+
Note: Stable secret_ids across restarts reduce credential churn
868877
869878
═══════════════════════════════════════════════════════════════════
870879
COMPLETION
@@ -1128,13 +1137,14 @@ Startup Order:
11281137
vault-init Behavior:
11291138
- Detects Vault already initialized
11301139
- Skips initialization steps
1131-
- Regenerates secret_ids only
1132-
- Updates credential files
1140+
- Validates existing secret_ids (reuses if still valid)
1141+
- Mints new secret_ids only if existing ones are invalid
11331142
11341143
Result:
1135-
All services start with fresh credentials
1144+
All services start with validated credentials
11361145
Existing secrets preserved
11371146
No manual intervention needed
1147+
Stable secret_ids reduce unnecessary credential churn
11381148
```
11391149

11401150
### Token Regeneration Strategy
@@ -1143,22 +1153,23 @@ Result:
11431153
Current Implementation:
11441154
11451155
1. On Every Container Restart:
1146-
└─► vault-init regenerates secret_ids
1147-
─► Vault agents get new tokens
1148-
└─► Old tokens remain valid until expiration
1156+
└─► vault-init validates existing secret_ids
1157+
─► If valid: Reuse (agents continue with same credentials)
1158+
└─► If invalid: Mint new secret_id, agents re-authenticate
11491159
11501160
2. Token Lifecycle:
1151-
└─► Issue: vault-agent authenticates
1161+
└─► Issue: vault-agent authenticates (periodic token, token_period per role)
11521162
└─► Use: Application makes requests
1153-
└─► Renew: vault-agent extends TTL
1154-
└─► Expire: Automatic renewal failed
1155-
└─► Re-issue: vault-agent re-authenticates
1163+
└─► Renew: vault-agent renews within the period (~2/3 of period)
1164+
└─► No max-TTL: renewal continues indefinitely
1165+
└─► Re-issue: only on agent restart, via secret_id login
11561166
11571167
3. Security Benefits:
1158-
Short-lived tokens (1 hour for LLM, 32 days for others)
1159-
Automatic rotation on agent restart
1160-
No manual token management
1161-
Compromised tokens have limited lifetime
1168+
Periodic tokens (period 1h LLM, 30m Cron, 20m GUI), renewed continuously
1169+
Steady-state operation never re-runs approle/login (a stale secret_id
1170+
cannot strand a running agent)
1171+
Stable secret_ids (no unnecessary churn on restart)
1172+
Compromised tokens limited to one un-renewed period
11621173
```
11631174

11641175
### Audit Logging Capabilities

0 commit comments

Comments
 (0)