Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 603346 - app-admin/amazon-ec2-init: mask for quality and security issues
Summary: app-admin/amazon-ec2-init: mask for quality and security issues
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: No maintainer - Look at https://wiki.gentoo.org/wiki/Project:Proxy_Maintainers if you want to take care of it
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 604998
  Show dependency tree
 
Reported: 2016-12-21 14:53 UTC by Michael Orlitzky
Modified: 2017-02-01 02:19 UTC (History)
4 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Orlitzky gentoo-dev 2016-12-21 14:53:36 UTC
One look at this init script, and I'm pretty sure it should just be masked for removal. It's grabbing random data over plain HTTP and stuffing it into /root/.ssh/authorized_keys? Okay...
Comment 1 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2016-12-21 15:52:56 UTC
Sounds like security business to me. However, feel free to mask it straight away.
Comment 2 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2017-01-07 21:18:00 UTC
Please unmask it.

If you want to mask it on account of doing what SEEMS to be security-fail, then you also need to remove other tools that do the same thing: cloud-init, amiconfig, flamingo [1], etc.

The trick, and why this SHOULD stay, is to look at the address:
169.254.169.254

In an EC2 environment, or anything else that implements that same metadata system (there are implementations for OpenStack, Ganeti [2] & others), 169.254.169.254 is a special address within the 169.254.0.0/16 IPv4 link-local block, authenticates the request by out-of-band-means (eg traffic from the correct hypervisor switchport), and provides a response.

If you install this package in a non-cloud environment, your attack scope is still limited the local network.

[1] https://github.com/tmrts/flamingo
[2] http://docs.ganeti.org/ganeti/2.15/html/design-os.html#metadata-service
Comment 3 Thomas Deutschmann (RETIRED) gentoo-dev 2017-01-07 21:34:33 UTC
Yes, please stop removal if the only reason were security concerns.

See https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html to learn more about this service.
Comment 4 Michael Orlitzky gentoo-dev 2017-01-07 21:45:33 UTC
It's not just the HTTP data, but the fact that damn near everything can go wrong:

  depend() {
         before hostname
         need net.eth0
  }

Hard-coding the interface name...

  local hostname=$(wget -t 2 -T 5 -q -O - 
                     http://169.254.169.254/latest/meta-data/local-hostname)
  echo "hostname=${hostname}" >> /etc/conf.d/hostname

What if that outputs an error?

  wget ... >> >> /root/.ssh/authorized_keys

Same here.

  if [ -f /root/.ssh/authorized_keys ]; then
      chown root:root /root/.ssh/authorized_keys
      chmod 0600 /root/.ssh/authorized_keys
  fi

Messing with the ownership and read/write bits on one of the most sensitive files on the system?

The security concerns aren't why I filed the bug, but anyone on your physical segment can grab root, right?

That init script is likely to screw up your machine if you use it long enough. It needs to be rewritten, but of course there's no maintainer. I'll drop the mask if you insist, but I think this is asking for trouble.
Comment 5 Michael Orlitzky gentoo-dev 2017-01-07 22:02:48 UTC
And to beat a dead horse:

  mkdir -p /root/.ssh

Now root's private .ssh directory is world-readable. For an example of what can go wrong, if I run this on one of my machines with an eth0, then $(wget ...) returns the empty string, and

  echo "hostname=${hostname}" >> /etc/conf.d/hostname

wipes out the hostname and breaks postfix.
Comment 6 Philippe Chaintreuil 2017-01-07 22:32:40 UTC
I've submitted a proxy-maintainer request for app-admin/amazon-ec2-init via bug #604998.
Comment 7 Reuben Martin 2017-01-22 04:22:25 UTC
https://github.com/bparsons/ec2-init

perhaps this might make a good alternative?
Comment 8 Michael Orlitzky gentoo-dev 2017-01-22 17:29:32 UTC
(In reply to Reuben Martin from comment #7)
> https://github.com/bparsons/ec2-init
> 
> perhaps this might make a good alternative?

It's a lot better but not all the way there. I listed the issues that need to be fixed over in bug 604998. Not all of them are critical, though. Here's what ec2-init would fix:

  1. It doesn't always overwrite your hostname configuration. It still tries
     to with open('/etc/hostname', 'w'), but that will fail if the file
     doesn't exist. It still shouldn't do that, though.

  2. It checks for HTTP errors to avoid trashing the system.

  3. It's better about appending duplicate keys and messing up the permissions
     on /root/.ssh, but it still isn't perfect.

But here's what it doesn't:

  1. We still need a guard like I_KNOW_WHAT_I_AM_DOING in a conf.d file
     to prevent people from running this accidentally. The user should
     acknowledge the fact that anyone connected to his ethernet port
     is about to gain root.

  2. There's no stop() to undo the things that the script does.

I would say the only critical thing is the guard variable to prevent people from running the init script accidentally. It's not so bad if the missing stop() permanently changes your system after you've claimed that I_KNOW_WHAT_I_AM_DOING.
Comment 9 Philippe Chaintreuil 2017-01-27 14:45:20 UTC
Sorry for the radio silence.  I've been chipping away at a version of the original script to satisfy @mjo's requests.  Hopefully I'll be done in the next few days and submit a pull request.


A few points I've realized the last few weeks:

1.)  I realized I don't need this script at all because I don't care about dynamic hostnames & SSH keys.  But that's because I run a single static server with a persistent drive, as opposed to the standard ephemeral drives that most EC2 instances use.
     So some of you might also not require this script at all, if you've just installed it because https://www.artembutusov.com/gentoo-on-aws/ mentioned it, but aren't spinning up instances of an AMI that doesn't have a stable user system.

2.)  It seems the "plus" of this script is that it's simple and minimal.  Amazon Linux uses cloud-init instead of a small script like this, but it gives them features like scripts to run at start-up and control over initialization of the system.  It would seem to me that people that need more advanced features should look at cloud-init or a similar product.

3.)  I_KNOW_WHAT_AM_DOING=1 usually allow people to unlock dangerous sub-features; but this whole script requires extreme trust of 169.254.169.254.  It feels to me that this script should be permanently masked with a message stating that it trusts the local network excessively and is only intended to be used on Amazon's EC2 service.  (But not masked for removal.)  Unmasking would be acknowledgement and acceptance of that warning.

If anyone disagrees with the above, let me know (and why, so I can understand).
Comment 10 Michael Orlitzky gentoo-dev 2017-02-01 02:19:25 UTC
(In reply to Philippe Chaintreuil from comment #9)
> It feels to me that this script should be permanently
> masked with a message stating that it trusts the local network excessively
> and is only intended to be used on Amazon's EC2 service.  (But not masked
> for removal.)  Unmasking would be acknowledgement and acceptance of that
> warning.

I've updated the mask to say that it's masked for QA/security issues. I'm not going to remove it so long as people need it, and having it masked should be enough to prevent accidental use.

Although if somebody still wants to fix it, that's cool too =)