Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
19 changes: 17 additions & 2 deletions api/datareading.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,14 @@ func (v *GatheredResource) UnmarshalJSON(data []byte) error {
return nil
}

// DynamicData is the DataReading.Data returned by the k8s.DataGathererDynamic
// DynamicData is the DataReading.Data returned by the k8sdynamic.DataGathererDynamic
// gatherer
type DynamicData struct {
// Items is a list of GatheredResource
Items []*GatheredResource `json:"items"`
}

// DiscoveryData is the DataReading.Data returned by the k8s.ConfigDiscovery
// DiscoveryData is the DataReading.Data returned by the k8sdiscovery.DataGathererDiscovery
// gatherer
type DiscoveryData struct {
// ClusterID is the unique ID of the Kubernetes cluster which this snapshot was taken from.
Expand All @@ -149,3 +149,18 @@ type DiscoveryData struct {
// See https://godoc.org/k8s.io/apimachinery/pkg/version#Info
ServerVersion *version.Info `json:"server_version"`
}

// OIDCDiscoveryData is the DataReading.Data returned by the oidc.OIDCDiscovery
// gatherer
type OIDCDiscoveryData struct {
// OIDCConfig contains OIDC configuration data from the API server's
// `/.well-known/openid-configuration` endpoint
OIDCConfig map[string]any `json:"openid_configuration,omitempty"`
// OIDCConfigError contains any error encountered while fetching the OIDC configuration
OIDCConfigError string `json:"openid_configuration_error,omitempty"`

// JWKS contains JWKS data from the API server's `/openid/v1/jwks` endpoint
JWKS map[string]any `json:"jwks,omitempty"`
// JWKSError contains any error encountered while fetching the JWKS
JWKSError string `json:"jwks_error,omitempty"`
}
2 changes: 0 additions & 2 deletions deploy/charts/disco-agent/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ data:
{{- . | toYaml | nindent 6 }}
{{- end }}
data-gatherers:
- kind: oidc
name: ark/oidc
- kind: k8s-discovery
name: ark/discovery
- kind: k8s-dynamic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ custom-cluster-description:
cluster_description: "A cloud hosted Kubernetes cluster hosting production workloads.\n\nteam: team-1\nemail: team-1@example.com\npurpose: Production workloads\n"
period: "12h0m0s"
data-gatherers:
- kind: oidc
name: ark/oidc
- kind: k8s-discovery
name: ark/discovery
- kind: k8s-dynamic
Expand Down Expand Up @@ -116,8 +114,6 @@ custom-cluster-name:
cluster_description: ""
period: "12h0m0s"
data-gatherers:
- kind: oidc
name: ark/oidc
- kind: k8s-discovery
name: ark/discovery
- kind: k8s-dynamic
Expand Down Expand Up @@ -225,8 +221,6 @@ custom-period:
cluster_description: ""
period: "1m"
data-gatherers:
- kind: oidc
name: ark/oidc
- kind: k8s-discovery
name: ark/discovery
- kind: k8s-dynamic
Expand Down Expand Up @@ -334,8 +328,6 @@ defaults:
cluster_description: ""
period: "12h0m0s"
data-gatherers:
- kind: oidc
name: ark/oidc
- kind: k8s-discovery
name: ark/discovery
- kind: k8s-dynamic
Expand Down
10 changes: 2 additions & 8 deletions pkg/datagatherer/oidc/oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"k8s.io/client-go/rest"

"github.com/jetstack/preflight/api"
"github.com/jetstack/preflight/pkg/datagatherer"
"github.com/jetstack/preflight/pkg/kubeconfig"
)
Expand Down Expand Up @@ -73,21 +74,14 @@ func (g *DataGathererOIDC) Fetch() (any, int, error) {
return ""
}

return OIDCDiscoveryData{
return api.OIDCDiscoveryData{
OIDCConfig: oidcResponse,
OIDCConfigError: errToString(oidcErr),
JWKS: jwksResponse,
JWKSError: errToString(jwksErr),
}, 1 /* we have 1 result, so return 1 as count */, nil
}

type OIDCDiscoveryData struct {
OIDCConfig map[string]any `json:"openid_configuration,omitempty"`
OIDCConfigError string `json:"openid_configuration_error,omitempty"`
JWKS map[string]any `json:"jwks,omitempty"`
JWKSError string `json:"jwks_error,omitempty"`
}

func (g *DataGathererOIDC) fetchOIDCConfig(ctx context.Context) (map[string]any, error) {
// Fetch the OIDC discovery document from the well-known endpoint.
bytes, err := g.cl.Get().AbsPath("/.well-known/openid-configuration").Do(ctx).Raw()
Expand Down
6 changes: 4 additions & 2 deletions pkg/datagatherer/oidc/oidc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (

"k8s.io/client-go/discovery"
"k8s.io/client-go/rest"

"github.com/jetstack/preflight/api"
)

func makeRESTClient(t *testing.T, ts *httptest.Server) rest.Interface {
Expand Down Expand Up @@ -55,7 +57,7 @@ func TestFetch_Success(t *testing.T) {
t.Fatalf("expected count 1, got %d", count)
}

res, ok := anyRes.(OIDCDiscoveryData)
res, ok := anyRes.(api.OIDCDiscoveryData)
if !ok {
t.Fatalf("unexpected result type: %T", anyRes)
}
Expand Down Expand Up @@ -99,7 +101,7 @@ func TestFetch_Errors(t *testing.T) {
t.Fatalf("Fetch returned error: %v", err)
}

res, ok := anyRes.(OIDCDiscoveryData)
res, ok := anyRes.(api.OIDCDiscoveryData)
if !ok {
t.Fatalf("unexpected result type: %T", anyRes)
}
Expand Down