-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[INS-241] Datadogapikey detector #4627
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
base: main
Are you sure you want to change the base?
Changes from 12 commits
bab758d
a942fe2
8d6a588
7951443
c6a2b6f
3152a40
3e3a7de
ffb8d69
5fa6481
30bc23c
e2bc5d8
829c986
20f4f19
491341c
8dd5d50
a82c86d
b41f6a3
52b1a19
a475fbf
19fea8a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,29 +26,33 @@ func (a Analyzer) Type() analyzers.AnalyzerType { | |
|
|
||
| // Analyze performs the analysis of the Datadog API key and returns the analyzer result. | ||
| func (a Analyzer) Analyze(ctx context.Context, credInfo map[string]string) (*analyzers.AnalyzerResult, error) { | ||
| apiKey, exist := credInfo["apiKey"] | ||
| if !exist { | ||
| return nil, errors.New("API key not found in credentials info") | ||
| } | ||
| apiKey := credInfo["apiKey"] | ||
|
|
||
| // Get appKey if provided | ||
| appKey := credInfo["appKey"] | ||
|
|
||
| info, err := AnalyzePermissions(a.Cfg, apiKey, appKey) | ||
| // Endpoint | ||
| endpoint := credInfo["endpoint"] | ||
|
|
||
| info, err := AnalyzePermissions(a.Cfg, apiKey, appKey, endpoint) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return secretInfoToAnalyzerResult(info), nil | ||
| } | ||
|
|
||
| func AnalyzeAndPrintPermissions(cfg *config.Config, apiKey string, appKey string) { | ||
| info, err := AnalyzePermissions(cfg, apiKey, appKey) | ||
| func AnalyzeAndPrintPermissions(cfg *config.Config, apiKey, appKey, endpoint string) { | ||
| info, err := AnalyzePermissions(cfg, apiKey, appKey, endpoint) | ||
| if err != nil { | ||
| // just print the error in cli and continue as a partial success | ||
| color.Red("[x] Error : %s", err.Error()) | ||
| } | ||
|
|
||
| if info == nil { | ||
| color.Red("[x] No information retrieved") | ||
| return | ||
| } | ||
|
|
||
| color.Green("[i] Valid Datadog API Key\n") | ||
|
|
||
| printUser(info.User) | ||
|
|
@@ -57,16 +61,30 @@ func AnalyzeAndPrintPermissions(cfg *config.Config, apiKey string, appKey string | |
| } | ||
|
|
||
| // AnalyzePermissions will collect all the scopes assigned to token along with resource it can access | ||
| func AnalyzePermissions(cfg *config.Config, apiKey string, appKey string) (*SecretInfo, error) { | ||
| func AnalyzePermissions(cfg *config.Config, apiKey, appKey, endpoint string) (*SecretInfo, error) { | ||
| if apiKey == "" { | ||
| return nil, errors.New("api key not found in credentials info") | ||
| } | ||
| if appKey == "" { | ||
| return nil, errors.New("app key not found in credentials info") | ||
| } | ||
|
|
||
| // create the http client | ||
| client := analyzers.NewAnalyzeClient(cfg) | ||
|
|
||
| var secretInfo = &SecretInfo{} | ||
|
|
||
| // First detect which DataDog domain works with this API key | ||
| baseURL, err := DetectDomain(client, apiKey, appKey) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("[x] %v", err) | ||
| var baseURL string | ||
| var err error | ||
|
|
||
| // If endpoint is provided, use it directly; otherwise detect domain | ||
| if endpoint != "" { | ||
| baseURL = endpoint + "/api" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue: Let's use |
||
| } else { | ||
| baseURL, err = DetectDomain(client, apiKey, appKey) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("[x] %v", err) | ||
| } | ||
MuneebUllahKhan222 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| // capture user information in secretInfo | ||
|
|
@@ -114,7 +132,10 @@ func secretInfoToAnalyzerResult(info *SecretInfo) *analyzers.AnalyzerResult { | |
| } | ||
|
|
||
| permissionBindings := secretInfoPermissionsToAnalyzerPermission(info.Permissions) | ||
| result.Bindings = analyzers.BindAllPermissions(*userResource, *permissionBindings...) | ||
|
|
||
| if userResource != nil && len(*permissionBindings) > 0 { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: I might unify these under an |
||
| result.Bindings = analyzers.BindAllPermissions(*userResource, *permissionBindings...) | ||
| } | ||
|
|
||
| // Extract information from resources to create bindings | ||
| for _, resource := range info.Resources { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.