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

Add "shibaken" generator to populate user-data with public keys from IMDS #1331

Merged
merged 3 commits into from
Feb 24, 2021

Conversation

jpculp
Copy link
Member

@jpculp jpculp commented Feb 18, 2021

Issue number:
N/A

Description of changes:

Add "shibaken" generator to populate user-data with public keys from IMDS

This populates the host container's user-data setting with public keys
available from IMDS in the event that user-data has not been populated
by the user.

Adds a new migration helper AddMetadataMigration to remove setting
metadata (like setting-generators).

Adds a new migration for shibaken setting-generator.

Testing done:

Build aws-ecs-1 image and launched instance.

Verified that host-containers.admin.user-data contained a base64-encoded block.

Enabled and launched admin container, which started fine.

Verified that /.bottlerocket/host-containers/admin/user-data contained JSON with the following structure:

{
   "ssh":{
      "authorized_keys":[
         "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQClKsfkNkuSevGj3eYhCe53pcjqP3maAhDFcvBS7O6V
          hz2ItxCih+PnDSUaw+WNQn/mZphTk/a/gU8jEzoOWbkM4yxyb/wB96xbiFveSFJuOp/d6RJhJOI0iBXr
          lsLnBItntckiJ7FbtxJMXLvvwJryDUilBMTjYtwB+QhYXUMOzce5Pjz5/i8SeJtjnV3iAoG/cQk+0FzZ
          qaeJAAHco+CY/5WrUBkrHmFJr6HcXkvJdWPkYQS3xqC0+FmUZofz221CBt5IMucxXPkX4rWi+z7wB3Rb
          BQoQzd8v7yeb7OzlPnWOyN0qFU0XA246RA8QFYiCNYwI3f05p6KLxEXAMPLE my-key-pair"
      ]
   }
}

Ran sudo sheltie to verify root shell was still available.

@etungsten verified the migration between (1.0.5, 1.0.6)

Terms of contribution:

By submitting this pull request, I agree that this contribution is dual-licensed under the terms of both the Apache License, version 2.0, and the MIT license.

packages/os/os.spec Outdated Show resolved Hide resolved
sources/api/shibaken/src/main.rs Outdated Show resolved Hide resolved
sources/api/shibaken/src/main.rs Outdated Show resolved Hide resolved
sources/api/shibaken/src/main.rs Outdated Show resolved Hide resolved
sources/api/shibaken/src/main.rs Outdated Show resolved Hide resolved
sources/api/shibaken/src/main.rs Outdated Show resolved Hide resolved
sources/api/shibaken/src/main.rs Outdated Show resolved Hide resolved
sources/api/shibaken/src/main.rs Outdated Show resolved Hide resolved
sources/api/shibaken/src/main.rs Outdated Show resolved Hide resolved
sources/api/shibaken/src/main.rs Show resolved Hide resolved
@jpculp jpculp force-pushed the shibaken branch 2 times, most recently from 21b15d4 to 6894374 Compare February 19, 2021 04:36
@jpculp jpculp requested a review from bcressey February 19, 2021 04:42
GLOSSARY.md Outdated Show resolved Hide resolved
packages/os/os.spec Outdated Show resolved Hide resolved
sources/api/shibaken/src/main.rs Show resolved Hide resolved
sources/api/shibaken/src/main.rs Outdated Show resolved Hide resolved
sources/api/shibaken/src/main.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@zmrow zmrow left a comment

Choose a reason for hiding this comment

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

Also - could we update the testing of this PR to reflect that the migration up/down was tested and the settings appeared as we expected them to and the admin host container works in both versions?

@jpculp jpculp changed the title Add "shibaken" generator to build user-data with public keys from IMDS Add "shibaken" generator to populate user-data with public keys from IMDS Feb 19, 2021
Copy link
Contributor

@zmrow zmrow left a comment

Choose a reason for hiding this comment

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

Looks good!

🪂

GLOSSARY.md Outdated Show resolved Hide resolved
}

/// Helper to fetch an IMDSv2 session token that is valid for 60 seconds.
fn fetch_imds_session_token(client: &Client) -> Result<String> {
Copy link
Contributor

Choose a reason for hiding this comment

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

tangent: It is a bit unfortunate to have three implementations of this now, each slightly different. We should consider making an imds crate as a follow-up.

Copy link
Member Author

Choose a reason for hiding this comment

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

I definitely agree. I can take that on in another PR if folks are interested.

sources/api/shibaken/src/main.rs Outdated Show resolved Hide resolved
sources/api/shibaken/src/main.rs Outdated Show resolved Hide resolved
sources/api/shibaken/src/main.rs Outdated Show resolved Hide resolved
sources/api/shibaken/src/main.rs Outdated Show resolved Hide resolved
sources/api/shibaken/src/main.rs Show resolved Hide resolved
@jpculp jpculp force-pushed the shibaken branch 4 times, most recently from 925e9f1 to 11e5885 Compare February 23, 2021 21:00
@jpculp
Copy link
Member Author

jpculp commented Feb 23, 2021

For some context on the recent pushes that squashed together...

Rebased and addressed comments/concerns with the shibaken crate itself:
https://github.com/bottlerocket-os/bottlerocket/compare/e617e9ec..0d9fb467

Replaced instances of host container with admin container and enhanced the AddMetadataMigration to accept multiple settings (+ unit test):
https://github.com/bottlerocket-os/bottlerocket/compare/0d9fb467..30d61d14

Attempt to manually fix merge conflict:
https://github.com/bottlerocket-os/bottlerocket/compare/30d61d14..925e9f1c

Went back and just rebased instead:
https://github.com/bottlerocket-os/bottlerocket/compare/925e9f1c..11e5885fc2463e2495bcdff0ca7a61d6dd730df0

sources/api/shibaken/src/main.rs Outdated Show resolved Hide resolved
sources/api/shibaken/src/main.rs Outdated Show resolved Hide resolved
sources/api/shibaken/src/main.rs Outdated Show resolved Hide resolved
packages/os/os.spec Outdated Show resolved Hide resolved
@jpculp
Copy link
Member Author

jpculp commented Feb 24, 2021

  • Changed SettingsMetadata to SettingMetadata
  • Simplified parse_args function logic
  • Replaced 'a lifetimes with static in AddMetadataMigration code
  • Additional clean-up

@jpculp jpculp requested a review from zmrow February 24, 2021 04:37
sources/api/shibaken/src/main.rs Outdated Show resolved Hide resolved
…IMDS

This populates the admin container's user-data setting with public keys
available from IMDS in the event that user-data has not been populated
by the user.
Adds new migration helper `AddMetadataMigration` to remove setting
metadata (like setting-generators).
@jpculp
Copy link
Member Author

jpculp commented Feb 24, 2021

  • Changed SettingMetadata from a vec to a slice in AddMetadataMigration
  • Replaced instances of url with uri in shibaken
  • Removed comma from the last element of the (1.0.5, 1.0.6) migration list for consistency

tjkirch
tjkirch previously approved these changes Feb 24, 2021
@tjkirch tjkirch dismissed their stale review February 24, 2021 20:15

(CI failure)

Copy link
Contributor

@zmrow zmrow left a comment

Choose a reason for hiding this comment

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

🦺

Adds a new migration for shibaken setting-generator
@jpculp
Copy link
Member Author

jpculp commented Feb 24, 2021

  • Changed SettingMetadata from a vec to a slice in add-shibaken
  • Added additional commas to migration lists in Release.toml. The hope is we can be consistent in adding them to make it easier to append additional migrations between PRs.

@jpculp jpculp merged commit ba9afa4 into bottlerocket-os:develop Feb 24, 2021
@jpculp jpculp deleted the shibaken branch February 26, 2021 02:12
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.

6 participants