Advanced Usage

Advanced Usage #

Downloading the binary #

export VERSION="v1.49.3"
# darwin, windows, and linux accepted.
# 386, amd64, and arm64.
# More OS/arch combinations can be requested.
export GOOS="linux"
export GOARCH="amd64"
curl -o "trufflehog-scanner-$VERSION-$GOOS-$GOARCH.tar.gz" "https://storage.googleapis.com/thog-releases/trufflehog-scanner/$VERSION/trufflehog-scanner-$VERSION-$GOOS-$GOARCH.tar.gz"
tar -zxf "trufflehog-scanner-$VERSION-$GOOS-$GOARCH.tar.gz"
./scanner --help

Running as a Systemd daemon #

If you’re looking to run the scanner on a Linux system, setting it up to run as a systemd unit is a good way to ensure that it

  • starts automatically on startup
  • has logs rotated
  • is able to run without any users connected to the server

Most modern Linux distributions include systemd to manage daemons and other configuration.

We’ll provide an example below that is tailored for Ubuntu, but compatible with other systems with some minor alterations.

  1. Extract the TruffleHog scanner archive to /home/ubuntu

  2. Copy your config.yaml into /home/ubuntu

  3. Copy the Systemd Unit file given below into /etc/systemd/system/trufflehog.service

    Systemd Unit file:

    [Unit]
    Description=Run the TruffleHog scanner as a daemon
    
    [Service]
    Type=simple
    ExecStart=/home/ubuntu/scanner scan --config /home/ubuntu/config.yaml
    Restart=on-failure
    RestartSec=15s
    User=ubuntu
    PrivateUser=yes
    
    [Install]
    WantedBy=multi-user.target
    
  4. Reload Systemd to make it aware of the new service unit file: systemctl daemon-reload

  5. Configure the Systemd to run TruffleHog at boot: systemctl enable trufflehog.service

  6. Start TruffleHog right now: systemctl start trufflehog.service

  7. View the status of TruffleHog systemctl status trufflehog.service

  8. View the TruffleHog logs: journalctl logs -u trufflehog

  9. Tail the TruffleHog logs: journalctl logs -fu trufflehog

Deploying to Kubernetes via manifest #

The following instructions will help you setup a basic deployment of the TruffleHog scanner in Kubernetes. Kubernetes will ensure that TruffleHog stays running, manage your configuration secrets, and collect the logs.

  1. Create the namespace
    $ kubectl create namespace trufflehog
    namespace/trufflehog created
    
  2. Create the configuration secret
    $ kubectl create secret --namespace trufflehog generic --from-file config.yaml config
    secret/config created
    
  3. Create the deployment
    1. Create a yaml file with these contents:
      
      apiVersion: apps/v1
      kind: Deployment
      metadata:
        name: trufflehog
        labels:
          app: trufflehog
      spec:
        replicas: 1
        selector:
          matchLabels:
            app: trufflehog
        template:
          metadata:
            labels:
              app: trufflehog
          spec:
            volumes:
            - name: config-secret-volume
              secret:
                secretName: config
            containers:
            - name: trufflehog
              image: us-docker.pkg.dev/thog-artifacts/public/scanner:latest
              command: ["/usr/local/bin/scanner", "scan", "--config=/secret/config.yaml"]
              volumeMounts:
              - name: config-secret-volume
                mountPath: /secret/
      
    2. Apply the manifest
      $ kubectl apply -f /tmp/thog.yaml --namespace trufflehog
      deployment.apps/trufflehog configured
      
  4. Wait for TruffleHog to be running
    $ kubectl get pods --namespace trufflehog --watch
    NAME                          READY   STATUS    RESTARTS   AGE
    trufflehog-7f76dc4c49-szxwv   1/1     Running   0          0m22s
    
  5. Follow the logs
    $ kubectl logs --namespace trufflehog -f -l app=trufflehog 
    🐷🔑🐷 TruffleHog. Unearth your secrets. 🐷🔑🐷
    version:  v1.50.22
    
    INFO[0000] starting scanner service client               scanner_group=On-prem