Repository navigation
fix: improve logs when Ubuntu Pro credentials are not available - #326
cristiangirlea wants to merge 4 commits into
Conversation
When a release defines Ubuntu Pro archives and no credentials are
available, Chisel logged an error-like message for every Pro archive
("Cannot open credentials directory ...") followed by one "Archive
... ignored: credentials not found" line per archive. Users not using
Pro archives at all found this confusing.
A missing credentials directory is now handled silently (other errors
opening it are still logged), and the archives ignored because of
missing credentials are reported in a single informative message:
Ubuntu Pro subscription not available, ignoring archives: ubuntu-esm-apps, ubuntu-esm-infra
When valid credentials are available the logs are unchanged.
Fixes canonical#207
Assisted-by: AI tools
upils
left a comment
There was a problem hiding this comment.
Thanks for your submission @cristiangirlea!
I agree the user experience could be improved. You are on the right track but the approach can be refined to avoid misleading messages.
| if err != nil { | ||
| if err == archive.ErrCredentialsNotFound { | ||
| logf("Archive %q ignored: credentials not found", archiveName) | ||
| ignoredArchives = append(ignoredArchives, archiveName) |
There was a problem hiding this comment.
Getting this error here is not conceptually tied to Pro. Even if today we only look for creds for Pro, in the future it could be for other archives, for example PPA. But this knowledge is confined to the archive package. So presenting these errors as "Ubuntu Pro subscription not available..." is making assumption on the archive package behavior and so can quickly become misleading.
Also a Pro subscription could cover different archives (ESM, FIPS), so Pro could be available but only for a subset of them. The current message would then be misleading (even if ignored archives are listed), staying the subscription is not available when it actually is.
So maybe what we could do instead is:
- have
archivepackage clearly communicate some credentials for pro archives were not found (maybe with a new error type or named error returned bycandidateArchiveURLs?) - report that, without claiming anything on the actual subscription status. Maybe with something like "Ignored Pro archives: ....".
| if !os.IsNotExist(err) { | ||
| logf("Cannot open credentials directory %q: %v", credsDir, err) | ||
| } |
There was a problem hiding this comment.
With this approach, user giving by mistake a non-existent credsDir would end up with a message not providing any lead on how to solve the issue.
Only the archive package knows that credentials were looked up for an Ubuntu Pro archive, so candidateArchiveURLs now returns ErrProCredentialsNotFound in that case. The error wraps ErrCredentialsNotFound, and cut and debug check-release-archives check both with errors.Is: Pro archives are listed in a single line saying what was ignored and why, without claiming anything about the subscription itself, since credentials may exist for other Pro archives. An archive ignored for missing credentials for any other reason keeps its own log line. Also puts the makeChiselYaml doc comment back on that function.
The previous commit skipped the "Cannot open credentials directory" log for any missing directory, so a mistyped CHISEL_AUTH_DIR left no lead at all. Now only the default /etc/apt/auth.conf.d is allowed to be missing silently, since that is the normal state of a system without Ubuntu Pro credentials. A directory set via CHISEL_AUTH_DIR, or any other problem reading the default one, is logged as before.
|
Thanks, both points taken. The archive package now returns For the directory: only the default The description is updated to match. |
upils
left a comment
There was a problem hiding this comment.
Thanks @cristiangirlea. I have a few more comments, but this is getting close :).
| continue | ||
| } else if errors.Is(err, archive.ErrCredentialsNotFound) { |
There was a problem hiding this comment.
| continue | |
| } else if errors.Is(err, archive.ErrCredentialsNotFound) { | |
| continue | |
| } | |
| if errors.Is(err, archive.ErrCredentialsNotFound) { |
} else if after a continue is unnecessary. (following another comment this one may become irrelevant)
There was a problem hiding this comment.
Done, it's two separate ifs now, as in your suggestion.
| // logIgnoredProArchives logs a single message listing the Ubuntu Pro archives | ||
| // that were ignored because no credentials were found for them. It says | ||
| // nothing about the subscription itself: credentials may well exist for | ||
| // other Pro archives. |
There was a problem hiding this comment.
4 lines of comments stating what a 6 lines function does is not great. I think what the function does is easily enough to grasp to not need a comment.
| // ErrProCredentialsNotFound is returned when an Ubuntu Pro archive is requested | ||
| // but no credentials for it are found. It matches ErrCredentialsNotFound in | ||
| // errors.Is comparisons. |
There was a problem hiding this comment.
This also feels superfluous, documenting a behavior living in another place and an obvious behavior (error wrapping and error.Is).
There was a problem hiding this comment.
Gone together with the error.
| return | ||
| } | ||
| sort.Strings(archiveNames) | ||
| logf("Ignored Ubuntu Pro archives without credentials: %s", strings.Join(archiveNames, ", ")) |
There was a problem hiding this comment.
Sorry my suggestion was slightly inconsistent with the other error message for non-Pro archives. What about "Ubuntu Pro archives without credentials ignored: %s"?
There was a problem hiding this comment.
Changed to "Ubuntu Pro archives without credentials ignored: %s".
| // ErrProCredentialsNotFound is returned when an Ubuntu Pro archive is requested | ||
| // but no credentials for it are found. It matches ErrCredentialsNotFound in | ||
| // errors.Is comparisons. | ||
| var ErrProCredentialsNotFound = fmt.Errorf("%w for Ubuntu Pro archive", ErrCredentialsNotFound) |
There was a problem hiding this comment.
Now I think this it not the best approach because this credentials file has to gain knowledge of the "Pro" concept and I think we can avoid that.
We can keep returning the same error as before (so credential.go would be untouched) and in cmd_cut.go we know the archive we try to open is pro so there we can branch and collect the errors.
There was a problem hiding this comment.
Agreed, that's cleaner. ErrProCredentialsNotFound is gone and archive.go is back to what it was, so the archive package returns ErrCredentialsNotFound as before. Both commands now check archiveInfo.Pro to collect the Pro archives. The only change left in internal/archive is the default directory handling from the last round.
| // A directory given explicitly is reported when it cannot be read, so a | ||
| // mistyped CHISEL_AUTH_DIR leaves a lead in the logs. |
There was a problem hiding this comment.
Same here on the level of docs.
| restoreDir := archive.FakeDefaultCredsDir(credsDir) | ||
| defer restoreDir() | ||
|
|
||
| // Without Ubuntu Pro credentials the default directory usually does not |
There was a problem hiding this comment.
This is not true, this default folder comes from the apt package, this is unrelated to Ubuntu Pro. So without apt is it likely to not exist and without Ubuntu Pro it may be empty but there might be content in it for any other archives configured on the machine. It just happens that for now it only surfaces when trying to open a Pro archive but from the perspective of the findCredentials function this is not tied to Pro.
There was a problem hiding this comment.
You're right, thanks. Corrected: the comment now says the directory comes with apt.
The commands already know which archives are Ubuntu Pro ones, so they can group the Pro archives whose credentials are not found without a Pro-specific credentials error. Drop ErrProCredentialsNotFound and its test, branch on the archive's Pro setting instead, and word the message like the one for other archives. Also correct a test comment that tied a missing /etc/apt/auth.conf.d to Ubuntu Pro: the directory comes with apt.
Fixes #207
When a release defines Ubuntu Pro archives (as
ubuntu-24.04does) and nocredentials are available,
chisel cutlogged an error-like message forevery Pro archive followed by a per-archive "ignored" line. Users not
using Pro archives at all found this confusing, and nothing tied the
messages to Ubuntu Pro.
Chisel now reports the ignored Pro archives in a single line, stays quiet
about the default credentials directory being absent, and still reports a
credentials directory that was set explicitly but cannot be read. When
valid credentials are present the logs are unchanged.
Changes
cmd/chisel:cutanddebug check-release-archivescollect the Proarchives (
archiveInfo.Proset) whose credentials are not found and logthem once, sorted:
Ubuntu Pro archives without credentials ignored: .... Any other archive without credentials keeps its own log line. Thearchive package is unchanged in this respect and returns
ErrCredentialsNotFoundas before.internal/archive: a missing/etc/apt/auth.conf.dis no longer logged,since that directory comes with apt. A directory set via
CHISEL_AUTH_DIRthat cannot be read, or any other error reading thedefault one, is still logged so a mistyped path leaves a lead. The doc
comment of
findCredentialsInDirwas also corrected: it claimed thefunction returns empty credentials with a nil error, but it returns
ErrCredentialsNotFound.TestRunIgnoresProArchivesWithoutCredentialscovers the singleline for Pro archives and the per-archive line for others through
debug check-release-archives(which has thearchiveOpenhook;cutshares the same logic);
TestFindCredentialsDefaultDirMissing,TestFindCredentialsandTestFindCredentialsInDirMissingDircoverwhich directory problems are logged.
Verification
go test ./...,go test ./internal/archive/ --real-archive,go fmtandgolangci-lint run(v2.11.3, as in CI) pass, also after merging currentmain. The new tests fail without the change they cover.Before / after with a real release:
chisel cut --release ubuntu-24.04 --root /tmp/rootfs base-files_baseNo
/etc/apt/auth.conf.d, before:After (the same with an empty
/etc/apt/auth.conf.d):With
CHISEL_AUTH_DIR=/nonexistentthe "Cannot open credentials directory"line is still printed, since the directory was asked for explicitly.