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

fix: always treat link destinations as files to ensure an error when the destination is a directory #187

Merged
merged 1 commit into from
Jun 14, 2024

Conversation

oddlama
Copy link
Contributor

@oddlama oddlama commented May 20, 2023

If a secret is used in the initrd with stage1 systemd, it will be copied into the initrd on activation time, after agenix has run. If the system is then restarted, the directory /run/agenix will be created by the initrd because the file is included in the cpio archive. This will in turn cause agenix to silently create an incorrect link /run/agenix/0 -> /run/agenix.d/0 instead of /run/agenix -> /run/agenix.d/0 when switching to stage2.

Technically this is not a bug in agenix, since including a secret under /run/agenix can be considered invalid use. Yet I believe it would be good if agenix errors in such cases instead of creating a wrong link, to make users aware of the issue. Therefore I propose to replace ln -sfn with ln -sfT which will unconditionally treat the target as a file, and as such error if the target is a directory.

Another approach is to force remove any existing directories, which might also be a desirable alternative option. This would then allow using agenix secrets in the systemd stage1 initrd without taking any special care. But as unconditionally removing might be a undesirable default behavior, this could require a new option. Do you have an opinion on this matter?

@oddlama
Copy link
Contributor Author

oddlama commented Dec 17, 2023

Any updates on this?

…tination is a directory.

This can happen if for example a secret is used in the initrd, which
materializes it as a directory, which then causes agenix to silently
create an incorrect link when switching to stage2. This ensures that
agenix will abort with an error.
@oddlama
Copy link
Contributor Author

oddlama commented May 21, 2024

Rebased on main. As stated before, currently this only causes agenix to emit an error. Deleting the directory before linking could also be a desirable option to ensure agenix takes precedence. Any opinions?

@mweinelt
Copy link

mweinelt commented Jun 7, 2024

@n8henrie PTAL

Copy link
Collaborator

@n8henrie n8henrie left a comment

Choose a reason for hiding this comment

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

This seems reasonable as far as I can think, it doesn't make sense to be linking a directory under any circumstance that comes to mind. @ryantm any issues come to mind?

@ryantm ryantm merged commit 3a56735 into ryantm:main Jun 14, 2024
4 checks passed
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.

4 participants