purpleclay / imds-mock Goto Github PK
View Code? Open in Web Editor NEWEasy mocking of the Amazon EC2 Instance Metadata Service (IMDS)
Home Page: https://docs.purpleclay.dev/imds-mock/
License: MIT License
Easy mocking of the Amazon EC2 Instance Metadata Service (IMDS)
Home Page: https://docs.purpleclay.dev/imds-mock/
License: MIT License
Provide documentation for imds-mock
using Mkdocs Material.
Generated documentation should adopt the same theme used across over PurpleClay projects.
No response
Typically a spot instance will be interrupted at an unknown interval. To help simulate this behaviour, introduce a new flag that allows the spot behaviour to be configured by an event that will be raised at a specified duration after the mock launch.
Introduce a new flag --spot-action terminate=2m
that will allow the type of spot action to be configured with a duration to raise the relevant event and change the data returned.
No response
The gin framework uses its own logging style, which can produce inconsistent log output from the container. Consolidate a single structured logging approach.
Switch to using Zap. Zap can be incorporated within middleware directly for logging requests and can also be used ad-hoc at key points within the mock
https://github.com/gin-contrib/zap
The IMDS mock has a built-in cache for caching responses by instance category path. The cache is only invalidated if the mock is terminated and restarted. This functionality doesn't support more advanced functionality such as spot simulation when events are raised.
Add support for invalidating the cache at a given path.
No response
When strict IMDSv2 is enabled, all of the endpoints are protected through the Gin middleware. The token endpoint should not be protected.
imds-mock --imdsv2
PUT http://localhost:1338/latest/api/token -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>401 - Unauthorized</title>
</head>
<body>
<h1>401 - Unauthorized</h1>
</body>
</html>
v0.3.0
All
IMDS supports the inclusion of EC2 instance tags. Once enabled, all tags are exposed through the tags/instance
category path. Expose a default Name
tag for the mock EC2.
Add an --include-instance-tags
flag to toggle the inclusion of EC2 tags within the IMDS mock. Patch the existing JSON with a default Name
tag
No response
By default, the imds-mock will start on port 1338
. This should be configurable.
Provide a flag for overriding the default port. Include the provided port in the serving options and pass to Gin on startup of the service.
No response
Improve the efficiency of the mock by caching responses for each given metadata category path.
The data returned by the mock is static and won't change once started. So remove the need to reprocess the JSON response every time by caching the output of each request. This can just be stored in memory with a simple map lookup.
No response
Allow a configurable set of tags to be included within the IMDS mock response.
Add a new flag called --instance-tags
that can be used to provide a key/value list of tags to include in the mocked response. Basic validation is required to ensure the tags conform to the expected specification.
No response
The imds-mock
is incorrectly treating the iam/security-credentials/ssm-access
instance category as a parent category and returning all JSON fields as queryable paths:
Code
LastUpdated
Type
AccessKeyId
SecretAccessKey
Token
Expiration
It should be returning it as compact JSON.
iam/security-credentials/ssm-access
v0.3.0
All
Create a new mock server that responds with a predefined JSON response that mirrors that of a the IMDS service on an EC2
Respond to all available instance categories by path. If an invalid path is provided, the mock should respond with the exact same error code and response message as the IMDS service
No response
Enable Gin release mode by default within the published container.
The environment variable GIN_MODE=release
can be used to enable release mode. Include this within the Dockerfile. When the container is started, debug mode can be re-enabled on an ad-hoc basis if needed.
No response
Use Gin middleware to control the pretty printing of JSON output for supported categories. By default any JSON string will be returned in a compact format
Include an additional flag to control the use of Gin middleware. A flag such as --pretty
could be used and exposed through Cobra as a global flag. This should be passed into IMDS mock through the existing startup options.
No response
The IMDS service comes in two flavours, V1 and V2. By default, an EC2 can access IMDS using either. This behaviour needs to be replicated.
It is also possible to explicitly enable V2-only support.
Support the generation and verification of an IMDS session token across all endpoints. Once a token is generated, it should last for 6 hours. Subsequent requests should check the token's validity and reject the request as required.
Once explicit IMDS v2 mode is enabled, only token-based requests will work.
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-instance-metadata-service.html
The IMDS service exposes additional metadata categories for a spot EC2 instance. These are exposed through the following categories:
spot/instance-action
spot/termination-time
events/recommendations/rebalance
Support a feature flag to dynamically change the mock to simulate an EC2 spot instance upon startup.
Introduce a new flag --spot
that will trigger the IMDS mock to patch the base JSON file upon startup, exposing the relevant categories required to simulate a spot instance.
The above instance categories are event-driven, and the events are not necessarily delivered in a uniform fashion. Expose an additional flag --spot-action terminate=2m
that can trigger a spot action using a configurable delay.
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-instance-termination-notices.html#instance-action-metadata
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/rebalance-recommendations.html
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.