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

buildextend-installer: move PXE squashfs and osmet to separate initrd #1608

Merged
merged 5 commits into from
Jul 27, 2020
Merged

Conversation

bgilbert
Copy link
Contributor

@bgilbert bgilbert commented Jul 20, 2020

For live images, add PXE rootfs image containing osmet files and the root squashfs. This can be appended as a second initrd or fetched by the initramfs at runtime. Write the build ID into flag files in the initramfs and rootfs so the initramfs can confirm that both came from the same build. Store the hash of the rootfs into the PXE initramfs so rootfs integrity can be verified after a runtime fetch.

If --legacy-pxe is specified, continue as we were before, but generate a rootfs image containing only a flag file. This allows a transition period where the initramfs can check for the flag file and warn that the rootfs hasn't been provided.

For coreos/fedora-coreos-tracker#390.

@openshift-ci-robot
Copy link

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

Copy link
Member

@dustymabe dustymabe left a comment

Choose a reason for hiding this comment

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

Overall LGTM. A few comments throughout the code.

src/cmd-buildextend-installer Show resolved Hide resolved
Comment on lines 188 to 189
# Generate initramfs stamp file which says whether it's a live or legacy
# initramfs.
Copy link
Member

Choose a reason for hiding this comment

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

I'll be glad when we can drop the legacy (non-live) installer.

# Add the padding
with open(initramfs, 'ab') as fdst:
fdst.write(bytes(initrd_ignition_padding))
# Generate initramfses
Copy link
Member

Choose a reason for hiding this comment

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

Say "Generate initramfses" ten times fast! 😜

@dustymabe
Copy link
Member

In our discussion for this we deemed the "unify the ISO and PXE rootfs paths" out of scope. If we do unify those paths in the future do you think it would make the code in here easier? I see a lot of if not args.no_pxe in here that I think would mostly go away because we'd be generating the same rootfs file for both and the real difference is just at the end when you put together the ISO. The hard part is obviously on the other end (making the ISO boot up use the different artifact).

@bgilbert
Copy link
Contributor Author

If we do unify those paths in the future do you think it would make the code in here easier?

I don't think so. IMO the initrd generation is pretty clean now. The args.no_pxe checks are an optimization and aren't all that intrusive. I'd say dropping the installer images would be a larger maintainability improvement.

@bgilbert
Copy link
Contributor Author

Moved initial refactor to #1612.

@dustymabe
Copy link
Member

rebase now that #1612 merged

Copy link
Member

@dustymabe dustymabe left a comment

Choose a reason for hiding this comment

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

LGTM

A few optional comments.

src/cmd-buildextend-installer Show resolved Hide resolved
src/cmd-buildextend-installer Outdated Show resolved Hide resolved
@dustymabe
Copy link
Member

/approve

@bgilbert bgilbert changed the title WIP: buildextend-installer: move PXE squashfs and osmet to separate initrd buildextend-installer: move PXE squashfs and osmet to separate initrd Jul 24, 2020
@bgilbert bgilbert marked this pull request as ready for review July 24, 2020 01:22
@bgilbert
Copy link
Contributor Author

bgilbert commented Jul 24, 2020

Ready for review. We should hold on merging this until rdcore has landed and the fedora-coreos-config PR is ready to merge.

/hold

Copy link
Member

@jlebon jlebon left a comment

Choose a reason for hiding this comment

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

Cool, I like that you added tests for this already in testiso!

One missing case I noticed is appending to the initrd= PXE config instead of concatenating. OTOH, it's identical behaviour from our point of view either way; I'm not sure it's possible for that to break without concatenating also breaking and it being a bug in our code (well except maybe in our kola PXE config, but that's our problem).

Comment on lines 155 to 157
# Make stream hash for `rdcore stream-hash`
def make_stream_hash(src, dest):
Copy link
Member

Choose a reason for hiding this comment

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

Any reason you implemented this in Python instead of rdcore as well so both reading and writing the hash file sit together? Plus, we're sure to use OpenSSL for hashing, whereas... briefly looking at the Python hashlib docs and the CPython source, it seems like it uses its own C implementation for SHA-256. How's the speed?

Cool as is too of course (and we can change it in a follow-up as well).

Though maybe once we document the format a bit, let's add a permalink to it here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any reason you implemented this in Python instead of rdcore as well so both reading and writing the hash file sit together?

My initial instinct was to put it in rdcore, but the additional build-time dependency seemed more troublesome than the 10 lines of Python. But yeah, we can always change it later. I'll add a link to the format docs.

Plus, we're sure to use OpenSSL for hashing, whereas... briefly looking at the Python hashlib docs and the CPython source, it seems like it uses its own C implementation for SHA-256. How's the speed?

I'm seeing 347 MiB/sec for this code (using timeit) and 335 MiB/sec for rdcore stream-hash (including process startup overhead).

Comment on lines +225 to +229
if args.legacy_pxe:
tmpinitrd_pxe_or_rootfs = tmpinitrd_pxe
else:
tmpinitrd_pxe_or_rootfs = tmpinitrd_pxe_rootfs
Copy link
Member

Choose a reason for hiding this comment

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

Could move this down lower to where it's actually used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Eh, I think it's a bit cleaner to keep it outside the conditionals.

@bgilbert
Copy link
Contributor Author

One missing case I noticed is appending to the initrd= PXE config instead of concatenating.

I actually did that first, and it worked fine on x86_64. I tore it out because unconditional concatenation was less intrusive. Every architecture has its own way of plumbing additional initrds to its bootloader, which I couldn't test, and s390x required concatenation anyway.

it's identical behaviour from our point of view either way

Yup, agreed.

bgilbert added 5 commits July 27, 2020 08:13
For live images, add PXE "rootfs" image containing osmet files and the root
squashfs.  This can be appended as a second initrd or fetched by the
initramfs at runtime.  Write the build ID into flag files in the initramfs
and rootfs so the initramfs can confirm that both came from the same build.
Store a chunked hash of the rootfs into the PXE initramfs so rootfs
integrity can be verified after a runtime fetch.

If --legacy-pxe is specified, continue as we were before, but generate a
rootfs image containing only a flag file.  This allows a transition period
where the initramfs can check for the flag file and warn that the rootfs
hasn't been provided.
Eventually, we'll default to having the initramfs fetch the rootfs via
HTTP, since that's the hard case.  Or, if --pxe-append-rootfs is
specified, concatenate the initramfs and rootfs together into one image.

But for now, we need to ratchet CI by unconditionally concatenating.
@bgilbert
Copy link
Contributor Author

Updated to add link to rdcore stream-hash format.

@jlebon
Copy link
Member

jlebon commented Jul 27, 2020

/lgtm

@dustymabe
Copy link
Member

/lgtm

@openshift-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bgilbert, dustymabe, jlebon

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [bgilbert,dustymabe,jlebon]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@bgilbert
Copy link
Contributor Author

/unhold

@openshift-merge-robot openshift-merge-robot merged commit 2d699f0 into coreos:master Jul 27, 2020
@bgilbert bgilbert deleted the rootfs branch July 27, 2020 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants