Skip to content

Commit 6e1e859

Browse files
kibanamachinespong
andauthored
[8.19] [Security Assistant] Simplifies Security Gen AI Evaluation secret management (elastic#219885) (elastic#220700)
# Backport This will backport the following commits from `main` to `8.19`: - [[Security Assistant] Simplifies Security Gen AI Evaluation secret management (elastic#219885)](elastic#219885) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Garrett Spong","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-05-09T17:01:36Z","message":"[Security Assistant] Simplifies Security Gen AI Evaluation secret management (elastic#219885)\n\n## Summary\n\nSimplifies secret management for running the Security Gen AI\nEvaluations. See updated README.md for full details, but includes:\n\n* Consolidation of multiple vault keys to a single\n`KIBANA_SECURITY_GEN_AI_CONFIG` key, which contains all connectors,\nlangsmith creds and now a way to specify `evaluatorConnectorId`.\n* Added `vault` params to both `retrieve_secrets.js` and\n`upload_secrets.js` for specifying the vault. Defaults to `sieam-team`\nsecrets.elastic.co for ease of use by developers.\n* Introduces `get_commands.js` script for fetching commands to hand off\nto either Kibana Ops for updating, or specifying config overrides when\nmanually running BuildKite pipelines.\n* Deleted `export_env_secrets.js` as it couldn't be used for setting env\nvars locally for the dev testing experience.\n* Updated `connectors` as per team discussion to include: GPT-4.1,\nClaude 3.5/3.7, and Gemini 2.5 Pro. This was a config change made by\nKibana Ops, so no code change present. But you can confirm by running\n`retrieve_secrets.js`.\n\nAnd finally, a much more detailed `README.md` for testing locally, on\nPR's and CI, and the process for updating secrets. See full\n[README.md](https://github.com/spong/kibana/blob/ci-eval-tweaks/x-pack/test/security_solution_api_integration/test_suites/genai/evaluations/README.md)\n\n\n\nExample LangSmith Runs:\n\n* `ES|QL Generation Regression Suite`: [Run\n298372](https://smith.langchain.com/o/b739bf24-7ba4-4994-b632-65dd677ac74e/datasets/261dcc59-fbe7-4397-a662-ff94042f666c)\n* `Alerts RAG Regression (Episodes 1-8)`: [Run\n298372](https://smith.langchain.com/o/b739bf24-7ba4-4994-b632-65dd677ac74e/datasets/bd5bba1d-97aa-4512-bce7-b09aa943c651)\n* `Assistant Eval: Custom Knowledge`: [Run\n298372](https://smith.langchain.com/o/b739bf24-7ba4-4994-b632-65dd677ac74e/datasets/2d5f7c18-4bf4-4cdb-97a1-16e39a865cab)\n* `Eval AD: All Scenarios`: [Run\n300138](https://smith.langchain.com/o/b739bf24-7ba4-4994-b632-65dd677ac74e/datasets/4690ee16-9df5-416c-8bf0-b62bc2f2aba9/compare?selectedSessions=6d44134b-6492-4f2d-9b28-6d4a82a0e9ae&baseline=undefined)\n\nNote: there is currently a timing bug with Alerts/KB entries being\ncleaned up before the server is complete, so you may see poor evals for\n`Alerts RAG Regression (Episodes 1-8)` and `Assistant Eval: Custom\nKnowledge` until that is fixed. I'll address this in a follow-up PR\nsince it is unrelated to this change-set.","sha":"e9a8909fad8075cee246793697d6f252e6227a44","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:Security Generative AI","Feature:Assistant Evaluation","backport:version","v9.1.0","v8.19.0","ci:security-genai-run-evals"],"title":"[Security Assistant] Simplifies Security Gen AI Evaluation secret management","number":219885,"url":"https://github.com/elastic/kibana/pull/219885","mergeCommit":{"message":"[Security Assistant] Simplifies Security Gen AI Evaluation secret management (elastic#219885)\n\n## Summary\n\nSimplifies secret management for running the Security Gen AI\nEvaluations. See updated README.md for full details, but includes:\n\n* Consolidation of multiple vault keys to a single\n`KIBANA_SECURITY_GEN_AI_CONFIG` key, which contains all connectors,\nlangsmith creds and now a way to specify `evaluatorConnectorId`.\n* Added `vault` params to both `retrieve_secrets.js` and\n`upload_secrets.js` for specifying the vault. Defaults to `sieam-team`\nsecrets.elastic.co for ease of use by developers.\n* Introduces `get_commands.js` script for fetching commands to hand off\nto either Kibana Ops for updating, or specifying config overrides when\nmanually running BuildKite pipelines.\n* Deleted `export_env_secrets.js` as it couldn't be used for setting env\nvars locally for the dev testing experience.\n* Updated `connectors` as per team discussion to include: GPT-4.1,\nClaude 3.5/3.7, and Gemini 2.5 Pro. This was a config change made by\nKibana Ops, so no code change present. But you can confirm by running\n`retrieve_secrets.js`.\n\nAnd finally, a much more detailed `README.md` for testing locally, on\nPR's and CI, and the process for updating secrets. See full\n[README.md](https://github.com/spong/kibana/blob/ci-eval-tweaks/x-pack/test/security_solution_api_integration/test_suites/genai/evaluations/README.md)\n\n\n\nExample LangSmith Runs:\n\n* `ES|QL Generation Regression Suite`: [Run\n298372](https://smith.langchain.com/o/b739bf24-7ba4-4994-b632-65dd677ac74e/datasets/261dcc59-fbe7-4397-a662-ff94042f666c)\n* `Alerts RAG Regression (Episodes 1-8)`: [Run\n298372](https://smith.langchain.com/o/b739bf24-7ba4-4994-b632-65dd677ac74e/datasets/bd5bba1d-97aa-4512-bce7-b09aa943c651)\n* `Assistant Eval: Custom Knowledge`: [Run\n298372](https://smith.langchain.com/o/b739bf24-7ba4-4994-b632-65dd677ac74e/datasets/2d5f7c18-4bf4-4cdb-97a1-16e39a865cab)\n* `Eval AD: All Scenarios`: [Run\n300138](https://smith.langchain.com/o/b739bf24-7ba4-4994-b632-65dd677ac74e/datasets/4690ee16-9df5-416c-8bf0-b62bc2f2aba9/compare?selectedSessions=6d44134b-6492-4f2d-9b28-6d4a82a0e9ae&baseline=undefined)\n\nNote: there is currently a timing bug with Alerts/KB entries being\ncleaned up before the server is complete, so you may see poor evals for\n`Alerts RAG Regression (Episodes 1-8)` and `Assistant Eval: Custom\nKnowledge` until that is fixed. I'll address this in a follow-up PR\nsince it is unrelated to this change-set.","sha":"e9a8909fad8075cee246793697d6f252e6227a44"}},"sourceBranch":"main","suggestedTargetBranches":["9.0","8.19"],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/219885","number":219885,"mergeCommit":{"message":"[Security Assistant] Simplifies Security Gen AI Evaluation secret management (elastic#219885)\n\n## Summary\n\nSimplifies secret management for running the Security Gen AI\nEvaluations. See updated README.md for full details, but includes:\n\n* Consolidation of multiple vault keys to a single\n`KIBANA_SECURITY_GEN_AI_CONFIG` key, which contains all connectors,\nlangsmith creds and now a way to specify `evaluatorConnectorId`.\n* Added `vault` params to both `retrieve_secrets.js` and\n`upload_secrets.js` for specifying the vault. Defaults to `sieam-team`\nsecrets.elastic.co for ease of use by developers.\n* Introduces `get_commands.js` script for fetching commands to hand off\nto either Kibana Ops for updating, or specifying config overrides when\nmanually running BuildKite pipelines.\n* Deleted `export_env_secrets.js` as it couldn't be used for setting env\nvars locally for the dev testing experience.\n* Updated `connectors` as per team discussion to include: GPT-4.1,\nClaude 3.5/3.7, and Gemini 2.5 Pro. This was a config change made by\nKibana Ops, so no code change present. But you can confirm by running\n`retrieve_secrets.js`.\n\nAnd finally, a much more detailed `README.md` for testing locally, on\nPR's and CI, and the process for updating secrets. See full\n[README.md](https://github.com/spong/kibana/blob/ci-eval-tweaks/x-pack/test/security_solution_api_integration/test_suites/genai/evaluations/README.md)\n\n\n\nExample LangSmith Runs:\n\n* `ES|QL Generation Regression Suite`: [Run\n298372](https://smith.langchain.com/o/b739bf24-7ba4-4994-b632-65dd677ac74e/datasets/261dcc59-fbe7-4397-a662-ff94042f666c)\n* `Alerts RAG Regression (Episodes 1-8)`: [Run\n298372](https://smith.langchain.com/o/b739bf24-7ba4-4994-b632-65dd677ac74e/datasets/bd5bba1d-97aa-4512-bce7-b09aa943c651)\n* `Assistant Eval: Custom Knowledge`: [Run\n298372](https://smith.langchain.com/o/b739bf24-7ba4-4994-b632-65dd677ac74e/datasets/2d5f7c18-4bf4-4cdb-97a1-16e39a865cab)\n* `Eval AD: All Scenarios`: [Run\n300138](https://smith.langchain.com/o/b739bf24-7ba4-4994-b632-65dd677ac74e/datasets/4690ee16-9df5-416c-8bf0-b62bc2f2aba9/compare?selectedSessions=6d44134b-6492-4f2d-9b28-6d4a82a0e9ae&baseline=undefined)\n\nNote: there is currently a timing bug with Alerts/KB entries being\ncleaned up before the server is complete, so you may see poor evals for\n`Alerts RAG Regression (Episodes 1-8)` and `Assistant Eval: Custom\nKnowledge` until that is fixed. I'll address this in a follow-up PR\nsince it is unrelated to this change-set.","sha":"e9a8909fad8075cee246793697d6f252e6227a44"}},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Garrett Spong <[email protected]>
1 parent 2e6e08e commit 6e1e859

File tree

10 files changed

+247
-149
lines changed

10 files changed

+247
-149
lines changed

.buildkite/scripts/common/setup_job_env.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,7 @@ EOF
144144
{
145145
if [[ "${FTR_SECURITY_GEN_AI:-}" =~ ^(1|true)$ ]]; then
146146
echo "FTR_SECURITY_GEN_AI was set - exposing LLM connectors"
147-
export KIBANA_SECURITY_TESTING_AI_CONNECTORS="$(vault_get security-gen-ai/connectors config)"
148-
export KIBANA_SECURITY_TESTING_LANGSMITH_KEY="$(vault_get security-gen-ai/langsmith key)"
147+
export KIBANA_SECURITY_GEN_AI_CONFIG="$(vault_get security-gen-ai config)"
149148
fi
150149
}
151150

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
connector_config.json
22
langsmith_key.txt
3+
config.json

x-pack/test/security_solution_api_integration/scripts/genai/vault/export_env_secrets.js

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
require('@kbn/babel-register').install();
9+
const { getCommand } = require('./manage_secrets');
10+
const minimist = require('minimist');
11+
12+
/**
13+
* Gets a command for working with Security Gen AI secrets either as a vault write command or environment variable.
14+
* By default, the command is formatted as a 'vault-write' command, but it can be overridden with the --format parameter
15+
* to use 'env-var' format.
16+
*
17+
* @returns {Promise<void>}
18+
*/
19+
async function run() {
20+
const argv = minimist(process.argv.slice(2));
21+
const format = argv.format || 'vault-write';
22+
const vault = argv.vault || 'ci-prod';
23+
24+
if (format !== 'vault-write' && format !== 'env-var') {
25+
console.error('Error: format parameter must be either "vault-write" or "env-var"');
26+
process.exit(1);
27+
}
28+
29+
if (format === 'vault-write' && vault !== 'siem-team' && vault !== 'ci-prod') {
30+
console.error('Error: vault parameter must be either "siem-team" or "ci-prod"');
31+
process.exit(1);
32+
}
33+
34+
console.log(await getCommand(format, vault));
35+
}
36+
37+
run();

x-pack/test/security_solution_api_integration/scripts/genai/vault/manage_secrets.ts

Lines changed: 100 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,42 @@ import { writeFile, readFile } from 'fs/promises';
1111
import { REPO_ROOT } from '@kbn/repo-info';
1212
import { schema } from '@kbn/config-schema';
1313

14-
const SECURITY_GEN_AI_CONNECTORS_ENV_VAR = 'KIBANA_SECURITY_TESTING_AI_CONNECTORS';
15-
const SECURITY_GEN_AI_LANGSMITH_KEY_ENV_VAR = 'KIBANA_SECURITY_TESTING_LANGSMITH_KEY';
16-
17-
// siem-team secrets discussed w/ operations and we will mirror them here
18-
// const SECURITY_GEN_AI_VAULT = 'secret/siem-team/security-gen-ai';
19-
20-
// CI Vault
21-
const SECURITY_GEN_AI_VAULT = 'secret/ci/elastic-kibana/security-gen-ai';
22-
const SECURITY_GEN_AI_VAULT_CONNECTORS = `${SECURITY_GEN_AI_VAULT}/connectors`;
23-
const SECURITY_GEN_AI_VAULT_LANGSMITH = `${SECURITY_GEN_AI_VAULT}/langsmith`;
24-
const SECURITY_GEN_AI_CONNECTORS_FIELD = 'config';
25-
const SECURITY_GEN_AI_LANGSMITH_FIELD = 'key';
26-
const CONNECTOR_FILE = Path.join(
27-
REPO_ROOT,
28-
'x-pack/test/security_solution_api_integration/scripts/genai/vault/connector_config.json'
29-
);
30-
const LANGSMITH_FILE = Path.join(
14+
// Environment variable set within BuildKite and read from in FTR tests
15+
// CI env vars are set by .buildkite/scripts/common/setup_job_env.sh
16+
const KIBANA_SECURITY_GEN_AI_CONFIG = 'KIBANA_SECURITY_GEN_AI_CONFIG';
17+
18+
// Vault paths
19+
// siem-team users (secrets.elastic.co vault) do not have access to the ci-prod vault, so secrets
20+
// are mirrored between the two vaults
21+
type VaultType = 'siem-team' | 'ci-prod';
22+
const VAULT_PATHS: Record<VaultType, string> = {
23+
'siem-team': 'secret/siem-team/security-gen-ai',
24+
'ci-prod': 'secret/ci/elastic-kibana/security-gen-ai',
25+
};
26+
27+
const getVaultPath = (vault: VaultType = 'siem-team') => {
28+
return VAULT_PATHS[vault];
29+
};
30+
31+
const SECURITY_GEN_AI_CONFIG_FIELD = 'config';
32+
const SECURITY_GEN_AI_CONFIG_FILE = Path.join(
3133
REPO_ROOT,
32-
'x-pack/test/security_solution_api_integration/scripts/genai/vault/langsmith_key.txt'
34+
'x-pack/test/security_solution_api_integration/scripts/genai/vault/config.json'
3335
);
3436

35-
const connectorsSchema = schema.recordOf(
36-
schema.string(),
37-
schema.object({
38-
name: schema.string(),
39-
actionTypeId: schema.string(),
40-
config: schema.recordOf(schema.string(), schema.any()),
41-
secrets: schema.recordOf(schema.string(), schema.any()),
42-
})
43-
);
37+
const configSchema = schema.object({
38+
evaluatorConnectorId: schema.string(),
39+
langsmithKey: schema.string(),
40+
connectors: schema.recordOf(
41+
schema.string(),
42+
schema.object({
43+
name: schema.string(),
44+
actionTypeId: schema.string(),
45+
config: schema.recordOf(schema.string(), schema.any()),
46+
secrets: schema.recordOf(schema.string(), schema.any()),
47+
})
48+
),
49+
});
4450

4551
export interface AvailableConnector {
4652
name: string;
@@ -49,50 +55,75 @@ export interface AvailableConnector {
4955
secrets: Record<string, unknown>;
5056
}
5157

52-
export const retrieveFromVault = async (
53-
vault: string,
54-
filePath: string,
55-
field: string,
56-
isJson = true
57-
) => {
58+
/**
59+
* Retrieve generic value from vault and write to file
60+
*
61+
* @param vault
62+
* @param filePath
63+
* @param field
64+
*/
65+
export const retrieveFromVault = async (vault: string, filePath: string, field: string) => {
5866
const { stdout } = await execa('vault', ['read', `-field=${field}`, vault], {
5967
cwd: REPO_ROOT,
6068
buffer: true,
6169
});
6270

6371
const value = Buffer.from(stdout, 'base64').toString('utf-8').trim();
64-
const config = isJson ? JSON.stringify(JSON.parse(value), null, 2) : value;
72+
const config = JSON.stringify(JSON.parse(value), null, 2);
6573

6674
await writeFile(filePath, config);
6775

6876
// eslint-disable-next-line no-console
69-
console.log(`Config dumped into ${filePath}`);
77+
console.log(`Config written to: ${filePath}`);
7078
};
7179

72-
export const retrieveConnectorConfig = async () => {
73-
await retrieveFromVault(
74-
SECURITY_GEN_AI_VAULT_CONNECTORS,
75-
CONNECTOR_FILE,
76-
SECURITY_GEN_AI_CONNECTORS_FIELD
77-
);
78-
};
79-
80-
export const retrieveLangsmithKey = async () => {
80+
/**
81+
* Retrieve Security Gen AI secrets config from vault and write to file
82+
* @param vault
83+
*/
84+
export const retrieveConfigFromVault = async (vault: VaultType = 'siem-team') => {
8185
await retrieveFromVault(
82-
SECURITY_GEN_AI_VAULT_LANGSMITH,
83-
LANGSMITH_FILE,
84-
SECURITY_GEN_AI_LANGSMITH_FIELD,
85-
false
86+
getVaultPath(vault),
87+
SECURITY_GEN_AI_CONFIG_FILE,
88+
SECURITY_GEN_AI_CONFIG_FIELD
8689
);
8790
};
8891

89-
export const formatCurrentConfig = async (filePath: string) => {
90-
const config = await readFile(filePath, 'utf-8');
92+
/**
93+
* Returns command for manually working with secrets from `config.json`.
94+
* Format can be either 'vault-write' (for vault command) or 'env-var' (for environment variable).
95+
* Run this command and share with @kibana-ops via https://p.elstc.co to make updating secrets easier, or for pasting
96+
* custom configs into the BuildKite pipeline: https://buildkite.com/elastic/kibana-ess-security-solution-gen-ai-evals
97+
98+
* Alternatively, have @kibana-ops run the following to update the secrets for CI:
99+
*
100+
* node retrieve_secrets.js --vault siem-team
101+
* node upload_secrets.js --vault ci-prod
102+
*
103+
* @param format - The format of the command to return ('vault-write' or 'env-var')
104+
* @param vault - The vault to use (only applicable for 'vault-write' format)
105+
*/
106+
export const getCommand = async (
107+
format: 'vault-write' | 'env-var' = 'vault-write',
108+
vault: VaultType = 'ci-prod'
109+
) => {
110+
const config = await readFile(SECURITY_GEN_AI_CONFIG_FILE, 'utf-8');
91111
const asB64 = Buffer.from(config).toString('base64');
92-
// eslint-disable-next-line no-console
93-
console.log(asB64);
112+
113+
if (format === 'vault-write') {
114+
return `vault write ${getVaultPath(vault)} ${SECURITY_GEN_AI_CONFIG_FIELD}=${asB64}`;
115+
} else {
116+
return `${KIBANA_SECURITY_GEN_AI_CONFIG}=${asB64}`;
117+
}
94118
};
95119

120+
/**
121+
* Write generic value to vault from a file
122+
*
123+
* @param vault
124+
* @param filePath
125+
* @param field
126+
*/
96127
export const uploadToVault = async (vault: string, filePath: string, field: string) => {
97128
const config = await readFile(filePath, 'utf-8');
98129
const asB64 = Buffer.from(config).toString('base64');
@@ -103,69 +134,35 @@ export const uploadToVault = async (vault: string, filePath: string, field: stri
103134
});
104135
};
105136

106-
export const uploadConnectorConfigToVault = async () => {
107-
await uploadToVault(
108-
SECURITY_GEN_AI_VAULT_CONNECTORS,
109-
CONNECTOR_FILE,
110-
SECURITY_GEN_AI_CONNECTORS_FIELD
111-
);
112-
};
113-
114-
export const uploadLangsmithKeyToVault = async () => {
137+
/**
138+
* Read Security Gen AI secrets from `config.json` and upload to vault
139+
* @param vault
140+
*/
141+
export const uploadConfigToVault = async (vault: VaultType = 'siem-team') => {
115142
await uploadToVault(
116-
SECURITY_GEN_AI_VAULT_LANGSMITH,
117-
LANGSMITH_FILE,
118-
SECURITY_GEN_AI_LANGSMITH_FIELD
143+
getVaultPath(vault),
144+
SECURITY_GEN_AI_CONFIG_FILE,
145+
SECURITY_GEN_AI_CONFIG_FIELD
119146
);
120147
};
121148

122149
/**
123-
* FOR LOCAL USE ONLY! Export connectors and langsmith secrets from vault to env vars before manually
124-
* running evaluations. CI env vars are set by .buildkite/scripts/common/setup_job_env.sh
150+
* Returns parsed config from environment variable
125151
*/
126-
export const exportToEnvVars = async () => {
127-
const { stdout: connectors } = await execa(
128-
'vault',
129-
['read', `-field=${SECURITY_GEN_AI_CONNECTORS_FIELD}`, SECURITY_GEN_AI_VAULT_CONNECTORS],
130-
{
131-
cwd: REPO_ROOT,
132-
buffer: true,
133-
}
134-
);
135-
const { stdout: langsmithKey } = await execa(
136-
'vault',
137-
['read', `-field=${SECURITY_GEN_AI_LANGSMITH_FIELD}`, SECURITY_GEN_AI_VAULT_LANGSMITH],
138-
{
139-
cwd: REPO_ROOT,
140-
buffer: true,
141-
}
142-
);
143-
process.env[SECURITY_GEN_AI_CONNECTORS_ENV_VAR] = connectors;
144-
process.env[SECURITY_GEN_AI_LANGSMITH_KEY_ENV_VAR] = langsmithKey;
145-
};
146-
147-
export const loadConnectorsFromEnvVar = (): Record<string, AvailableConnector> => {
148-
const connectorsValue = process.env[SECURITY_GEN_AI_CONNECTORS_ENV_VAR];
149-
if (!connectorsValue) {
150-
return {};
152+
export const getSecurityGenAIConfigFromEnvVar = () => {
153+
const configValue = process.env[KIBANA_SECURITY_GEN_AI_CONFIG];
154+
if (!configValue) {
155+
throw new Error(`Environment variable ${KIBANA_SECURITY_GEN_AI_CONFIG} does not exist!`);
151156
}
152157

153-
let connectors: Record<string, AvailableConnector>;
158+
let config: typeof configSchema;
154159
try {
155-
connectors = JSON.parse(Buffer.from(connectorsValue, 'base64').toString('utf-8'));
160+
config = JSON.parse(Buffer.from(configValue, 'base64').toString('utf-8'));
156161
} catch (e) {
157162
throw new Error(
158-
`Error trying to parse value from ${SECURITY_GEN_AI_CONNECTORS_ENV_VAR} environment variable: ${e.message}`
163+
`Error trying to parse value from ${KIBANA_SECURITY_GEN_AI_CONFIG} environment variable: ${e.message}`
159164
);
160165
}
161-
return connectorsSchema.validate(connectors);
162-
};
163-
164-
export const loadLangSmithKeyFromEnvVar = (): string | undefined => {
165-
const langsmithKeyValue = process.env[SECURITY_GEN_AI_LANGSMITH_KEY_ENV_VAR];
166-
if (!langsmithKeyValue) {
167-
return undefined;
168-
}
169166

170-
return Buffer.from(langsmithKeyValue, 'base64').toString('utf-8').trim();
167+
return configSchema.validate(config);
171168
};

x-pack/test/security_solution_api_integration/scripts/genai/vault/retrieve_secrets.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,27 @@
66
*/
77

88
require('@kbn/babel-register').install();
9-
const { retrieveConnectorConfig, retrieveLangsmithKey } = require('./manage_secrets');
9+
const { retrieveConfigFromVault } = require('./manage_secrets');
10+
const minimist = require('minimist');
1011

11-
async function retrieveConfigs() {
12-
await retrieveConnectorConfig();
13-
await retrieveLangsmithKey();
12+
/**
13+
* Retrieves Security Gen AI secrets for testing from vault. By default, the 'siem-team' accessible
14+
* vault from secrets.elastic.co is used, but it can be overridden with the --vault parameter to use
15+
* the 'ci-prod' vault.
16+
*
17+
* @returns {Promise<void>}
18+
*/
19+
async function retrieveSecrets() {
20+
const argv = minimist(process.argv.slice(2));
21+
const vault = argv.vault || 'siem-team';
22+
23+
if (vault !== 'siem-team' && vault !== 'ci-prod') {
24+
console.error('Error: vault parameter must be either "siem-team" or "ci-prod"');
25+
process.exit(1);
26+
}
27+
28+
console.log(`Using ${vault} vault...`);
29+
await retrieveConfigFromVault(vault);
1430
}
1531

16-
retrieveConfigs();
32+
retrieveSecrets();

x-pack/test/security_solution_api_integration/scripts/genai/vault/upload_secrets.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,27 @@
66
*/
77

88
require('@kbn/babel-register').install();
9+
const { uploadConfigToVault } = require('./manage_secrets');
10+
const minimist = require('minimist');
911

10-
const { uploadConnectorConfigToVault, uploadLangsmithKeyToVault } = require('./manage_secrets');
12+
/**
13+
* Uploads Security Gen AI secrets for testing from local `config.json` to vault. By default, the 'siem-team' accessible
14+
* vault from secrets.elastic.co is used, but it can be overridden with the --vault parameter to use the 'ci-prod' vault.
15+
*
16+
* @returns {Promise<void>}
17+
*/
18+
async function uploadSecrets() {
19+
const argv = minimist(process.argv.slice(2));
20+
const vault = argv.vault || 'siem-team';
21+
22+
if (vault !== 'siem-team' && vault !== 'ci-prod') {
23+
console.error('Error: vault parameter must be either "siem-team" or "ci-prod"');
24+
process.exit(1);
25+
}
1126

12-
async function uploadConfigs() {
13-
await uploadConnectorConfigToVault();
14-
await uploadLangsmithKeyToVault();
27+
console.log(`Using ${vault} vault...`);
28+
await uploadConfigToVault(vault);
29+
console.log(`Secret upload complete!`);
1530
}
1631

17-
uploadConfigs();
32+
uploadSecrets();

0 commit comments

Comments
 (0)