mirror of
https://github.com/ostreedev/ostree.git
synced 2025-01-05 13:18:17 +03:00
Merge pull request #3277 from cgwalters/karg-disable-composefs
prepare-root: Add ostree.prepare-root.composefs
This commit is contained in:
commit
4b96359e10
@ -153,6 +153,18 @@ License along with this library. If not, see <https://www.gnu.org/licenses/>.
|
|||||||
commit must match the target composefs image.</para></listitem>
|
commit must match the target composefs image.</para></listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
</variablelist>
|
</variablelist>
|
||||||
|
|
||||||
|
<para>
|
||||||
|
The following kernel commandline parameters are also parsed:
|
||||||
|
</para>
|
||||||
|
<variablelist>
|
||||||
|
<varlistentry>
|
||||||
|
<term><varname>ostree.prepare-root.composefs</varname></term>
|
||||||
|
<listitem><para>This accepts the same values as <literal>composefs.enabled</literal> above, and overrides the config file (if present).
|
||||||
|
For example, specifying <literal>ostree.prepare-root.composefs=0</literal> will disable composefs, even if it is enabled by default in the initrd config.</para></listitem>
|
||||||
|
</varlistentry>
|
||||||
|
</variablelist>
|
||||||
|
|
||||||
</refsect1>
|
</refsect1>
|
||||||
|
|
||||||
|
|
||||||
|
@ -655,7 +655,7 @@ checkout_deployment_tree (OstreeSysroot *sysroot, OstreeRepo *repo, OstreeDeploy
|
|||||||
// However, we don't load the keys here, because they may not exist, such
|
// However, we don't load the keys here, because they may not exist, such
|
||||||
// as in the initial deploy
|
// as in the initial deploy
|
||||||
g_autoptr (ComposefsConfig) composefs_config
|
g_autoptr (ComposefsConfig) composefs_config
|
||||||
= otcore_load_composefs_config (prepare_root_config, FALSE, error);
|
= otcore_load_composefs_config ("", prepare_root_config, FALSE, error);
|
||||||
if (!composefs_config)
|
if (!composefs_config)
|
||||||
return glnx_prefix_error (error, "Reading composefs config");
|
return glnx_prefix_error (error, "Reading composefs config");
|
||||||
|
|
||||||
|
@ -24,6 +24,8 @@
|
|||||||
// in use, the ostree commit metadata will contain the composefs image digest,
|
// in use, the ostree commit metadata will contain the composefs image digest,
|
||||||
// which can be used to fully verify the target filesystem tree.
|
// which can be used to fully verify the target filesystem tree.
|
||||||
#define BINDING_KEYPATH "/etc/ostree/initramfs-root-binding.key"
|
#define BINDING_KEYPATH "/etc/ostree/initramfs-root-binding.key"
|
||||||
|
// The kernel argument to configure composefs
|
||||||
|
#define CMDLINE_KEY_COMPOSEFS "ostree.prepare-root.composefs"
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
proc_cmdline_has_key_starting_with (const char *cmdline, const char *key)
|
proc_cmdline_has_key_starting_with (const char *cmdline, const char *key)
|
||||||
@ -161,8 +163,12 @@ otcore_free_composefs_config (ComposefsConfig *config)
|
|||||||
|
|
||||||
// Parse the [composefs] section of the prepare-root.conf.
|
// Parse the [composefs] section of the prepare-root.conf.
|
||||||
ComposefsConfig *
|
ComposefsConfig *
|
||||||
otcore_load_composefs_config (GKeyFile *config, gboolean load_keys, GError **error)
|
otcore_load_composefs_config (const char *cmdline, GKeyFile *config, gboolean load_keys,
|
||||||
|
GError **error)
|
||||||
{
|
{
|
||||||
|
g_assert (cmdline);
|
||||||
|
g_assert (config);
|
||||||
|
|
||||||
GLNX_AUTO_PREFIX_ERROR ("Loading composefs config", error);
|
GLNX_AUTO_PREFIX_ERROR ("Loading composefs config", error);
|
||||||
|
|
||||||
g_autoptr (ComposefsConfig) ret = g_new0 (ComposefsConfig, 1);
|
g_autoptr (ComposefsConfig) ret = g_new0 (ComposefsConfig, 1);
|
||||||
@ -214,5 +220,22 @@ otcore_load_composefs_config (GKeyFile *config, gboolean load_keys, GError **err
|
|||||||
return glnx_null_throw (error, "public key file specified, but no public keys found");
|
return glnx_null_throw (error, "public key file specified, but no public keys found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_autofree char *ostree_composefs = otcore_find_proc_cmdline_key (cmdline, CMDLINE_KEY_COMPOSEFS);
|
||||||
|
if (ostree_composefs)
|
||||||
|
{
|
||||||
|
if (g_strcmp0 (ostree_composefs, "signed") == 0)
|
||||||
|
{
|
||||||
|
ret->enabled = OT_TRISTATE_YES;
|
||||||
|
ret->is_signed = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// The other states force off signatures
|
||||||
|
ret->is_signed = false;
|
||||||
|
if (!_ostree_parse_tristate (ostree_composefs, &ret->enabled, error))
|
||||||
|
return glnx_prefix_error (error, "handling karg " CMDLINE_KEY_COMPOSEFS), NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return g_steal_pointer (&ret);
|
return g_steal_pointer (&ret);
|
||||||
}
|
}
|
||||||
|
@ -59,8 +59,8 @@ typedef struct
|
|||||||
void otcore_free_composefs_config (ComposefsConfig *config);
|
void otcore_free_composefs_config (ComposefsConfig *config);
|
||||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ComposefsConfig, otcore_free_composefs_config)
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ComposefsConfig, otcore_free_composefs_config)
|
||||||
|
|
||||||
ComposefsConfig *otcore_load_composefs_config (GKeyFile *config, gboolean load_keys,
|
ComposefsConfig *otcore_load_composefs_config (const char *cmdline, GKeyFile *config,
|
||||||
GError **error);
|
gboolean load_keys, GError **error);
|
||||||
|
|
||||||
// Our directory with transient state (eventually /run/ostree-booted should be a link to
|
// Our directory with transient state (eventually /run/ostree-booted should be a link to
|
||||||
// /run/ostree/booted)
|
// /run/ostree/booted)
|
||||||
|
@ -113,14 +113,11 @@ sysroot_is_configured_ro (const char *sysroot)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
resolve_deploy_path (const char *root_mountpoint)
|
resolve_deploy_path (const char *kernel_cmdline, const char *root_mountpoint)
|
||||||
{
|
{
|
||||||
char destpath[PATH_MAX];
|
char destpath[PATH_MAX];
|
||||||
struct stat stbuf;
|
struct stat stbuf;
|
||||||
char *deploy_path;
|
char *deploy_path;
|
||||||
g_autofree char *kernel_cmdline = read_proc_cmdline ();
|
|
||||||
if (!kernel_cmdline)
|
|
||||||
errx (EXIT_FAILURE, "Failed to read kernel cmdline");
|
|
||||||
|
|
||||||
g_autoptr (GError) error = NULL;
|
g_autoptr (GError) error = NULL;
|
||||||
g_autofree char *ostree_target = NULL;
|
g_autofree char *ostree_target = NULL;
|
||||||
@ -268,6 +265,10 @@ main (int argc, char *argv[])
|
|||||||
err (EXIT_FAILURE, "usage: ostree-prepare-root SYSROOT");
|
err (EXIT_FAILURE, "usage: ostree-prepare-root SYSROOT");
|
||||||
const char *root_arg = argv[1];
|
const char *root_arg = argv[1];
|
||||||
|
|
||||||
|
g_autofree char *kernel_cmdline = read_proc_cmdline ();
|
||||||
|
if (!kernel_cmdline)
|
||||||
|
errx (EXIT_FAILURE, "Failed to read kernel cmdline");
|
||||||
|
|
||||||
// Since several APIs want to operate in terms of file descriptors, let's
|
// Since several APIs want to operate in terms of file descriptors, let's
|
||||||
// open the initramfs now. Currently this is just used for the config parser.
|
// open the initramfs now. Currently this is just used for the config parser.
|
||||||
glnx_autofd int initramfs_rootfs_fd = -1;
|
glnx_autofd int initramfs_rootfs_fd = -1;
|
||||||
@ -289,7 +290,7 @@ main (int argc, char *argv[])
|
|||||||
// We always parse the composefs config, because we want to detect and error
|
// We always parse the composefs config, because we want to detect and error
|
||||||
// out if it's enabled, but not supported at compile time.
|
// out if it's enabled, but not supported at compile time.
|
||||||
g_autoptr (ComposefsConfig) composefs_config
|
g_autoptr (ComposefsConfig) composefs_config
|
||||||
= otcore_load_composefs_config (config, TRUE, &error);
|
= otcore_load_composefs_config (kernel_cmdline, config, TRUE, &error);
|
||||||
if (!composefs_config)
|
if (!composefs_config)
|
||||||
errx (EXIT_FAILURE, "%s", error->message);
|
errx (EXIT_FAILURE, "%s", error->message);
|
||||||
|
|
||||||
@ -308,7 +309,7 @@ main (int argc, char *argv[])
|
|||||||
const char *root_mountpoint = realpath (root_arg, NULL);
|
const char *root_mountpoint = realpath (root_arg, NULL);
|
||||||
if (root_mountpoint == NULL)
|
if (root_mountpoint == NULL)
|
||||||
err (EXIT_FAILURE, "realpath(\"%s\")", root_arg);
|
err (EXIT_FAILURE, "realpath(\"%s\")", root_arg);
|
||||||
g_autofree char *deploy_path = resolve_deploy_path (root_mountpoint);
|
g_autofree char *deploy_path = resolve_deploy_path (kernel_cmdline, root_mountpoint);
|
||||||
const char *deploy_directory_name = glnx_basename (deploy_path);
|
const char *deploy_directory_name = glnx_basename (deploy_path);
|
||||||
// Note that realpath() should have stripped any trailing `/` which shouldn't
|
// Note that realpath() should have stripped any trailing `/` which shouldn't
|
||||||
// be in the karg to start with, but we assert here to be sure we have a non-empty
|
// be in the karg to start with, but we assert here to be sure we have a non-empty
|
||||||
|
@ -131,6 +131,19 @@ fn verify_composefs_signed(sh: &xshell::Shell, metadata: &glib::VariantDict) ->
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn verify_disable_composefs(sh: &xshell::Shell, metadata: &glib::VariantDict) -> Result<()> {
|
||||||
|
assert_eq!(
|
||||||
|
metadata
|
||||||
|
.lookup::<bool>("composefs")
|
||||||
|
.unwrap()
|
||||||
|
.unwrap_or_default(),
|
||||||
|
false
|
||||||
|
);
|
||||||
|
let fstype = cmd!(sh, "findmnt -n -o FSTYPE /").read()?;
|
||||||
|
assert_ne!(fstype.as_str(), "overlay");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn itest_composefs() -> Result<()> {
|
pub(crate) fn itest_composefs() -> Result<()> {
|
||||||
let sh = &xshell::Shell::new()?;
|
let sh = &xshell::Shell::new()?;
|
||||||
let mark = match crate::test::get_reboot_mark()? {
|
let mark = match crate::test::get_reboot_mark()? {
|
||||||
@ -165,7 +178,16 @@ pub(crate) fn itest_composefs() -> Result<()> {
|
|||||||
Err(reboot("2"))?;
|
Err(reboot("2"))?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
"2" => verify_composefs_signed(sh, &metadata),
|
"2" => {
|
||||||
|
verify_composefs_signed(sh, &metadata)?;
|
||||||
|
cmd!(
|
||||||
|
sh,
|
||||||
|
"rpm-ostree kargs --append=ostree.prepare-root.composefs=0"
|
||||||
|
)
|
||||||
|
.run()?;
|
||||||
|
Err(reboot("3"))
|
||||||
|
}
|
||||||
|
"3" => verify_disable_composefs(sh, &metadata),
|
||||||
o => anyhow::bail!("Unrecognized reboot mark {o}"),
|
o => anyhow::bail!("Unrecognized reboot mark {o}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user