[FLEET] Increase asset size limit for installing ML model packages (#115890)

* update size limit for assets to 50mb

* use different size limit for ml model

* add byte constant for clarity
This commit is contained in:
Melissa Alvarez 2021-10-21 16:19:17 -04:00 committed by GitHub
parent ce546998a4
commit 29e5a3a37f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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;
@ -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}`
);
}