metadata

package module
v0.0.0-...-d9a9f41 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 19, 2019 License: Apache-2.0 Imports: 5 Imported by: 0

README

mock-ec2-metadata Build Status

A simple service (written in go using 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 and 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:

/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:

$ 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:

Getting started

This project requires Go to be installed. On OS X with Homebrew you can just run brew install go.

Running it then should be as simple as:

$ make deps
$ make
$ ./bin/mock-ec2-metadata
Testing

make test

License

See LICENSE

Contributing

See CONTRIBUTING.md for more details.

Documentation

Index

Constants

View Source
const Version = "0.4.1"

The main version number that is being run at the moment.

View Source
const VersionPrerelease = ""

A pre-release marker for the version. If this is "" (empty string) then it means that it is a final release. Otherwise, this is a pre-release such as "dev" (in development), "beta", "rc1", etc.

Variables

View Source
var GitCommit string

The git commit that was compiled. This will be filled in by the compiler.

Functions

This section is empty.

Types

type Config

type Config struct {
	Server           *server.Config
	MetadataValues   *MetadataValues
	MetadataPrefixes []string
	UserdataValues   map[string]string
	UserdataPrefixes []string
}

type MetadataService

type MetadataService struct {
	// contains filtered or unexported fields
}

func NewMetadataService

func NewMetadataService(cfg *Config) *MetadataService

func (*MetadataService) Endpoints

func (service *MetadataService) Endpoints() map[string]map[string]http.HandlerFunc

Endpoints is a listing of all endpoints available in the MetadataService.

func (*MetadataService) GetAmiId

func (s *MetadataService) GetAmiId(w http.ResponseWriter, r *http.Request)

func (*MetadataService) GetAmiLaunchIndex

func (s *MetadataService) GetAmiLaunchIndex(w http.ResponseWriter, r *http.Request)

func (*MetadataService) GetAmiManifestPath

func (s *MetadataService) GetAmiManifestPath(w http.ResponseWriter, r *http.Request)

func (*MetadataService) GetAvailabilityZone

func (s *MetadataService) GetAvailabilityZone(w http.ResponseWriter, r *http.Request)

func (*MetadataService) GetHostName

func (s *MetadataService) GetHostName(w http.ResponseWriter, r *http.Request)

func (*MetadataService) GetIAM

func (s *MetadataService) GetIAM(w http.ResponseWriter, r *http.Request)

func (*MetadataService) GetIndex

func (s *MetadataService) GetIndex(w http.ResponseWriter, r *http.Request)

func (*MetadataService) GetInstanceAction

func (s *MetadataService) GetInstanceAction(w http.ResponseWriter, r *http.Request)

func (*MetadataService) GetInstanceId

func (s *MetadataService) GetInstanceId(w http.ResponseWriter, r *http.Request)

func (*MetadataService) GetInstanceType

func (s *MetadataService) GetInstanceType(w http.ResponseWriter, r *http.Request)

func (*MetadataService) GetLocalHostName

func (s *MetadataService) GetLocalHostName(w http.ResponseWriter, r *http.Request)

func (*MetadataService) GetLocalIpv4

func (s *MetadataService) GetLocalIpv4(w http.ResponseWriter, r *http.Request)

func (*MetadataService) GetMac

func (s *MetadataService) GetMac(w http.ResponseWriter, r *http.Request)

func (*MetadataService) GetMetadataIndex

func (s *MetadataService) GetMetadataIndex(w http.ResponseWriter, r *http.Request)

func (*MetadataService) GetProfile

func (s *MetadataService) GetProfile(w http.ResponseWriter, r *http.Request)

func (*MetadataService) GetReservationId

func (s *MetadataService) GetReservationId(w http.ResponseWriter, r *http.Request)

func (*MetadataService) GetSecurityCredentialDetails

func (s *MetadataService) GetSecurityCredentialDetails(w http.ResponseWriter, r *http.Request)

func (*MetadataService) GetSecurityCredentials

func (s *MetadataService) GetSecurityCredentials(w http.ResponseWriter, r *http.Request)

func (*MetadataService) GetSecurityGroups

func (s *MetadataService) GetSecurityGroups(w http.ResponseWriter, r *http.Request)

func (*MetadataService) GetUserData

func (s *MetadataService) GetUserData(w http.ResponseWriter, r *http.Request)

func (*MetadataService) Middleware

func (s *MetadataService) Middleware(h http.Handler) http.Handler

func (*MetadataService) Prefix

func (s *MetadataService) Prefix() string

type MetadataValues

type MetadataValues struct {
	AmiId               string              `json:"ami-id"`
	AmiLaunchIndex      string              `json:"ami-launch-index"`
	AmiManifestPath     string              `json:"ami-manifest-path"`
	AvailabilityZone    string              `json:"availability-zone"`
	Hostname            string              `json:"hostname"`
	InstanceAction      string              `json:"instance-action"`
	InstanceId          string              `json:"instance-id"`
	InstanceType        string              `json:"instance-type"`
	LocalHostName       string              `json:"local-hostname"`
	LocalIpv4           string              `json:"local-ipv4"`
	Mac                 string              `json:"mac"`
	Profile             string              `json:"profile"`
	ReservationId       string              `json:"reservation-id"`
	User                string              `json:"User"`
	SecurityGroups      []string            `json:"security-groups"`
	SecurityCredentials SecurityCredentials `json:"security-credentials"`
}

type SecurityCredentials

type SecurityCredentials struct {
	AccessKeyId     string `json:"AccessKeyId"`
	SecretAccessKey string `json:"SecretAccessKey"`
	Token           string `json:"Token"`
	Expiration      string `json:"Expiration"`
	Code            string `json:"Code"`
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL