-
Notifications
You must be signed in to change notification settings - Fork 120
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
detect which cloud provider we are using #38
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4fd3f29
testing cloud detection
devsecfranklin bbdd544
detect which cloud provider we are currently running on
devsecfranklin 0852b5e
move cloud detection to a library
devsecfranklin 5347e84
testing cloud detection
devsecfranklin 4ca8c3c
Merge remote-tracking branch 'upstream/main' into dev37-20230508
devsecfranklin 0e392b8
Merge remote-tracking branch 'upstream/main' into dev37-20230508
devsecfranklin b583759
Merge branch 'main' into dev37-20230508
devsecfranklin b66f559
update pkg/cloud_detection.go
devsecfranklin 365de50
Merge branch 'dev37-20230508' of github.com:DEAD10C5/peirates into de…
devsecfranklin ca51467
Merge branch 'main' into dev37-20230508
JayBeale File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
PACKAGES:=$(shell go list ./... | grep -v /vendor/) | ||
|
||
default: lint | ||
|
||
gofmt: | ||
go fmt ./... | ||
|
||
lint: gofmt | ||
$(GOPATH)/bin/golint $(PACKAGES) | ||
$(GOPATH)/bin/gosec -quiet -no-fail ./... | ||
$(GOPATH)/bin/golangci-lint run | ||
|
||
update-deps: | ||
go clean -modcache | ||
go get -u ./... | ||
go mod tidy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,90 @@ | ||
module github.com/inguardians/peirates | ||
|
||
go 1.16 | ||
go 1.17 | ||
|
||
require ( | ||
github.com/aws/aws-sdk-go v1.42.4 | ||
github.com/aws/aws-sdk-go v1.44.293 | ||
github.com/trung/jwt-tools v0.0.0-20191029184913-432ee57a2445 | ||
golang.org/x/net v0.10.0 // indirect | ||
gopkg.in/square/go-jose.v2 v2.6.0 | ||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b | ||
k8s.io/cli-runtime v0.22.3 // indirect | ||
k8s.io/kubectl v0.22.3 | ||
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect | ||
github.com/MakeNowJust/heredoc v1.0.0 // indirect | ||
github.com/chai2010/gettext-go v1.0.2 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/daviddengcn/go-colortext v1.0.0 // indirect | ||
github.com/docker/distribution v2.8.2+incompatible // indirect | ||
github.com/emicklei/go-restful/v3 v3.10.2 // indirect | ||
github.com/evanphx/json-patch v5.6.0+incompatible // indirect | ||
github.com/exponent-io/jsonpath v0.0.0-20210407135951-1de76d718b3f // indirect | ||
github.com/fatih/camelcase v1.0.0 // indirect | ||
github.com/fvbommel/sortorder v1.1.0 // indirect | ||
github.com/go-errors/errors v1.4.2 // indirect | ||
github.com/go-logr/logr v1.2.4 // indirect | ||
github.com/go-openapi/jsonpointer v0.19.6 // indirect | ||
github.com/go-openapi/jsonreference v0.20.2 // indirect | ||
github.com/go-openapi/swag v0.22.4 // indirect | ||
github.com/gogo/protobuf v1.3.2 // indirect | ||
github.com/golang/protobuf v1.5.3 // indirect | ||
github.com/google/btree v1.1.2 // indirect | ||
github.com/google/gnostic v0.6.9 // indirect | ||
github.com/google/gnostic-models v0.6.8 // indirect | ||
github.com/google/go-cmp v0.5.9 // indirect | ||
github.com/google/gofuzz v1.2.0 // indirect | ||
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect | ||
github.com/google/uuid v1.3.0 // indirect | ||
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect | ||
github.com/imdario/mergo v0.3.16 // indirect | ||
github.com/inconshreveable/mousetrap v1.1.0 // indirect | ||
github.com/jmespath/go-jmespath v0.4.0 // indirect | ||
github.com/jonboulle/clockwork v0.4.0 // indirect | ||
github.com/josharian/intern v1.0.0 // indirect | ||
github.com/json-iterator/go v1.1.12 // indirect | ||
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect | ||
github.com/lithammer/dedent v1.1.0 // indirect | ||
github.com/mailru/easyjson v0.7.7 // indirect | ||
github.com/mitchellh/go-wordwrap v1.0.1 // indirect | ||
github.com/moby/spdystream v0.2.0 // indirect | ||
github.com/moby/term v0.5.0 // indirect | ||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||
github.com/modern-go/reflect2 v1.0.2 // indirect | ||
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect | ||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect | ||
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect | ||
github.com/opencontainers/go-digest v1.0.0 // indirect | ||
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect | ||
github.com/pkg/errors v0.9.1 // indirect | ||
github.com/russross/blackfriday/v2 v2.1.0 // indirect | ||
github.com/spf13/cobra v1.7.0 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
github.com/stretchr/testify v1.8.4 // indirect | ||
github.com/tidwall/pretty v1.2.1 // indirect | ||
github.com/xlab/treeprint v1.2.0 // indirect | ||
go.starlark.net v0.0.0-20230612165344-9532f5667272 // indirect | ||
golang.org/x/crypto v0.10.0 // indirect | ||
golang.org/x/net v0.11.0 // indirect | ||
golang.org/x/oauth2 v0.9.0 // indirect | ||
golang.org/x/sys v0.9.0 // indirect | ||
golang.org/x/term v0.9.0 // indirect | ||
golang.org/x/text v0.10.0 // indirect | ||
golang.org/x/time v0.3.0 // indirect | ||
google.golang.org/appengine v1.6.7 // indirect | ||
google.golang.org/protobuf v1.31.0 // indirect | ||
gopkg.in/inf.v0 v0.9.1 // indirect | ||
gopkg.in/yaml.v2 v2.4.0 // indirect | ||
k8s.io/api v0.27.3 // indirect | ||
k8s.io/apimachinery v0.27.3 // indirect | ||
k8s.io/cli-runtime v0.27.3 // indirect | ||
k8s.io/client-go v0.27.3 // indirect | ||
k8s.io/component-base v0.27.3 // indirect | ||
k8s.io/component-helpers v0.27.3 // indirect | ||
k8s.io/klog/v2 v2.100.1 // indirect | ||
k8s.io/kube-openapi v0.0.0-20230614213217-ba0abe644833 // indirect | ||
k8s.io/metrics v0.27.3 // indirect | ||
k8s.io/utils v0.0.0-20230505201702-9f6742963106 // indirect | ||
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect | ||
sigs.k8s.io/kustomize/api v0.14.0 // indirect | ||
sigs.k8s.io/kustomize/kustomize/v5 v5.1.0 // indirect | ||
sigs.k8s.io/kustomize/kyaml v0.14.3 // indirect | ||
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect | ||
sigs.k8s.io/yaml v1.3.0 // indirect | ||
|
||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Internal | ||
|
||
Private application and library code. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
package pkg | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
"runtime" | ||
"strings" | ||
"time" | ||
) | ||
|
||
var hc = &http.Client{Timeout: 300 * time.Millisecond} | ||
|
||
type CloudProvider struct { | ||
Name string | ||
URL string | ||
HTTPMethod string | ||
CustomHeader string | ||
CustomHeaderValue string | ||
ResultString string | ||
} | ||
|
||
func populateAndCheckCloudProviders() { | ||
providers := []CloudProvider{ | ||
{ | ||
Name: "AWS", | ||
URL: "http://169.254.169.254/latest/", | ||
HTTPMethod: "GET", | ||
CustomHeader: "", | ||
CustomHeaderValue: "", | ||
ResultString: "Amazon Web Services", | ||
}, | ||
{ | ||
Name: "Azure", | ||
URL: "http://169.254.169.254/metadata/v1/InstanceInfo", | ||
HTTPMethod: "GET", | ||
CustomHeader: "", | ||
CustomHeaderValue: "", | ||
ResultString: "Microsoft Azure", | ||
}, | ||
{ | ||
Name: "DigitalOcean", | ||
URL: "http://169.254.169.254/metadata/v1.json", | ||
HTTPMethod: "GET", | ||
CustomHeader: "", | ||
CustomHeaderValue: "", | ||
ResultString: "Microsoft Azure", | ||
}, | ||
{ | ||
Name: "Google Cloud", | ||
URL: "http://metadata.google.internal/computeMetadata/v1/instance/tags", | ||
HTTPMethod: "GET", | ||
CustomHeader: "Metadata-Flavor", | ||
CustomHeaderValue: "Google", | ||
ResultString: "Google Compute Engine", | ||
}, | ||
{ | ||
Name: "SoftLayer", | ||
URL: "https://api.service.softlayer.com/rest/v3/SoftLayer_Resource_Metadata/UserMetadata.txt", | ||
HTTPMethod: "GET", | ||
CustomHeader: "", | ||
CustomHeaderValue: "", | ||
ResultString: "SoftLayer", | ||
}, | ||
{ | ||
Name: "Vultr", | ||
URL: "http://169.254.169.254/v1.json", | ||
HTTPMethod: "GET", | ||
CustomHeader: "", | ||
CustomHeaderValue: "", | ||
ResultString: "Vultr", | ||
}, | ||
} | ||
|
||
for _, provider := range providers { | ||
fmt.Printf("Checking %s...\n", provider.Name) | ||
|
||
// Use DoHTTPRequestAndGetBody() | ||
req, err := http.NewRequest(provider.HTTPMethod, provider.URL, nil) | ||
if err != nil { | ||
fmt.Printf("Failed to create request for %s: %v\n", provider.Name, err) | ||
continue | ||
} | ||
|
||
if provider.CustomHeader != "" { | ||
req.Header.Set(provider.CustomHeader, provider.CustomHeaderValue) | ||
} | ||
|
||
// use DoHTTPRequestAndGetBody | ||
resp, err := client.Do(req) | ||
if err != nil { | ||
fmt.Printf("Failed to make request to %s: %v\n", provider.Name, err) | ||
continue | ||
} | ||
defer resp.Body.Close() | ||
|
||
// Use DoHTTPRequestAndGetBody() | ||
if resp.StatusCode == http.StatusOK { | ||
// Check if there's a body string returned that matches ResultString | ||
} else { | ||
fmt.Printf("%s responded with HTTP %d\n", provider.Name, resp.StatusCode) | ||
} | ||
} | ||
} | ||
|
||
func detectContainer() string { | ||
b, err := ioutil.ReadFile("/proc/self/cgroup") | ||
if err != nil { | ||
return "" | ||
} | ||
|
||
fc := string(b) | ||
kube := strings.Contains(fc, "kube") | ||
container := strings.Contains(fc, "containerd") | ||
|
||
if kube { | ||
return "K8S Container" | ||
} | ||
|
||
if container { | ||
return "Container" | ||
} | ||
|
||
return "" | ||
} | ||
|
||
func detectOpenStack() string { | ||
if runtime.GOOS != "windows" { | ||
data, err := ioutil.ReadFile("/sys/class/dmi/id/sys_vendor") | ||
if err != nil { | ||
return "" | ||
} | ||
if strings.Contains(string(data), "OpenStack Foundation") { | ||
return "OpenStack" | ||
} | ||
return "" | ||
} | ||
return "" | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a copy-paste error on this line that can be easily fixed.