Skip to content

Add support for crun hook stdout/stderr annotations in precreate hooks - #1089

Merged
mtrmac merged 1 commit into
podman-container-tools:mainfrom
ajoshua2004:hook-annotations
Sep 2, 2026
Merged

mtrmac merged 1 commit into
podman-container-tools:mainfrom
ajoshua2004:hook-annotations

Conversation

@ajoshua2004

Copy link
Copy Markdown
Contributor

OCI hooks can redirect their output to a file via 2 crun annotations run.oci.hooks.stdout=FILE/run.oci.hooks.stderr=FILE This works for every hook type except precreatehooks, since those are executed directly by podman before the OCI runtime is invoked so crun doesnt get a chance to honor the annotations. This adds the same annotation support to RuntimeConfigFilterWithOptions so precreate hook output anc be redirected too. PR in podman will be needed to bump vendor dependency.

Test

go test ./pkg/hooks/exec/... -run TestRuntimeConfigFilterOutputRedirection -v

@github-actions github-actions Bot added the common Related to "common" package label Aug 17, 2026
Comment thread common/pkg/hooks/exec/runtimeconfigfilter.go Outdated
Comment thread common/pkg/hooks/exec/runtimeconfigfilter_test.go Outdated
Comment thread common/pkg/hooks/exec/runtimeconfigfilter_test.go Outdated
Comment thread common/pkg/hooks/exec/runtimeconfigfilter_test.go Outdated
Comment thread common/pkg/hooks/exec/runtimeconfigfilter_test.go Outdated

@Luap99 Luap99 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM overall, but looks like you need to rebase

Comment thread common/pkg/hooks/exec/runtimeconfigfilter_test.go Outdated

@mtrmac mtrmac left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks!

Comment thread common/pkg/hooks/exec/runtimeconfigfilter.go
Comment thread common/pkg/hooks/exec/runtimeconfigfilter.go Outdated
Comment on lines +276 to +277
preExistingStdout string
checkStdoutMode bool

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These are not really independent test variants; they can be always used if a stdout annotation is used.

Similarly preExistingStdout is not a test parameter, it can be a constant, and exercised whenever stdout is recorded.


If these checks are worth doing, they might also be worth doing for stderr.

Comment thread common/pkg/hooks/exec/runtimeconfigfilter.go Outdated
Comment thread common/pkg/hooks/exec/runtimeconfigfilter_test.go Outdated
Comment thread common/pkg/hooks/exec/runtimeconfigfilter_test.go
Comment thread common/pkg/hooks/exec/runtimeconfigfilter_test.go Outdated
@ajoshua2004
ajoshua2004 force-pushed the hook-annotations branch 3 times, most recently from bd9671f to e0c69ce Compare September 1, 2026 21:32
}
}

func TestRuntimeConfigFilterCreatesStdoutFileWithCorrectMode(t *testing.T) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don’t think this is really worth a separate function (both for the cognitive/maintenance load and for the time to start the shell) … add the stat after the ReadFile content check, both for stdout and stderr (this test checks stdout only).


Absolutely non-blocking: It might be convenient to use a assertHookFileMatches(path, expectedContents) function to share the stdout+stderr code, I’m not immediately sure whether it would be worth it. Either two copies, or a shared helper, is fine with me.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

don’t think this is really worth a separate function

… oh, right, this was separate because we only set mode when creating a new file, wasn’t it? And now, with always writing the preExisting…Content data, we never create a new file. So we do need either this separate function, or a separate preExistingStdout test parameter; without that, we never actually test what permissions we create the file with.

I’m afraid I overlooked that completely.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

np, just restored the separate function

@mtrmac

mtrmac commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

A late design question: Are we fine with creating the stdout/stderr files if there are stderr/stdout annotations, but no hooks? It feels a bit unclean in principle, but it also probably makes little difference in practice.

Precreate hooks run directly by Podman before the OCI runtime is
invoked, so they never benefit from crun's run.oci.hooks.stdout/
run.oci.hooks.stderr annotations. This adds the same support to
RuntimeConfigFilterWithOptions, opening the annotated file(s) in
append mode (creating if missing, mode 0700 to match crun) and
wiring hook stdout/stderr into them.

Signed-off-by: Joshua Arrevillaga <2004jarrevillaga@gmail.com>
@ajoshua2004

Copy link
Copy Markdown
Contributor Author

In practice doesn't make sense to create the files if there's no hooks to actually redirect so I added an early return for the case options.Hooks is empty. Added a regression test too just in case

@mtrmac mtrmac left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks!

@mtrmac
mtrmac merged commit 144f9a5 into podman-container-tools:main Sep 2, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

common Related to "common" package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants