
Un modo adatto alle aziende per rilevare e prevenire segreti nel codice.
detect-secrets è un modulo giustamente chiamato per (sorpresa, sorpresa) rilevare segreti all'interno di una base di codice.
Tuttavia, a differenza di altri pacchetti simili che si concentrano esclusivamente sulla ricerca di segreti, questo pacchetto è progettato pensando al cliente enterprise: fornendo un mezzo retrocompatibile e sistematico per:
In questo modo, si crea una separazione delle responsabilità: accettando che possano esserci attualmente segreti nascosti nel vostro grande repository (questo è ciò che chiamiamo una baseline), ma impedendo che il problema diventi più grande, senza dover affrontare lo sforzo potenzialmente enorme di spostare i segreti esistenti.
Lo fa eseguendo output diff periodici rispetto a espressioni regex costruite euristicamente, per identificare se è stato commesso un nuovo segreto. In questo modo, evita l'overhead di scavare in tutta la storia di git, così come la necessità di scansionare l'intero repository ogni volta.
Per dare un'occhiata ai cambiamenti recenti, consultare CHANGELOG.md.
Se desideri contribuire, consulta CONTRIBUTING.md.
Per documentazione più dettagliata, dai un'occhiata alla nostra altra documentazione.
Crea una baseline dei potenziali segreti attualmente trovati nel tuo repository git.```bash $ detect-secrets scan > .secrets.baseline
oppure, per eseguirlo da una directory diversa:```bash
$ detect-secrets -C /path/to/directory scan > /path/to/directory/.secrets.baseline
Scansione dei file non tracciati da git:```bash $ detect-secrets scan test_data/ --all-files > .secrets.baseline
### Aggiunta di nuovi segreti alla baseline:
Questo eseguirà una nuova scansione del tuo codebase e:
1. Aggiorna/upgrade la tua baseline per renderla compatibile con l'ultima versione,
2. Aggiunge eventuali nuovi segreti trovati alla tua baseline,
3. Rimuove eventuali segreti non più presenti nel tuo codebase
Questo conserverà anche eventuali segreti etichettati che hai.```bash
$ detect-secrets scan --baseline .secrets.baseline
Per baseline più vecchie della versione 0.9, basta ricrearle.
Scansione solo dei file in staging:```bash $ git diff --staged --name-only -z | xargs -0 detect-secrets-hook --baseline .secrets.baseline
**Scansione di tutti i file tracciati:**```bash
$ git ls-files -z | xargs -0 detect-secrets-hook --baseline .secrets.baseline
$ detect-secrets scan --list-all-plugins ArtifactoryDetector AWSKeyDetector AzureStorageKeyDetector BasicAuthDetector CloudantDetector DiscordBotTokenDetector GitHubTokenDetector GitLabTokenDetector Base64HighEntropyString HexHighEntropyString IbmCloudIamDetector IbmCosHmacDetector IPPublicDetector JwtTokenDetector KeywordDetector MailchimpDetector NpmDetector OpenAIDetector PrivateKeyDetector PypiTokenDetector SendGridDetector SlackDetector SoftlayerDetector SquareOAuthDetector StripeDetector TelegramBotTokenDetector TwilioKeyDetector
### Disabilitazione dei Plugin:```bash
$ detect-secrets scan --disable-plugin KeywordDetector --disable-plugin AWSKeyDetector
Se vuoi solo eseguire un plugin specifico, puoi fare:```bash
$ detect-secrets scan --list-all-plugins |
grep -v 'BasicAuthDetector' |
sed "s#^#--disable-plugin #g" |
xargs detect-secrets scan test_data
### Verifica di una Baseline:
Questo è un passaggio opzionale per etichettare i risultati nella tua baseline. Può essere utilizzato per restringere la tua checklist di segreti da migrare, o per configurare meglio i tuoi plugin al fine di migliorare il rapporto segnale-rumore.```bash
$ detect-secrets audit .secrets.baseline
Uso base:```python from detect_secrets import SecretsCollection from detect_secrets.settings import default_settings
secrets = SecretsCollection() with default_settings(): secrets.scan_file('test_data/config.ini')
import json print(json.dumps(secrets.json(), indent=2))
**Configurazione più avanzata:**```python
from detect_secrets import SecretsCollection
from detect_secrets.settings import transient_settings
secrets = SecretsCollection()
with transient_settings({
# Only run scans with only these plugins.
# This format is the same as the one that is saved in the generated baseline.
'plugins_used': [
# Example of configuring a built-in plugin
{
'name': 'Base64HighEntropyString',
'limit': 5.0,
},
# Example of using a custom plugin
{
'name': 'HippoDetector',
'path': 'file:///Users/aaronloo/Documents/github/detect-secrets/testing/plugins.py',
},
],
# We can also specify whichever additional filters we want.
# This is an example of using the function `is_identified_by_ML_model` within the
# local file `./private-filters/example.py`.
'filters_used': [
{
'path': 'file://private-filters/example.py::is_identified_by_ML_model',
},
]
}) as settings:
# If we want to make any further adjustments to the created settings object (e.g.
# disabling default filters), we can do so as such.
settings.disable_filters(
'detect_secrets.filters.heuristic.is_prefixed_with_dollar_sign',
'detect_secrets.filters.heuristic.is_likely_id_string',
)
secrets.scan_file('test_data/config.ini')
$ pip install detect-secrets ✨🍰✨
Installa tramite [brew](https://brew.sh/):```bash
$ brew install detect-secrets
detect-secrets viene fornito con tre diversi strumenti, e c'è spesso confusione su quale usare. Usa questa pratica checklist per aiutarti a decidere:
detect-secrets scan.detect-secrets-hook.detect-secrets audit.