Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for doing HTTP request against instances. #57

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

blentz
Copy link
Contributor

@blentz blentz commented Jul 26, 2021

This adds support for doing an HTTP GET to a cloud instance using the instance's network IP.

This facilitates checking instance healthchecks and running services in order to determine whether an instance should be acted upon.

For performance reasons, there is a TCP port check leading up to the HTTP request. The HTTP request is only executed if the instance is found to be listening on the requested port.

Example use case:

  • scanning for non-conforming instances, such as instances with a "webserver" label that aren't listening on ports 80 or 443
  • scanning for specific service responses, such as instances that respond with "{status: "active"}" or "{status: "failed"}"

Copy link
Contributor

@mhmxs mhmxs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice feature, thanks, I'm glad to see in main :)

types/instance.go Outdated Show resolved Hide resolved
types/instance.go Outdated Show resolved Hide resolved
types/instance.go Outdated Show resolved Hide resolved
types/instance.go Outdated Show resolved Hide resolved
types/instance.go Show resolved Hide resolved
checkPort := "80"

if port == "" {
uri = fmt.Sprintf("http://%s%s", i.IpAddress, path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to make protocol configurable?


log.Debugf("[GET_URL] Making HTTP request to %s", uri)
client := http.Client{
Timeout: 3 * time.Second,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to make timeout configurable?

}

// GetUrl returns the result of an HTTP request to the instance
func (i Instance) GetUrl(path string, port string) RemoteResponse {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name doesn't represents all the functionality defined in the function.

log.Error("[GET_URL] Error reading response body", err)
}

if resp.Header.Get("Content-Type") == "application/json" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe json unmarshalling is out of the scope of this function

if err != nil {
log.Infof("Error making TCP connection to %s -> %s", net.JoinHostPort(host, port), err)
}
if conn != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if conn == nil should be a bit more goish

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants