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

[Feature] Secondary fallback for package signature verification #3453

Merged
merged 12 commits into from
Oct 2, 2023

Conversation

michalpristas
Copy link
Contributor

What does this PR do?

This PR adds a capability to check for fleet server hosted PGP as the last resort in case elastic artifact API is unavailable.
Fleet server will host this PGP per version. any snapshot flags or other version qualifiers are ignored.

Why is it important?

Add ability to upgrade securiely in Air gapped environment where fleet server is only reachable URI.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in ./changelog/fragments using the changelog tool
  • I have added an integration test or an E2E test

Fixes: #3264

@michalpristas michalpristas added enhancement New feature or request Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team Team:Elastic-Agent Label for the Agent team backport-v8.10.0 Automated backport with mergify labels Sep 21, 2023
@michalpristas michalpristas self-assigned this Sep 21, 2023
@elasticmachine
Copy link
Contributor

elasticmachine commented Sep 21, 2023

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2023-10-02T17:49:57.684+0000

  • Duration: 26 min 55 sec

Test stats 🧪

Test Results
Failed 0
Passed 6465
Skipped 59
Total 6524

💚 Flaky test report

Tests succeeded.

🤖 GitHub comments

Expand to view the GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • /package : Generate the packages.

  • run integration tests : Run the Elastic Agent Integration tests.

  • run end-to-end tests : Generate the packages and run the E2E Tests.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@elasticmachine
Copy link
Contributor

elasticmachine commented Sep 21, 2023

🌐 Coverage report

Name Metrics % (covered/total) Diff
Packages 98.78% (81/82) 👍
Files 66.221% (198/299) 👍 0.334
Classes 65.343% (362/554) 👍
Methods 52.811% (1146/2170) 👍 0.114
Lines 38.45% (13073/34000) 👍 0.108
Conditionals 100.0% (0/0) 💚

@michalpristas michalpristas marked this pull request as ready for review September 25, 2023 13:17
@michalpristas michalpristas requested a review from a team as a code owner September 25, 2023 13:17
@elasticmachine
Copy link
Contributor

Pinging @elastic/elastic-agent-control-plane (Team:Elastic-Agent-Control-Plane)

Copy link
Member

@pchila pchila left a comment

Choose a reason for hiding this comment

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

Aside from one specific comment in the code, why don't we have an abstraction over the available PGP keys we can use for validating ?

Something like a PGPKeyProvider that would return all the available PGP keys (the builtin one, the one retrieved from internet, the one from fleet, the one from command line...) and return the available ones so that the verifier can try them in order to validate the software?

Wouldn't that make this also easier to test ?

Comment on lines +250 to +253
if strings.HasPrefix(host, string(ProtocolHTTPS)+"://") ||
strings.HasPrefix(host, string(ProtocolHTTP)+"://") {
return host + "/" + c.config.Path
}
Copy link
Member

Choose a reason for hiding this comment

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

Nit: wouldn't at this point be better to use a url.Parse to extract the various parts and then url.JoinPath the configured path ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i see where you're heading. don't have benchmarks but for this simple case it feels like parse and join (which does another fancy things internally) like overkill.

Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering why have you added this extra case. Is it a valid case the protocol on host to be optional?

Normally I'd agree with Paolo, but as this function does not return an error and url.Parse returns one, it'd not be possible to handle the error here. Therefore, I like how you did it.

Copy link
Member

@AndersonQ AndersonQ left a comment

Choose a reason for hiding this comment

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

I don't see any blocker, just a few suggestions

internal/pkg/agent/application/upgrade/step_download.go Outdated Show resolved Hide resolved
internal/pkg/agent/application/upgrade/step_download.go Outdated Show resolved Hide resolved
Comment on lines +250 to +253
if strings.HasPrefix(host, string(ProtocolHTTPS)+"://") ||
strings.HasPrefix(host, string(ProtocolHTTP)+"://") {
return host + "/" + c.config.Path
}
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering why have you added this extra case. Is it a valid case the protocol on host to be optional?

Normally I'd agree with Paolo, but as this function does not return an error and url.Parse returns one, it'd not be possible to handle the error here. Therefore, I like how you did it.

@michalpristas michalpristas enabled auto-merge (squash) October 2, 2023 17:51
@elastic-sonarqube
Copy link

@michalpristas michalpristas merged commit cdca211 into elastic:main Oct 2, 2023
11 checks passed
mergify bot pushed a commit that referenced this pull request Oct 2, 2023
Adds a capability to check for fleet server hosted PGP as the last resort in case elastic artifact API is unavailable.
Fleet server will host this PGP per version. any snapshot flags or other version qualifiers are ignored.

(cherry picked from commit cdca211)
michalpristas added a commit that referenced this pull request Oct 3, 2023
… (#3497)

Adds a capability to check for fleet server hosted PGP as the last resort in case elastic artifact API is unavailable.
Fleet server will host this PGP per version. any snapshot flags or other version qualifiers are ignored.

(cherry picked from commit cdca211)

Co-authored-by: Michal Pristas <[email protected]>
pchila added a commit to pchila/elastic-agent that referenced this pull request Oct 4, 2023
pchila added a commit to pchila/elastic-agent that referenced this pull request Oct 4, 2023
cmacknz pushed a commit that referenced this pull request Oct 4, 2023
cmacknz pushed a commit that referenced this pull request Oct 4, 2023
michalpristas added a commit to michalpristas/elastic-agent that referenced this pull request Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-v8.10.0 Automated backport with mergify enhancement New feature or request Team:Elastic-Agent Label for the Agent team Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GPG key - Add a second fallback URL
4 participants