Skip to content

Fix signature verification using the upgrade command with the --source-uri flag for fleet-managed agents#11826

Merged
michel-laterman merged 2 commits intoelastic:mainfrom
michel-laterman:bug/fleet-upgrade-command-source-uri-asc
Dec 22, 2025
Merged

Fix signature verification using the upgrade command with the --source-uri flag for fleet-managed agents#11826
michel-laterman merged 2 commits intoelastic:mainfrom
michel-laterman:bug/fleet-upgrade-command-source-uri-asc

Conversation

@michel-laterman
Copy link
Contributor

What does this PR do?

Fix PGP verification to use the .asc file located in the dir specified by --source-uri when upgrading a fleet-managed agent.

Why is it important?

Upgrading using a local source currently requires a work-around.

Checklist

  • I have read and understood the pull request guidelines of this project.
  • 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

Disruptive User Impact

N/A

Related issues

@michel-laterman michel-laterman added bug Something isn't working Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team backport-active-all Automated backport with mergify to all the active branches labels Dec 15, 2025
@michel-laterman michel-laterman force-pushed the bug/fleet-upgrade-command-source-uri-asc branch 2 times, most recently from b8f90c8 to dfc42fa Compare December 17, 2025 16:52
@michel-laterman michel-laterman changed the title Fix --source-uri for local paths when upgrading fleet-managed agents Dec 17, 2025
@michel-laterman michel-laterman force-pushed the bug/fleet-upgrade-command-source-uri-asc branch 3 times, most recently from e14d737 to e8d50e0 Compare December 17, 2025 20:42
Fix PGP verification to use the .asc file located in the dir specified
by --source-uri when upgrading a fleet-managed agent.
@michel-laterman michel-laterman force-pushed the bug/fleet-upgrade-command-source-uri-asc branch from b1d0696 to da13908 Compare December 18, 2025 16:58
@michel-laterman michel-laterman marked this pull request as ready for review December 18, 2025 21:32
@michel-laterman michel-laterman requested a review from a team as a code owner December 18, 2025 21:32
@elasticmachine
Copy link
Contributor

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

@ycombinator
Copy link
Contributor

ycombinator commented Dec 19, 2025

I think you need to play the same game that you have in this PR for the .asc file with the .sha512 file as well. Otherwise, you get the following error, even though the .sha512 file is present in the folder specified by --source-uri:

$ sudo elastic-agent upgrade --force --source-uri file://$(pwd)/development/github/elastic-agent/build/distributions/ 9.4.0-SNAPSHOT
Error: Failed trigger upgrade of daemon: failed verification of agent binary: failed to verify SHA512 hash: could not read checksum file: checksum for "elastic-agent-9.4.0-SNAPSHOT-linux-arm64.tar.gz" was not found in "/opt/Elastic/Agent/data/elastic-agent-9.3.0-SNAPSHOT-e495ca/downloads/elastic-agent-9.4.0-SNAPSHOT-linux-arm64.tar.gz.sha512"
For help, please see our troubleshooting guide at https://www.elastic.co/docs/troubleshoot/ingest/fleet/common-problems
@michel-laterman
Copy link
Contributor Author

Nope, the sha512 is already handled as part of the fs downloade:

hashPath, err := e.download(e.config.OS(), a, *version, ".sha512")
downloadedFiles = append(downloadedFiles, hashPath)

@ycombinator, the error you're seeing is indicating a (silent) permissions issue; the source-uri path does not match the path in the error message (it silently falls back to paths.Download if there is a permissions issue).

@ycombinator
Copy link
Contributor

@ycombinator, the error you're seeing is indicating a (silent) permissions issue; the source-uri path does not match the path in the error message (it silently falls back to paths.Download if there is a permissions issue).

The path I specified in the --source-uri was file://$(pwd)/development/github/elastic-agent/build/distributions/. Here are the permissions for that path:

ls -al $(pwd)/development/github/elastic-agent/build/distributions/
total 410376
drwxr-xr-x 1 shaunak shaunak       128 Dec 19 02:09 .
drwxr-xr-x 1 shaunak shaunak       224 Dec 19 02:00 ..
-rw-r--r-- 1 shaunak shaunak 407341646 Dec 19 02:03 elastic-agent-9.4.0-SNAPSHOT-linux-arm64.tar.gz
-rw-r--r-- 1 shaunak shaunak       186 Dec 19 02:03 elastic-agent-9.4.0-SNAPSHOT-linux-arm64.tar.gz.sha512

As you can see, the .tar.gz.sha512 file is world-readable. And in any case, the elastic-agent command was executed with sudo. So I'm not following why this would be a permissions issue. 🤔

What changes should I make to file permissions to make the issue go away so that the following command would not error out on the .sha512 file (I realize it will error out due to the lack of a .asc file but that's a separate issue):

$ sudo elastic-agent upgrade --force --source-uri file://$(pwd)/development/github/elastic-agent/build/distributions/ 9.4.0-SNAPSHOT
@michel-laterman
Copy link
Contributor Author

Using a multipass VM, i'm unable to recreate:

ubuntu@fleet-server-dev:~$ ls -la
total 407660
drwxr-x--- 9 ubuntu ubuntu      4096 Dec 19 12:37 .
drwxr-xr-x 3 root   root        4096 Dec 19 12:08 ..
-rw-rw-r-- 1 ubuntu ubuntu 417380783 Dec 15 22:07 elastic-agent-9.3.0-SNAPSHOT-linux-arm64.tar.gz
-rw-rw-r-- 1 ubuntu ubuntu       488 Dec 15 23:33 elastic-agent-9.3.0-SNAPSHOT-linux-arm64.tar.gz.asc
-rw-rw-r-- 1 ubuntu ubuntu       178 Dec 15 23:33 elastic-agent-9.3.0-SNAPSHOT-linux-arm64.tar.gz.sha512
ubuntu@fleet-server-dev:~$ sudo elastic-agent upgrade 9.3.0-SNAPSHOT --force --source-uri file://$(pwd)
Upgrade triggered to version 9.3.0-SNAPSHOT, Elastic Agent is currently restarting
ubuntu@fleet-server-dev:~$ sudo elastic-agent status
┌─ fleet
│  └─ status: (STARTING)
├─ elastic-agent
│  └─ status: (HEALTHY) Running
└─ upgrade_details
   ├─ target_version: 9.3.0
   ├─ state: UPG_WATCHING
   └─ metadata
ubuntu@fleet-server-dev:~$ sudo elastic-agent version
Binary: 9.3.0-SNAPSHOT (build: 612bfcd1e89ee79f41243a1b005cd33f4c42d4ab at 2025-12-16 01:47:25 +0000 UTC)
Daemon: 9.3.0-SNAPSHOT (build: 612bfcd1e89ee79f41243a1b005cd33f4c42d4ab at 2025-12-16 01:47:25 +0000 UTC)

I've even altered the permissions to what you have in order to try:

ubuntu@fleet-server-dev:~$ ls -la
total 407660
drwxr-x--- 9 ubuntu ubuntu      4096 Dec 19 12:37 .
drwxr-xr-x 3 root   root        4096 Dec 19 12:08 ..
-rw-r--r-- 1 ubuntu ubuntu 417380783 Dec 15 22:07 elastic-agent-9.3.0-SNAPSHOT-linux-arm64.tar.gz
-rw-rw-r-- 1 ubuntu ubuntu       488 Dec 15 23:33 elastic-agent-9.3.0-SNAPSHOT-linux-arm64.tar.gz.asc
-rw-r--r-- 1 ubuntu ubuntu       178 Dec 15 23:33 elastic-agent-9.3.0-SNAPSHOT-linux-arm64.tar.gz.sha512
ubuntu@fleet-server-dev:~$ sudo elastic-agent version
Binary: 9.3.0-SNAPSHOT (build: e495cacfae09aec99cf7c888faa797e9f55773c6 at 2025-12-19 18:14:33 +0000 UTC)
Daemon: 9.3.0-SNAPSHOT (build: e495cacfae09aec99cf7c888faa797e9f55773c6 at 2025-12-19 18:14:33 +0000 UTC)
ubuntu@fleet-server-dev:~$ sudo elastic-agent upgrade 9.3.0-SNAPSHOT --force --source-uri file://$(pwd)
Upgrade triggered to version 9.3.0-SNAPSHOT, Elastic Agent is currently restarting
ubuntu@fleet-server-dev:~$ sudo elastic-agent version
Binary: 9.3.0-SNAPSHOT (build: 612bfcd1e89ee79f41243a1b005cd33f4c42d4ab at 2025-12-16 01:47:25 +0000 UTC)
Daemon: 9.3.0-SNAPSHOT (build: 612bfcd1e89ee79f41243a1b005cd33f4c42d4ab at 2025-12-16 01:47:25 +0000 UTC)
ubuntu@fleet-server-dev:~$ sudo elastic-agent status
┌─ fleet
│  └─ status: (STARTING)
├─ elastic-agent
│  └─ status: (HEALTHY) Running
└─ upgrade_details
   ├─ target_version: 9.3.0
   ├─ state: UPG_WATCHING
   └─ metadata

But I'm not able to recreate your error at all.

Can you see what's in /opt/Elastic/Agent/data/elastic-agent-9.3.0-SNAPSHOT-e495ca/downloads/ after it fails for you?

@ycombinator
Copy link
Contributor

ycombinator commented Dec 22, 2025

Can you see what's in /opt/Elastic/Agent/data/elastic-agent-9.3.0-SNAPSHOT-e495ca/downloads/ after it fails for you?

$ whoami
root
$ ls -al /opt/Elastic/Agent/data/elastic-agent-9.3.0-SNAPSHOT-e495ca/downloads/
total 4
drwxr-x--- 1 root root   0 Dec 21 19:53 .
drwxr-x--- 1 root root 166 Dec 21 19:53 ..

I turned on debug level logging and retried the upgrade command. I see these logs:

{"log.level":"info","@timestamp":"2025-12-22T03:56:18.144Z","log.origin":{"function":"github.com/elastic/elastic-agent/internal/pkg/agent/application/coordinator.(*Coordinator).logUpgradeDetails","file.name":"coordinator/coordinator.go","file.line":899},"message":"updated upgrade details","log":{"source":"elastic-agent"},"upgrade_details":{"target_version":"9.4.0-SNAPSHOT","state":"UPG_REQUESTED","metadata":{}},"ecs.version":"1.6.0"}
{"log.level":"info","@timestamp":"2025-12-22T03:56:18.145Z","log.origin":{"function":"github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade.(*Upgrader).Upgrade","file.name":"upgrade/upgrade.go","file.line":289},"message":"Upgrading agent","log":{"source":"elastic-agent"},"version":"9.4.0-SNAPSHOT","source_uri":"file:///home/shaunak","ecs.version":"1.6.0"}
{"log.level":"info","@timestamp":"2025-12-22T03:56:18.145Z","log.origin":{"function":"github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade.cleanNonMatchingVersionsFromDownloads","file.name":"upgrade/cleanup.go","file.line":21},"message":"Cleaning up non-matching downloaded versions","log":{"source":"elastic-agent"},"version":"9.3.0","downloads.path":"/opt/Elastic/Agent/data/elastic-agent-9.3.0-SNAPSHOT-e495ca/downloads","ecs.version":"1.6.0"}
{"log.level":"debug","@timestamp":"2025-12-22T03:56:18.145Z","log.origin":{"function":"github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade.(*artifactDownloader).appendFallbackPGP","file.name":"upgrade/step_download.go","file.line":159},"message":"Considering fleet server uri for pgp check fallback \"\"","log":{"source":"elastic-agent"},"ecs.version":"1.6.0"}
{"log.level":"info","@timestamp":"2025-12-22T03:56:18.145Z","log.origin":{"function":"github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade.(*artifactDownloader).downloadArtifact","file.name":"upgrade/step_download.go","file.line":103},"message":"Using local upgrade artifact","log":{"source":"elastic-agent"},"version":"9.4.0-SNAPSHOT","drop_path":"/home/shaunak","target_path":"/opt/Elastic/Agent/data/elastic-agent-9.3.0-SNAPSHOT-e495ca/downloads","install_path":"/opt/Elastic/Agent/data/elastic-agent-9.3.0-SNAPSHOT-e495ca/install","ecs.version":"1.6.0"}
{"log.level":"info","@timestamp":"2025-12-22T03:56:18.145Z","log.origin":{"function":"github.com/elastic/elastic-agent/internal/pkg/agent/application/coordinator.(*Coordinator).logUpgradeDetails","file.name":"coordinator/coordinator.go","file.line":899},"message":"updated upgrade details","log":{"source":"elastic-agent"},"upgrade_details":{"target_version":"9.4.0-SNAPSHOT","state":"UPG_DOWNLOADING","metadata":{}},"ecs.version":"1.6.0"}
{"log.level":"warn","@timestamp":"2025-12-22T03:56:18.145Z","log.origin":{"function":"github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade/artifact/download.VerifySHA512HashWithCleanup","file.name":"download/verifier.go","file.line":114},"message":"error verifying the package using hash file \"/opt/Elastic/Agent/data/elastic-agent-9.3.0-SNAPSHOT-e495ca/downloads/elastic-agent-9.4.0-SNAPSHOT-linux-arm64.tar.gz.sha512\", contents: \"32f6feefaa4734f61e001b7ebb19735955a6b18e9cd6c3aa41ba0158706527cf417f1a2ba6f2842f4c274b9ec52f3cf2cab684792194caebd6f53a979373f6a6  elastic-agent-9.4.0-SNAPSHOT-SNAPSHOT-linux-arm64.tar.gz\"","log":{"source":"elastic-agent"},"ecs.version":"1.6.0"}
{"log.level":"info","@timestamp":"2025-12-22T03:56:18.145Z","log.origin":{"function":"github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade.cleanNonMatchingVersionsFromDownloads","file.name":"upgrade/cleanup.go","file.line":21},"message":"Cleaning up non-matching downloaded versions","log":{"source":"elastic-agent"},"version":"9.3.0","downloads.path":"/opt/Elastic/Agent/data/elastic-agent-9.3.0-SNAPSHOT-e495ca/downloads","ecs.version":"1.6.0"}
{"log.level":"error","@timestamp":"2025-12-22T03:56:18.145Z","log.origin":{"function":"github.com/elastic/elastic-agent/internal/pkg/agent/application/coordinator.(*Coordinator).Upgrade","file.name":"coordinator/coordinator.go","file.line":873},"message":"upgrade failed","log":{"source":"elastic-agent"},"error":{"Key":"error","Type":26,"Integer":0,"String":"","Interface":{}},"ecs.version":"1.6.0"}
{"log.level":"info","@timestamp":"2025-12-22T03:56:18.145Z","log.origin":{"function":"github.com/elastic/elastic-agent/internal/pkg/agent/application/coordinator.(*Coordinator).logUpgradeDetails","file.name":"coordinator/coordinator.go","file.line":899},"message":"updated upgrade details","log":{"source":"elastic-agent"},"upgrade_details":{"target_version":"9.4.0-SNAPSHOT","state":"UPG_FAILED","metadata":{"failed_state":"UPG_DOWNLOADING","error_msg":"failed verification of agent binary: failed to verify SHA512 hash: could not read checksum file: checksum for \"elastic-agent-9.4.0-SNAPSHOT-linux-arm64.tar.gz\" was not found in \"/opt/Elastic/Agent/data/elastic-agent-9.3.0-SNAPSHOT-e495ca/downloads/elastic-agent-9.4.0-SNAPSHOT-linux-arm64.tar.gz.sha512\""}},"ecs.version":"1.6.0"}
@ycombinator
Copy link
Contributor

Interestingly, I don't run into any issues if I download the target version's .tar.gz, .sha512, and .asc files from https://www.elastic.co/downloads/elastic-agent. The problems I was running into only seem to happen if I've built the target version from source. 🤷

Anyway, I'm able to test the changes in this PR now, so I'm unblocked.

@michel-laterman michel-laterman merged commit 18ec02e into elastic:main Dec 22, 2025
22 checks passed
@michel-laterman michel-laterman deleted the bug/fleet-upgrade-command-source-uri-asc branch December 22, 2025 15:04
@github-actions
Copy link
Contributor

@Mergifyio backport 8.19 9.1 9.2 9.3

mergify bot pushed a commit that referenced this pull request Dec 22, 2025
…e-uri flag for fleet-managed agents (#11826)

Fix PGP verification to use the .asc file located in the dir specified by --source-uri when upgrading a fleet-managed agent.

(cherry picked from commit 18ec02e)
mergify bot pushed a commit that referenced this pull request Dec 22, 2025
…e-uri flag for fleet-managed agents (#11826)

Fix PGP verification to use the .asc file located in the dir specified by --source-uri when upgrading a fleet-managed agent.

(cherry picked from commit 18ec02e)
mergify bot pushed a commit that referenced this pull request Dec 22, 2025
…e-uri flag for fleet-managed agents (#11826)

Fix PGP verification to use the .asc file located in the dir specified by --source-uri when upgrading a fleet-managed agent.

(cherry picked from commit 18ec02e)
mergify bot pushed a commit that referenced this pull request Dec 22, 2025
…e-uri flag for fleet-managed agents (#11826)

Fix PGP verification to use the .asc file located in the dir specified by --source-uri when upgrading a fleet-managed agent.

(cherry picked from commit 18ec02e)
@nimarezainia
Copy link
Contributor

VihasMakwana pushed a commit to VihasMakwana/elastic-agent that referenced this pull request Dec 23, 2025
…e-uri flag for fleet-managed agents (elastic#11826)

Fix PGP verification to use the .asc file located in the dir specified by --source-uri when upgrading a fleet-managed agent.
michel-laterman added a commit that referenced this pull request Dec 23, 2025
…e-uri flag for fleet-managed agents (#11826) (#11977)

Fix PGP verification to use the .asc file located in the dir specified by --source-uri when upgrading a fleet-managed agent.

(cherry picked from commit 18ec02e)

Co-authored-by: Michel Laterman <82832767+michel-laterman@users.noreply.github.com>
michel-laterman added a commit that referenced this pull request Dec 23, 2025
…e-uri flag for fleet-managed agents (#11826) (#11978)

Fix PGP verification to use the .asc file located in the dir specified by --source-uri when upgrading a fleet-managed agent.

(cherry picked from commit 18ec02e)

Co-authored-by: Michel Laterman <82832767+michel-laterman@users.noreply.github.com>
michel-laterman added a commit that referenced this pull request Dec 23, 2025
…e-uri flag for fleet-managed agents (#11826) (#11975)

Fix PGP verification to use the .asc file located in the dir specified by --source-uri when upgrading a fleet-managed agent.

(cherry picked from commit 18ec02e)

Co-authored-by: Michel Laterman <82832767+michel-laterman@users.noreply.github.com>
michel-laterman added a commit that referenced this pull request Dec 23, 2025
…e-uri flag for fleet-managed agents (#11826) (#11976)

Fix PGP verification to use the .asc file located in the dir specified by --source-uri when upgrading a fleet-managed agent.

(cherry picked from commit 18ec02e)

Co-authored-by: Michel Laterman <82832767+michel-laterman@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-active-all Automated backport with mergify to all the active branches bug Something isn't working Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team

4 participants