Skip to content

user-data: only verify mime-types for TYPE_NEEDED and x-shellscript#511

Merged
OddBloke merged 3 commits into
canonical:masterfrom
raharper:fix/user-data-payload-probe
Aug 14, 2020
Merged

user-data: only verify mime-types for TYPE_NEEDED and x-shellscript#511
OddBloke merged 3 commits into
canonical:masterfrom
raharper:fix/user-data-payload-probe

Conversation

@raharper
Copy link
Copy Markdown
Collaborator

Commit d00126c regressed cloud-init
handling in multipart MIME user-data. Specifically, cloud-init would
examine the payload of the MIME part to determine what the content
type and subsequently which handler to use. This meant that user-data
which had shellscript payloads (starts with #!) were always handled
as shellscripts, rather than their declared MIME type and affected
when the payload was handled.

One failing scenario was a MIME part with text/cloud-boothook type
declared and a shellscript payload. This was run at shellscript
processing time rather than boothook time resulting in an change in
behavior from previous cloud-init releases.

To continue to support known scenarios where clouds have specifed
a MIME type of text/x-shellscript but provided a payload of something
other than shellscripts, we're changing the lookup logic to check for
the TYPES_NEEDED (text/plain, text/x-not-multipart) and only
text/x-shellscript.

It is safe to check text/x-shellscript parts as all shellscripts must
include the #! marker and will be detected as text/x-shellscript types.
If the content is missing the #! marker, it will not be excuted. If
the content is detected as something cloud-init supports, such as
#cloud-config the appropriate cloud-init handler will be used.

This change will fix hanldling for parts which were shellscripts but
ran with the wrong handler due to ignoring of the provided mime-type.

LP: #1888822

Commit d00126c regressed cloud-init
handling in multipart MIME user-data.  Specifically, cloud-init would
examine the payload of the MIME part to determine what the content
type and subsequently which handler to use.  This meant that user-data
which had shellscript payloads (starts with #!) were always handled
as shellscripts, rather than their declared MIME type and affected
when the payload was handled.

One failing scenario was a MIME part with text/cloud-boothook type
declared and a shellscript payload.  This was run at shellscript
processing time rather than boothook time resulting in an change in
behavior from previous cloud-init releases.

To continue to support known scenarios where clouds have specifed
a MIME type of text/x-shellscript but provided a payload of something
other than shellscripts, we're changing the lookup logic to check for
the TYPES_NEEDED (text/plain, text/x-not-multipart) and only
text/x-shellscript.

It is safe to check text/x-shellscript parts as all shellscripts must
include the #! marker and will be detected as text/x-shellscript types.
If the content is missing the #! marker, it will not be excuted.  If
the content is detected as something cloud-init supports, such as
 #cloud-config the appropriate cloud-init handler will be used.

This change will fix hanldling for parts which were shellscripts but
ran with the wrong handler due to ignoring of the provided mime-type.

LP: #1888822
@raharper raharper force-pushed the fix/user-data-payload-probe branch from 62eb7e0 to 8990a6a Compare July 29, 2020 18:23
Copy link
Copy Markdown

@detiber detiber left a comment

Choose a reason for hiding this comment

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

These changes look good to me and I believe will resolve the issue we've been seeing where our boothook is being interpreted as 'text/x-shellscript'

@raharper raharper requested a review from OddBloke August 10, 2020 15:03
Copy link
Copy Markdown
Collaborator

@OddBloke OddBloke left a comment

Choose a reason for hiding this comment

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

Thanks!

@OddBloke OddBloke merged commit ef041fd into canonical:master Aug 14, 2020
@voor
Copy link
Copy Markdown

voor commented Aug 14, 2020

I'm still getting up to speed on the release cadence of cloud-init, do you know the ETA for this to make it live to an Ubuntu image pulling from the regular canonical repositories?

@mitechie
Copy link
Copy Markdown
Contributor

mitechie commented Aug 14, 2020 via email

@OddBloke
Copy link
Copy Markdown
Collaborator

OddBloke commented Aug 14, 2020 via email

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.

5 participants