Skip to content

Commit 27c5ca4

Browse files
committed
Allowing global auth headers
1 parent 19e2470 commit 27c5ca4

File tree

22 files changed

+240
-100
lines changed

22 files changed

+240
-100
lines changed

src/platform/packages/shared/kbn-connector-specs/README.md

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ export const MyConnector: SingleFileConnectorDefinition = {
5757
supportedFeatureIds: ['workflows'],
5858
},
5959

60-
authTypes: ['bearer'],
60+
auth: {
61+
types: ['bearer'],
62+
headers: {
63+
'Content-Type': 'application/json',
64+
}
65+
},
6166

6267
schema: z.object({
6368
url: z.string().url().describe('API URL'),
@@ -155,17 +160,23 @@ are specified, defaults to no authentication. Can also specify a custom schema f
155160
which will be used in place of the default
156161

157162
```typescript
158-
authTypes: [
159-
// use basic auth type with the default schema
160-
'basic',
161-
// use api_key_header auth type with a custom header field
162-
{
163-
type: 'api_key_header',
164-
defaults: {
165-
headerField: 'custom-api-key-field'
163+
auth: {
164+
types: [
165+
// use basic auth type with the default schema
166+
'basic',
167+
// use api_key_header auth type with a custom header field
168+
{
169+
type: 'api_key_header',
170+
defaults: {
171+
headerField: 'custom-api-key-field'
172+
}
166173
}
174+
],
175+
// optionally add headers that will be added to all requests
176+
headers: {
177+
'Content-Type': 'application/json',
167178
}
168-
]
179+
}
169180
```
170181

171182
### Schema

src/platform/packages/shared/kbn-connector-specs/src/connector_spec.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import type { z } from '@kbn/zod/v4';
2525
import type { Logger } from '@kbn/logging';
2626
import type { LicenseType } from '@kbn/licensing-types';
27-
import type { AxiosInstance } from 'axios';
27+
import type { AxiosHeaderValue, AxiosInstance } from 'axios';
2828

2929
export { UISchemas } from './connector_spec_ui';
3030

@@ -239,7 +239,10 @@ export interface AuthTypeDef {
239239
export interface ConnectorSpec {
240240
metadata: ConnectorMetadata;
241241

242-
authTypes?: Array<string | AuthTypeDef>;
242+
auth?: {
243+
types: Array<string | AuthTypeDef>;
244+
headers?: Record<string, AxiosHeaderValue>;
245+
};
243246

244247
// Single unified schema for all connector fields (config + secrets)
245248
// Mark sensitive fields with withUIMeta({ sensitive: true })

src/platform/packages/shared/kbn-connector-specs/src/lib/generate_secrets_schema_from_spec.test.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,28 @@ import { generateSecretsSchemaFromSpec } from './generate_secrets_schema_from_sp
1212

1313
describe('generateSecretsSchemaFromSpec', () => {
1414
test('correctly generates schemas for array of auth types', () => {
15-
const schema = generateSecretsSchemaFromSpec([
16-
'none',
17-
'basic',
18-
'bearer',
19-
'oauth_client_credentials',
20-
{
21-
type: 'api_key_header',
22-
defaults: {
23-
headerField: 'custom-api-key-field',
15+
const schema = generateSecretsSchemaFromSpec({
16+
types: [
17+
'none',
18+
'basic',
19+
'bearer',
20+
'oauth_client_credentials',
21+
{
22+
type: 'api_key_header',
23+
defaults: {
24+
headerField: 'custom-api-key-field',
25+
},
2426
},
27+
],
28+
headers: {
29+
'X-Custom-Header': 'CustomValue',
2530
},
26-
]);
31+
});
2732
expect(z.toJSONSchema(schema)).toMatchSnapshot();
2833
});
2934

3035
test('returns empty object schema when no auth types are provided', () => {
31-
const schema = generateSecretsSchemaFromSpec([]);
36+
const schema = generateSecretsSchemaFromSpec({ types: [] });
3237
expect(z.toJSONSchema(schema)).toMatchSnapshot();
3338
});
3439
});

src/platform/packages/shared/kbn-connector-specs/src/lib/generate_secrets_schema_from_spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import { z } from '@kbn/zod/v4';
1111
import type { ConnectorSpec } from '../connector_spec';
1212
import { getSchemaForAuthType } from '.';
1313

14-
export const generateSecretsSchemaFromSpec = (authTypes: ConnectorSpec['authTypes']) => {
14+
export const generateSecretsSchemaFromSpec = (authSpec: ConnectorSpec['auth']) => {
1515
const secretSchemas: z.core.$ZodTypeDiscriminable[] = [];
16-
for (const authType of authTypes || []) {
16+
for (const authType of authSpec?.types || []) {
1717
secretSchemas.push(getSchemaForAuthType(authType));
1818
}
1919
return secretSchemas.length > 0

src/platform/packages/shared/kbn-connector-specs/src/specs/abuseipdb.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,9 @@ export const AbuseIPDBConnector: ConnectorSpec = {
3131
supportedFeatureIds: ['workflows'],
3232
},
3333

34-
authTypes: [
35-
{
36-
type: 'api_key_header',
37-
defaults: {
38-
headerField: 'Key',
39-
},
40-
},
41-
],
34+
auth: {
35+
types: [{ type: 'api_key_header', defaults: { headerField: 'Key' } }],
36+
},
4237

4338
actions: {
4439
checkIp: {

src/platform/packages/shared/kbn-connector-specs/src/specs/alienvault_otx.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,9 @@ export const AlienVaultOTXConnector: ConnectorSpec = {
3131
supportedFeatureIds: ['workflows'],
3232
},
3333

34-
authTypes: [
35-
{
36-
type: 'api_key_header',
37-
defaults: {
38-
headerField: 'X-OTX-API-KEY',
39-
},
40-
},
41-
],
34+
auth: {
35+
types: [{ type: 'api_key_header', defaults: { headerField: 'X-OTX-API-KEY' } }],
36+
},
4237

4338
actions: {
4439
getIndicator: {

src/platform/packages/shared/kbn-connector-specs/src/specs/greynoise.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,9 @@ export const GreyNoiseConnector: ConnectorSpec = {
3131
supportedFeatureIds: ['workflows'],
3232
},
3333

34-
authTypes: [
35-
{
36-
type: 'api_key_header',
37-
defaults: {
38-
headerField: 'key',
39-
},
40-
},
41-
],
34+
auth: {
35+
types: [{ type: 'api_key_header', defaults: { headerField: 'key' } }],
36+
},
4237

4338
actions: {
4439
getIpContext: {

src/platform/packages/shared/kbn-connector-specs/src/specs/shodan.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,9 @@ export const ShodanConnector: ConnectorSpec = {
3131
supportedFeatureIds: ['workflows'],
3232
},
3333

34-
authTypes: [
35-
{
36-
type: 'api_key_header',
37-
defaults: {
38-
headerField: 'X-Api-Key',
39-
},
40-
},
41-
],
34+
auth: {
35+
types: [{ type: 'api_key_header', defaults: { headerField: 'X-Api-Key' } }],
36+
},
4237

4338
actions: {
4439
searchHosts: {

src/platform/packages/shared/kbn-connector-specs/src/specs/urlvoid.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,9 @@ export const URLVoidConnector: ConnectorSpec = {
3232
supportedFeatureIds: ['workflows'],
3333
},
3434

35-
authTypes: [
36-
{
37-
type: 'api_key_header',
38-
defaults: {
39-
headerField: 'X-Api-Key',
40-
},
41-
},
42-
],
35+
auth: {
36+
types: [{ type: 'api_key_header', defaults: { headerField: 'X-Api-Key' } }],
37+
},
4338

4439
actions: {
4540
scanDomain: {

src/platform/packages/shared/kbn-connector-specs/src/specs/virustotal.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,15 @@ export const VirusTotalConnector: ConnectorSpec = {
3131
supportedFeatureIds: ['workflows'],
3232
},
3333

34-
authTypes: [
35-
{
36-
type: 'api_key_header',
37-
defaults: {
38-
headerField: 'x-apikey',
34+
auth: {
35+
types: [
36+
{
37+
type: 'api_key_header',
38+
defaults: { headerField: 'x-apikey' },
39+
overrides: { meta: { 'x-apikey': { placeholder: 'vt-...' } } },
3940
},
40-
overrides: {
41-
meta: {
42-
'x-apikey': { placeholder: 'vt-...' },
43-
},
44-
},
45-
},
46-
],
41+
],
42+
},
4743

4844
actions: {
4945
scanFileHash: {

0 commit comments

Comments
 (0)