Skip to content

Commit fce42cc

Browse files
committed
upload OIDC discovery data to disco backend
Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com>
1 parent dfc7c39 commit fce42cc

5 files changed

Lines changed: 33 additions & 3 deletions

File tree

api/datareading.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ func (o *DataReading) UnmarshalJSON(data []byte) error {
6464
target any
6565
assign func(any)
6666
}{
67+
{&OIDCDiscoveryData{}, func(v any) { o.Data = v.(*OIDCDiscoveryData) }},
6768
{&DiscoveryData{}, func(v any) { o.Data = v.(*DiscoveryData) }},
6869
{&DynamicData{}, func(v any) { o.Data = v.(*DynamicData) }},
6970
}

internal/cyberark/dataupload/dataupload.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ type Snapshot struct {
5757
ClusterDescription string `json:"cluster_description,omitempty"`
5858
// K8SVersion is the version of Kubernetes which the cluster is running.
5959
K8SVersion string `json:"k8s_version"`
60+
// OIDCConfig contains OIDC configuration data from the API server's
61+
// `/.well-known/openid-configuration` endpoint
62+
OIDCConfig map[string]any `json:"openid_configuration,omitempty"`
63+
// OIDCConfigError contains any error encountered while fetching the OIDC configuration
64+
OIDCConfigError string `json:"openid_configuration_error,omitempty"`
65+
// JWKS contains JWKS data from the API server's `/openid/v1/jwks` endpoint
66+
JWKS map[string]any `json:"jwks,omitempty"`
67+
// JWKSError contains any error encountered while fetching the JWKS
68+
JWKSError string `json:"jwks_error,omitempty"`
6069
// Secrets is a list of Secret resources in the cluster. Not all Secret
6170
// types are included and only a subset of the Secret data is included.
6271
Secrets []runtime.Object `json:"secrets"`

pkg/client/client_cyberark.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,25 @@ func baseSnapshotFromOptions(opts Options) dataupload.Snapshot {
104104
}
105105
}
106106

107+
// extractOIDCFromReading converts the opaque data from a OIDCDiscoveryData
108+
// data reading to allow access to the OIDC fields within.
109+
func extractOIDCFromReading(reading *api.DataReading, target *dataupload.Snapshot) error {
110+
if reading == nil {
111+
return fmt.Errorf("programmer mistake: the DataReading must not be nil")
112+
}
113+
data, ok := reading.Data.(*api.OIDCDiscoveryData)
114+
if !ok {
115+
return fmt.Errorf(
116+
"programmer mistake: the DataReading must have data type *api.OIDCDiscoveryData. "+
117+
"This DataReading (%s) has data type %T", reading.DataGatherer, reading.Data)
118+
}
119+
target.OIDCConfig = data.OIDCConfig
120+
target.OIDCConfigError = data.OIDCConfigError
121+
target.JWKS = data.JWKS
122+
target.JWKSError = data.JWKSError
123+
return nil
124+
}
125+
107126
// extractClusterIDAndServerVersionFromReading converts the opaque data from a DiscoveryData
108127
// data reading to allow access to the Kubernetes version fields within.
109128
func extractClusterIDAndServerVersionFromReading(reading *api.DataReading, target *dataupload.Snapshot) error {
@@ -161,6 +180,7 @@ func extractResourceListFromReading(reading *api.DataReading, target *[]runtime.
161180
// and populates the relevant field(s) of the Snapshot based on the DataReading's data.
162181
// Deleted resources are excluded from the snapshot because they are not needed by CyberArk.
163182
var defaultExtractorFunctions = map[string]func(*api.DataReading, *dataupload.Snapshot) error{
183+
"ark/oidc": extractOIDCFromReading,
164184
"ark/discovery": extractClusterIDAndServerVersionFromReading,
165185
"ark/secrets": func(r *api.DataReading, s *dataupload.Snapshot) error {
166186
return extractResourceListFromReading(r, &s.Secrets)

pkg/datagatherer/oidc/oidc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func (g *DataGathererOIDC) Fetch() (any, int, error) {
7474
return ""
7575
}
7676

77-
return api.OIDCDiscoveryData{
77+
return &api.OIDCDiscoveryData{
7878
OIDCConfig: oidcResponse,
7979
OIDCConfigError: errToString(oidcErr),
8080
JWKS: jwksResponse,

pkg/datagatherer/oidc/oidc_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func TestFetch_Success(t *testing.T) {
5757
t.Fatalf("expected count 1, got %d", count)
5858
}
5959

60-
res, ok := anyRes.(api.OIDCDiscoveryData)
60+
res, ok := anyRes.(*api.OIDCDiscoveryData)
6161
if !ok {
6262
t.Fatalf("unexpected result type: %T", anyRes)
6363
}
@@ -101,7 +101,7 @@ func TestFetch_Errors(t *testing.T) {
101101
t.Fatalf("Fetch returned error: %v", err)
102102
}
103103

104-
res, ok := anyRes.(api.OIDCDiscoveryData)
104+
res, ok := anyRes.(*api.OIDCDiscoveryData)
105105
if !ok {
106106
t.Fatalf("unexpected result type: %T", anyRes)
107107
}

0 commit comments

Comments
 (0)