Skip to content

Commit 2aa38d2

Browse files
authored
Fix for Vault configuration issue (buerokratt#473)
* fixed vault configuration issue * address Vault via unique rag-vault alias to avoid cross -stack DNS collision * fixed vector indexer statistics analysis issue
1 parent 59c5765 commit 2aa38d2

18 files changed

Lines changed: 624 additions & 195 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
@@ -503,7 +503,11 @@ services:
503503
- ./vault/config:/vault/config:ro
504504
- ./vault/logs:/vault/logs
505505
networks:
506-
- vault-network # Only on vault-network for security
506+
vault-network: # Only on vault-network for security
507+
# Local testing: bare "vault" collides with the ckb stack on the shared
508+
# bykstack network, so expose this Vault under a unique alias instead.
509+
aliases:
510+
- rag-vault
507511
restart: unless-stopped
508512
healthcheck:
509513
test: ["CMD", "sh", "-c", "wget -q -O- http://127.0.0.1:8200/v1/sys/health || exit 0"]
@@ -520,7 +524,7 @@ services:
520524
vault:
521525
condition: service_healthy
522526
environment:
523-
VAULT_ADDR: http://vault:8200
527+
VAULT_ADDR: http://rag-vault:8200
524528
volumes:
525529
- vault-data:/vault/data
526530
- vault-agent-creds:/agent/credentials
@@ -529,8 +533,8 @@ services:
529533
- vault-agent-llm-token:/agent/llm-token
530534
- ./vault-init.sh:/vault-init.sh:ro
531535
networks:
532-
- vault-network # Access vault
533-
- bykstack # Access to write agent tokens
536+
# vault-network only: tokens/creds go via shared volumes, not the network.
537+
- vault-network
534538
entrypoint: ["/bin/sh"]
535539
command:
536540
- -c

docker-compose.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ services:
193193
environment:
194194
- server.port=9010
195195
- PYTHONPATH=/app:/app/src/vector_indexer:/app/src/intent_data_enrichment:/app/src/api_tool_indexer
196-
- VAULT_AGENT_URL=http://vault-agent-cron:8203
196+
- vaultAgentUrl=http://vault-agent-cron:8203
197197
ports:
198198
- 9010:8080
199199
depends_on:
@@ -451,7 +451,11 @@ services:
451451
- ./vault/config:/vault/config:ro
452452
- ./vault/logs:/vault/logs
453453
networks:
454-
- vault-network # Only on vault-network for security
454+
vault-network: # Only on vault-network for security
455+
# Local testing: bare "vault" collides with the ckb stack on the shared
456+
# bykstack network, so expose this Vault under a unique alias instead.
457+
aliases:
458+
- rag-vault
455459
restart: unless-stopped
456460
healthcheck:
457461
test: ["CMD", "sh", "-c", "wget -q -O- http://127.0.0.1:8200/v1/sys/health || exit 0"]
@@ -468,7 +472,7 @@ services:
468472
vault:
469473
condition: service_healthy
470474
environment:
471-
VAULT_ADDR: http://vault:8200
475+
VAULT_ADDR: http://rag-vault:8200
472476
volumes:
473477
- vault-data:/vault/data
474478
- vault-agent-creds:/agent/credentials
@@ -477,8 +481,8 @@ services:
477481
- vault-agent-llm-token:/agent/llm-token
478482
- ./vault-init.sh:/vault-init.sh:ro
479483
networks:
480-
- vault-network # Access vault
481-
- bykstack # Access to write agent tokens
484+
# vault-network only: tokens/creds go via shared volumes, not the network.
485+
- vault-network
482486
entrypoint: ["/bin/sh"]
483487
command:
484488
- -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)