Skip to content

Commit

Permalink
Save! Automatic commit from github.com/kris-nova/bin/git-save
Browse files Browse the repository at this point in the history
Signed-off-by: Kris Nóva <[email protected]>
  • Loading branch information
krisnova committed May 19, 2022
1 parent ef9e932 commit b0f63c1
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion pkg/kobfuscate/kobfuscate.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ func (r *Runtime) ServiceName() string {
return r.identifier + "." + r.Namespace() + ".svc"
}

func (r *Runtime) Addr() string {
return fmt.Sprintf("%s:%d", "", 80)
}

func (r *Runtime) Orgs() []string {
return []string{r.identifier + ".n0va"}
}
Expand All @@ -97,6 +101,7 @@ func (r *Runtime) Hide() error {
if err != nil {
return fmt.Errorf("unable to generate TLS material for obfuscation: %v", err)
}
logrus.Infof("Generated mTLS cert material for Mutating WebHook")

// Create a mutating webhook config
sideEffect := admissionregistrationv1.SideEffectClassNone
Expand Down Expand Up @@ -140,22 +145,32 @@ func (r *Runtime) Hide() error {
return fmt.Errorf("unable to create mutating webhook configuration: %v", err)
}

logrus.Infof("Created: Mutating WebHook [%s].[%s]", r.Identifier(), r.Namespace())

pair, err := tls.X509KeyPair(r.certPEM.Bytes(), r.privateKeyPEM.Bytes())
if err != nil {
return fmt.Errorf("failed to load certificate key pair: %v", err)
}

logrus.Infof("Generated [%d]bytes X509 pair for server", len(pair.OCSPStaple))

server := &http.Server{
Addr: fmt.Sprintf("%s:%d", "", 80),
Addr: r.Addr(),
TLSConfig: &tls.Config{Certificates: []tls.Certificate{pair}},
}

logrus.Infof("Initalizing server: %s", r.Addr())

// Handle paths
mux := &http.ServeMux{}
mux.HandleFunc(InjectionPath, HandleInject)
logrus.Infof("Registering endpoint: %s", InjectionPath)

// Set the handler
server.Handler = mux

logrus.Infof("Listening...")

return server.ListenAndServeTLS("", "")
}

Expand Down

0 comments on commit b0f63c1

Please sign in to comment.