Skip to content

Commit

Permalink
[FLEET] Increase asset size limit for installing ML model packages (#…
Browse files Browse the repository at this point in the history
…115890)

* update size limit for assets to 50mb

* use different size limit for ml model

* add byte constant for clarity
  • Loading branch information
alvarezmelissa87 authored Oct 21, 2021
1 parent ce54699 commit 29e5a3a
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions x-pack/plugins/fleet/server/services/epm/archive/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ import { getArchiveEntry, setArchiveEntry, setArchiveFilelist, setPackageInfo }
import type { ArchiveEntry } from './index';
import { parseAndVerifyPolicyTemplates, parseAndVerifyStreams } from './validation';

const ONE_BYTE = 1024 * 1024;
// could be anything, picked this from https://github.com/elastic/elastic-agent-client/issues/17
const MAX_ES_ASSET_BYTES = 4 * 1024 * 1024;
const MAX_ES_ASSET_BYTES = 4 * ONE_BYTE;
// Updated to accomodate larger package size in some ML model packages
const ML_MAX_ES_ASSET_BYTES = 50 * ONE_BYTE;

export interface PackageAsset {
package_name: string;
Expand Down Expand Up @@ -64,15 +67,20 @@ export async function archiveEntryToESDocument(opts: {
const bufferIsBinary = await isBinaryFile(buffer);
const dataUtf8 = bufferIsBinary ? '' : buffer.toString('utf8');
const dataBase64 = bufferIsBinary ? buffer.toString('base64') : '';
const currentMaxAssetBytes = path.includes('ml_model')
? ML_MAX_ES_ASSET_BYTES
: MAX_ES_ASSET_BYTES;

// validation: filesize? asset type? anything else
if (dataUtf8.length > MAX_ES_ASSET_BYTES) {
throw new Error(`File at ${path} is larger than maximum allowed size of ${MAX_ES_ASSET_BYTES}`);
if (dataUtf8.length > currentMaxAssetBytes) {
throw new Error(
`File at ${path} is larger than maximum allowed size of ${currentMaxAssetBytes}`
);
}

if (dataBase64.length > MAX_ES_ASSET_BYTES) {
if (dataBase64.length > currentMaxAssetBytes) {
throw new Error(
`After base64 encoding file at ${path} is larger than maximum allowed size of ${MAX_ES_ASSET_BYTES}`
`After base64 encoding file at ${path} is larger than maximum allowed size of ${currentMaxAssetBytes}`
);
}

Expand Down

0 comments on commit 29e5a3a

Please sign in to comment.