mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
fix headers in Fleet
This commit is contained in:
parent
0831ef0b6d
commit
94470547ae
11 changed files with 29 additions and 16 deletions
|
@ -51,7 +51,7 @@ export class ElasticsearchAdapter implements ElasticsearchAdapterType {
|
|||
}
|
||||
|
||||
if (user.kind === 'authenticated') {
|
||||
return await callWithRequest({ headers: user[internalAuthData] }, endpoint, params);
|
||||
return await callWithRequest(user[internalAuthData], endpoint, params);
|
||||
}
|
||||
|
||||
throw new Error('Elastic search call is not implemented for unauthenticated user');
|
||||
|
|
|
@ -43,7 +43,7 @@ export class HapiFrameworkAdapter {
|
|||
return isAuthenticated
|
||||
? {
|
||||
kind: 'authenticated',
|
||||
[internalAuthData]: request.headers,
|
||||
[internalAuthData]: request,
|
||||
}
|
||||
: {
|
||||
kind: 'unauthenticated',
|
||||
|
|
|
@ -39,9 +39,7 @@ export class SODatabaseAdapter implements SODatabaseAdapterType {
|
|||
|
||||
private getClient(user: FrameworkUser) {
|
||||
if (user.kind === 'authenticated') {
|
||||
return this.savedObject.getScopedSavedObjectsClient({
|
||||
headers: user[internalAuthData],
|
||||
});
|
||||
return this.savedObject.getScopedSavedObjectsClient(user[internalAuthData]);
|
||||
}
|
||||
|
||||
if (user.kind === 'internal') {
|
||||
|
|
|
@ -51,7 +51,7 @@ export class ApiKeyLib implements Interface<ApiKeyLibType> {
|
|||
user: FrameworkUser
|
||||
): Promise<EnrollmentApiKeyVerificationResponse> {
|
||||
if (user.kind === 'authenticated') {
|
||||
const apiKeyHeader = user[internalAuthData].authorization.split(' ')[1];
|
||||
const apiKeyHeader = user[internalAuthData].headers.authorization.split(' ')[1];
|
||||
const apiKey = Buffer.from(apiKeyHeader, 'base64')
|
||||
.toString('utf8')
|
||||
.split(':')[1];
|
||||
|
@ -76,7 +76,7 @@ export class ApiKeyLib implements Interface<ApiKeyLibType> {
|
|||
user: FrameworkUser<any>
|
||||
): Promise<AccessApiKeyVerificationResponse> {
|
||||
if (user.kind === 'authenticated') {
|
||||
const apiKeyHeader = user[internalAuthData].authorization.split(' ')[1];
|
||||
const apiKeyHeader = user[internalAuthData].headers.authorization.split(' ')[1];
|
||||
const [apiKeyId, apiKey] = Buffer.from(apiKeyHeader, 'base64')
|
||||
.toString('utf8')
|
||||
.split(':');
|
||||
|
|
|
@ -23,9 +23,11 @@ function getUser(apiKey?: string, apiKeyId?: string) {
|
|||
return ({
|
||||
kind: 'authenticated',
|
||||
[internalAuthData]: {
|
||||
authorization: `ApiKey ${Buffer.from(`${apiKeyId || 'key_id'}:${apiKey}`).toString(
|
||||
'base64'
|
||||
)}`,
|
||||
headers: {
|
||||
authorization: `ApiKey ${Buffer.from(`${apiKeyId || 'key_id'}:${apiKey}`).toString(
|
||||
'base64'
|
||||
)}`,
|
||||
},
|
||||
},
|
||||
} as unknown) as FrameworkUser;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,9 @@ function getUser(): FrameworkUser {
|
|||
return ({
|
||||
kind: 'authenticated',
|
||||
[internalAuthData]: {
|
||||
authorization: `Basic ${Buffer.from(`elastic:changeme`).toString('base64')}`,
|
||||
headers: {
|
||||
authorization: `Basic ${Buffer.from(`elastic:changeme`).toString('base64')}`,
|
||||
},
|
||||
},
|
||||
} as unknown) as FrameworkUser;
|
||||
}
|
||||
|
@ -33,7 +35,9 @@ function getUserForApiKey(apiKey: { id: string; api_key: string }) {
|
|||
return {
|
||||
kind: 'authenticated',
|
||||
[internalAuthData]: {
|
||||
authorization: `ApiKey ${apiKeyToString(apiKey)}`,
|
||||
headers: {
|
||||
authorization: `ApiKey ${apiKeyToString(apiKey)}`,
|
||||
},
|
||||
},
|
||||
} as FrameworkUser;
|
||||
}
|
||||
|
|
|
@ -183,7 +183,7 @@ export class ApiKeyLib {
|
|||
throw new Error('Error must provide an authenticated user');
|
||||
}
|
||||
|
||||
const authorizationHeader = user[internalAuthData].authorization;
|
||||
const authorizationHeader = user[internalAuthData].headers.authorization;
|
||||
|
||||
if (!authorizationHeader) {
|
||||
throw new Error('Authorization header must be set');
|
||||
|
|
|
@ -60,6 +60,9 @@ export const mappings = {
|
|||
name: {
|
||||
type: 'keyword',
|
||||
},
|
||||
type: {
|
||||
type: 'keyword',
|
||||
},
|
||||
api_key: {
|
||||
type: 'binary',
|
||||
},
|
||||
|
|
|
@ -22,7 +22,9 @@ describe('AgentsEventsRepository', () => {
|
|||
return ({
|
||||
kind: 'authenticated',
|
||||
[internalAuthData]: {
|
||||
authorization: `Basic ${Buffer.from(`elastic:changeme`).toString('base64')}`,
|
||||
headers: {
|
||||
authorization: `Basic ${Buffer.from(`elastic:changeme`).toString('base64')}`,
|
||||
},
|
||||
},
|
||||
} as unknown) as FrameworkUser;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,9 @@ describe('AgentsRepository', () => {
|
|||
return ({
|
||||
kind: 'authenticated',
|
||||
[internalAuthData]: {
|
||||
authorization: `Basic ${Buffer.from(`elastic:changeme`).toString('base64')}`,
|
||||
headers: {
|
||||
authorization: `Basic ${Buffer.from(`elastic:changeme`).toString('base64')}`,
|
||||
},
|
||||
},
|
||||
} as unknown) as FrameworkUser;
|
||||
}
|
||||
|
|
|
@ -40,7 +40,9 @@ describe('Enrollment api key Repository', () => {
|
|||
return ({
|
||||
kind: 'authenticated',
|
||||
[internalAuthData]: {
|
||||
authorization: `Basic ${Buffer.from(`elastic:changeme`).toString('base64')}`,
|
||||
headers: {
|
||||
authorization: `Basic ${Buffer.from(`elastic:changeme`).toString('base64')}`,
|
||||
},
|
||||
},
|
||||
} as unknown) as FrameworkUser;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue