Skip to content

Commit

Permalink
Merge pull request #3 from deggja/interactive_ui
Browse files Browse the repository at this point in the history
Interactive UI
  • Loading branch information
deggja authored Nov 26, 2023
2 parents fd1d163 + 7db70b3 commit 8720b83
Show file tree
Hide file tree
Showing 28 changed files with 12,799 additions and 53 deletions.
44 changes: 29 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
![image](https://github.com/deggja/netfetch/assets/15778492/b9a93dce-a09a-4823-be99-dcda5dbf6dc7)

## Using Netfetch Tool
## Using Netfetch

The `netfetch` tool is designed to scan Kubernetes namespaces for network policies, checking if there are implicit defautl deny policies in place or any other policy targetting the pods.
The `netfetch` tool is designed to scan Kubernetes namespaces for network policies, checking whether implicit default deny policies are in place and examining if there are any other policies targeting the pods.

This document guides you on how to use `netfetch` to perform these scans.

## Contribute
You are welcome to contribute!

Open an issue or create a pull request if there is some functionality missing that you would like.

## Installation via Homebrew for Mac

You can install `netfetch` using our Homebrew tap:
Expand All @@ -20,21 +15,23 @@ brew tap deggja/netfetch https://github.com/deggja/netfetch
brew install netfetch
```

For specific Linux distros, Windows etc. Check the latest release for a downloadable binary.
For specific Linux distros and other install binaries, check the latest release.

### Prerequisites

Before you begin, ensure you have the following:

- `netfetch` binary installed in your system.
- Access to a Kubernetes cluster with configured `kubectl`.
- Sufficient permissions to list namespaces and network policies in the cluster.
- Permissions to read and create network policies in at least one namespace.

### Basic usage
### Usage

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

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

Scan entire cluster.

```sh
netfetch scan
Expand All @@ -43,15 +40,32 @@ netfetch scan
You can also specifiy namespaces when running netfetch.

```sh
netfetch scan default
netfetch scan production
```

Launch interactive dashboard.

```sh
netfetch dash
```

![Netfetch Dashboard](https://github.com/deggja/netfetch/assets/netfetch_dash.png)

## Netfetch score

The `netfetch` tool provides a 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.
The `netfetch` tool provides a simple but accurate 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.

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

## Contribute
You are welcome to contribute!

This score reflects the security posture of your Kubernetes namespaces based on network policies and pod coverage. If changes are made based on recommendations from the initial scan, rerunning `netfetch` will likely result in an improved score.
1. Fork the Project
2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
3. Commit your Changes (git commit -m 'Add some AmazingFeature')
4. Push to the Branch (git push origin feature/AmazingFeature)
5. Open a Pull Request

## License

[MIT License], see [LICENSE](LICENSE).
Netfetch is distributed under the MIT License. See the LICENSE file for more information. See the [LICENSE](LICENSE) for more information.
53 changes: 53 additions & 0 deletions backend/cmd/dash.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package cmd

import (
"fmt"
"log"
"net/http"

"github.com/deggja/netfetch/backend/pkg/k8s"
"github.com/rs/cors"
"github.com/spf13/cobra"
)

var dashCmd = &cobra.Command{
Use: "dash",
Short: "Launch the Netfetch interactive dashboard",
Run: func(cmd *cobra.Command, args []string) {
startDashboardServer()
},
}

func init() {
rootCmd.AddCommand(dashCmd)
}

func startDashboardServer() {
// Set up CORS
c := cors.New(cors.Options{
AllowedOrigins: []string{"http://localhost:8081"},
AllowedMethods: []string{"GET", "POST", "OPTIONS"},
AllowedHeaders: []string{"Accept", "Content-Type", "X-CSRF-Token"},
})

// Set up handlers
http.HandleFunc("/", dashboardHandler)
http.HandleFunc("/scan", k8s.HandleScanRequest)
http.HandleFunc("/namespaces", k8s.HandleNamespaceListRequest)
http.HandleFunc("/add-policy", k8s.HandleAddPolicyRequest)

// Wrap the default serve mux with the CORS middleware
handler := c.Handler(http.DefaultServeMux)

// Start the server
port := "8080"
fmt.Printf("Starting dashboard server on http://localhost:%s\n", port)
if err := http.ListenAndServe(":"+port, handler); err != nil {
log.Fatalf("Failed to start server: %v\n", err)
}
}

func dashboardHandler(w http.ResponseWriter, r *http.Request) {
// Serve the Vue.js UI
http.FileServer(http.Dir("netfetch/frontend/dash")).ServeHTTP(w, r)
}
6 changes: 4 additions & 2 deletions cmd/root.go → backend/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ var rootCmd = &cobra.Command{
netfetch [command]
Available Commands:
scan Scan Kubernetes namespaces for network policies
help Help about any command
scan Scan Kubernetes namespaces for network policies
scan namespace Scan specific namespace in cluster
help Help about any command
dash Open interactive dashboard
Flags:
-h, --help help for netfetch`,
Expand Down
11 changes: 9 additions & 2 deletions cmd/scan.go → backend/cmd/scan.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package cmd

import (
"github.com/deggja/netfetch/pkg/k8s"
"fmt"

"github.com/deggja/netfetch/backend/pkg/k8s"
"github.com/spf13/cobra"
)

Expand All @@ -15,7 +17,12 @@ var scanCmd = &cobra.Command{
if len(args) > 0 {
namespace = args[0]
}
k8s.ScanNetworkPolicies(namespace)
_, err := k8s.ScanNetworkPolicies(namespace, false, true)
if err != nil {
// Handle the error appropriately
fmt.Println("Error during scan:", err)
return
}
},
}

Expand Down
3 changes: 2 additions & 1 deletion go.mod → backend/go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/deggja/netfetch
module github.com/deggja/netfetch/backend

go 1.19

Expand Down Expand Up @@ -35,6 +35,7 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/rs/cors v1.10.1
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/oauth2 v0.8.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum → backend/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ github.com/onsi/gomega v1.27.6 h1:ENqfyGeS5AX/rlXDd/ETokDz93u0YufY1Pgxuy/PvWE=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/rs/cors v1.10.1 h1:L0uuZVXIKlI1SShY2nhFfo44TYvDPQ1w4oFkUJNfhyo=
github.com/rs/cors v1.10.1/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
Expand Down
2 changes: 1 addition & 1 deletion main.go → backend/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"github.com/deggja/netfetch/cmd"
"github.com/deggja/netfetch/backend/cmd"
)

func main() {
Expand Down
Binary file renamed netfetch → backend/netfetch
Binary file not shown.
File renamed without changes.
Loading

0 comments on commit 8720b83

Please sign in to comment.