Commit Graph
86 Commits
Author SHA1 Message Date
Amaan Ullah 586f66d788 use struct-based SourceMetadataFunc signature across git sources (#4813)
* use struct-based SourceMetadataFunc signature across git sources

* incorporated feedback

- pass SourceMetadataInfo by value
- remove LegacySourceMetadataFunc
2026-03-24 16:22:30 +05:00
Cody Rose 041f07e9df Move verify flag into detectableChunk (#4558)
Chunk.Verify is an odd field - it originally conveys whether a source is going to run with verification, but then, at a certain point in the scanning pipeline, is mutated such that it instead indicates whether the chunk should be scanned with verification - which is not solely dependent on the source's verify flag. This is unnecessarily difficult to understand and maintain. This commit separates those two pieces of information into two flags:

- Chunk.Verify has been renamed to Chunk.SourceVerify
- It is no longer mutated; instead "should this chunk's secrets be verified?" is now captured by a new field on detectableChunk
2026-02-27 10:05:52 -05:00
Muneeb Ullah Khan f70218bad0 [INS-249] Updated Gitlab client from v0.129.0 to v1.12.0(latest) (#4655)
* updated gitlab client from v0.129.0 to v1.12.0(latest)

* fixed integration test

* unpinned v0.129 gitlab client and migrated code

* Migrated auth code

* Remove unused 'time' import

Removed unused 'time' import from gitlab.go

* reverted merged case statements

* splitted line like before

* splitted code into multiple lines

* resolved bugbot comments
2026-02-03 16:52:13 +05:00
Kashif Khan fc3f35cedd Gitlab Source: Backoff from Scan2 which is experimental to legacy pagination API call (#4608)
* Backoff from Scan2 which is experimental to legacy pagination API call

This commit rewrite simplifiedGitlabEnumeration to use legacy pagination API call with keyset pagination instead of Scan2 which is currently in experimental state. Note
that this doesn't promise to fix this problem it's just a test to check. It also adds a retry logic in case any 500 error occurs. I added some logs as well to keep track
of no of projects being enumerated.

* implemented builtin retry mechanism for gitlab and proper handling of next page

* fixed basic auth

* Some enhancements

Reversed the gitlab cloud logic to add membership flag, so that we use the default false for non gitlab.com instances.
This can help if the issue really was membership flag as mentioned in some gitlab issues.
Also added simple flag in list projects to get only minimal fields in response instead of big json response for each project.

Added test case as well.

* enhance the test case
2026-01-14 09:58:21 +05:00
Mustansir a633174c3b [INS-206] Store Gitlab Project ID in secret location metadata (#4601)
* add wrapper reporter to append project details to chunk metadata

* use cache to store project details

* revert unnecessary change

* delete from cache when done with scanning in ChunkUnit, implement PR suggestions

* query project details using repo instead of having it in source unit

* revert removal of build tag

* Incorporated PR comments
2025-12-22 10:45:42 +05:00
Cody Rose 1d87fba935 Apply configured include/ignore lists to GitLab unit scans (#4592)
Previously, the GitLab include and ignore lists were only applied during repository enumeration, which meant that they would be ignored after enumeration completed. For large environments, post-enumeration scanning can take days, and it was awkward that the include/ignore lists could effectively not be modified during that time. This PR changes things such that repositories can be configured to be skipped even post-enumeration.

Importantly, repositories cannot be "un-ignored" post-enumeration. This is unfortunate, but this PR still represents improvement on the status quo.
2025-12-09 09:50:33 -05:00
Kashif Khan 18c7b1fc33 Added feature flag to configure projects per page in gitlab enumeration (#4437)
* Added flag to configure projects per page in gitlab enumeration

* changed comments wording

* Resolved conflicts

* use features instead of flag

* updated comment
2025-09-04 19:02:33 +05:00
Shahzad Haider 2114e77d56 Fix legacy json flag for Github and Gitlab private repos (#4386)
* fix legacy json flag for gitlab private repos

* some code

* incorporated code from main

* remove cloned repositories after the scan is complete

* enhanced the code

* comment addressed

* changed the approach for persisting the repositories for legacy json printing

* addressed comments; updated the variable names
2025-09-03 11:19:28 +05:00
Kashif Khan 07c16636eb Enable cloning repository to a specified location with retention option (#4408)
* Enabled cloning repositories to a specified path with retention option

* Fixes after testing

* resolved lint issue

* resolved comments

* enabled clone path for github basic auth
2025-08-20 18:10:02 +05:00
Shahzad Haider a95f8bc878 Scan GitLab Groups (#4320)
* gitlab groups init

* added list group projects api

* list group projects updated

* added duplicate repo scan check

* comments addressed

* added error when repo and group id flags are provided at the same time

* added test case for gitlab group projects
2025-07-29 15:14:31 +05:00
Kashif Khan 7792f0263e Added KeySet Pagination for Gitlab Projects V2 Enumeration (#4319)
* Added keyset pagination for Gitlab Projects V2 Enumeration

* fallback to safe version

* resolved comments

* pinned gitlab-client-go to v0.129.0

* pinned gitlab-client-go to v0.129.0
2025-07-17 10:57:37 +05:00
Kashif Khan 7907482dec Simplified Gitlab Enumeration (#4283)
* simplified gitlab enumeration

* few more enhancements

* configurable

* added feature flag

* resolved cody's comment
2025-07-09 11:56:17 +05:00
Kashif Khan 92e9157267 Github and Gitlab Authentication via http.extraHeader for cloning Repositories (#4139)
* initial code changes

* move args before clone command

* add comments

* added flag for github source to support backward compatibility

* added flag for gitlab source to support backward compatibility

* inverse the logic for enterprise

* remove print statement

* remove flag defaults

* updated comments and removed CloneRepoUsingTokenInHeader function

* false->true
2025-05-27 11:24:43 +05:00
Abdul Basit 1ed4ef05c1 [Fix] - Migrated github.com/xanzy/go-gitlab to gitlab.com/gitlab-org/api/client-go
The package, github.com/xanzy/go-gitlab, has been deprecated and moved to gitlab.com/gitlab-org/api/client-go. This PR replace it with the migrated one.

Reference: https://pkg.go.dev/github.com/xanzy/go-gitlab@v0.115.0#section-readme
2025-04-07 11:00:29 -04:00
Eng Zer Jun 52ae3c343c Replace golang.org/x/exp with stdlib (#3916)
These experimental packages are now available in the Go standard
library.

	1. golang.org/x/exp/slices -> slices [1]
	2. golang.org/x/exp/rand -> math/rand/v2 [2]

[1]: https://go.dev/doc/go1.21#slices
[2]: https://go.dev/doc/go1.22#math_rand_v2

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2025-02-15 18:04:24 -08:00
Cody Rose 18a1a5d494 Add GitLab shared exclusion flag (#3572)
We've been seeing some suspicious behavior from the GitLab API when we're scanning a very large organization that has lots of group sharing. Since reproducing the behavior in a test environment isn't really tractable, this PR adds an optional configuration flag that can be used to investigate the phenomenon in the actual environment we're seeing it in.
2024-11-18 11:46:30 -05:00
Bob Idleandahrav 409beeb18b golangci-lint: replace exportloopref with copyloopvar and remove the copy of the 'for' variables (#3591)
* fix: replace golangci-lint exportloopref with copyloopvar

* fix: remove copy of the 'for' variables

---------

Co-authored-by: ahrav <ahravdutta02@gmail.com>
2024-11-13 12:52:04 -08:00
Cody Rose e6d786a7d9 stop logging all GitLab projects (#3541)
#3532 stopped logging one huge GItLab slice, but there's a second one! We should stop logging it for the same reason.
2024-11-01 12:27:44 -04:00
Cody RoseandAbdul Basit 65e913e2c8 stop logging detailed group info (#3532)
Co-authored-by: Abdul Basit <basit.mussani@gmail.com>
2024-10-30 10:04:33 -04:00
Abdul Basit f4670aaab1 [feat] Gitlab inclusion globbing (#3500)
* Implemented gitlab inclusion globbing.
Included test.

* implemented two new flags for gitlab scan, includeRepo and excludeRepo to support globbing.
Apply globbing filter when repos is not provided.

* implemented integration test for inclusion globbing
remove test to check errors if globs are invalid.

* made changes to support glob compile errors.
modified changes to support glob compilation errors.

* removed unused context from few functions.
2024-10-30 18:23:34 +05:00
Cody Rose f42f63271b Create global log redaction capability (#3522)
Some source use client libraries that can emit errors that contain sensitive information - in particular, git-facing libraries that embed tokens into repository URLs. This PR introduces a way of redacting them - starting with GitLab (where we've seen this most recently), but in theory extensible to other sources as needed.

This implementation uses a custom zap core; this might also be possible with a custom zap encoder, but I didn't test it out.

(The deleted core.go file was entirely unused.)
2024-10-29 09:44:07 -04:00
Cody Rose 296379d5a0 Log more GitLab stuff (#3040)
Our GitLab happy path logging could use some love.

go.sum also needed a little love, for some reason.
2024-07-09 10:53:40 -04:00
Cody Rose 1a73442088 Order GitLab repos by ID (#3047) 2024-07-09 10:39:47 -04:00
Cody Rose f7214cfee3 Log reasons for GitLab repo exclusion (#2875)
We have some evidence that some GitLab repos are getting incorrectly ignored, but it's not clear why this is happening, so this PR adds some more logging to the relevant code.
2024-05-23 09:08:36 -04:00
Miccah 6cf3a25a04 [chore] Add some happy path logs to GitLab (#2765) 2024-04-29 16:42:35 -07:00
Cody Rose b745cfd495 Enrich Gitlab enumeration logging (#2678)
This PR modifies the GitLab source:

* emits a new "groups enumerated" metric
* logs more information about group enumeration
* emits the repo enumeration metric inside getAllProjectRepos, which means it will work when units are flipped on
* emits the repo enumeration metric more granularly
2024-04-08 10:47:05 -04:00
trufflesteeeveandMiccah 12ff21f245 Improve Gitlab default URL handling (#2491)
Co-authored-by: Miccah <m.castorina93@gmail.com>
2024-02-28 14:15:11 -05:00
ahrav 9ef5151200 Gitlab scan targets (#2470)
* add method to scan targets

* Add logic to handle targetted scan

* address comments

* remove pagination opts

* add kvp with scan type
2024-02-23 07:40:52 -08:00
Miccah c60443891b Add Display method to SourceUnit and Kind member to the CommonSourceUnit (#2450)
* Add Display method to SourceUnit and Kind member to the CommonSourceUnit

* Make SourceUnitID return the ID and a kind

These two values together uniquely represent a unit.
2024-02-20 11:24:13 -08:00
Miccah aace92b64d Implement SourceUnitEnumChunker for GitLab (#2367)
* Implement SourceUnitEnumChunker for GitLab

* Add GitLab engine integration test

* Use a SliceReporter instead of checking for nil reporters

* Use more generic VisitorReporter

* Merge logic from getReposFromGitlab into getAllProjectRepos

* Update integration test to have a lower bound

Unfortunately, the GitLab integration test does not appear to be
deterministic. Sometimes 36390 chunks are found, sometimes 36312, or
even lower.
2024-02-09 11:06:31 -08:00
Miccah 27b30e65ed [chore] Cleanup GitLab source errors (#2345)
* [chore] Cleanup GitLab source errors

* Ungroup compile time interface checks and revert error message
2024-02-02 20:00:34 -08:00
ahrav 9867ce8eb8 Allow for configuring the buffered file writer (#2319)
* Write large diffs to tmp files

* address comments

* Move bufferedfilewriter to own pkg

* update test

* swallow write err

* use buffer pool

* use size vs len

* use interface

* fix test

* update comments

* fix test

* Allow for configuring the buffered file writer

* remove unused

* add missing method

* remove

* remove unused

* move parser and commit struct closer to where they are used

* linter change

* fix snifftest

* address comments

* add more kvp pairs to error

* fix test

* update

* add back missing metadata fields

* address comments

* remove bufferedfile writer

* fix

* address comments

* use unint8

* update interface

* adjust interface

* fix tests

* make linter happy

* fix finalize

* address comments

* update test

* address comments

* lint

* remove guard

* fix test

* fix

* add TODO

* fix tests
2024-01-30 12:51:58 -08:00
Cody Rose 80f2696ae0 Update Gitlab repo count in tests #2333 2024-01-23 15:04:11 -05:00
ahrav fb927e011b update test (#2283) 2024-01-10 09:56:21 -08:00
Dustin Decker 7d93adc1d0 Add skip archive support (#2257) 2023-12-22 11:55:23 -08:00
ahrav 5c6ce693c1 [feat] - Make skipping binaries configurable (#2226)
* Make skipping binaries configurable

* remove ioutil

* fix

* address comments

* address comments

* use multi-reader

* remove print

* use const

* fix test

* fix my stupidness
2023-12-15 11:46:27 -08:00
ahrav 2728e514d2 move logic to main Chunks method (#2194) 2023-12-08 14:51:24 -08:00
ahrav 2a7813929b add metrics for gitlab (#2190) 2023-12-08 09:50:09 -08:00
ahrav b75991850a [chore] - Compile regex once (#2176)
* move regex compilation out of the fxn

* missed a spot

* merge main
2023-12-07 07:26:27 -08:00
ahrav 996a11dcc0 [chore] - remove deprecated types (#2168)
* remove deprecated types

* missed one
2023-12-04 13:23:58 -08:00
ahrav 37d9e5eedf [chore] - Increase pagination limit (#2154)
* increae pagination limit

* rename
2023-12-04 10:14:46 -08:00
Miccah 52600a897a [chore] Replace chunks channel with ChunkReporter in git based sources (#2082)
ChunkReporter is more flexible and will allow code reuse for unit
chunking. ChanReporter was added as a way to maintain the original
channel functionality, so this PR should not alter existing behavior.
2023-11-01 09:22:44 -07:00
Miccah dbcb888063 Update Source interface to use SourceID and JobID types (#1774)
The previous implementation used int64 for both, which can be mixed up
easily. Using distinct types adds a layer of type safety checked by the
compiler.
2023-09-14 11:28:24 -07:00
Cody Rose 1155ee2736 Implement Gitlab source validation (#1765)
This PR implements validation of Gitlab source configuration.

I was hoping to be able to unify more of the implementation of Validate and Chunks, but there was more divergence than I expected. Specifically, Chunks handles a fair number of Gitlab errors that aren't configuration errors (e.g. "Gitlab returned a repo with an unparseable URL"). Accommodating these in the Validate code path felt wrong, and I wasn't able to create a common code path that could accommodate both Validate and Chunks without looking awful.
2023-09-13 11:51:12 -04:00
Miccah 72b6a9ec6b Add a SourceType constant to all source packages (#1768) 2023-09-12 17:23:25 -07:00
ahrav 2a9f34962d Add optional param to Chunks (#1747)
* Add interface for targeted chunking.

* use optional args.

* update Chunks method signature.

* update tests.

* fix test.

* update QueryCriteria type.
2023-09-07 09:03:37 -07:00
ahrav 4f4a79f62b Support azure git links (#1662)
* Support azure git links.

* update comment.

* update test names.
2023-08-24 14:36:52 -07:00
Richard Gomez 1594fddf05 feat(git): include line in github & gitlab links (#1466) 2023-07-11 20:02:27 -07:00
Miccah f3152b6885 Implement SourceUnitUnmarshaller for all sources (#1416)
* Implement CommonSourceUnitUnmarshaller

* Add SourceUnitUnmarshaller to all sources using

All sources, with the exception of git, will use the CommonSourceUnit as
they only contain a single type of unit to scan.

* Fix method comments to adhere to Go's style guide
2023-06-23 11:15:51 -05:00
Dustin Decker c8944825de Surface missing git as an error during initialization (#1362) 2023-05-26 15:23:08 -07:00