Skip to content

Commit

Permalink
add catch all handler for k8s
Browse files Browse the repository at this point in the history
  • Loading branch information
joshrendek committed Nov 15, 2024
1 parent 00d31f4 commit 5e10c74
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions kubernetes/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ func (h *honeypot) apiHandler(w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode(response)
}

func (h *honeypot) catchAllHandler(w http.ResponseWriter, r *http.Request) {
body := make([]byte, r.ContentLength)
_, _ = r.Body.Read(body)
h.logger.Info().Str("path", r.URL.Path).Str("method", r.Method).Bytes("body", body).Msg("Request received")
}

// Handler for /api/v1
func (h *honeypot) apiV1Handler(w http.ResponseWriter, r *http.Request) {
response := map[string]interface{}{
Expand Down
4 changes: 4 additions & 0 deletions kubernetes/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ func (h *honeypot) Start() {

// Handle /api/v1/namespaces/{namespace}/pods
router.HandleFunc("/api/v1/namespaces/{namespace}/pods", h.podsHandler).Methods("GET", "POST")
// add a catch all route and log the request and body
router.PathPrefix("/").HandlerFunc(h.catchAllHandler).Methods("GET", "POST")



// Generate the TLS certificate
cert, err := generateSelfSignedCert()
Expand Down

0 comments on commit 5e10c74

Please sign in to comment.