Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added auth policy for app-validator, app-event-service and source adapter #7349

Merged
merged 18 commits into from Mar 18, 2020
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -81,9 +81,9 @@ func NewProxyHandler(
appRegistryPathPrefix: appRegistryPathPrefix,
appRegistryHost: appRegistryHost,

eventsProxy: createReverseProxy(eventServiceHost),
eventMeshProxy: createReverseProxy(eventMeshHost, withRewriteBaseURL("/"), withEnforceURLHost),
appRegistryProxy: createReverseProxy(appRegistryHost),
eventsProxy: createReverseProxy(eventServiceHost, withEmptyRequestHost, withEmptyXFwdClientCert, withHTTPScheme),
eventMeshProxy: createReverseProxy(eventMeshHost, withRewriteBaseURL("/"), withEmptyRequestHost, withEmptyXFwdClientCert, withHTTPScheme),
appRegistryProxy: createReverseProxy(appRegistryHost, withEmptyRequestHost, withHTTPScheme),

applicationGetter: applicationGetter,
cache: cache,
Expand Down Expand Up @@ -293,9 +293,7 @@ func extractSubject(subject string) map[string]string {
func createReverseProxy(destinationHost string, reqOpts ...requestOption) *httputil.ReverseProxy {
return &httputil.ReverseProxy{
Director: func(request *http.Request) {
request.URL.Scheme = "http"
request.URL.Host = destinationHost

for _, opt := range reqOpts {
opt(request)
}
Expand All @@ -318,8 +316,18 @@ func withRewriteBaseURL(path string) requestOption {
}
}

// withEnforceURLHost enforces the Request's Host field to be empty to ensure
// withEmptyRequestHost clears the Request's Host field to ensure
// the 'Host' HTTP header is set to the host name defined in the Request's URL.
func withEnforceURLHost(req *http.Request) {
func withEmptyRequestHost(req *http.Request) {
req.Host = ""
}

// withHTTPScheme sets the URL scheme to HTTP
func withHTTPScheme(req *http.Request) {
req.URL.Scheme = "http"
}

// withEmptyXFwdClientCert clears the value of X-Forwarded-Client-Cert header
func withEmptyXFwdClientCert(req *http.Request) {
req.Header.Del("X-Forwarded-Client-Cert")
}
1 change: 1 addition & 0 deletions components/application-operator/README.md
Expand Up @@ -31,6 +31,7 @@ Application Operator (AO) performs different operations as a result of the follo
- **eventServiceImage** is the Event Service image version to use in the Application chart.
- **eventServiceTestsImage** is the Event Service Tests image version to use in the Application chart.
- **applicationConnectivityValidatorImage** is the Application Connectivity Validator image version to use in the Application chart.
- **strictMode** is a toggle used to enable or disable Istio authorization policy for validator and HTTP source adapter. The default value is `disabled`.

## Testing on a local deployment

Expand Down
@@ -0,0 +1,121 @@
{{- if eq .Values.global.strictMode "enabled" }}
---
apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
name: {{ .Release.Name }}-connectivity-validator
labels:
app: {{ .Release.Name }}-connectivity-validator
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
spec:
selector:
matchLabels:
app: {{ .Release.Name }}-connectivity-validator
rules:
- from:
- source:
principals:
- cluster.local/ns/istio-system/sa/istio-ingressgateway-service-account
to:
- operation:
methods:
- POST
paths:
- /{{ .Release.Name }}/v1/events
- /{{ .Release.Name }}/v2/events
- /{{ .Release.Name }}/events
- operation:
methods:
- GET
- PUT
- POST
sayanh marked this conversation as resolved.
Show resolved Hide resolved
paths:
- /{{ .Release.Name }}/v1/metadata*
- from:
- source:
principals:
- cluster.local/ns/kyma-system/sa/{{ .Values.authorizationPolicy.serviceAccount.consoleBackendService }}
to:
- operation:
methods:
- GET
paths:
- /v1/health
---
apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
name: {{ .Release.Name }}-event-service
labels:
app: {{ .Release.Name }}-event-service
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
spec:
selector:
matchLabels:
app: {{ .Release.Name }}-event-service
rules:
- from:
- source:
principals:
- cluster.local/ns/kyma-integration/sa/{{ .Release.Name }}-connectivity-validator
sayanh marked this conversation as resolved.
Show resolved Hide resolved
to:
- operation:
methods:
- POST
paths:
- /{{ .Release.Name }}/v1/events
- /{{ .Release.Name }}/v2/events
- operation:
methods:
- GET
paths:
- /{{ .Release.Name }}/v1/events/subscribed
- /v1/health
- from:
- source:
principals:
- cluster.local/ns/kyma-system/sa/{{ .Values.authorizationPolicy.serviceAccount.consoleBackendService }}
to:
- operation:
methods:
- GET
paths:
- /v1/health
selector:
matchLabels:
app: newapp-event-service
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be?

Suggested change
app: newapp-event-service
app: {{ .Release.Name }}-event-service

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

---
apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
labels:
app: {{ .Release.Name }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
name: {{ .Release.Name }}-http-source
namespace: kyma-integration
spec:
rules:
- from:
- source:
principals:
- cluster.local/ns/knative-serving/sa/controller
to:
- operation:
methods:
- POST
- GET
paths:
- /*
- to:
- operation:
methods:
- GET
paths:
- /metrics
selector:
matchLabels:
serving.knative.dev/service: {{ .Release.Name }}
{{- end }}

This file was deleted.

Expand Up @@ -89,9 +89,13 @@ metadata:
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
rules:
- apiGroups: ["*"]
resources: ["namespaces", "subscriptions", "triggers"]
- apiGroups: [""]
resources: ["namespaces"]
verbs: ["get", "list", "watch"]
- apiGroups: ["eventing.knative.dev"]
resources: ["triggers"]
verbs: ["get", "list", "watch"]

---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
Expand All @@ -109,3 +113,33 @@ roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ .Release.Name }}-event-service
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: {{ .Release.Name }}-connectivity-validator
labels:
app: {{ .Release.Name }}-connectivity-validator
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
rules:
- apiGroups: ["applicationconnector.kyma-project.io"]
resources: ["applications"]
verbs: ["get", "list"]
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: {{ .Release.Name }}-connectivity-validator
labels:
app: {{ .Release.Name }}-connectivity-validator
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
subjects:
- kind: User
name: system:serviceaccount:{{ .Release.Namespace }}:{{ .Release.Name }}-connectivity-validator
apiGroup: rbac.authorization.k8s.io
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ .Release.Name }}-connectivity-validator
@@ -0,0 +1,8 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ .Release.Name }}-connectivity-validator
labels:
app: {{ .Release.Name }}-connectivity-validator
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
Expand Up @@ -25,6 +25,7 @@ spec:
kyma-project.io/dashboard: event-mesh
release: {{ .Release.Name }}
spec:
serviceAccountName: {{ .Release.Name }}-connectivity-validator
containers:
- name: {{ .Release.Name }}-connectivity-validator
image: {{ .Values.global.applicationConnectivityValidatorImage }}
Expand Down
Expand Up @@ -34,6 +34,10 @@ acceptanceTest:
image:
pullPolicy: IfNotPresent

# core-console-backend-service is a ServiceAccount which is installed as a part of *core* chart
authorizationPolicy:
serviceAccount:
consoleBackendService: core-console-backend-service
eventService:
deployment:
labels:
Expand Down
8 changes: 8 additions & 0 deletions components/application-operator/cmd/manager/manager.go
Expand Up @@ -107,6 +107,13 @@ func main() {
log.Fatal(err)
}

log.Printf("Setting up Application Controller.")

err = application_controller.InitApplicationController(mgr, releaseManager, options.appName)
if err != nil {
log.Fatal(err)
}

log.Printf("Setting up Service Instance Controller.")

err = service_instance_controller.InitServiceInstanceController(mgr, options.appName, gatewayManager)
Expand Down Expand Up @@ -143,6 +150,7 @@ func newApplicationReleaseManager(options *options, cfg *rest.Config, helmClient
EventServiceTestsImage: options.eventServiceTestsImage,
ApplicationConnectivityValidatorImage: options.applicationConnectivityValidatorImage,
GatewayOncePerNamespace: options.gatewayOncePerNamespace,
StrictMode: options.strictMode,
}

appClient, err := versioned.NewForConfig(cfg)
Expand Down
8 changes: 5 additions & 3 deletions components/application-operator/cmd/manager/options.go
Expand Up @@ -22,6 +22,7 @@ type options struct {
eventServiceTestsImage string
applicationConnectivityValidatorImage string
gatewayOncePerNamespace bool
strictMode string
}

func parseArgs() *options {
Expand All @@ -40,8 +41,8 @@ func parseArgs() *options {
eventServiceImage := flag.String("eventServiceImage", "", "The image of the Event Service to use")
eventServiceTestsImage := flag.String("eventServiceTestsImage", "", "The image of the Event Service Tests to use")
applicationConnectivityValidatorImage := flag.String("applicationConnectivityValidatorImage", "", "The image of the Application Connectivity Validator to use")

gatewayOncePerNamespace := flag.Bool("gatewayOncePerNamespace", false, "Specifies if Gateway should be deployed once per Namespace based on ServiceInstance or for every Application")
strictMode := flag.String("strictMode", "disabled", "Toggles Istio authorization policy for Validator and HTTP source adapter")

flag.Parse()

Expand All @@ -61,16 +62,17 @@ func parseArgs() *options {
eventServiceTestsImage: *eventServiceTestsImage,
applicationConnectivityValidatorImage: *applicationConnectivityValidatorImage,
gatewayOncePerNamespace: *gatewayOncePerNamespace,
strictMode: *strictMode,
}
}

func (o *options) String() string {
return fmt.Sprintf("--appName=%s --domainName=%s --namespace=%s --tillerUrl=%s"+
"--helmTLSKeyFile=%s --helmTLSCertificateFile=%s --tillerTLSSkipVerify=%v --syncPeriod=%d --installationTimeout=%d "+
"--applicationGatewayImage=%s --applicationGatewayTestsImage=%s --eventServiceImage=%s --eventServiceTestsImage=%s"+
"--applicationConnectivityValidatorImage=%s --gatewayOncePerNamespace=%v",
"--applicationConnectivityValidatorImage=%s --gatewayOncePerNamespace=%v --strictMode=%s",
o.appName, o.domainName, o.namespace, o.tillerUrl,
o.helmTLSKeyFile, o.helmTLSCertificateFile, o.tillerTLSSkipVerify, o.syncPeriod, o.installationTimeout,
o.applicationGatewayImage, o.applicationGatewayTestsImage, o.eventServiceImage, o.eventServiceTestsImage,
o.applicationConnectivityValidatorImage, o.gatewayOncePerNamespace)
o.applicationConnectivityValidatorImage, o.gatewayOncePerNamespace, o.strictMode)
}
Expand Up @@ -33,7 +33,8 @@ const (
applicationConnectivityValidatorImage:
tenant: %s
group: %s
deployGatewayOncePerNamespace: false`
deployGatewayOncePerNamespace: false
strictMode: `
)

var (
Expand Down
Expand Up @@ -10,7 +10,8 @@ const (
applicationConnectivityValidatorImage: {{ .ApplicationConnectivityValidatorImage }}
tenant: {{ .Tenant }}
group: {{ .Group }}
deployGatewayOncePerNamespace: {{ .GatewayOncePerNamespace }}`
deployGatewayOncePerNamespace: {{ .GatewayOncePerNamespace }}
strictMode: {{ .StrictMode }}`
)

type OverridesData struct {
Expand All @@ -23,4 +24,5 @@ type OverridesData struct {
Tenant string
Group string
GatewayOncePerNamespace bool
StrictMode string
}
Expand Up @@ -66,6 +66,7 @@ const (
tRevision = "varkes-foo"
tPolicy = "varkes-foo-private"
tRevisionSvc = "varkes-foo-private"
tTargetPort = "http-usermetric"

tMetricsDomain = "testing"
)
Expand Down Expand Up @@ -553,6 +554,13 @@ func newPolicyWithSpec() *authv1alpha1.Policy {
policy.Spec = authenticationv1alpha1api.Policy{
Targets: []*authenticationv1alpha1api.TargetSelector{{
Name: tRevisionSvc,
Ports: []*authenticationv1alpha1api.PortSelector{
{
Port: &authenticationv1alpha1api.PortSelector_Name{
Name: tTargetPort,
},
},
},
}},
Peers: []*authenticationv1alpha1api.PeerAuthenticationMethod{{
Params: &authenticationv1alpha1api.PeerAuthenticationMethod_Mtls{
Expand Down