summary refs log tree commit diff
path: root/nixos/modules/virtualisation/amazon-image.nix
diff options
context:
space:
mode:
authorGraham Christensen <graham@grahamc.com>2020-11-18 11:56:15 -0500
committerGraham Christensen <graham@grahamc.com>2020-11-19 13:00:56 -0500
commit83ea88e03fe2775601636c5f578b63276910a538 (patch)
tree9e094e34f05b8169790b4e67542cad4683af7a50 /nixos/modules/virtualisation/amazon-image.nix
parent21339b41bf60847b0b8880b8ca5ceb2867044bf1 (diff)
downloadnixpkgs-83ea88e03fe2775601636c5f578b63276910a538.tar
nixpkgs-83ea88e03fe2775601636c5f578b63276910a538.tar.gz
nixpkgs-83ea88e03fe2775601636c5f578b63276910a538.tar.bz2
nixpkgs-83ea88e03fe2775601636c5f578b63276910a538.tar.lz
nixpkgs-83ea88e03fe2775601636c5f578b63276910a538.tar.xz
nixpkgs-83ea88e03fe2775601636c5f578b63276910a538.tar.zst
nixpkgs-83ea88e03fe2775601636c5f578b63276910a538.zip
nixos: ec2 ami: support IMDSv2
AWS's metadata service has two versions. Version 1 allowed plain HTTP
requests to get metadata. However, this was frequently abused when a
user could trick an AWS-hosted server in to proxying requests to the
metadata service. Since the metadata service is frequently used to
generate AWS access keys, this is pretty gnarly. Version two is
identical except it requires the caller to request a token and provide
it on each request.

Today, starting a NixOS AMI in EC2 where the metadata service is
configured to only allow v2 requests fails: the user's SSH key is not
placed, and configuration provided by the user-data is not applied.
The server is useless. This patch addresses that.

Note the dependency on curl is not a joyful one, and it expand the
initrd by 30M. However, see the added comment for more information
about why this is needed. Note the idea of using `echo` and `nc` are
laughable. Don't do that.
Diffstat (limited to 'nixos/modules/virtualisation/amazon-image.nix')
-rw-r--r--nixos/modules/virtualisation/amazon-image.nix1
1 files changed, 1 insertions, 0 deletions
diff --git a/nixos/modules/virtualisation/amazon-image.nix b/nixos/modules/virtualisation/amazon-image.nix
index 44cb6080945..819e93a43e5 100644
--- a/nixos/modules/virtualisation/amazon-image.nix
+++ b/nixos/modules/virtualisation/amazon-image.nix
@@ -11,6 +11,7 @@ with lib;
 let
   cfg = config.ec2;
   metadataFetcher = import ./ec2-metadata-fetcher.nix {
+    inherit (pkgs) curl;
     targetRoot = "$targetRoot/";
     wgetExtraOptions = "-q";
   };