Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable changing bound service account token issuer from default
- Loading branch information
Showing
3 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
pkg/operator/configobservation/auth/auth_serviceaccountissuer.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package auth | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
|
||
"k8s.io/apimachinery/pkg/api/errors" | ||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
"k8s.io/klog" | ||
|
||
"github.com/openshift/cluster-kube-apiserver-operator/pkg/operator/configobservation" | ||
"github.com/openshift/library-go/pkg/operator/configobserver" | ||
"github.com/openshift/library-go/pkg/operator/events" | ||
) | ||
|
||
// ObserveServiceAccountIssuer changes apiServerArguments.service-account-issuer from the default | ||
// value if Authentication.Spec.ServiceAccountIssuer specifies a valid non-empty value. | ||
func ObserveServiceAccountIssuer(genericListers configobserver.Listers, recorder events.Recorder, existingConfig map[string]interface{}) (map[string]interface{}, []error) { | ||
listers := genericListers.(configobservation.Listers) | ||
errs := []error{} | ||
prevObservedConfig := map[string]interface{}{} | ||
|
||
topLevelMetadataFilePath := []string{"apiServerArguments", "service-account-issuer"} | ||
currentIssuer, _, err := unstructured.NestedString(existingConfig, topLevelMetadataFilePath...) | ||
if err != nil { | ||
errs = append(errs, err) | ||
} | ||
if len(currentIssuer) > 0 { | ||
if err := unstructured.SetNestedField(prevObservedConfig, currentIssuer, topLevelMetadataFilePath...); err != nil { | ||
errs = append(errs, err) | ||
} | ||
} | ||
|
||
observedConfig := map[string]interface{}{} | ||
authConfig, err := listers.AuthConfigLister.Get("cluster") | ||
if errors.IsNotFound(err) { | ||
klog.Warningf("authentications.config.openshift.io/cluster: not found") | ||
return observedConfig, errs | ||
} | ||
if err != nil { | ||
errs = append(errs, err) | ||
return prevObservedConfig, errs | ||
} | ||
|
||
newIssuer := authConfig.Spec.ServiceAccountIssuer | ||
if len(newIssuer) > 0 { | ||
if _, err := url.Parse(newIssuer); err != nil { | ||
errs = append(errs, fmt.Errorf("spec.serviceAccountIssuer contained a ':' but was not a valid URL: %v", err)) | ||
return prevObservedConfig, errs | ||
} | ||
} | ||
if err := unstructured.SetNestedField(observedConfig, newIssuer, topLevelMetadataFilePath...); err != nil { | ||
errs = append(errs, err) | ||
} | ||
|
||
return observedConfig, errs | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters