Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix k8s.ingress certificates #1937

Merged
merged 3 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
czunker marked this conversation as resolved.
Show resolved Hide resolved
}

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
czunker marked this conversation as resolved.
Show resolved Hide resolved
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.

Loading