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

v1_5_exp: Add sugar to create user.cfg #339

Merged
merged 4 commits into from
Jun 22, 2022

Conversation

saqibali-2k
Copy link
Member

@saqibali-2k saqibali-2k commented Apr 11, 2022

We want to add sugar to butane which will allow users to indirectly
modify the GRUB configuration. The sugar added here will abstract
the mounting of /boot and will allow users to create /boot/grub2/user.cfg
which is sourced by grub.cfg.

@saqibali-2k saqibali-2k force-pushed the pr/grub-user-sugar branch 2 times, most recently from 58241fa to 7bf3c16 Compare April 11, 2022 18:49
Copy link
Contributor

@bgilbert bgilbert left a comment

Choose a reason for hiding this comment

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

Let's mention coreos/fedora-coreos-tracker#134 in the commit message.

base/v0_5_exp/schema.go Outdated Show resolved Hide resolved
base/v0_5_exp/schema.go Outdated Show resolved Hide resolved
@saqibali-2k saqibali-2k changed the title v0_5_exp/schema,translate.go: Add sugar to create user.cfg v1_5_exp: Add sugar to create user.cfg Apr 12, 2022
Copy link
Contributor

@bgilbert bgilbert left a comment

Choose a reason for hiding this comment

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

Thanks for handling this! There are some details, but this has the right general idea. 👍

config/fcos/v1_5_exp/schema.go Outdated Show resolved Hide resolved
config/fcos/v1_5_exp/schema.go Show resolved Hide resolved
config/fcos/v1_5_exp/translate.go Outdated Show resolved Hide resolved
config/fcos/v1_5_exp/schema.go Outdated Show resolved Hide resolved
config/fcos/v1_5_exp/translate.go Outdated Show resolved Hide resolved
config/fcos/v1_5_exp/translate.go Outdated Show resolved Hide resolved
config/fcos/v1_5_exp/validate.go Outdated Show resolved Hide resolved
@travier
Copy link
Member

travier commented Apr 21, 2022

Can you paste here an example config?
Can you also make a PR for the docs with that example?
Thanks!

@jlebon
Copy link
Member

jlebon commented Apr 21, 2022

This is essentially making user.cfg a public API that users can edit directly via Ignition. Should we enhance grub.cfg to source a specific e.g. password.cfg file dedicated to password protection so that a user can both use this sugar and add their own user.cfg? The ideal would be a user.cfg.d/ but it doesn't seem like source supports directories or globs.

@bgilbert
Copy link
Contributor

As I mentioned in #339 (comment), I think we should actively discourage users from making arbitrary changes to their GRUB configuration. By limiting the available sugar and not documenting how to make arbitrary changes, we can make user.cfg a semi-private API between FCOS and Butane. We can always add additional sugar later, including support for arbitrary config fragments if we really want to.

@saqibali-2k
Copy link
Member Author

saqibali-2k commented Apr 21, 2022

Example Config:

variant: fcos
version: 1.5.0-experimental
grub:
  users:
    - user: root
      key: grub.pbkdf2.sha512.10000.874A958E526409...

Note: user and key will be changed to name and password_hash respectively

@saqibali-2k
Copy link
Member Author

Rebased baseutil.MakeDataURL changes and pushed documentation updates.

Copy link
Contributor

@bgilbert bgilbert left a comment

Choose a reason for hiding this comment

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

Code generally looks good! Just a pile of small cleanups. 🧹

config/fcos/v1_5_exp/schema.go Outdated Show resolved Hide resolved
docs/examples.md Show resolved Hide resolved
docs/examples.md Outdated Show resolved Hide resolved
docs/examples.md Outdated Show resolved Hide resolved
docs/examples.md Outdated Show resolved Hide resolved
config/fcos/v1_5_exp/translate_test.go Show resolved Hide resolved
config/fcos/v1_5_exp/validate_test.go Show resolved Hide resolved
docs/config-fcos-v1_5-exp.md Outdated Show resolved Hide resolved
docs/config-fcos-v1_5-exp.md Outdated Show resolved Hide resolved
docs/config-fcos-v1_5-exp.md Outdated Show resolved Hide resolved
config/fcos/v1_5_exp/translate.go Outdated Show resolved Hide resolved
config/fcos/v1_5_exp/translate.go Outdated Show resolved Hide resolved
config/fcos/v1_5_exp/translate_test.go Outdated Show resolved Hide resolved
docs/config-fcos-v1_5-exp.md Outdated Show resolved Hide resolved
docs/examples.md Outdated Show resolved Hide resolved
@bgilbert
Copy link
Contributor

Currently, if a parent Butane config and a child Butane config both specify grub.users, then when Ignition merges the resulting Ignition configs at runtime, the parent users will be completely overwritten by the child. This is surprising, since it violates the usual config-merging semantics of replacing existing list entries and appending new ones.

In principle we could provide the usual semantics by having the sugar use storage.files.append instead of storage.files.contents, and using set superusers="$superusers ...". A couple concerns though:

  • This assumes that GRUB overwrites an existing password if it sees a second password_pbkdf2 command for a given user. @saqibali-2k, could you verify this?
  • This wouldn't work in openshift because the MCO doesn't support append. I'm not sure that should stop us though. The openshift variant can always have special-case code to look for user.cfg and move its append directive to contents. @jlebon, any thoughts?

@saqibali-2k
Copy link
Member Author

  • This assumes that GRUB overwrites an existing password if it sees a second password_pbkdf2 command for a given user. @saqibali-2k, could you verify this?

Verified this: the old password does not work after a second password_pbkdf2 command is given.

@bgilbert
Copy link
Contributor

(And I assume it's okay to list the same user twice in superusers.)

@saqibali-2k
Copy link
Member Author

(And I assume it's okay to list the same user twice in superusers.)

This is true, but this resets any previously defined password for that user. So in practice if no new password is set, we just get a username where the password has been thrown away.

@bgilbert
Copy link
Contributor

To be clear, are you saying that set superusers="foo" deletes any previous password for foo?

I think that's actually okay. As long as we define password_hash as required, we won't add a user to superusers unless we're also setting a password for it.

Copy link
Contributor

@bgilbert bgilbert left a comment

Choose a reason for hiding this comment

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

Thanks for switching to append. This should currently fail validation in the openshift experimental spec. Want to add some translation code there to find the user.cfg entry and convert its append to contents?

docs/config-fcos-v1_5-exp.md Outdated Show resolved Hide resolved
config/fcos/v1_5_exp/validate_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@bgilbert bgilbert left a comment

Choose a reason for hiding this comment

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

Thanks for making the additional changes!

config/openshift/v4_12_exp/translate.go Outdated Show resolved Hide resolved
config/openshift/v4_12_exp/translate.go Outdated Show resolved Hide resolved
config/openshift/v4_12_exp/translate.go Show resolved Hide resolved
config/openshift/v4_12_exp/translate.go Outdated Show resolved Hide resolved
docs/config-fcos-v1_5-exp.md Show resolved Hide resolved
config/openshift/v4_12_exp/translate.go Outdated Show resolved Hide resolved
config/openshift/v4_12_exp/translate.go Show resolved Hide resolved
We want to add sugar to butane which will allow users to indirectly
modify the GRUB configuration. The sugar added here will abstract
the mounting of /boot and will allow users to create /boot/grub2/user.cfg
which is sourced by grub.cfg.

related: coreos/fedora-coreos-tracker#134
Let's document the newly added GRUB functionality and add
an example config showing users how to use it.
config/openshift/v4_12_exp/translate.go Outdated Show resolved Hide resolved
config/openshift/v4_12_exp/translate.go Outdated Show resolved Hide resolved
config/openshift/v4_12_exp/translate.go Show resolved Hide resolved
config/openshift/v4_12_exp/translate_test.go Show resolved Hide resolved
@saqibali-2k saqibali-2k force-pushed the pr/grub-user-sugar branch 2 times, most recently from 4b611cb to 2efc84e Compare May 31, 2022 13:50
@jlebon jlebon mentioned this pull request Jun 6, 2022
40 tasks
Copy link
Contributor

@bgilbert bgilbert left a comment

Choose a reason for hiding this comment

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

Almost there; just some small fixes.

config/openshift/v4_12_exp/translate.go Outdated Show resolved Hide resolved
translate/set.go Outdated Show resolved Hide resolved
config/openshift/v4_12_exp/translate.go Outdated Show resolved Hide resolved
translate/set.go Outdated
func (ts TranslationSet) AddFromCommonObject(fromPrefix path.ContextPath, toPrefix path.ContextPath, to interface{}) {
vTo := reflect.ValueOf(to)
vPathsTo := prefixPaths(getAllPaths(vTo, ts.ToTag, true), toPrefix.Path...)
vPathsFrom := prefixPaths(getAllPaths(vTo, ts.FromTag, true), fromPrefix.Path...)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is probably okay as-is, but there's an unnecessary implicit assumption that getAllPaths() returns paths in a consistent order. Possible cleanup: call getAllPaths once, drop the prefixPaths calls, and then loop over paths:

ts.AddTranslation(prefixPath(path, fromPrefix.Path...), prefixPath(path, toPrefix.Path...))

Copy link
Contributor

Choose a reason for hiding this comment

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

It turns out that I've asked you to add a bug here, which is that both sides of the resulting translation are now using ToTag. I won't ask you to fix it though; I'll handle that in a followup.

Copy link
Contributor

Choose a reason for hiding this comment

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

Followup in #357.

translate/set.go Outdated Show resolved Hide resolved
This is a useful function for copying all the fields of one object to the
identically named fields of another object. We add translations prefixed by
fromPrefix and toPrefix, retrieving the subpaths from to.
Sugar in FCOS V1.5.0-exp creates a user.cfg file
using append; however, append is forbidden for MCO.
Let's add special handling that converts user.cfg's
append to contents for Openshift V4.12.0-exp.
Copy link
Contributor

@bgilbert bgilbert left a comment

Choose a reason for hiding this comment

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

Thanks for all your hard work on this! 💯 🎆

@travier
Copy link
Member

travier commented Jun 24, 2022

Awesome!

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.

4 participants