Skip to content

fix(agent): read the Kairos version from kairos-release, not os-release twice - #4766

Merged
mudler merged 2 commits into
kairos-io:masterfrom
ci-forks:fix/agent-kairos-release-version
Oct 14, 2026
Merged

mudler merged 2 commits into
kairos-io:masterfrom
ci-forks:fix/agent-kairos-release-version

Conversation

@ci-robbot

Copy link
Copy Markdown
Collaborator

Fixes #4765

config.Scan says it loads the Kairos version from the kairos-release file, then opens
/etc/os-release, and the branch commented "Fallback into os-release" opens the same
file a second time. kairos-init writes KAIROS_VERSION to /etc/kairos-release only,
so the "Kairos System" log line was never printed on an image it built, and the fallback
could never fire.

Two more defects in the same block:

  • Both deferred closes captured the same f variable, which the second Open reassigns,
    so the handle from the first Open was never closed. A verbatim copy of the old block
    run 50 times grows the process from 8 open descriptors to 58.
  • The error from Open was discarded, both assignments flagged by wastedassign, and a
    failed Open went into godotenv.Parse. That is safe today only because vfs.OSFS
    returns a typed-nil *os.File, whose methods are nil-safe.

The change reads the pair in the order sdk/utils.OSRelease already uses, kairos-release
first and os-release as the fallback, closes each file as soon as it is parsed, and skips
a path that cannot be opened.

Tests

Five ginkgo specs in agent/pkg/config/scan_internal_test.go, over a vfst filesystem
holding a real image's two files. Both halves were mutation-checked against this branch:

Mutation Spec that fails
Call site asks for os-release twice, as master does reads the version from kairos-release
f.Close() removed closes what it opens

go test ./agent/pkg/config/... passes, golangci-lint run ./agent/pkg/config/... reports
0 issues, and wastedassign no longer fires on the package.

Written by an AI agent. No human has read the code yet.

…se twice

config.Scan says it loads the version from the kairos-release file and then
opens /etc/os-release, and the branch commented "Fallback into os-release"
opens the same file again. kairos-init writes KAIROS_VERSION to
/etc/kairos-release only, so the line that names the running system's version
was never printed on an image it built, and the fallback could never fire.

Both deferred closes captured the same variable, which the second Open
reassigns, so the first handle was never closed: one leaked descriptor per
scan. The error from Open was discarded too, and a failed Open went into
godotenv.Parse, which is safe only because vfs.OSFS returns a typed-nil
*os.File.

Read the pair in the order sdk/utils.OSRelease already uses, close each file
as soon as it is parsed, and skip a path that cannot be opened.

Fixes kairos-io#4765

Signed-off-by: Ettore Di Giacinto <mudler@kairos.io>
@itxaka-agent

Copy link
Copy Markdown
Collaborator

Automated triage agent (kairos-triage-agent) running as @itxaka-agent.
This comment was generated by software. A human maintainer can override
any action taken here.

Taking a look at this one: reviewing the diff and the tests.

@itxaka-agent itxaka-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Automated triage agent (kairos-triage-agent) running as @itxaka-agent.
This comment was generated by software. A human maintainer can override
any action taken here.

Looks good. kairosVersion now reads /etc/kairos-release first and falls back to /etc/os-release, each file is closed right after parsing, and a failed open is skipped. The new tests cover the precedence, the fallback and the descriptor count.

@itxaka-agent

Copy link
Copy Markdown
Collaborator

Automated triage agent (kairos-triage-agent) running as @itxaka-agent.
This comment was generated by software. A human maintainer can override
any action taken here.

QA in progress: I'm testing this now. Results and proof will follow here.

@itxaka-agent

itxaka-agent commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Automated triage agent (kairos-triage-agent) running as @itxaka-agent.
This comment was generated by software. A human maintainer can override
any action taken here.

QA: pass at da47f93, details and proof: #4765 (comment)

@mudler
mudler merged commit bf38600 into kairos-io:master Oct 14, 2026
43 checks passed
@github-project-automation github-project-automation Bot moved this from QA OK to Done âś… in đź§™Issue tracking board Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Development

Successfully merging this pull request may close these issues.

kairos-agent: config.Scan reads the Kairos version from os-release twice, so it never finds it and leaks a descriptor per scan

3 participants