Skip to content

Commit

Permalink
🐛 Fix k8s.ingress certificates
Browse files Browse the repository at this point in the history
Fixes #1867

Signed-off-by: Christian Zunker <[email protected]>
  • Loading branch information
czunker committed Sep 26, 2023
1 parent 4ad834d commit 7bd275c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 14 deletions.
27 changes: 18 additions & 9 deletions providers/k8s/resources/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ import (
)

type mqlK8sIngressInternal struct {
lock sync.Mutex
obj *networkingv1.Ingress
lock sync.Mutex
obj *networkingv1.Ingress
objId string
mqlK8s *mqlK8s
}

func (k *mqlK8s) ingresses() ([]interface{}, error) {
Expand All @@ -45,11 +47,6 @@ func (k *mqlK8s) ingresses() ([]interface{}, error) {
return nil, err
}

tls, err := getTLS(ingress, objId, k.MqlRuntime, k.GetSecrets)
if err != nil {
return nil, err
}

r, err := CreateResource(k.MqlRuntime, "k8s.ingress", map[string]*llx.RawData{
"id": llx.StringData(objId),
"uid": llx.StringData(string(obj.GetUID())),
Expand All @@ -60,16 +57,28 @@ func (k *mqlK8s) ingresses() ([]interface{}, error) {
"created": llx.TimeData(ts.Time),
"manifest": llx.DictData(manifest),
"rules": llx.ArrayData(rules, types.Resource("k8s.ingressrule")),
"tls": llx.ArrayData(tls, types.Resource("k8s.ingresstls")),
})
if err != nil {
return nil, err
}
r.(*mqlK8sIngress).obj = ingress
r.(*mqlK8sIngress).objId = objId
r.(*mqlK8sIngress).mqlK8s = k
return r, nil
})
}

func (k *mqlK8sIngress) tls() ([]interface{}, error) {
ingress := k.obj
objId := k.objId
tls, err := getTLS(ingress, objId, k.MqlRuntime, k.mqlK8s.GetSecrets)
if err != nil {
return nil, err
}

return tls, nil
}

func (k *mqlK8sIngress) id() (string, error) {
return k.Id.Data, nil
}
Expand Down Expand Up @@ -296,7 +305,7 @@ func getTLS(ingress *networkingv1.Ingress, objId string, runtime *plugin.Runtime
ingressTls, err := CreateResource(runtime, "k8s.ingresstls", map[string]*llx.RawData{
"id": llx.StringData(fmt.Sprintf("%s-tls%d", objId, i)),
"hosts": llx.ArrayData(convert.SliceAnyToInterface(tls.Hosts), types.String),
"certificates": llx.ArrayData(secret.Certificates.Data, types.Resource("core.certificate")),
"certificates": llx.ArrayData(secret.Certificates.Data, types.Resource("network.certificate")),
})
if err != nil {
return nil, fmt.Errorf("error creating k8s.ingresstls: %s", err)
Expand Down
7 changes: 4 additions & 3 deletions providers/k8s/resources/k8s.lr
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: BUSL-1.1

import "../../os/resources/os.lr"
import "../../network/resources/network.lr"

option provider = "go.mondoo.com/cnquery/providers/k8s"
option go_package = "go.mondoo.com/cnquery/providers/k8s/resources"
Expand Down Expand Up @@ -465,7 +466,7 @@ private k8s.secret @defaults("namespace name created") {
// Secret type
type string
// Secret certificates
certificates() []certificate
certificates() []network.certificate
}

// Kubernetes ConfigMap
Expand Down Expand Up @@ -583,7 +584,7 @@ private k8s.ingresstls {
// List of hosts associated with TLS certificate
hosts []string
// Certificates data from TLS Secret
certificates []core.certificate
certificates []network.certificate
}

// Kubernetes Ingress
Expand Down Expand Up @@ -611,7 +612,7 @@ private k8s.ingress @defaults("namespace name created") {
// Ingress rules
rules []k8s.ingressrule
// Ingress TLS data
tls []k8s.ingresstls
tls() []k8s.ingresstls
}

// Kubernetes Service Account
Expand Down
16 changes: 14 additions & 2 deletions providers/k8s/resources/k8s.lr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7bd275c

Please sign in to comment.