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

new(cmd/driver): support user provided headers option for driver download #428

Merged
merged 2 commits into from
Feb 9, 2024

Conversation

toamto94
Copy link
Contributor

@toamto94 toamto94 commented Feb 8, 2024

What type of PR is this?

Uncomment one (or more) /kind <> lines:

/kind bug

/kind cleanup

/kind design

/kind documentation

/kind failing-test

/kind feature

/kind flaky-test

Any specific area of the project related to this PR?

Uncomment one (or more) /area <> lines:

/area library

/area cli

/area tests

/area examples

What this PR does / why we need it:
Added option to add headers in the http GET request for the driver download

Which issue(s) this PR fixes:
Option had been possible via environment variables in the script based download but is not possible anymore since the falcoctl migration

Fixes #426

Special notes for your reviewer:
example flag (for testing):
--http-headers="x-emc-namespace: default,Proxy-Authenticate: Basic"

@poiana
Copy link
Contributor

poiana commented Feb 8, 2024

Welcome @toamto94! It looks like this is your first PR to falcosecurity/falcoctl 🎉

@poiana poiana requested a review from loresuso February 8, 2024 21:11
@poiana poiana added the size/S label Feb 8, 2024
@FedeDP
Copy link
Contributor

FedeDP commented Feb 8, 2024

Thanks for this PR! I'll give it a look tomorrow!
/assign

@FedeDP
Copy link
Contributor

FedeDP commented Feb 9, 2024

/milestone v0.7.2

@poiana poiana added this to the v0.7.2 milestone Feb 9, 2024
@FedeDP FedeDP mentioned this pull request Feb 9, 2024
@FedeDP
Copy link
Contributor

FedeDP commented Feb 9, 2024

To fix linting: make sure to split the line:

driverdistro.Download(ctx, d, o.Printer.WithWriter(&buf), kr, o.Driver.Name, o.Driver.Type, o.Driver.Version, o.Driver.Repos, o.HTTPHeaders)

Into multiple lines ;)

FedeDP
FedeDP previously approved these changes Feb 9, 2024
Copy link
Contributor

@FedeDP FedeDP left a comment

Choose a reason for hiding this comment

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

/approve

@poiana poiana added the lgtm label Feb 9, 2024
@poiana
Copy link
Contributor

poiana commented Feb 9, 2024

LGTM label has been added.

Git tree hash: 1b9a401266077b97a5b366b061fa90ac478b163c

@poiana poiana added the approved label Feb 9, 2024
@FedeDP
Copy link
Contributor

FedeDP commented Feb 9, 2024

Can you run make fmt to fix linting? Thanks!

}

type driverInstallOptions struct {
*options.Common
*options.Driver
Download bool
Compile bool
Download: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

bool ?

@FedeDP FedeDP changed the title Fb header options new(cmd/driver): support user provided headers option for driver download Feb 9, 2024
@toamto94
Copy link
Contributor Author

toamto94 commented Feb 9, 2024 via email

@FedeDP
Copy link
Contributor

FedeDP commented Feb 9, 2024

I'd say we are quite ready; you just miss to run make fmt and perhaps i'd squash everything in a single commit :)

Copy link
Contributor Author

@toamto94 toamto94 left a comment

Choose a reason for hiding this comment

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

My IDE is messing around, I am sorry for the confusion

@toamto94
Copy link
Contributor Author

toamto94 commented Feb 9, 2024

I'd say we are quite ready; you just miss to run make fmt and perhaps i'd squash everything in a single commit :)

Alright, let me get things right now. Sorry for the confusion :D

@toamto94
Copy link
Contributor Author

toamto94 commented Feb 9, 2024

Oh you need to also bump helper message here: https://github.com/falcosecurity/falcoctl/blob/main/cmd/driver/install/install_test.go#L29 Sorry, forgot about it!

Ok no problem!

@toamto94
Copy link
Contributor Author

toamto94 commented Feb 9, 2024

ah need to sign of. sec

@toamto94
Copy link
Contributor Author

toamto94 commented Feb 9, 2024

Aah wait let me fix this

Signed-off-by: Tom Müller <[email protected]>

fixed linting for http-header option

fixed syntax error in driver download options

Signed-off-by: Tom Müller <[email protected]>

fixed syntax error in driver download options

Signed-off-by: Tom Müller <[email protected]>

fixed syntax error in driver download options

Signed-off-by: Tom Müller <[email protected]>

fixed linting for driver download options

Signed-off-by: Tom Müller <[email protected]>

moved header injection below error check

No need to inject a header into an empty request

Signed-off-by: Tom Müller <[email protected]>

fixed linting for Download function call

Line was too long so needed to be split in multiple lines

Signed-off-by: Tom Müller <[email protected]>

rearranged http-headers flag

http-headers flag moved to driverDownloadOptions

Signed-off-by: Tom Müller <[email protected]>

added leading space trimming for header keys

Added leading space trimming for header keys in order to make the function more robust

Signed-off-by: Tom Müller <[email protected]>

forwarding of the headers variable into the http GET request

Added functionality which parses the comma separated string of headers which were provided with the --http-headers flag to the Download function. The headers are unpacked and injected into the http GET request.

Signed-off-by: Tom Müller <[email protected]>

added header options for driver download

Added header options for the driver download via http GET. Headers should be provided via the --http-headers flag as a comma separated string (e.g. --http-headers="x-emc-namespace:default")

Signed-off-by: Tom Müller <[email protected]>
@toamto94
Copy link
Contributor Author

toamto94 commented Feb 9, 2024

Fighting with git is always fun :D

@toamto94
Copy link
Contributor Author

toamto94 commented Feb 9, 2024

Failed. What exactly needs to be done there @FedeDP

@toamto94 toamto94 force-pushed the fb_header_options branch 4 times, most recently from 8ab30b1 to 1676aed Compare February 9, 2024 13:16
@toamto94
Copy link
Contributor Author

toamto94 commented Feb 9, 2024

Don't seem to work hm. Any idea what I am doing wrong?

@FedeDP
Copy link
Contributor

FedeDP commented Feb 9, 2024

You can quickly locally test using go test ./cmd/driver/... ; am not sure about what's failing though :(

@toamto94
Copy link
Contributor Author

toamto94 commented Feb 9, 2024

You can quickly locally test using go test ./cmd/driver/... ; am not sure about what's failing though :(

Ah alright! Thx for the tip

@FedeDP
Copy link
Contributor

FedeDP commented Feb 9, 2024

  --http-headers string     Optional comma-separated list of headers for the http GET request (e.g. --http-headers="x-emc-namespace: default,Proxy-Authenticate: Basic"). Not necessary if default repo is used
      --http-insecure           Whether you want to allow insecure downloads or not

--http-headers should be above --http-insecure :D

@@ -37,6 +37,7 @@ Flags:
--download Whether to enable download of prebuilt drivers (default true)
-h, --help help for install
--http-insecure Whether you want to allow insecure downloads or not
--http-headers string Optional comma-separated list of headers for the http GET request (e.g. --http-headers='x-emc-namespace: default,Proxy-Authenticate: Basic'). Not necessary if default repo is used
Copy link
Contributor

Choose a reason for hiding this comment

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

Here, --http-headers should be before --http-insecure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Awesome!! Thank you very much! :)

Signed-off-by: Tom Müller <[email protected]>
Copy link
Contributor

@FedeDP FedeDP left a comment

Choose a reason for hiding this comment

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

/approve

@poiana poiana added the lgtm label Feb 9, 2024
@poiana
Copy link
Contributor

poiana commented Feb 9, 2024

LGTM label has been added.

Git tree hash: d40677f83658c1e4257ccbcc645000c3189d4d3d

@poiana
Copy link
Contributor

poiana commented Feb 9, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: FedeDP, toamto94

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@poiana poiana merged commit e03c73c into falcosecurity:main Feb 9, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Option to add headers to the http request of falcoctl driver install command
3 participants