forked from brancz/kube-rbac-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
opts: enforce loopback (or mTLS) for H2C/id header
h2c must happen on a loopback connection as the connection is not using TLS at all. identity headers must use a loopback connection or a mTLS conection is required. Trust in both directions is important. kube-rbac-proxy needs to provide certs, such that upstream can verify the authenticity of the headers. upstream needs certs, such that we can be sure to not leak secrets.
- Loading branch information
Showing
37 changed files
with
1,108 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: kube-rbac-proxy | ||
namespace: default | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: kube-rbac-proxy | ||
template: | ||
metadata: | ||
labels: | ||
app: kube-rbac-proxy | ||
spec: | ||
serviceAccountName: kube-rbac-proxy | ||
containers: | ||
- name: kube-rbac-proxy | ||
image: quay.io/brancz/kube-rbac-proxy:local | ||
args: | ||
- "--secure-port=8443" | ||
- "--upstream=http://http-echo-service.default.svc.cluster.local:80/" | ||
- "--authentication-skip-lookup" | ||
- "--upstream-force-h2c=true" | ||
- "--logtostderr=true" | ||
- "--v=10" | ||
ports: | ||
- containerPort: 8443 | ||
name: https | ||
- name: prometheus-example-app | ||
image: quay.io/brancz/prometheus-example-app:v0.4.0 | ||
args: | ||
- "--bind=127.0.0.1:8081" | ||
- "--h2c=true" | ||
|
36 changes: 36 additions & 0 deletions
36
test/e2e/h2c-upstream/deployment-upstream-non-loopback.yaml
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,36 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: http-echo | ||
labels: | ||
app: http-echo | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: http-echo | ||
template: | ||
metadata: | ||
labels: | ||
app: http-echo | ||
spec: | ||
containers: | ||
- name: http-echo | ||
image: mendhak/http-https-echo | ||
env: | ||
- name: HTTP_PORT | ||
value: 8080 | ||
ports: | ||
- containerPort: 8080 | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: http-echo-service | ||
spec: | ||
ports: | ||
- port: 80 | ||
targetPort: 8080 | ||
selector: | ||
app: http-echo | ||
|
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,133 @@ | ||
/* | ||
Copyright 2024 the kube-rbac-proxy maintainers. All rights reserved. | ||
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 e2e | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/brancz/kube-rbac-proxy/test/kubetest" | ||
"k8s.io/client-go/kubernetes" | ||
) | ||
|
||
func testIdentityHeaders(client kubernetes.Interface) kubetest.TestSuite { | ||
return func(t *testing.T) { | ||
command := `curl --connect-timeout 5 -v -s -k --fail -H "Authorization: Bearer $(cat /var/run/secrets/kubernetes.io/serviceaccount/token)" https://kube-rbac-proxy.default.svc.cluster.local:8443/metrics` | ||
|
||
kubetest.Scenario{ | ||
Name: "With x-remote-user", | ||
Description: ` | ||
Verifies that remote user is set to the service account, when | ||
upstreama is listening on loopback through a HTTP connection. | ||
`, | ||
|
||
Given: kubetest.Actions( | ||
kubetest.CreatedManifests( | ||
client, | ||
"identityheaders/default/clusterRole-client.yaml", | ||
"identityheaders/default/clusterRole.yaml", | ||
"identityheaders/default/clusterRoleBinding-client.yaml", | ||
"identityheaders/default/clusterRoleBinding.yaml", | ||
"identityheaders/default/configmap-nginx.yaml", | ||
"identityheaders/default/deployment.yaml", | ||
"identityheaders/default/service.yaml", | ||
"identityheaders/default/serviceAccount.yaml", | ||
), | ||
), | ||
When: kubetest.Actions( | ||
kubetest.PodsAreReady( | ||
client, | ||
1, | ||
"app=kube-rbac-proxy", | ||
), | ||
kubetest.ServiceIsReady( | ||
client, | ||
"kube-rbac-proxy", | ||
), | ||
), | ||
Then: kubetest.Actions( | ||
kubetest.ClientLogsContain( | ||
client, | ||
command, | ||
[]string{`< x-remote-user: system:serviceaccount:default:default`}, | ||
nil, | ||
), | ||
), | ||
}.Run(t) | ||
|
||
kubetest.Scenario{ | ||
Name: "With http on no loopback", | ||
Description: ` | ||
Verifies that the proxy is not able to connect to the remote upstream service, | ||
if upstream isn't offering TLS, when identity headers are being used. | ||
`, | ||
|
||
Given: kubetest.Actions( | ||
kubetest.CreatedManifests( | ||
client, | ||
"identityheaders/insecure/clusterRole-client.yaml", | ||
"identityheaders/insecure/clusterRole.yaml", | ||
"identityheaders/insecure/clusterRoleBinding-client.yaml", | ||
"identityheaders/insecure/clusterRoleBinding.yaml", | ||
"identityheaders/insecure/deployment-proxy.yaml", | ||
"identityheaders/insecure/deployment-upstream.yaml", | ||
"identityheaders/insecure/service-proxy.yaml", | ||
"identityheaders/insecure/service-upstream.yaml", | ||
"identityheaders/insecure/serviceAccount.yaml", | ||
), | ||
), | ||
Then: kubetest.Actions( | ||
kubetest.PodIsCrashLoopBackOff( | ||
client, | ||
"kube-rbac-proxy", | ||
), | ||
), | ||
}.Run(t) | ||
|
||
kubetest.Scenario{ | ||
Name: "With https on no loopback", | ||
Description: ` | ||
Verifies that the proxy is able to connect to the remote upstream service, | ||
through a mTLS connection, when providing identity headers. | ||
`, | ||
|
||
Given: kubetest.Actions( | ||
kubetest.CreateServerCerts(client, "nginx"), | ||
kubetest.CreateClientCerts(client, "kube-rbac-proxy-client"), | ||
kubetest.CreateServerCerts(client, "kube-rbac-proxy"), | ||
kubetest.CreatedManifests( | ||
client, | ||
"identityheaders/secure/clusterRole-client.yaml", | ||
"identityheaders/secure/clusterRole.yaml", | ||
"identityheaders/secure/clusterRoleBinding-client.yaml", | ||
"identityheaders/secure/clusterRoleBinding.yaml", | ||
"identityheaders/secure/configmap-nginx.yaml", | ||
"identityheaders/secure/deployment-proxy.yaml", | ||
"identityheaders/secure/deployment-upstream.yaml", | ||
"identityheaders/secure/service-proxy.yaml", | ||
"identityheaders/secure/service-upstream.yaml", | ||
"identityheaders/secure/serviceAccount.yaml", | ||
), | ||
), | ||
Then: kubetest.Actions( | ||
kubetest.ClientSucceeds( | ||
client, | ||
command, | ||
nil, | ||
), | ||
), | ||
}.Run(t) | ||
} | ||
} |
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,7 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
name: metrics | ||
rules: | ||
- nonResourceURLs: ["/metrics"] | ||
verbs: ["get"] |
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,14 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
name: kube-rbac-proxy | ||
namespace: default | ||
rules: | ||
- apiGroups: ["authentication.k8s.io"] | ||
resources: | ||
- tokenreviews | ||
verbs: ["create"] | ||
- apiGroups: ["authorization.k8s.io"] | ||
resources: | ||
- subjectaccessreviews | ||
verbs: ["create"] |
Oops, something went wrong.