-
Notifications
You must be signed in to change notification settings - Fork 94
Veles codecatalyst #1577
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
Merged
Merged
Veles codecatalyst #1577
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
de98e27
init
alessandro-Doyensec 272502a
add: validator
alessandro-Doyensec fc086ee
add: tests
alessandro-Doyensec 4c18a66
add: register plugin
alessandro-Doyensec 99c9dc6
add: validato registration
alessandro-Doyensec 6fe0f03
add: proto and proto conversion rules
alessandro-Doyensec 448310b
add: filesystem extractor
alessandro-Doyensec 29d3453
add: supported invenotory types
alessandro-Doyensec c1abfc7
edit: remove redundant fileRequired condition
alessandro-Doyensec 847f4af
fix: resolve conversation
alessandro-Doyensec fe9c461
edit: use simplevalidate.Validator
alessandro-Doyensec f691c9e
Merge branch 'main' into veles-codecatalyst
erikvarga 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
48 changes: 48 additions & 0 deletions
48
extractor/filesystem/secrets/gitbasicauth/codecatalyst/codecatalyst.go
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 |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| // Copyright 2025 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| // Package codecatalyst extends the veles codecatalyst.Detector to search inside the git config and history files | ||
| package codecatalyst | ||
|
|
||
| import ( | ||
| "path/filepath" | ||
| "strings" | ||
|
|
||
| "github.com/google/osv-scalibr/extractor/filesystem" | ||
| "github.com/google/osv-scalibr/veles/secrets/gitbasicauth/codecatalyst" | ||
|
|
||
| "github.com/google/osv-scalibr/extractor/filesystem/secrets/convert" | ||
| ) | ||
|
|
||
| const ( | ||
| // Name is the name of the extractor | ||
| Name = "secrets/codecatalystcredentials" | ||
| // Version is the version of the extractor | ||
| Version = 0 | ||
| ) | ||
|
|
||
| // New returns a filesystem.Extractor which extracts Amazon CodeCatalyst Credentials using the codecatalyst.Detector | ||
| func New() filesystem.Extractor { | ||
| return convert.FromVelesDetectorWithRequire( | ||
| codecatalyst.NewDetector(), Name, Version, FileRequired, | ||
| ) | ||
| } | ||
|
|
||
| // FileRequired returns true if a file should be searched by the plugin. | ||
| func FileRequired(api filesystem.FileAPI) bool { | ||
| path := filepath.ToSlash(api.Path()) | ||
| return strings.HasSuffix(path, ".git/config") || | ||
| strings.HasSuffix(path, ".git-credentials") || | ||
| strings.HasSuffix(path, "_history") | ||
| } | ||
145 changes: 145 additions & 0 deletions
145
extractor/filesystem/secrets/gitbasicauth/codecatalyst/codecatalyst_test.go
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 |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| // Copyright 2025 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package codecatalyst_test | ||
|
|
||
| import ( | ||
| "runtime" | ||
| "testing" | ||
|
|
||
| "github.com/google/go-cmp/cmp" | ||
| "github.com/google/go-cmp/cmp/cmpopts" | ||
| "github.com/google/osv-scalibr/extractor/filesystem/secrets/gitbasicauth/codecatalyst" | ||
| "github.com/google/osv-scalibr/extractor/filesystem/simplefileapi" | ||
| "github.com/google/osv-scalibr/inventory" | ||
| "github.com/google/osv-scalibr/testing/extracttest" | ||
| codecatalystdetector "github.com/google/osv-scalibr/veles/secrets/gitbasicauth/codecatalyst" | ||
| ) | ||
|
|
||
| func TestExtractor_FileRequired(t *testing.T) { | ||
| tests := []struct { | ||
| inputPath string | ||
| want bool | ||
| isWindows bool | ||
| }{ | ||
| {inputPath: "", want: false}, | ||
|
|
||
| // linux | ||
| {inputPath: `/Users/example-user/folder/.git/config`, want: true}, | ||
| {inputPath: `/Users/example-user/.git-credentials`, want: true}, | ||
| {inputPath: `/Users/example-user/.zsh_history`, want: true}, | ||
| {inputPath: `/Users/example-user/bad/path`, want: false}, | ||
|
|
||
| // windows | ||
| {inputPath: `C:\Users\USERNAME\folder\.git\config`, isWindows: true, want: true}, | ||
| {inputPath: `C:\Users\YourUserName\.git-credentials`, isWindows: true, want: true}, | ||
| {inputPath: `C:\Users\USERNAME\another\bad\path`, isWindows: true, want: false}, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.inputPath, func(t *testing.T) { | ||
| if tt.isWindows && runtime.GOOS != "windows" { | ||
| t.Skipf("Skipping test %q for %q", t.Name(), runtime.GOOS) | ||
| } | ||
| e := codecatalyst.New() | ||
| got := e.FileRequired(simplefileapi.New(tt.inputPath, nil)) | ||
| if got != tt.want { | ||
| t.Errorf("FileRequired(%s) got = %v, want %v", tt.inputPath, got, tt.want) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestExtractor_Extract(t *testing.T) { | ||
| tests := []*struct { | ||
| Name string | ||
| Path string | ||
| WantSecrets []*inventory.Secret | ||
| WantErr error | ||
| }{ | ||
| { | ||
| Name: "empty", | ||
| Path: "empty", | ||
| WantSecrets: nil, | ||
| }, | ||
| { | ||
| Name: "git_credentials", | ||
| Path: "git_credentials", | ||
| WantSecrets: []*inventory.Secret{ | ||
| { | ||
| Secret: codecatalystdetector.Credentials{ | ||
| FullURL: `https://user:[email protected]/v1/space/project/repo`, | ||
| }, | ||
| Location: "git_credentials", | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| Name: "git_config", | ||
| Path: "git_config", | ||
| WantSecrets: []*inventory.Secret{ | ||
| { | ||
| Secret: codecatalystdetector.Credentials{ | ||
| FullURL: `https://user:[email protected]/v1/space/project/repo`, | ||
| }, | ||
| Location: "git_config", | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| Name: "history_file", | ||
| Path: ".zsh_history", | ||
| WantSecrets: []*inventory.Secret{ | ||
| { | ||
| Secret: codecatalystdetector.Credentials{ | ||
| FullURL: `https://user:[email protected]/v1/space/project/test-repo`, | ||
| }, | ||
| Location: ".zsh_history", | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| Name: "random_content", | ||
| Path: "random_content", | ||
| WantSecrets: nil, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.Name, func(t *testing.T) { | ||
| extr := codecatalyst.New() | ||
|
|
||
| inputCfg := extracttest.ScanInputMockConfig{ | ||
| Path: tt.Path, | ||
| FakeScanRoot: "testdata", | ||
| } | ||
|
|
||
| scanInput := extracttest.GenerateScanInputMock(t, inputCfg) | ||
| defer extracttest.CloseTestScanInput(t, scanInput) | ||
|
|
||
| got, err := extr.Extract(t.Context(), &scanInput) | ||
|
|
||
| if diff := cmp.Diff(tt.WantErr, err, cmpopts.EquateErrors()); diff != "" { | ||
| t.Errorf("%s.Extract(%q) error diff (-want +got):\n%s", extr.Name(), tt.Path, diff) | ||
| return | ||
| } | ||
|
|
||
| wantInv := inventory.Inventory{Secrets: tt.WantSecrets} | ||
| opts := []cmp.Option{cmpopts.SortSlices(extracttest.PackageCmpLess), cmpopts.EquateEmpty()} | ||
| if diff := cmp.Diff(wantInv, got, opts...); diff != "" { | ||
| t.Errorf("%s.Extract(%q) diff (-want +got):\n%s", extr.Name(), tt.Path, diff) | ||
| } | ||
| }) | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
extractor/filesystem/secrets/gitbasicauth/codecatalyst/testdata/.zsh_history
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 |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| : 1:0;cd /tmp | ||
| : 2:0;git clone https://user:[email protected]/v1/space/project/test-repo | ||
| : 3:0;cd test-repo | ||
| : 4:0;ls | ||
| : 5:0;cd .git | ||
| : 6:0;ls | ||
| : 7:0;cat config | ||
| : 8:0;cat .zsh_history | ||
| : 9:0;cat .zsh_history | tail -50 | pbcopy |
Empty file.
13 changes: 13 additions & 0 deletions
13
extractor/filesystem/secrets/gitbasicauth/codecatalyst/testdata/git_config
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 |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| [core] | ||
| repositoryformatversion = 0 | ||
| filemode = true | ||
| bare = false | ||
| logallrefupdates = true | ||
| ignorecase = true | ||
| precomposeunicode = true | ||
| [remote "origin"] | ||
| url = https://user:[email protected]/v1/space/project/repo | ||
| fetch = +refs/heads/*:refs/remotes/origin/* | ||
| [branch "main"] | ||
| remote = origin | ||
| merge = refs/heads/main |
2 changes: 2 additions & 0 deletions
2
extractor/filesystem/secrets/gitbasicauth/codecatalyst/testdata/git_credentials
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 |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| https://user:[email protected]/v1/space/project/repo | ||
| https://anotheruser:[email protected]/user/repo |
10 changes: 10 additions & 0 deletions
10
extractor/filesystem/secrets/gitbasicauth/codecatalyst/testdata/random_content
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 |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| localhost:5432:mydb:myuser:mypassword | ||
| hostname:1234:testdb:testuser:testpass123 | ||
| hostname:1234:testdb:testuser:passw*ord | ||
| # space inside one group (except password) | ||
| hostname:1234:testdb:testuser:passw ord | ||
| hostname:1234:db name:testuser:password | ||
| # this is a comment and should be ignored | ||
| *:*:db:admin:supersecret | ||
| # valid with escaped : | ||
| prod.example.com:5432:db:admin:pass\:word |
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 |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // Copyright 2025 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| // Package codecatalyst contains the logic to extract CodeCatalyst credentials. | ||
alessandro-Doyensec marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| package codecatalyst | ||
|
|
||
| // Credentials contains basic auth credential for CodeCatalyst. | ||
| type Credentials struct { | ||
| FullURL string | ||
| } | ||
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.