-
Notifications
You must be signed in to change notification settings - Fork 7
Added probe that scans for Docker registry creds #25
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
jksolbakken
wants to merge
5
commits into
boostsecurityio:main
Choose a base branch
from
jksolbakken:dockercreds
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.
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
744bd22
Added probe that scans for Docker registry creds
jksolbakken 1befd44
Added myself to the CLA as requested in the contributing guidelines
jksolbakken 9d85825
Oops, didn't mean to delete this name
jksolbakken e306989
Using the file index
jksolbakken 7d1d659
Moved detection to detector
jksolbakken 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 |
|---|---|---|
|
|
@@ -33,3 +33,6 @@ go.work.sum | |
|
|
||
| /bagel | ||
| dist/ | ||
|
|
||
| # mise-en-place | ||
| mise.toml | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| // Copyright (C) 2026 boostsecurity.io | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
|
|
||
| package probe | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "fmt" | ||
| "os" | ||
|
|
||
| "github.com/boostsecurityio/bagel/pkg/fileindex" | ||
| "github.com/boostsecurityio/bagel/pkg/models" | ||
| "github.com/rs/zerolog/log" | ||
| ) | ||
|
|
||
| // DockerCredsProbe checks for Docker registry creds in cleartext | ||
| type DockerCredsProbe struct { | ||
| enabled bool | ||
| config models.ProbeSettings | ||
| fileIndex *fileindex.FileIndex | ||
| } | ||
|
|
||
| // NewDockerCredsProbe creates a new cloud credentials probe | ||
| func NewDockerCredsProbe(config models.ProbeSettings) *DockerCredsProbe { | ||
| return &DockerCredsProbe{ | ||
| enabled: config.Enabled, | ||
| config: config, | ||
| } | ||
| } | ||
|
|
||
| // Name returns the probe name | ||
| func (dcp *DockerCredsProbe) Name() string { | ||
| return "Docker credentials" | ||
| } | ||
|
|
||
| // IsEnabled returns whether the probe is enabled | ||
| func (dcp *DockerCredsProbe) IsEnabled() bool { | ||
| return dcp.enabled | ||
| } | ||
|
|
||
| // SetFileIndex sets the file index for this probe (implements FileIndexAware) | ||
| func (dcp *DockerCredsProbe) SetFileIndex(index *fileindex.FileIndex) { | ||
| dcp.fileIndex = index | ||
| } | ||
|
|
||
| // Execute runs the Docker credentials probe | ||
| func (dcp *DockerCredsProbe) Execute(ctx context.Context) ([]models.Finding, error) { | ||
| var findings []models.Finding | ||
|
|
||
| // If file index is not available, skip probe | ||
| if dcp.fileIndex == nil { | ||
| log.Ctx(ctx).Warn(). | ||
| Str("probe", dcp.Name()). | ||
| Msg("File index not available, skipping Docker credentials probe") | ||
| return findings, nil | ||
| } | ||
|
|
||
| locations := dcp.fileIndex.Get("docker_config") | ||
| for _, location := range locations { | ||
| _, err := os.Stat(location) | ||
| if err != nil { | ||
| continue | ||
| } | ||
| fileContents, err := os.ReadFile(location) | ||
| if err != nil { | ||
| return findings, err | ||
| } | ||
| registries, err := regsWithCreds(fileContents) | ||
| if err != nil { | ||
| return findings, err | ||
| } | ||
| for _, registry := range registries { | ||
| findings = append(findings, models.Finding{ | ||
| ID: fmt.Sprintf("%s:%s", location, registry), | ||
| Probe: dcp.Name(), | ||
| Title: "Docker credentials found", | ||
| Message: fmt.Sprintf("%s contains cleartext credentials for %s. Consider using a credential helper.", location, registry), | ||
| Path: location, | ||
| Severity: "high", | ||
| Locations: locations, | ||
| }) | ||
| } | ||
| } | ||
| return findings, nil | ||
| } | ||
|
|
||
| func regsWithCreds(fileContents []byte) ([]string, error) { | ||
| var registries []string | ||
| var config map[string]interface{} | ||
| if err := json.Unmarshal(fileContents, &config); err != nil { | ||
| return registries, err | ||
| } | ||
| auths, ok := config["auths"].(map[string]interface{}) | ||
| if !ok { | ||
| return registries, nil | ||
| } | ||
| for registry, settings := range auths { | ||
| propsForRegistry, ok := settings.(map[string]interface{}) | ||
| if !ok { | ||
| continue | ||
| } | ||
| if propsForRegistry["auth"] != nil { | ||
| registries = append(registries, registry) | ||
| } | ||
| } | ||
| return registries, nil | ||
| } | ||
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,62 @@ | ||
| // Copyright (C) 2026 boostsecurity.io | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
|
|
||
| package probe | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/boostsecurityio/bagel/pkg/models" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| var configFileWithCreds = `{ | ||
| "auths": { | ||
| "dhi.io": { | ||
| "auth": "supersecret" | ||
| }, | ||
| "docker.io": {}, | ||
| "ghcr.io": {} | ||
| }, | ||
| "credHelpers": { | ||
| "dhi.io": "osxkeychain", | ||
| "ghcr.io": "osxkeychain", | ||
| "docker.io": "osxkeychain" | ||
| } | ||
| } | ||
| ` | ||
|
|
||
| var configFileWithoutCreds = `{ | ||
| "auths": { | ||
| "dhi.io": {}, | ||
| "docker.io": {}, | ||
| "ghcr.io": {} | ||
| }, | ||
| "credHelpers": { | ||
| "dhi.io": "osxkeychain", | ||
| "ghcr.io": "osxkeychain", | ||
| "docker.io": "osxkeychain" | ||
| } | ||
| } | ||
| ` | ||
|
|
||
| var probeSettings = models.ProbeSettings{ | ||
| Enabled: true, | ||
| } | ||
|
|
||
| func TestName(t *testing.T) { | ||
| probe := NewDockerCredsProbe(probeSettings) | ||
| assert.Equal(t, probe.Name(), "Docker credentials") | ||
| } | ||
|
|
||
| func TestParsingFileWithCreds(t *testing.T) { | ||
| expected := []string{"dhi.io"} | ||
| actual, _ := regsWithCreds([]byte(configFileWithCreds)) | ||
| assert.Equal(t, expected, actual) | ||
| } | ||
|
|
||
| func TestParsingFileWithoutCreds(t *testing.T) { | ||
| var expected []string | ||
| actual, _ := regsWithCreds([]byte(configFileWithoutCreds)) | ||
| assert.Equal(t, expected, actual) | ||
| } |
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.
Sorry not being clear enough but the probe is used to access the files in the index but then you need to run the detectors on the content of your files to actually detect credentials. When credentials are actually detected then a finding can be created. The current implementation will just flag every docker and podman config files as having creds in clear when it is not necessarily the case