Skip to content

Google compute image #26214

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

Merged
merged 2 commits into from
Jul 19, 2017
Merged

Google compute image #26214

merged 2 commits into from
Jul 19, 2017

Conversation

zimbatm
Copy link
Member

@zimbatm zimbatm commented May 29, 2017

Motivation for this change

This makes NixOS a first-class citizen on the Google Cloud Platform, allowing to integrate with the dynamic features of the platform.

Things done
  • Tested using sandboxing
    (nix.useSandbox on NixOS,
    or option build-use-sandbox in nix.conf
    on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • Linux
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

Sorry, something went wrong.

@mention-bot
Copy link

@zimbatm, thanks for your PR! By analyzing the history of the files in this pull request, we identified @rbvermaa, @8573 and @copumpkin to be potential reviewers.

@zimbatm zimbatm requested a review from Fuuzetsu May 29, 2017 17:47

pushd google_compute_engine

patchPath /bin/systemctl /var/run/current-system/sw/bin/systemctl
Copy link
Member

Choose a reason for hiding this comment

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

don't understand motivation behind patchPath vs patchShebangs with proper links into store &c.

Copy link
Member

@Mic92 Mic92 May 29, 2017

Choose a reason for hiding this comment

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

Probably executables are referenced not just in shebangs. But I would actually also prefer explicit links to nix store.

@Fuuzetsu
Copy link
Member

LGTM except for patchPath stuff

wants = [ "local-fs.target" "network-online.target" "network.target"];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
ExecStart = "/run/current-system/sw/bin/true";
Copy link
Member

Choose a reason for hiding this comment

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

 ExecStart = "${coreutils}/bin/true";

@@ -191,56 +191,6 @@ in
};
};

# TODO: remove this
systemd.services.fetch-ssh-keys =
{ description = "Fetch host keys and authorized_keys for root user";
Copy link
Member

Choose a reason for hiding this comment

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

How does this works now?

Copy link
Member Author

Choose a reason for hiding this comment

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

The google-accounts-daemon also scans for the SSH keys, but creates individual accounts per SSH key owner (with passwordless sudo). The root account isn't directly accessible through SSH anymore.

@Mic92
Copy link
Member

Mic92 commented May 29, 2017

using ./nixos/maintainers/scripts/gce/create-gce.sh to build a gce image fails with:

Adding rules for package /nix/store/p7sm83r55gj4bl55k4pz794dsg6mxrny-extra-udev-rules                                                  
Copying /nix/store/p7sm83r55gj4bl55k4pz794dsg6mxrny-extra-udev-rules/etc/udev/rules.d/99-local.rules to /nix/store/llwyl34sl8ncrpxa7f3l49q8bhd98bns-udev-rules/99-local.rules                                                                                                  
Adding rules for package /nix/store/0pg85agkcjsz82b36kf4pzd87mm39iic-extra-hwdb-file                                                   
Checking that all programs called by relative paths in udev rules exist in /nix/store/rsilqxrxl6vcgd77ry4jd68a5jiwjnaw-systemd-232/lib/udev... OK                                                                                                                              
Checking that all programs called by absolute paths in udev rules exist... FAIL                                                        
/var/run/current-system/sw/bin/sh is called in udev rules but not installed by udev                                                    
building path(s) ‘/nix/store/708w74szmavanm8mg69wbyjzcgn2bjaq-initrd’                                                                  
building path(s) ‘/nix/store/nnq72hiq4kxryj9qi6izw1k2lz0c4csx-unit-google-startup-scripts.service’                                     
building path(s) ‘/nix/store/ic90njrpva2840xf3yjf2k3fayj4v038-unit-script’                                                             
building path(s) ‘/nix/store/ivv5qyznk4rc9k6qp1v3ii5qg50bbw9m-unit-script’                                                             
building path(s) ‘/nix/store/knq7r3b04lc6jq88gi92a47grxq3niaj-unit-script’                                                             
building path(s) ‘/nix/store/ckg4g12gsps10awy3g29mv1c3l654xhk-unit-serial-getty-hvc0.service-disabled’                                 
building path(s) ‘/nix/store/bbqib7f8j403ksr8fxpsg2simv7wv3l1-unit-serial-getty-ttyS0.service-disabled’                                
builder for ‘/nix/store/fafg91y4w6lm66jlq5r02q0ws8yiz3ay-udev-rules.drv’ failed with exit code 1                                       
cannot build derivation ‘/nix/store/1ga1lv36g7x9mfzwpam79499d511ylaa-etc.drv’: 1 dependencies couldn't be built                        
building path(s) ‘/nix/store/4cla2f0v95j02rw32abqib4j25vk7zzv-vm-run-stage2’                                                           
cannot build derivation ‘/nix/store/9r34z9lgrhxrqqdn7v4fcpbma89cym6l-nixos-system-unnamed-17.09.git.c1ef0ed.drv’: 1 dependencies couldn't be built                                                                                                                             
cannot build derivation ‘/nix/store/c8dxf2010n9hs45zzivkyc4qh4cxp9by-google-compute-image.drv’: 1 dependencies couldn't be built       
error: build of ‘/nix/store/c8dxf2010n9hs45zzivkyc4qh4cxp9by-google-compute-image.drv’ failed

@rbvermaa
Copy link
Member

How does the google compute engine tool behave when you chose not to allow mutableUsers? Is it possible to disable anything related to creating users in the tool? If so, can we implement that depending on the mutableUsers config option?


patches = [ ./0001-allow-nologin-other-paths.patch ];

patchPhase = ''
Copy link
Member

Choose a reason for hiding this comment

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

use postPatch, otherwise your patches is ignored because you define a new patchPhase.

@zimbatm
Copy link
Member Author

zimbatm commented May 30, 2017

How does the google compute engine tool behave when you chose not to allow mutableUsers? Is it possible to disable anything related to creating users in the tool? If so, can we implement that depending on the mutableUsers config option?

Good idea. I could not start the google-accounts-daemon is mutableUsers = false. In that case the nixos configuration would be provisioned through the metadata startup-script and would have to contain the SSH keys.

There is still work to do on this PR but thanks everyone for your feedback. I will let you know when it's ready for another round of review.

cp -r google_config/udev/*.rules $out/lib/udev/rules.d
'';

propagatedBuildInputs = with pythonPackages; [ boto setuptools ];
Copy link
Member

Choose a reason for hiding this comment

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

Curious why this would depend on boto 😮

Copy link
Member Author

Choose a reason for hiding this comment

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

Apparently just for one thing: setup boto to use the Google Cloud Storage as a backend (GCS has a S3-compatible API) ^_^ https://github.com/GoogleCloudPlatform/compute-image-packages#instance-setup

@rbvermaa
Copy link
Member

Good idea. I could not start the google-accounts-daemon is mutableUsers = false. In that case the nixos configuration would be provisioned through the metadata startup-script and would have to contain the SSH keys.

What do you mean with 'through the metadata startup-script'? I am mostly interested in if this is backwards compatible with nixops.

@zimbatm
Copy link
Member Author

zimbatm commented May 30, 2017

What do you mean with 'through the metadata startup-script'? I am mostly interested in if this is backwards compatible with nixops.

Okay we need to have a bit of a conversation because right now it breaks backward-compatibility. Potentially I could leave the fetch-ssh-keys service and provide a migration path for future nixops release. Do you know how SSH keys are being provisioned with nixops?

@zimbatm zimbatm force-pushed the google-compute-image branch 3 times, most recently from b40fe2f to 0895e6d Compare May 30, 2017 20:15
@zimbatm
Copy link
Member Author

zimbatm commented May 30, 2017

Fixed all the things and left the fetch-ssh-keys daemon for nixops back-compat as both can live side-by-side.

I don't have a clear idea of what to do with the mutableUsers option yet as this module is not really meant to be designed to be configurable in the first place.

@copumpkin
Copy link
Member

Potentially I could leave the fetch-ssh-keys service and provide a migration path for future nixops release. Do you know how SSH keys are being provisioned with nixops?

For EC2 at least, we left two options in place, so that the userdata could be used in two different ways for NixOps and for non-NixOps use cases. It would be nice to converge Google and EC2 behavior, so you can also configure Google Compute machines via userdata.

@8573
Copy link
Contributor

8573 commented Jul 8, 2017

What's the status of this?

@zimbatm
Copy link
Member Author

zimbatm commented Jul 11, 2017

@8573 it's missing a corner-case where mutableUsers = true. Otherwise it's pretty stable. Feel free to push onto the branch, I will deal with it on Friday otherwise.

@8573
Copy link
Contributor

8573 commented Jul 12, 2017

Okay; I don't understand GCE enough to help, so I'll wait. Thanks!

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@zimbatm zimbatm force-pushed the google-compute-image branch from 0895e6d to b4ba2cb Compare July 15, 2017 17:17

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
This adds a few google-specific services to setup the machine.

Accounts are now dynamically created using the google-accounts-daemon,
which allows to click on the "SSH" button in the console and have it
working.

The NixOS image now supports the userdata startup and shutdown scripts.

Misc:
* add all the google services from https://github.com/GoogleCloudPlatform/compute-image-packages/tree/master/google_compute_engine_init/systemd
* add udev rules for disk labels
* synched sysctl rules with https://github.com/GoogleCloudPlatform/compute-image-packages/blob/master/google_config/sysctl/11-gce-network-security.conf
@zimbatm zimbatm force-pushed the google-compute-image branch from b4ba2cb to c93d68b Compare July 15, 2017 18:36
@zimbatm
Copy link
Member Author

zimbatm commented Jul 15, 2017

Alright, the account service is now disabled if users.mutableUsers = false

@zimbatm
Copy link
Member Author

zimbatm commented Jul 19, 2017

I think the solution is reasonable right now. Let me know if you hit any issues.

@zimbatm zimbatm merged commit 14f53e5 into NixOS:master Jul 19, 2017
@zimbatm zimbatm deleted the google-compute-image branch July 19, 2017 08:49
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.

None yet

8 participants