Skip to content
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

clean up operator initialization code #2901

Merged
merged 5 commits into from
May 29, 2024
Merged

Conversation

flyth
Copy link
Member

@flyth flyth commented May 27, 2024

Previously, for image-based gadgets, operators would lazily be initialized by the gadget context. That made it difficult to forward the actual global configuration of operators. Since we didn't really use those in the past, it was not a big issue.

However, now that we're for example using image verification that can be enabled/disabled using parameters, we need to clean this up. Currently, the client decides whether image validation is done by sending the appropriate flag to the server. This is however insecure, as the client shouldn't have authority over that decision. We may later on allow (using another param/setting that can be enabled on the server) clients to override certain behavior, but in general the server should decide about the security features.

This PR moves the initialization to all our entry points for image-based gadgets and exports the parameters to be set there, if applicable.

This means:

  • cmd/common/oci.go exposes global operator params to client (or ig used in standalone mode)
  • pkg/gadget-service collects and exposes params using a function
  • cmd/ig/daemon.go uses the params exposed by the gadget-service
  • gadgettracermgr should also expose those params exposed by the gadget-service, this is however currently not handled in this PR (but maybe should also be added; using env variables on deployment maybe?)

Fixes #2891

Copy link
Member

@mauriciovasquezbernal mauriciovasquezbernal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for handling it.

gadgettracermgr should also expose those params exposed by the gadget-service, this is however currently not handled in this PR (but maybe should also be added; using env variables on deployment maybe?)

I think it can be handled once we have #2831 (cc @mqasimsarfraz)

I noticed that the order of the commits breaks the compilation for some of them, can it be fixed?

pkg/gadget-service/service.go Show resolved Hide resolved
@@ -89,6 +93,12 @@ func NewRunCommand(rootCmd *cobra.Command, runtime runtime.Runtime, hiddenColumn

ops := make([]operators.DataOperator, 0)
for _, op := range operators.GetDataOperators() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we have global parameters for layer operators? I suppose we'll need to add them later on.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not yet, but yeah, we should add them sooner or later.

pkg/gadget-service/service.go Outdated Show resolved Hide resolved
@flyth flyth force-pushed the michael/oci/fix-validate-settings branch 2 times, most recently from 3c9f4e7 to 87eb57a Compare May 29, 2024 14:51
flyth added 5 commits May 29, 2024 20:15
This change collects available operators when starting the service. Global operator
params can be retrieved through `GetOperatorMap()`.

Signed-off-by: Michael Friese <mfriese@microsoft.com>
This allows setting the eventBufferLength after creating the service. Will be used in
upcoming commits.

Signed-off-by: Michael Friese <mfriese@microsoft.com>
Signed-off-by: Michael Friese <mfriese@microsoft.com>
…mage-based gadgets

Signed-off-by: Michael Friese <mfriese@microsoft.com>
Operator initialization should be handled by the caller that is also creating the
gadget context, not the gadget context itself. This removes the old code and relies
on initialization taking place somewhere else.

Signed-off-by: Michael Friese <mfriese@microsoft.com>
@flyth flyth force-pushed the michael/oci/fix-validate-settings branch from 87eb57a to 6e250d5 Compare May 29, 2024 18:16
@flyth flyth merged commit 5b778c4 into main May 29, 2024
60 checks passed
@flyth flyth deleted the michael/oci/fix-validate-settings branch May 29, 2024 19:57
@flyth
Copy link
Member Author

flyth commented May 29, 2024

Thanks for the review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Initialize operators outside the gadget context
2 participants