Skip to content

Commit de20a0f

Browse files
authored
Merge branch 'main' into update-registry-from-release
2 parents 9da552a + 2cf46ef commit de20a0f

37 files changed

+3782
-107
lines changed

.github/workflows/autoupdate.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: autoupdate
2+
permissions:
3+
contents: read
4+
pull-requests: write
5+
on:
6+
# Update all PRs on merge to main
7+
push:
8+
branches:
9+
- main
10+
jobs:
11+
autoupdate:
12+
name: autoupdate
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: docker://chinthakagodawita/autoupdate-action:v1
16+
env:
17+
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'

.github/workflows/operator-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ jobs:
183183
go install github.com/stackloklabs/yardstick/cmd/yardstick-client@v0.0.2
184184
185185
- name: Install Chainsaw
186-
uses: kyverno/action-install-chainsaw@6354895e0f99ab23d3e38d85cf5c71b5dc21d727 # v0.2.13
186+
uses: kyverno/action-install-chainsaw@06560d18422209e9c1e08e931d477d04bf2674c1 # v0.2.14
187187
with:
188188
release: v0.2.12
189189

cmd/thv-operator/api/v1alpha1/mcpexternalauthconfig_types.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ const (
1111

1212
// ExternalAuthTypeHeaderInjection is the type for custom header injection
1313
ExternalAuthTypeHeaderInjection ExternalAuthType = "headerInjection"
14+
15+
// ExternalAuthTypeUnauthenticated is the type for no authentication
16+
// This should only be used for backends on trusted networks (e.g., localhost, VPC)
17+
// or when authentication is handled by network-level security
18+
ExternalAuthTypeUnauthenticated ExternalAuthType = "unauthenticated"
1419
)
1520

1621
// ExternalAuthType represents the type of external authentication
@@ -21,7 +26,7 @@ type ExternalAuthType string
2126
// MCPServer resources in the same namespace.
2227
type MCPExternalAuthConfigSpec struct {
2328
// Type is the type of external authentication to configure
24-
// +kubebuilder:validation:Enum=tokenExchange;headerInjection
29+
// +kubebuilder:validation:Enum=tokenExchange;headerInjection;unauthenticated
2530
// +kubebuilder:validation:Required
2631
Type ExternalAuthType `json:"type"`
2732

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package v1alpha1
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"k8s.io/apimachinery/pkg/runtime"
8+
ctrl "sigs.k8s.io/controller-runtime"
9+
"sigs.k8s.io/controller-runtime/pkg/webhook"
10+
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
11+
)
12+
13+
// SetupWebhookWithManager sets up the webhook with the Manager
14+
func (r *MCPExternalAuthConfig) SetupWebhookWithManager(mgr ctrl.Manager) error {
15+
return ctrl.NewWebhookManagedBy(mgr).
16+
For(r).
17+
Complete()
18+
}
19+
20+
//nolint:lll // kubebuilder webhook marker cannot be split
21+
// +kubebuilder:webhook:path=/validate-toolhive-stacklok-com-v1alpha1-mcpexternalauthconfig,mutating=false,failurePolicy=fail,sideEffects=None,groups=toolhive.stacklok.com,resources=mcpexternalauthconfigs,verbs=create;update,versions=v1alpha1,name=vmcpexternalauthconfig.kb.io,admissionReviewVersions=v1
22+
23+
var _ webhook.CustomValidator = &MCPExternalAuthConfig{}
24+
25+
// ValidateCreate implements webhook.CustomValidator
26+
func (r *MCPExternalAuthConfig) ValidateCreate(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
27+
var warnings admission.Warnings
28+
if r.Spec.Type == ExternalAuthTypeUnauthenticated {
29+
warnings = append(warnings,
30+
"'unauthenticated' type disables authentication to the backend. "+
31+
"Only use for backends on trusted networks or when authentication is handled by network-level security.")
32+
}
33+
return warnings, r.validate()
34+
}
35+
36+
// ValidateUpdate implements webhook.CustomValidator
37+
func (r *MCPExternalAuthConfig) ValidateUpdate(
38+
_ context.Context, _ runtime.Object, _ runtime.Object,
39+
) (admission.Warnings, error) {
40+
var warnings admission.Warnings
41+
if r.Spec.Type == ExternalAuthTypeUnauthenticated {
42+
warnings = append(warnings,
43+
"'unauthenticated' type disables authentication to the backend. "+
44+
"Only use for backends on trusted networks or when authentication is handled by network-level security.")
45+
}
46+
return warnings, r.validate()
47+
}
48+
49+
// ValidateDelete implements webhook.CustomValidator
50+
func (*MCPExternalAuthConfig) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
51+
// No validation needed for deletion
52+
return nil, nil
53+
}
54+
55+
// validate performs validation on the MCPExternalAuthConfig spec
56+
func (r *MCPExternalAuthConfig) validate() error {
57+
switch r.Spec.Type {
58+
case ExternalAuthTypeTokenExchange:
59+
if r.Spec.TokenExchange == nil {
60+
return fmt.Errorf("tokenExchange configuration is required when type is 'tokenExchange'")
61+
}
62+
if r.Spec.HeaderInjection != nil {
63+
return fmt.Errorf("headerInjection must not be set when type is 'tokenExchange'")
64+
}
65+
66+
case ExternalAuthTypeHeaderInjection:
67+
if r.Spec.HeaderInjection == nil {
68+
return fmt.Errorf("headerInjection configuration is required when type is 'headerInjection'")
69+
}
70+
if r.Spec.TokenExchange != nil {
71+
return fmt.Errorf("tokenExchange must not be set when type is 'headerInjection'")
72+
}
73+
74+
case ExternalAuthTypeUnauthenticated:
75+
if r.Spec.TokenExchange != nil {
76+
return fmt.Errorf("tokenExchange must not be set when type is 'unauthenticated'")
77+
}
78+
if r.Spec.HeaderInjection != nil {
79+
return fmt.Errorf("headerInjection must not be set when type is 'unauthenticated'")
80+
}
81+
82+
default:
83+
return fmt.Errorf("unsupported auth type: %s", r.Spec.Type)
84+
}
85+
86+
return nil
87+
}

0 commit comments

Comments
 (0)