-
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
Open
MuneebUllahKhan222
wants to merge
12
commits into
trufflesecurity:main
Choose a base branch
from
MuneebUllahKhan222:datadogapikey-detector
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,187
−787
Open
Changes from 3 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
bab758d
[INS-241] New detector (datadogapikey) for datadog apikeys
MuneebUllahKhan222 a942fe2
Analyzer updated to cater endpoint
MuneebUllahKhan222 8d6a588
Added new tests for anlyzers
MuneebUllahKhan222 7951443
Removed print statement
MuneebUllahKhan222 c6a2b6f
resolved comments and fixed integration tests.
MuneebUllahKhan222 3152a40
resolved comments
MuneebUllahKhan222 3e3a7de
changed cli prompt
MuneebUllahKhan222 ffb8d69
Merge branch 'main' into datadogapikey-detector
MuneebUllahKhan222 5fa6481
Merge branch 'main' into datadogapikey-detector
MuneebUllahKhan222 30bc23c
Fixed the comments and added app key validation in analyzer
MuneebUllahKhan222 e2bc5d8
Merge branch 'datadogapikey-detector' of https://github.com/MuneebUll…
MuneebUllahKhan222 829c986
Merge branch 'main' into datadogapikey-detector
MuneebUllahKhan222 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 hidden or 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 |
|---|---|---|
|
|
@@ -34,16 +34,19 @@ func (a Analyzer) Analyze(ctx context.Context, credInfo map[string]string) (*ana | |
| // 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 | ||
| } | ||
|
|
||
| fmt.Printf("SecretInfo: %+v\n", info) | ||
| 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()) | ||
|
|
@@ -57,16 +60,23 @@ 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) { | ||
| // 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" | ||
| } else { | ||
| baseURL, err = DetectDomain(client, apiKey, appKey) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("[x] %v", err) | ||
| } | ||
|
Comment on lines
+81
to
+87
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. I think this is right, keeping the domain detection helps OSS. |
||
| } | ||
|
|
||
| // capture user information in secretInfo | ||
|
|
@@ -114,7 +124,10 @@ func secretInfoToAnalyzerResult(info *SecretInfo) *analyzers.AnalyzerResult { | |
| } | ||
|
|
||
| permissionBindings := secretInfoPermissionsToAnalyzerPermission(info.Permissions) | ||
| result.Bindings = analyzers.BindAllPermissions(*userResource, *permissionBindings...) | ||
|
|
||
| if userResource != nil && len(*permissionBindings) > 0 { | ||
| result.Bindings = analyzers.BindAllPermissions(*userResource, *permissionBindings...) | ||
| } | ||
|
|
||
| // Extract information from resources to create bindings | ||
| for _, resource := range info.Resources { | ||
|
|
||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.