Skip to content

Commit 9c8e218

Browse files
authored
Merge pull request #40 from SimonTheLeg/configure-groups-in-fp
✨ allow configuring pass-on and dropped groups in frontproxy
2 parents 915b39c + 0c092ab commit 9c8e218

File tree

7 files changed

+117
-13
lines changed

7 files changed

+117
-13
lines changed

config/crd/bases/operator.kcp.io_frontproxies.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ spec:
8080
description: 'Optional: Auth configures various aspects of Authentication
8181
and Authorization for this front-proxy instance.'
8282
properties:
83+
dropGroups:
84+
description: 'Optional: DropGroups configures groups to be dropped
85+
before forwarding requests to Shards'
86+
items:
87+
type: string
88+
type: array
8389
oidc:
8490
description: 'Optional: OIDC configures OpenID Connect Authentication.'
8591
properties:
@@ -122,6 +128,12 @@ spec:
122128
- enabled
123129
- issuerURL
124130
type: object
131+
passOnGroups:
132+
description: 'Optional: PassOnGroups configures groups to be passed
133+
on before forwarding requests to Shards'
134+
items:
135+
type: string
136+
type: array
125137
type: object
126138
externalHostname:
127139
description: 'Optional: ExternalHostname under which the FrontProxy

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ require (
77
github.com/go-logr/logr v1.4.2
88
github.com/go-logr/zapr v1.3.0
99
github.com/go-test/deep v1.1.0
10+
github.com/google/go-cmp v0.6.0
1011
github.com/kcp-dev/apimachinery/v2 v2.0.1-0.20240817110845-a9eb9752bfeb
1112
github.com/kcp-dev/client-go v0.0.0-20240912145314-f5949d81732a
1213
github.com/kcp-dev/code-generator/v2 v2.3.1
@@ -54,7 +55,6 @@ require (
5455
github.com/golang/protobuf v1.5.4 // indirect
5556
github.com/google/cel-go v0.20.1 // indirect
5657
github.com/google/gnostic-models v0.6.8 // indirect
57-
github.com/google/go-cmp v0.6.0 // indirect
5858
github.com/google/gofuzz v1.2.1-0.20210504230335-f78f29fc09ea // indirect
5959
github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8 // indirect
6060
github.com/google/uuid v1.6.0 // indirect

internal/resources/frontproxy/deployment.go

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package frontproxy
1818

1919
import (
2020
"fmt"
21+
"strings"
2122

2223
"k8c.io/reconciler/pkg/reconciling"
2324

@@ -41,7 +42,7 @@ func DeploymentReconciler(frontProxy *operatorv1alpha1.FrontProxy, rootShard *op
4142
dep.Spec.Template.ObjectMeta.SetLabels(resources.GetFrontProxyResourceLabels(frontProxy))
4243

4344
image, _ := resources.GetImageSettings(frontProxy.Spec.Image)
44-
args := getArgs()
45+
args := getArgs(&frontProxy.Spec)
4546

4647
container := corev1.Container{
4748
Name: "kcp-front-proxy",
@@ -236,16 +237,28 @@ func DeploymentReconciler(frontProxy *operatorv1alpha1.FrontProxy, rootShard *op
236237
}
237238
}
238239

239-
func getArgs() []string {
240-
args := []string{
241-
"--secure-port=6443",
242-
"--root-kubeconfig=/etc/kcp-front-proxy/kubeconfig/kubeconfig",
243-
"--shards-kubeconfig=/etc/kcp-front-proxy/kubeconfig/kubeconfig",
244-
"--tls-private-key-file=/etc/kcp-front-proxy/tls/tls.key",
245-
"--tls-cert-file=/etc/kcp-front-proxy/tls/tls.crt",
246-
"--client-ca-file=/etc/kcp-front-proxy/client-ca/tls.crt",
247-
"--mapping-file=/etc/kcp-front-proxy/config/path-mapping.yaml",
248-
"--service-account-key-file=/etc/kcp/tls/service-account/tls.key",
240+
var defaultArgs = []string{
241+
"--secure-port=6443",
242+
"--root-kubeconfig=/etc/kcp-front-proxy/kubeconfig/kubeconfig",
243+
"--shards-kubeconfig=/etc/kcp-front-proxy/kubeconfig/kubeconfig",
244+
"--tls-private-key-file=/etc/kcp-front-proxy/tls/tls.key",
245+
"--tls-cert-file=/etc/kcp-front-proxy/tls/tls.crt",
246+
"--client-ca-file=/etc/kcp-front-proxy/client-ca/tls.crt",
247+
"--mapping-file=/etc/kcp-front-proxy/config/path-mapping.yaml",
248+
"--service-account-key-file=/etc/kcp/tls/service-account/tls.key",
249+
}
250+
251+
func getArgs(fps *operatorv1alpha1.FrontProxySpec) []string {
252+
args := defaultArgs
253+
254+
if fps.Auth != nil {
255+
if fps.Auth.DropGroups != nil {
256+
args = append(args, fmt.Sprintf("--authentication-drop-groups=%q", strings.Join(fps.Auth.DropGroups, ",")))
257+
}
258+
259+
if fps.Auth.PassOnGroups != nil {
260+
args = append(args, fmt.Sprintf("--authentication-pass-on-groups=%q", strings.Join(fps.Auth.PassOnGroups, ",")))
261+
}
249262
}
250263

251264
return args
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package frontproxy
2+
3+
import (
4+
"testing"
5+
6+
"github.com/google/go-cmp/cmp"
7+
8+
operatorv1alpha1 "github.com/kcp-dev/kcp-operator/sdk/apis/operator/v1alpha1"
9+
)
10+
11+
func TestGetArgs(t *testing.T) {
12+
tests := map[string]struct {
13+
in *operatorv1alpha1.FrontProxySpec
14+
exp []string
15+
}{
16+
"only defaults configured": {
17+
in: &operatorv1alpha1.FrontProxySpec{Auth: &operatorv1alpha1.AuthSpec{}},
18+
exp: defaultArgs,
19+
},
20+
"drop-groups and pass-on-groups configured": {
21+
in: &operatorv1alpha1.FrontProxySpec{
22+
Auth: &operatorv1alpha1.AuthSpec{
23+
DropGroups: []string{"some-group", "some-other-group"},
24+
PassOnGroups: []string{"totally-different-group"},
25+
},
26+
},
27+
exp: append(defaultArgs, []string{
28+
"--authentication-drop-groups=\"some-group,some-other-group\"",
29+
"--authentication-pass-on-groups=\"totally-different-group\"",
30+
}...),
31+
},
32+
}
33+
for name, tc := range tests {
34+
t.Run(name, func(t *testing.T) {
35+
res := getArgs(tc.in)
36+
if !cmp.Equal(res, tc.exp) {
37+
t.Error(cmp.Diff(res, tc.exp))
38+
}
39+
})
40+
}
41+
}

sdk/apis/operator/v1alpha1/frontproxy_types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ type FrontProxySpec struct {
4343
type AuthSpec struct {
4444
// Optional: OIDC configures OpenID Connect Authentication.
4545
OIDC *OIDCConfiguration `json:"oidc,omitempty"`
46+
47+
// Optional: DropGroups configures groups to be dropped before forwarding requests to Shards
48+
DropGroups []string `json:"dropGroups,omitempty"`
49+
50+
// Optional: PassOnGroups configures groups to be passed on before forwarding requests to Shards
51+
PassOnGroups []string `json:"passOnGroups,omitempty"`
4652
}
4753

4854
type ServiceSpec struct {

sdk/apis/operator/v1alpha1/zz_generated.deepcopy.go

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/applyconfiguration/operator/v1alpha1/authspec.go

Lines changed: 23 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)