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

In SQLite state, use defaults for empty-string checks #24775

Merged
merged 1 commit into from
Feb 11, 2025

Conversation

mheon
Copy link
Member

@mheon mheon commented Dec 5, 2024

As part of our database init, we perform a check of the current values for a few fields (graph driver, graph root, static dir, and a few more) to validate that Libpod is being started with a sane & sensible config, and the user's containers can actually be expected to work. Basically, we take the current runtime config and compare against values cached in the database from the first time Podman was run.

We've had some issues with this logic before this year around symlink resolution, but this is a new edge case. Somehow, the database is being loaded with the empty string for some fields (at least graph driver) which is causing comparisons to fail because we will never compare against "" for those fields - we insert the default value instead, assuming we have one.

Having a value of "" in the database largely invalidates the check so arguably we could just drop it, but what BoltDB did - and what SQLite does after this patch - is to use the default value for comparison instead of "". This should still catch some edge cases, and shouldn't be too harmful.

What this does not do is identify or solve the reason that we are seeing the empty string in the database at all. From my read on the logic, it must mean that the graph driver is explicitly set to "" in the c/storage config at the time Podman is first run and I'm not precisely sure how that happens.

Fixes #24738

Does this PR introduce a user-facing change?

Fixed a bug where Podman would fail to start due to a database configuration mismatch when certain fields were configured to the empty string.

@openshift-ci openshift-ci bot added release-note approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Dec 5, 2024
@mheon mheon added the No New Tests Allow PR to proceed without adding regression tests label Dec 5, 2024
@mheon
Copy link
Member Author

mheon commented Dec 5, 2024

Adding no new tests as we don't do database config tests like this in CI

@Luap99
Copy link
Member

Luap99 commented Dec 5, 2024

The way to trigger this is create an empty storage.conf without driver then run podman to init db (you must reset the storage before of course)

$ podman ps
WARN[0000] The storage 'driver' option should be set in /home/pholzing/.config/containers/storage.conf. A driver was picked automatically. 
WARN[0000] The storage 'driver' option should be set in /home/pholzing/.config/containers/storage.conf. A driver was picked automatically. 
CONTAINER ID  IMAGE       COMMAND     CREATED     STATUS      PORTS       NAMES

# Follow the advice and add the driver, i.e. overlay
$ vi ~/.config/containers/storage.conf
$ cat ~/.config/containers/storage.conf
[storage]
driver="overlay"
$ podman ps
Error: database graph driver "" does not match our graph driver "overlay": database configuration mismatch

I think we can must test this somehow in CI.

I really must say they for every bug I dislike the validation logic more and more

@baude
Copy link
Member

baude commented Dec 5, 2024

could we just use the podman cli and the --storage-driver string? I think if you did an e2e test you could skip the step to prepopulate the image cache and then add the storage driver option as a one-off ?

@Luap99
Copy link
Member

Luap99 commented Dec 5, 2024

--storage-driver "" is ignored AFAIk so it must come from the config file I think. But that should not be much more difficult as we can use the CONTAINERS_STORAGE_CONF env to set it for a single test

@mheon mheon force-pushed the fix_24738 branch 2 times, most recently from 7df556c to 1e04b52 Compare December 10, 2024 15:46
@@ -291,4 +291,52 @@ var _ = Describe("Podman Info", func() {
Expect(info).ToNot(ExitCleanly())
podmanTest.StartRemoteService() // Start service again so teardown runs clean
})

It("podman startup: ensure database checks for graph driver accommodate empty string", func() {
Copy link
Member

Choose a reason for hiding this comment

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

Actually this will never work because all the e2e test pass all option via cli such as --storage-driver so it not matter what we set in the config.

I think this might have to be in test/system and you pass your own --root/-runroot/--tmpdir and just leave the driver to the storage .conf

Copy link

A friendly reminder that this PR had no activity for 30 days.

@mheon mheon force-pushed the fix_24738 branch 2 times, most recently from 1614605 to 34e3f22 Compare February 5, 2025 20:57
Comment on lines 314 to 315
# Force all custom directories so we don't pick up an existing database
CONTAINERS_STORAGE_CONF=$PODMAN_TMPDIR/storage.conf run_podman --root $PODMAN_TMPDIR/root --runroot $PODMAN_TMPDIR/runroot --tmpdir $PODMAN_TMPDIR/tmpdir info
Copy link
Member

Choose a reason for hiding this comment

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

use safe_opts=$(podman_isolation_opts ${PODMAN_TMPDIR})

and then just add $safe_opts as args here and below, see the test above as example.

Second storage prints an warning for the unset driver so you need to tell the test to ignore it

run_podman 0+w $safe_opts info
    require_warning "The storage 'driver' option should be set" \
                    "c/storage should warn on empty storage driver"

@mheon mheon force-pushed the fix_24738 branch 2 times, most recently from 6c42f8f to b1418b8 Compare February 6, 2025 14:49
@mheon
Copy link
Member Author

mheon commented Feb 6, 2025

F40 rootless is using VFS by default. That seems odd.

@Luap99
Copy link
Member

Luap99 commented Feb 6, 2025

F40 rootless is using VFS by default. That seems odd.

Because we should test all storage drivers we actively "support" so vfs for fedora -1 and overlayfs for 41/rawhide AFAIK to have good coverage.

That said we are using a custom --root here and custom storage conf so I don't follow with the env around it matters at all...

@mheon
Copy link
Member Author

mheon commented Feb 6, 2025

That was my thinking - everything that would configure storage driver is being overridden... Maybe I should do a system reset first to make sure there isn't a database at the location?

@Luap99
Copy link
Member

Luap99 commented Feb 6, 2025

system reset would not help, podman_isolation_opts is just an echo an the tmpdir is unique for each test so there really should not be any podman content prior to running the first command.

The test environment creates /etc/containers/storage.conf with vfs so maybe the empty storage conf file does not actual overwrite it somehow despite c/storage complaining about it?

@mheon
Copy link
Member Author

mheon commented Feb 6, 2025

@nalind CONTAINERS_STORAGE_CONF should fully override the default /etc/containers/storage.conf and not layer on top of it, right?

@nalind
Copy link
Member

nalind commented Feb 6, 2025

It should, yes. Experimentally verified using the a sample file from the storage library's repository and env CONTAINERS_STORAGE_CONF=./types/storage_test.conf strace -f podman info as root.

# Now add a valid graph driver to storage.conf
cat >$PODMAN_TMPDIR/storage.conf <<EOF
[storage]
driver="overlay"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
driver="overlay"
driver="$(podman_storage_driver)"

That should use the right storage driver and turn into vfs on fedora -1, I am somewhat sure this is the right fix for the test instead of ignoring the vfs error

As part of our database init, we perform a check of the current
values for a few fields (graph driver, graph root, static dir,
and a few more) to validate that Libpod is being started with a
sane & sensible config, and the user's containers can actually be
expected to work. Basically, we take the current runtime config
and compare against values cached in the database from the first
time Podman was run.

We've had some issues with this logic before this year around
symlink resolution, but this is a new edge case. Somehow, the
database is being loaded with the empty string for some fields
(at least graph driver) which is causing comparisons to fail
because we will never compare against "" for those fields - we
insert the default value instead, assuming we have one.

Having a value of "" in the database largely invalidates the
check so arguably we could just drop it, but what BoltDB did -
and what SQLite does after this patch - is to use the default
value for comparison instead of "". This should still catch some
edge cases, and shouldn't be too harmful.

What this does not do is identify or solve the reason that we are
seeing the empty string in the database at all. From my read on
the logic, it must mean that the graph driver is explicitly set
to "" in the c/storage config at the time Podman is first run and
I'm not precisely sure how that happens.

Fixes containers#24738

Signed-off-by: Matt Heon <[email protected]>
Copy link

Cockpit tests failed for commit cb53abc. @martinpitt, @jelly, @mvollmer please check.

Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

openshift-ci bot commented Feb 10, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Luap99, mheon

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@mheon
Copy link
Member Author

mheon commented Feb 10, 2025

@containers/podman-maintainers PTAL and merge

@mheon
Copy link
Member Author

mheon commented Feb 10, 2025

/cherry-pick v5.4

@openshift-cherrypick-robot
Copy link
Collaborator

@mheon: once the present PR merges, I will cherry-pick it on top of v5.4 in a new PR and assign it to you.

In response to this:

/cherry-pick v5.4

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@mheon
Copy link
Member Author

mheon commented Feb 11, 2025

@containers/podman-maintainers Anyone care to merge?

@rhatdan
Copy link
Member

rhatdan commented Feb 11, 2025

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Feb 11, 2025
@rhatdan rhatdan removed lgtm Indicates that a PR is ready to be merged. stale-pr labels Feb 11, 2025
@mheon mheon added the lgtm Indicates that a PR is ready to be merged. label Feb 11, 2025
@openshift-merge-bot openshift-merge-bot bot merged commit 4a0b230 into containers:main Feb 11, 2025
82 of 83 checks passed
@openshift-cherrypick-robot
Copy link
Collaborator

@mheon: new pull request created: #25294

In response to this:

/cherry-pick v5.4

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. No New Tests Allow PR to proceed without adding regression tests release-note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error: database graph driver "" does not match our graph driver "overlay": database configuration mismatch
6 participants