# Kubernetes tool for scanning clusters for network policies and identifying unprotected workloads.


# Netfetch

### Scan your Kubernetes clusters to identifiy unprotected workloads and map your existing Network policies

![Netfetch](https://private-user-images.githubusercontent.com/17279882/298736337-64306f2f-abbf-462c-97d6-a326ca70c2ad.gif?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjY0OTc1NDksIm5iZiI6MTcyNjQ5NzI0OSwicGF0aCI6Ii8xNzI3OTg4Mi8yOTg3MzYzMzctNjQzMDZmMmYtYWJiZi00NjJjLTk3ZDYtYTMyNmNhNzBjMmFkLmdpZj9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA5MTYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwOTE2VDE0MzQwOVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTBjMmNhZmRlNmNlYjk1NDQ4NDI4ZjAxYTk4YzViYjRhOGQyOGRhNjNlZmRmOWMzZTBjNWFlM2ZiZWZiZDUyY2MmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.BQtB9WqxqSBEMpcIVOcg6zXlW_z09Is7W2LNzE49Sro align="center")

## Contents

* [**What is this project?**](https://github.com/deggja/netfetch#-what-is-this-project-)
    
    * [Support](https://github.com/deggja/netfetch#networkpolicy-type-support-in-netfetch)
        
* [**Installation**](https://github.com/deggja/netfetch#installation)
    
    * [Install with brew](https://github.com/deggja/netfetch#installation-via-homebrew-for-mac-)
        
    * [Install in Kubernetes](https://github.com/deggja/netfetch#installation-via-helm-)
        
* [**Usage**](https://github.com/deggja/netfetch#usage)
    
    * [Get started](https://github.com/deggja/netfetch#get-started)
        
    * [Dashboard](https://github.com/deggja/netfetch#using-the-dashboard-)
        
    * [Score](https://github.com/deggja/netfetch#netfetch-score-)
        
    * [Uninstalling](https://github.com/deggja/netfetch#uninstalling-netfetch)
        
* [**Contribute**](https://github.com/deggja/netfetch#contribute-)
    

## ⭐ What is this project ⭐

This project aims to demystify network policies in Kubernetes. It's a work in progress!

The `netfetch` tool will scan your Kubernetes cluster and let you know if you have any pods running without being targeted by network policies.

| Feature | CLI | Dashboard |
| --- | --- | --- |
| Scan cluster identify pods without network policies | ✓ | ✓ |
| Save scan output to a text file | ✓ |  |
| Visualize network policies and pods in a interactive network map |  | ✓ |
| Create default deny network policies where this is missing | ✓ | ✓ |
| Get suggestions for network policies based on existing workloads |  | ✓ |
| Calculate a security score based on scan findings | ✓ | ✓ |
| Scan a specific policy by name to see what pods it targets | ✓ |  |

### NetworkPolicy type support in Netfetch

| Type | CLI | Dashboard |
| --- | --- | --- |
| Kubernetes | ✓ | ✓ |
| Cilium | ✓ |  |

Support for additional types of network policies is in the works. No support for the type you need? Check out [issues](https://github.com/deggja/netfetch/issues) for an existing request or create a new one if there is none.

## Installation

### Installation via Homebrew for Mac 💻

You can install `netfetch` using our Homebrew tap:

```basic
brew tap deggja/netfetch https://github.com/deggja/netfetch
brew install netfetch
```

For specific Linux distros, Windows and other install binaries, check the latest release.

### Installation via Helm 🎩

You can deploy the `netfetch` dashboard in your Kubernetes clusters using Helm.

```basic
helm repo add deggja https://deggja.github.io/netfetch/
helm repo update
helm install netfetch deggja/netfetch --namespace netfetch --create-namespace
```

Follow the instructions after deployment to access the dashboard.

#### Prerequisites 🌌

* Installed `netfetch` via homebrew or a release binary.
    
* Access to a Kubernetes cluster with `kubectl` configured.
    
* Permissions to read and create network policies.
    

## Usage

### Get started

The primary command provided by `netfetch` is `scan`. This command scans all non-system Kubernetes namespaces for network policies.

You can also scan specific namespaces by specifying the name of that namespace.

You may add the --dryrun or -d flag to run a dryrun of the scan. The application will not prompt you about adding network policies, but still give you the output of the scan.

Run `netfetch` in dryrun against a cluster.

```basic
netfetch scan --dryrun
```

Run `netfetch` in dryrun against a namespace

```basic
netfetch scan crossplane-system --dryrun
```

[![netfetch-demo](https://private-user-images.githubusercontent.com/15778492/297470643-015e9d9f-a678-4a14-a8bd-607f02c13d9f.gif?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjY0OTc1NDksIm5iZiI6MTcyNjQ5NzI0OSwicGF0aCI6Ii8xNTc3ODQ5Mi8yOTc0NzA2NDMtMDE1ZTlkOWYtYTY3OC00YTE0LWE4YmQtNjA3ZjAyYzEzZDlmLmdpZj9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA5MTYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwOTE2VDE0MzQwOVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTAyZWUyYjgxOTA5ZGI2ZTIzMjk1NDRlZjU0MTNlODEwODcxMGEwNGFkZTBiYzhjOTY5MDFkZWJhYzg0MTY2NTUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.r2yyQjBDstUm5AZwPOkhDXGCj38a9B3ADD0Euyg6HO8 align="left")](https://private-user-images.githubusercontent.com/15778492/297470643-015e9d9f-a678-4a14-a8bd-607f02c13d9f.gif?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjY0OTc1NDksIm5iZiI6MTcyNjQ5NzI0OSwicGF0aCI6Ii8xNTc3ODQ5Mi8yOTc0NzA2NDMtMDE1ZTlkOWYtYTY3OC00YTE0LWE4YmQtNjA3ZjAyYzEzZDlmLmdpZj9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA5MTYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwOTE2VDE0MzQwOVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTAyZWUyYjgxOTA5ZGI2ZTIzMjk1NDRlZjU0MTNlODEwODcxMGEwNGFkZTBiYzhjOTY5MDFkZWJhYzg0MTY2NTUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.r2yyQjBDstUm5AZwPOkhDXGCj38a9B3ADD0Euyg6HO8)

Scan entire cluster.

```basic
netfetch scan
```

Scan a namespace called crossplane-system.

```basic
netfetch scan crossplane-system
```

Scan entire cluster for Cilium Network Policies and or Cluster Wide Cilium Network Policies.

```basic
netfetch scan --cilium
```

Scan a namespace called production for regular Cilium Network Policies.

```basic
netfetch scan production --cilium
```

Scan a specific network policy.

```basic
netfetch scan --target my-policy-name
```

Scan a specific Cilium Network Policy.

```basic
netfetch scan --cilium --target default-cilium-default-deny-all
```

[![asciicast](https://camo.githubusercontent.com/78d4b2fa787a2d2695cd0ba2f0d185dd1c840f70d1d2c728c3b38c5cdaae3168/68747470733a2f2f61736369696e656d612e6f72672f612f3636313230302e737667 align="left")](https://asciinema.org/a/661200)

### Using the dashboard 📟

Launch the dashboard:

```basic
netfetch dash
```

You may also specify a port for the dashboard to run on (default is 8080).

```basic
netfetch dash --port 8081
```

### Dashboard functionality overview

The Netfetch Dashboard offers an intuitive interface for interacting with your Kubernetes cluster's network policies. Below is a detailed overview of the functionalities available through the dashboard:

| Action | Description | Screenshot Link |
| --- | --- | --- |
| Scan Cluster | Initiates a cluster-wide scan to identify pods without network policies, similar to `netfetch scan`. |  |

![Netfetch Dashboard](https://github.com/deggja/netfetch/raw/main/frontend/dash/src/assets/new-dash.png align="left")

<table><tbody><tr><td colspan="1" rowspan="1"><p></p></td><td colspan="1" rowspan="1"><p></p></td><td colspan="1" rowspan="1"><p></p></td></tr><tr><td colspan="1" rowspan="1"><p>Scan Namespace</p></td><td colspan="1" rowspan="1"><p>Scans a selected namespace for pods not covered by network policies, equivalent to <code>netfetch scan namespace</code>.</p></td><td colspan="1" rowspan="1"><p></p></td></tr></tbody></table>

![Cluster map](https://github.com/deggja/netfetch/raw/main/frontend/dash/src/assets/new-clustermap.png align="left")

<table><tbody><tr><td colspan="1" rowspan="1"><p></p></td><td colspan="1" rowspan="1"><p></p></td><td colspan="1" rowspan="1"><p></p></td></tr><tr><td colspan="1" rowspan="1"><p>Create Cluster Map</p></td><td colspan="1" rowspan="1"><p>Generates a D3-rendered network map of all pods and policies across accessible namespaces.</p></td><td colspan="1" rowspan="1"><p></p></td></tr></tbody></table>

![Suggested policies](https://github.com/deggja/netfetch/raw/main/frontend/dash/src/assets/new-suggestpolicy.png align="left")

<table><tbody><tr><td colspan="1" rowspan="1"><p></p></td><td colspan="1" rowspan="1"><p></p></td><td colspan="1" rowspan="1"><p></p></td></tr><tr><td colspan="1" rowspan="1"><p>Suggest Policy</p></td><td colspan="1" rowspan="1"><p>Provides network policy suggestions based on existing workloads within a selected namespace.</p></td><td colspan="1" rowspan="1"><p></p></td></tr></tbody></table>

![Suggested policies](https://github.com/deggja/netfetch/raw/main/frontend/dash/src/assets/new-suggestpolicy.png align="left")

### Interactive Features

* **Table View**: Shows pods not targeted by network policies. It updates based on the cluster or namespace scans.
    
* **Network Map Visualization**: Rendered using D3 to show how pods and policies interact within the cluster.
    
* **Policy Preview**: Double-click network policy nodes within the network map to view policy YAML.
    
* **Policy Editing**: Edit suggested policies directly within the dashboard or copy the YAML for external use.
    

### Netfetch score 🥇

The `netfetch` tool provides a basic score at the end of each scan. The score ranges from 1 to 42, with 1 being the lowest and 42 being the highest possible score.

Your score will decrease based on the amount of workloads in your cluster that are running without being targeted by a network policy.

The score reflects the security posture of your Kubernetes namespaces based on network policies and general policy coverage. If changes are made based on recommendations from the initial scan, rerunning `netfetch` will likely result in a higher score.

### Uninstalling netfetch

If you want to uninstall the application - you can do so by running the following commands.

```basic
brew uninstall netfetch
brew cleanup -s netfetch
brew untap deggja/netfetch https://github.com/deggja/netfetch
```

## Running Tests

To run tests for netfetch, follow these steps:

1. Navigate to the root directory of the project in your terminal.
    
2. Navigate to the backend directory within the project:
    

```basic
cd backend
```

3. Run the following command to execute all tests in the project:
    

```basic
go test ./...
```

This command will recursively search for tests in all subdirectories (./...) and run them.

4. After executing the command, you will see the test results in the terminal output.
    

## Contribute 🔨

Thank you to the following awesome people:

* [roopeshsn](https://github.com/roopeshsn)
    
* [s-rd](https://github.com/s-rd)
    
* [JJGadgets](https://github.com/JJGadgets)
    
* [Home Operations Discord](https://github.com/onedr0p/home-ops)
    
* [pehlicd](https://github.com/pehlicd)
    

You are welcome to contribute!

See [CONTRIBUTING](https://github.com/deggja/netfetch/blob/main/CONTRIBUTING.md) for instructions on how to proceed.

## Tools 🧰

Netfetch uses other tools for a plethora of different things. It would not be possible without the following:

* [statik](https://github.com/rakyll/statik)
    
* [D3](https://d3-graph-gallery.com/network.html)
    
* [Helm](https://helm.sh/docs/)
    
* [Brew](https://brew.sh/)
    
* [lipgloss](https://github.com/charmbracelet/lipgloss)
    

## License

Netfetch is distributed under the MIT License. See the [LICENSE](https://github.com/deggja/netfetch/blob/main/LICENSE) for more information.
