mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-28 20:24:22 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3fedf6f8e7 | ||
|
|
6f6ebd454f |
No files matched your search
@@ -9,6 +9,12 @@ builds:
|
|||||||
- windows
|
- windows
|
||||||
goarch:
|
goarch:
|
||||||
- amd64
|
- amd64
|
||||||
|
- "386"
|
||||||
|
- arm
|
||||||
|
- arm64
|
||||||
|
goarm:
|
||||||
|
- "6"
|
||||||
|
- "7"
|
||||||
ldflags:
|
ldflags:
|
||||||
- -s -w -X=github.com/zricethezav/gitleaks/v8/cmd.Version={{.Version}}
|
- -s -w -X=github.com/zricethezav/gitleaks/v8/cmd.Version={{.Version}}
|
||||||
archives:
|
archives:
|
||||||
|
|||||||
@@ -78,9 +78,9 @@ Flags:
|
|||||||
-c, --config string config file path
|
-c, --config string config file path
|
||||||
order of precedence:
|
order of precedence:
|
||||||
1. --config/-c
|
1. --config/-c
|
||||||
2. (--source/-s)/.gitleaks.toml
|
2. env var GITLEAKS_CONFIG
|
||||||
if --config/-c is not set and no (--source/-s)/.gitleaks.toml present
|
3. (--source/-s)/.gitleaks.toml
|
||||||
then .gitleaks.toml will be written to (--source/-s)/.gitleaks.toml for future use
|
If none of the three options are used, then gitleaks will use the default config
|
||||||
--exit-code string exit code when leaks have been encountered (default: 1)
|
--exit-code string exit code when leaks have been encountered (default: 1)
|
||||||
-h, --help help for gitleaks
|
-h, --help help for gitleaks
|
||||||
-l, --log-level string log level (debug, info, warn, error, fatal) (default "info")
|
-l, --log-level string log level (debug, info, warn, error, fatal) (default "info")
|
||||||
|
|||||||
+16
-15
@@ -26,9 +26,9 @@ const banner = `
|
|||||||
const configDescription = `config file path
|
const configDescription = `config file path
|
||||||
order of precedence:
|
order of precedence:
|
||||||
1. --config/-c
|
1. --config/-c
|
||||||
2. (--source/-s)/.gitleaks.toml
|
2. env var GITLEAKS_CONFIG
|
||||||
if --config/-c is not set and no (--source/s)/.gitleaks.toml is present
|
3. (--source/-s)/.gitleaks.toml
|
||||||
then .gitleaks.toml will be written to (--source/-s)/.gitleaks.toml for future use`
|
If none of the three options are used, then gitleaks will use the default config`
|
||||||
|
|
||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
Use: "gitleaks",
|
Use: "gitleaks",
|
||||||
@@ -38,10 +38,10 @@ var rootCmd = &cobra.Command{
|
|||||||
func init() {
|
func init() {
|
||||||
cobra.OnInitialize(initLog)
|
cobra.OnInitialize(initLog)
|
||||||
rootCmd.PersistentFlags().StringP("config", "c", "", configDescription)
|
rootCmd.PersistentFlags().StringP("config", "c", "", configDescription)
|
||||||
rootCmd.PersistentFlags().Int("exit-code", 1, "exit code when leaks have been encountered (default: 1)")
|
rootCmd.PersistentFlags().Int("exit-code", 1, "exit code when leaks have been encountered")
|
||||||
rootCmd.PersistentFlags().StringP("source", "s", ".", "path to source (default: $PWD)")
|
rootCmd.PersistentFlags().StringP("source", "s", ".", "path to source (default: $PWD)")
|
||||||
rootCmd.PersistentFlags().StringP("report-path", "r", "", "report file")
|
rootCmd.PersistentFlags().StringP("report-path", "r", "", "report file")
|
||||||
rootCmd.PersistentFlags().StringP("report-format", "f", "", "output format (json, csv, sarif)")
|
rootCmd.PersistentFlags().StringP("report-format", "f", "json", "output format (json, csv, sarif)")
|
||||||
rootCmd.PersistentFlags().StringP("log-level", "l", "info", "log level (debug, info, warn, error, fatal)")
|
rootCmd.PersistentFlags().StringP("log-level", "l", "info", "log level (debug, info, warn, error, fatal)")
|
||||||
rootCmd.PersistentFlags().BoolP("verbose", "v", false, "show verbose output from scan")
|
rootCmd.PersistentFlags().BoolP("verbose", "v", false, "show verbose output from scan")
|
||||||
rootCmd.PersistentFlags().Bool("redact", false, "redact secrets from logs and stdout")
|
rootCmd.PersistentFlags().Bool("redact", false, "redact secrets from logs and stdout")
|
||||||
@@ -78,7 +78,11 @@ func initConfig() {
|
|||||||
}
|
}
|
||||||
if cfgPath != "" {
|
if cfgPath != "" {
|
||||||
viper.SetConfigFile(cfgPath)
|
viper.SetConfigFile(cfgPath)
|
||||||
log.Debug().Msgf("Using gitleaks config %s", cfgPath)
|
log.Debug().Msgf("Using gitleaks config %s from `--config`", cfgPath)
|
||||||
|
} else if os.Getenv("GITLEAKS_CONFIG") != "" {
|
||||||
|
envPath := os.Getenv("GITLEAKS_CONFIG")
|
||||||
|
viper.SetConfigFile(envPath)
|
||||||
|
log.Debug().Msgf("Using gitleaks config from GITLEAKS_CONFIG env var: %s", envPath)
|
||||||
} else {
|
} else {
|
||||||
source, err := rootCmd.Flags().GetString("source")
|
source, err := rootCmd.Flags().GetString("source")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -90,7 +94,7 @@ func initConfig() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !fileInfo.IsDir() {
|
if !fileInfo.IsDir() {
|
||||||
log.Debug().Msgf("Unable to write default gitleaks config to %s since --source=%s is a file, using default config",
|
log.Debug().Msgf("Unable to load gitleaks config from %s since --source=%s is a file, using default config",
|
||||||
filepath.Join(source, ".gitleaks.toml"), source)
|
filepath.Join(source, ".gitleaks.toml"), source)
|
||||||
viper.SetConfigType("toml")
|
viper.SetConfigType("toml")
|
||||||
viper.ReadConfig(strings.NewReader(config.DefaultConfig))
|
viper.ReadConfig(strings.NewReader(config.DefaultConfig))
|
||||||
@@ -98,15 +102,12 @@ func initConfig() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if _, err := os.Stat(filepath.Join(source, ".gitleaks.toml")); os.IsNotExist(err) {
|
if _, err := os.Stat(filepath.Join(source, ".gitleaks.toml")); os.IsNotExist(err) {
|
||||||
log.Debug().Msgf("No gitleaks config found, writing default gitleaks config to %s", filepath.Join(source, ".gitleaks.toml"))
|
log.Debug().Msgf("No gitleaks config found in path %s, using default gitleaks config", filepath.Join(source, ".gitleaks.toml"))
|
||||||
if err := os.WriteFile(filepath.Join(source, ".gitleaks.toml"), []byte(config.DefaultConfig), os.ModePerm); err != nil {
|
viper.SetConfigType("toml")
|
||||||
log.Debug().Msgf("Unable to write default gitleaks config to %s, using default config", filepath.Join(source, ".gitleaks.toml"))
|
viper.ReadConfig(strings.NewReader(config.DefaultConfig))
|
||||||
viper.SetConfigType("toml")
|
return
|
||||||
viper.ReadConfig(strings.NewReader(config.DefaultConfig))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
log.Debug().Msgf("Using existing gitleaks config %s", filepath.Join(source, ".gitleaks.toml"))
|
log.Debug().Msgf("Using existing gitleaks config %s from `(--source)/.gitleaks.toml`", filepath.Join(source, ".gitleaks.toml"))
|
||||||
}
|
}
|
||||||
|
|
||||||
viper.AddConfigPath(source)
|
viper.AddConfigPath(source)
|
||||||
|
|||||||
@@ -51,6 +51,10 @@ func FromFiles(source string, cfg config.Config, outputOptions Options) ([]repor
|
|||||||
}
|
}
|
||||||
fis := DetectFindings(cfg, b, p, "")
|
fis := DetectFindings(cfg, b, p, "")
|
||||||
for _, fi := range fis {
|
for _, fi := range fis {
|
||||||
|
// need to add 1 since line counting starts at 1
|
||||||
|
fi.StartLine++
|
||||||
|
fi.EndLine++
|
||||||
|
|
||||||
if outputOptions.Redact {
|
if outputOptions.Redact {
|
||||||
fi.Redact()
|
fi.Redact()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ func TestFromFiles(t *testing.T) {
|
|||||||
expectedFindings: []report.Finding{
|
expectedFindings: []report.Finding{
|
||||||
{
|
{
|
||||||
Description: "AWS Access Key",
|
Description: "AWS Access Key",
|
||||||
StartLine: 19,
|
StartLine: 20,
|
||||||
EndLine: 19,
|
EndLine: 20,
|
||||||
StartColumn: 16,
|
StartColumn: 16,
|
||||||
EndColumn: 35,
|
EndColumn: 35,
|
||||||
Match: "AKIALALEMEL33243OLIA",
|
Match: "AKIALALEMEL33243OLIA",
|
||||||
@@ -43,8 +43,8 @@ func TestFromFiles(t *testing.T) {
|
|||||||
expectedFindings: []report.Finding{
|
expectedFindings: []report.Finding{
|
||||||
{
|
{
|
||||||
Description: "AWS Access Key",
|
Description: "AWS Access Key",
|
||||||
StartLine: 19,
|
StartLine: 20,
|
||||||
EndLine: 19,
|
EndLine: 20,
|
||||||
StartColumn: 16,
|
StartColumn: 16,
|
||||||
EndColumn: 35,
|
EndColumn: 35,
|
||||||
Match: "AKIALALEMEL33243OLIA",
|
Match: "AKIALALEMEL33243OLIA",
|
||||||
|
|||||||
Reference in new issue
Block a user