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

cleanup /etc/opkg/keys on upgrades #2665

Open
rotanid opened this issue Oct 11, 2022 · 3 comments · May be fixed by openwrt/openwrt#13433
Open

cleanup /etc/opkg/keys on upgrades #2665

rotanid opened this issue Oct 11, 2022 · 3 comments · May be fixed by openwrt/openwrt#13433
Milestone

Comments

@rotanid
Copy link
Member

rotanid commented Oct 11, 2022

we discussed in today's gluon meetup that we want to clear old opkg signing keys on each upgrade
currently, nodes that are around for years might have a load of old signing keys in that directory if the keys weren't re-used for new builds by the community.

@rotanid rotanid added this to the 2022.2 milestone Oct 12, 2022
@maurerle
Copy link
Member

maurerle commented Jun 8, 2023

currently I have a bunch of untrusted comment: Local build key and a key for 19.07, 21.02 and 22.03 each starting with:
untrusted comment: Public usign key for 22.03 release builds

Do you think there is any way to distinguish between the current and previous keys?

I see 2 ways out:

  1. delete all keys resulting in one release without usable opkg, have a working one shortly after
  2. use reused keys for the future and add a different comment in a the reused key and delete all Local build key keys.

Both ways include having a package which contains something like this (tested and works):

#!/usr/bin/lua
local handle = io.popen("ls /etc/opkg/keys -1")
local files = handle:read("*a")
handle:close()

for file in files:gmatch("[^\r\n]+") do
  local filePath = "/etc/opkg/keys/" .. file
  local fileHandle = io.open(filePath, "r")
  local fileContent = fileHandle:read("*all")
  fileHandle:close()

  if fileContent:find("untrusted comment: Local build key") then
    os.remove(filePath)
    print("Deleted file:", filePath)
  end
end

should this be part of a optional gluon-package to be run on upgrade or is this more something for the community-repo?

@Djfe
Copy link
Contributor

Djfe commented Jun 13, 2023

From the gluon meetup

Roughly where this code can be added:
Once a sysupgrade test was successful, empty the keys folder (right before the actual sysupgrade is run)
https://github.com/freifunk-gluon/packages/blob/master/admin/autoupdater/src/autoupdater.c#L385

Other code related to the autoupdater:
https://github.com/freifunk-gluon/packages/tree/master/admin/autoupdater
Other code related to the sysupgrade itself:
https://github.com/openwrt/openwrt/blob/main/package/base-files/files/sbin/sysupgrade
https://github.com/openwrt/openwrt/tree/main/package/base-files/files/lib/upgrade (for example stage2)

@maurerle
Copy link
Member

That seems like a good way to do it:
I would add the above script right here:
https://github.com/freifunk-gluon/packages/tree/master/admin/autoupdater/files/usr/lib/autoupdater/upgrade.d

so that it gets picked up right after checking if the upgrade should actually be done here:
https://github.com/freifunk-gluon/packages/blob/master/admin/autoupdater/src/autoupdater.c#L420

maurerle added a commit to ffac/packages that referenced this issue Jun 14, 2023
- does trigger on autoupdate after checking that the image is correct

fixes freifunk-gluon/gluon#2665
@blocktrron blocktrron modified the milestones: 2023.1, v2023.2 Aug 8, 2023
@maurerle maurerle linked a pull request Sep 10, 2023 that will close this issue
@blocktrron blocktrron modified the milestones: v2023.2, v2024.1 Dec 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants