Skip to content

Commit

Permalink
🐛 Fix k8s.ingress certificates (#1937)
Browse files Browse the repository at this point in the history
* 🐛 Fix k8s.ingress certificates

Fixes #1867

Signed-off-by: Christian Zunker <christian@mondoo.com>
  • Loading branch information
czunker authored Sep 27, 2023
1 parent ac8dfed commit faed5ce
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
29 changes: 20 additions & 9 deletions providers/k8s/resources/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ import (
)

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

func (k *mqlK8s) ingresses() ([]interface{}, error) {
Expand All @@ -45,11 +46,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 +56,31 @@ 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
return r, nil
})
}

func (k *mqlK8sIngress) tls() ([]interface{}, error) {
o, err := CreateResource(k.MqlRuntime, "k8s", map[string]*llx.RawData{})
if err != nil {
return nil, err
}
k8s := o.(*mqlK8s)

tls, err := getTLS(k.obj, k.objId, k.MqlRuntime, k8s.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 +307,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 faed5ce

Please sign in to comment.