-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Fleet] Add experimental package verification (server side) #135570
[Fleet] Add experimental package verification (server side) #135570
Conversation
@@ -60,6 +61,9 @@ const getHTTPResponseCode = (error: IngestManagerError): number => { | |||
if (error instanceof PackageUnsupportedMediaTypeError) { | |||
return 415; // Unsupported Media Type | |||
} | |||
if (error instanceof PackageFailedVerificationError) { | |||
return 422; // Unprocessable Entity |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about this response code for when a package fails verification, I was also tempted by Forbidden or Bad Request
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
400 Bad Request seems most appropriate here. 422 is usually more applicable when creating/updating some resource and the request body fails some validation check in my experience.
@@ -5,7 +5,7 @@ | |||
* 2.0. | |||
*/ | |||
|
|||
import type { AssetParts, InstallSource } from '../../../../common/types'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
installSource was unused
if (verificationResult) { | ||
savedObjectUpdate = { | ||
...savedObjectUpdate, | ||
verification_key_id: null, // unset any previous verification key id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is a bit messy, if for example I install a packge and it is verified, then I reinstall it and it is "unknown", we need to unset the verification key ID, I've done this by nulling it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense to me
@@ -256,32 +282,65 @@ function ensureContentType(archivePath: string) { | |||
return contentType; | |||
} | |||
|
|||
export async function ensureCachedArchiveInfo( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this function was unused
Pinging @elastic/fleet (Team:Fleet) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
security_solution bits are 👌
eb62b01
to
e61cebd
Compare
const archiveEntryCache: Map<ArchiveEntry['path'], ArchiveEntry['buffer']> = new Map(); | ||
export const getArchiveEntry = (key: string) => archiveEntryCache.get(key); | ||
export const setArchiveEntry = (key: string, value: Buffer) => archiveEntryCache.set(key, value); | ||
export const hasArchiveEntry = (key: string) => archiveEntryCache.has(key); | ||
export const clearArchiveEntries = () => archiveEntryCache.clear(); | ||
export const deleteArchiveEntry = (key: string) => archiveEntryCache.delete(key); | ||
|
||
const verificationResultCache: Map<SharedKeyString, PackageVerificationResult> = new Map(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am wondering if we should avoid this cache pattern at some point it's not going to scale (it's probably more problematic for archiveEntryCache
) do we really need to cache things how often are computing the verification?
If we really need to cache it it's probably better to use an LRU cache with a max size
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked into removing caching, unfortunately as we do not cache the full archive only the sub-files this wasn't possible. I agree that the way that we cache isn't great, I think changing the way we cache should be done as a seperate ticket which I have raised here: #135790
58ea0e8
to
4236cbb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple naming suggestions and one clarification around log level. Requested changes are nonblocking though, so marking as approved.
if (verificationResult) { | ||
savedObjectUpdate = { | ||
...savedObjectUpdate, | ||
verification_key_id: null, // unset any previous verification key id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense to me
x-pack/plugins/fleet/server/services/epm/packages/package_verification.ts
Outdated
Show resolved
Hide resolved
x-pack/plugins/fleet/server/services/epm/packages/package_verification.ts
Show resolved
Hide resolved
4236cbb
to
36a17de
Compare
💚 Build SucceededMetrics [docs]Public APIs missing comments
Async chunks
Page load bundle
Saved Objects .kibana field count
History
To update your PR or re-run it, just comment with: cc @hop-dev |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onboarding-lifecycle-management team files look good to me
Summary
Part of #133822.
Add package verification on package install. Verify a package signature if:
packageVerification
xpack.fleet.packageVerification.gpgKeyPath
Otherwise package verification status is always set to "unknown".
Summary of changes
packageVerification
, disabled by defaultverification_status
-unknown | verified | unverified
verification_key_id
- present if status is not unknown, they id of the key used to do verification.force: true
then install will proceed even if verification failsTesting steps
docker run -p 8080:8080 docker.elastic.co/observability-ci/package-registry/distribution:PR-463
xpack.fleet.registryUrl: http://localhost:8080
curl https://artifacts.elastic.co/GPG-KEY-elasticsearch -o /tmp/GPG-KEY-elasticsearch
xpack.fleet.packageVerification.gpgKeyPath: /tmp/GPG-KEY-elasticsearch
NOT_THE_ELASTIC_KEY.txt
Test scenarios:
verification_key_id
should bed27d666cd88e42b4
andverification_status
should beverified
verification_key_id
should bed27d666cd88e42b4
andverification_status
should beunverified
verification_key_id
should not be set andverification_status
should beunknown
verification_key_id
should not be set andverification_status
should beunknown
verification_key_id
should not be set andverification_status
should beunknown
Checklist
Delete any items that are not applicable to this PR.