Skip to content

✨ Collect snap packages#5519

Merged
czunker merged 2 commits intomainfrom
czunker/snap
May 9, 2025
Merged

✨ Collect snap packages#5519
czunker merged 2 commits intomainfrom
czunker/snap

Conversation

@czunker
Copy link
Copy Markdown
Contributor

@czunker czunker commented May 8, 2025

This collects data about the present snap packages. It currently appllies to:

  • Ubuntu
  • Debian
  • Fedora

Fixes: #4879

@czunker
Copy link
Copy Markdown
Contributor Author

czunker commented May 8, 2025

This is slow over ssh connections:

time cnspec run vagrant default -c "packages.where(format == 'snap'){ name version purl }" 
→ loaded configuration from /etc/opt/mondoo/mondoo.yml using source default
packages.where.list: [
  0: {
    version: "1.0"
    purl: "pkg:snap/ubuntu/bare@1.0?distro=ubuntu-22.04"
    name: "bare"
  }
...
  11: {
    version: "1.18.5"
    purl: "pkg:snap/ubuntu/vault@1.18.5?arch=amd64&distro=ubuntu-22.04"
    name: "vault"
  }
]
cnspec run vagrant default -c   16,69s user 20,81s system 36% cpu 1:41,40 total

Alternatives described in #4879 would require running as root or executing a command.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 8, 2025

Test Results

4 238 tests  +1   4 234 ✅ +1   2m 49s ⏱️ +46s
  402 suites ±0       4 💤 ±0 
   30 files   ±0       0 ❌ ±0 

Results for commit 70b0bb2. ± Comparison against base commit 4bd8b22.

♻️ This comment has been updated with latest results.

This collects data about the present snap packages.
It currently appllies to:
- Ubuntu
- Debian
- Fedora

Fixes: #4879

Signed-off-by: Christian Zunker <christian@mondoo.com>
for _, file := range files {
manifest, err := afs.Open(file)
if err != nil {
log.Error().Err(err).Str("file", file).Msg("could not open manifest file")
Copy link
Copy Markdown
Contributor

@glower glower May 8, 2025

Choose a reason for hiding this comment

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

should we not add continue here? otherwise manifest would be nil

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Thank you.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I opted not to defer but to explicitly close because of the loop.

}
pkg, err := spm.parseSnapManifest(manifest)
if err != nil {
log.Error().Err(err).Str("file", file).Msg("could not parse manifest file")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same here but with pkg

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Thank you.

}
log.Debug().Int("updates", len(available)).Msg("mql[packages]> available updates")
for k, v := range available {
availableList[k] = v
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

could it be that if two different package managers (e.g., apt and snap) both provide an update for the same package name (e.g., "firefox"), the entry would be overwritten?
Don't know if this could be a problem or not

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Currently not, because snap does not provide available at the moment.

@glower
Copy link
Copy Markdown
Contributor

glower commented May 8, 2025

fun fact, I was working in the team responsible for snaps at Canonical :)

Signed-off-by: Christian Zunker <christian@mondoo.com>
@czunker
Copy link
Copy Markdown
Contributor Author

czunker commented May 9, 2025

fun fact, I was working in the team responsible for snaps at Canonical :)

We need to talk 😄

@czunker czunker merged commit 3753edc into main May 9, 2025
13 checks passed
@czunker czunker deleted the czunker/snap branch May 9, 2025 09:21
@github-actions github-actions Bot locked and limited conversation to collaborators May 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Discover applications installed via snap on Linux distributions

2 participants