Skip to content

Commit

Permalink
Update system script, readme, and configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
jimbydamonk committed Jul 20, 2016
1 parent 7fd6c72 commit eda7c1a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
29 changes: 28 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
# mock-ec2-metadata [![Build Status](https://travis-ci.org/NYTimes/mock-ec2-metadata.svg?branch=master)](https://travis-ci.org/NYTimes/mock-ec2-metadata)


A simple service to mock the ec2 metadata service.
A simple service (written in [go](https://golang.org/) using [gizmo](https://github.com/NYTimes/gizmo)) to mock the ec2 metadata service. This is usefully for development images (like vagrant or packer) that require Instance base IAM permission or other metadata information.

For example, [cob](https://github.com/henrysher/cob) and [s3-iam](https://github.com/seporaitis/yum-s3-iam) can both use s3 as a yum repo. Both of these systems rely on the instances the proper credentials to have authorization to the s3 repos that yum uses.


The metadata service normal listens on a special private ip address `169.254.169.254`. This is a special address that will not exist on your system. One option is to bind an alias to the loopback iterface. This can be done with the following command:

```console
/sbin/ifconfig lo:1 inet 169.254.169.254 netmask 255.255.255.255 up
```

Many services assume that use the metadata service uses a default port 80 and do not allow configuration or override. A simple IP talbes rule and IP forwarding can get around that, as follows:

```console
$ echo 1 > /proc/sys/net/ipv4/ip_forward
$ iptables -t nat -A OUTPUT -p tcp -d 169.254.169.254/32 --dport 80 -j DNAT --to-destination 169.254.169.254:8111
$ service iptables save
```

## Configuration
All configuration is contained in either `./mock-ec2-metadata-config.json` or `/etc/mock-ec2-metadata-config.json`, the former overriding the latter.

Currently the support URLs for the metadata service are:
* http://169.254.169.154/latest/meta-data/latest/
* http://169.254.169.154/latest/meta-data/latest/meta-data/hostname
* http://169.254.169.154/latest/meta-data/latest/instance-id
* http://169.254.169.154/latest/meta-data/latest/instance-type
* http://169.254.169.154/latest/meta-data/latest/iam/security-credentials

## Getting started

Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func main() {

if _, err := os.Stat("./mock-ec2-metadata-config.json"); err == nil {
config.LoadJSONFile("./mock-ec2-metadata-config.json", &cfg)
} else if _, err := os.Stat("/etc/config.json"); err == nil {
} else if _, err := os.Stat("/etc/mock-ec2-metadata-config.json"); err == nil {
config.LoadJSONFile("/etc/mock-ec2-metadata-config.json", &cfg)
} else {
server.Log.Fatal("unable to locate config file")
Expand Down
1 change: 1 addition & 0 deletions systemd/mock-ec2-metadata.service
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ After=network.target
[Service]
Type=simple
ExecStart=/usr/local/bin/mock-ec2-metadata
Restart=always

[Install]
WantedBy=multi-user.target

0 comments on commit eda7c1a

Please sign in to comment.