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

jail: add JID, JNAME and JPATH to environment for exec.* commands #1609

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

Conversation

Defenso-QTH
Copy link
Contributor

Although variable substitution is available in the jail configuration file, the jail identifier is often not since it is dynamically attributed at run time.

In order to facilitate scripting of exec.* commands executed on the system, this change sets the JID, JNAME and JPATH environment variables.

These variables are not added when using exec.clean. Neither are they for commands executed inside jails, to avoid disclosing information about the host system.

Although variable substitution is available in the jail configuration
file, the jail identifier is often not since it is dynamically
attributed at run time.

In order to facilitate scripting of exec.* commands executed on the
system, this change sets the JID, JNAME and JPATH environment variables.

These variables are not added when using exec.clean. Neither are they
for commands executed inside jails, to avoid disclosing information
about the host system.
@Crest
Copy link

Crest commented Mar 18, 2025

You can write this to export the jail id and jail name to the shell script, but the quoting gets ugly:

exec.start = "
    export JID='$jid' JNAME='$name'
    echo \"Hello \$JNAME from \$JID.\"
";

@Defenso-QTH
Copy link
Contributor Author

Defenso-QTH commented Mar 19, 2025

That could work. It seems my issue comes from using iocage, which does not rely on jail to exec the prestart/poststart commands but does it itself, so we don't get replacement, and it does not set environment variables either.

https://github.com/freebsd/iocage/blob/c55e05aebb305b4013554ec80298113c50d1c74c/iocage_lib/ioc_start.py#L873C1-L877C14

        # Running exec_poststart now
        poststart_success, poststart_error = \
            iocage_lib.ioc_common.runscript(
                exec_poststart
            )

Maybe it makes more sense patching iocage then.

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