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

Fixes #38236 - copy /run/containers/0/auth.json only if it exists #11323

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pmoravec
Copy link
Member

What are the changes introduced in this pull request?

Don't fail on copy /run/containers/0/auth.json to /etc/flatpak/oci-auth.json if the source file does not exist - its presence is optional.

Considerations taken when implementing this change?

There are a few options how to fix this, i.e. redirect stderr to /dev/null. I chose this cp option:

   -u, --update
          copy only when the SOURCE file is newer than the destination file or when the destination file is missing

for its positive side-effect: dont overwrite oci-auth.json if it has a newer content (at least I see this as a feature and not a bug of the chosen fix - let me see if you think otherwise).

What are the testing steps for this pull request?

Ensure no /run/containers/0/auth.json is present on a Host with podman and flatpak (this is default), and apply the job template to the Host.

@ianballou
Copy link
Member

ianballou commented Mar 3, 2025

I haven't tested this via REX yet, but does it work in practice? Seeing this on the shell:

[root@9 ~]# cat /run/containers/0/auth.json 
cat: /run/containers/0/auth.json: No such file or directory
[root@9 ~]# sudo cp --update /run/containers/0/auth.json /etc/flatpak/oci-auth.json
cp: cannot stat '/run/containers/0/auth.json': No such file or directory
[root@9 ~]# echo $?
1

It looks like the return code is still 1 if the source exists, which should fail the REX job.

I suppose an alternate solution could be to use test:

if test -f "/run/containers/0/auth.json"; then
  sudo cp --update /run/containers/0/auth.json /etc/flatpak/oci-auth.json
fi

Copy link
Member

@ianballou ianballou left a comment

Choose a reason for hiding this comment

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

I tested it just to be safe and saw this:


   1:
Login Succeeded!
   2:
cp: cannot create regular file '/etc/flatpak/oci-auth.json': No such file or directory
   3:
Exit status: 1
   4:
StandardError: Job execution failed

Edit: this occurred because flatpak wasn't installed yet. The dir should exist if flatpak is installed.

@ianballou
Copy link
Member

I'm confused how /run/containers/0/auth.json would not exist, it gets populated when you podman login. Unless podman can be configured to not create the file?

@ianballou
Copy link
Member

Testing with the current changes and flatpak installed, I see:


   1:
cp: cannot stat '/run/containers/0/auth.json': No such file or directory
   2:
Exit status: 1
   3:
StandardError: Job execution failed

Testing with the if statement added (described above) lets the job succeed.

sudo cp --update /run/containers/0/auth.json /etc/flatpak/oci-auth.json
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
sudo cp --update /run/containers/0/auth.json /etc/flatpak/oci-auth.json
if test -f "/run/containers/0/auth.json"; then
sudo cp --update /run/containers/0/auth.json /etc/flatpak/oci-auth.json
fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants