-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement authorization options for kcp
On-behalf-of: @SAP christoph.mewes@sap.com
- Loading branch information
Showing
16 changed files
with
432 additions
and
12 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
Copyright 2025 The KCP Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package utils | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"strings" | ||
|
||
appsv1 "k8s.io/api/apps/v1" | ||
corev1 "k8s.io/api/core/v1" | ||
|
||
operatorv1alpha1 "github.com/kcp-dev/kcp-operator/sdk/apis/operator/v1alpha1" | ||
) | ||
|
||
func applyAuthorizationConfiguration(deployment *appsv1.Deployment, config *operatorv1alpha1.AuthorizationSpec) (*appsv1.Deployment, error) { | ||
if len(deployment.Spec.Template.Spec.Containers) == 0 { | ||
return deployment, errors.New("Deployment does not contain any containers") | ||
} | ||
|
||
if config == nil || config.Webhook == nil { | ||
return deployment, nil | ||
} | ||
|
||
return applyAuthorizationWebhookConfiguration(deployment, *config.Webhook), nil | ||
} | ||
|
||
func applyAuthorizationWebhookConfiguration(deployment *appsv1.Deployment, config operatorv1alpha1.AuthorizationWebhookSpec) *appsv1.Deployment { | ||
podSpec := deployment.Spec.Template.Spec | ||
|
||
var extraArgs []string | ||
|
||
if vals := config.AllowPaths; len(vals) > 0 { | ||
extraArgs = append(extraArgs, fmt.Sprintf("--authorization-always-allow-paths=%s", strings.Join(vals, ","))) | ||
} | ||
|
||
if val := config.CacheAuthorizedTTL; val != nil { | ||
extraArgs = append(extraArgs, fmt.Sprintf("--authorization-webhook-cache-authorized-ttl=%v", val.String())) | ||
} | ||
|
||
if val := config.CacheUnauthorizedTTL; val != nil { | ||
extraArgs = append(extraArgs, fmt.Sprintf("--authorization-webhook-cache-unauthorized-ttl=%v", val.String())) | ||
} | ||
|
||
if val := config.Version; val != "" { | ||
extraArgs = append(extraArgs, fmt.Sprintf("--authorization-webhook-version=%s", val)) | ||
} | ||
|
||
if val := config.ConfigSecretName; val != "" { | ||
volumeName := "authorization-webhook-config" | ||
mountPath := "/etc/kcp/authorization/webhook" | ||
|
||
extraArgs = append(extraArgs, fmt.Sprintf("--authorization-webhook-config-file=%s/kubeconfig", mountPath)) | ||
podSpec.Containers[0].VolumeMounts = append(podSpec.Containers[0].VolumeMounts, corev1.VolumeMount{ | ||
Name: volumeName, | ||
ReadOnly: true, | ||
MountPath: mountPath, | ||
}) | ||
|
||
deployment.Spec.Template.Spec.Volumes = append(deployment.Spec.Template.Spec.Volumes, corev1.Volume{ | ||
Name: volumeName, | ||
VolumeSource: corev1.VolumeSource{ | ||
Secret: &corev1.SecretVolumeSource{ | ||
SecretName: val, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
podSpec.Containers[0].Args = append(podSpec.Containers[0].Args, extraArgs...) | ||
deployment.Spec.Template.Spec = podSpec | ||
|
||
return deployment | ||
} |
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,39 @@ | ||
/* | ||
Copyright 2025 The KCP Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package utils | ||
|
||
import ( | ||
"fmt" | ||
|
||
appsv1 "k8s.io/api/apps/v1" | ||
|
||
operatorv1alpha1 "github.com/kcp-dev/kcp-operator/sdk/apis/operator/v1alpha1" | ||
) | ||
|
||
func ApplyCommonShardConfig(deployment *appsv1.Deployment, spec *operatorv1alpha1.CommonShardSpec) (*appsv1.Deployment, error) { | ||
deployment, err := applyAuditConfiguration(deployment, spec.Audit) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to apply audit configuration: %w", err) | ||
} | ||
|
||
deployment, err = applyAuthorizationConfiguration(deployment, spec.Authorization) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to apply authorization configuration: %w", err) | ||
} | ||
|
||
return deployment, nil | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
39 changes: 39 additions & 0 deletions
39
sdk/applyconfiguration/operator/v1alpha1/authorizationspec.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.