Skip to content

Commit 675506a

Browse files
Merge pull request #188 from stlaz/rebase_1.19
Bug 1873043: kube 1.19.2 rebase
2 parents ae292c5 + 8a2f884 commit 675506a

File tree

1,329 files changed

+161626
-118157
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,329 files changed

+161626
-118157
lines changed

go.mod

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
module github.com/openshift/oauth-proxy
22

3-
go 1.13
3+
go 1.15
44

55
require (
66
github.com/18F/hmacauth v0.0.0-20151013130326-9232a6386b73
77
github.com/BurntSushi/toml v0.3.1
88
github.com/bitly/go-simplejson v0.5.1-0.20170206154632-da1a8928f709
99
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869
10-
github.com/fsnotify/fsnotify v1.4.7
11-
github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7 // indirect
12-
github.com/mreiferson/go-options v0.0.0-20161229190002-77551d20752b
13-
github.com/openshift/library-go v0.0.0-20190731063920-9fac0f4cee90
10+
github.com/fsnotify/fsnotify v1.4.9
11+
github.com/mreiferson/go-options v1.0.0
12+
github.com/openshift/library-go v0.0.0-20200918101923-1e4c94603efe
1413
github.com/yhat/wsutil v0.0.0-20170731153501-1d66fa95c997
15-
golang.org/x/net v0.0.0-20191004110552-13f9640d40b9
16-
golang.org/x/text v0.3.3 // indirect
17-
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
18-
k8s.io/api v0.17.0
19-
k8s.io/apimachinery v0.17.0
20-
k8s.io/apiserver v0.17.0
21-
k8s.io/client-go v0.17.0
14+
golang.org/x/net v0.0.0-20200904194848-62affa334b73
15+
k8s.io/api v0.19.2
16+
k8s.io/apimachinery v0.19.2
17+
k8s.io/apiserver v0.19.2
18+
k8s.io/client-go v0.19.2
2219
)
20+
21+
replace vbom.ml/util => github.com/fvbommel/util v0.0.0-20180919145318-efcd4e0f9787

go.sum

+434-17
Large diffs are not rendered by default.

main.go

+15-15
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ func main() {
2121
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
2222
flagSet := flag.NewFlagSet("oauth2_proxy", flag.ExitOnError)
2323

24-
emailDomains := StringArray{}
25-
upstreams := StringArray{}
26-
skipAuthRegex := StringArray{}
27-
bypassAuthRegex := StringArray{}
28-
bypassAuthExceptRegex := StringArray{}
29-
openshiftCAs := StringArray{}
24+
emailDomains := NewStringArray()
25+
upstreams := NewStringArray()
26+
skipAuthRegex := NewStringArray()
27+
bypassAuthRegex := NewStringArray()
28+
bypassAuthExceptRegex := NewStringArray()
29+
openshiftCAs := NewStringArray()
3030
clientCA := ""
31-
upstreamCAs := StringArray{}
31+
upstreamCAs := NewStringArray()
3232

3333
config := flagSet.String("config", "", "path to config file")
3434
showVersion := flagSet.Bool("version", false, "print version string")
@@ -41,22 +41,22 @@ func main() {
4141
flagSet.StringVar(&clientCA, "tls-client-ca", clientCA, "path to a CA file for admitting client certificates.")
4242
flagSet.String("redirect-url", "", "the OAuth Redirect URL. ie: \"https://internalapp.yourcompany.com/oauth/callback\"")
4343
flagSet.Bool("set-xauthrequest", false, "set X-Auth-Request-User and X-Auth-Request-Email response headers (useful in Nginx auth_request mode)")
44-
flagSet.Var(&upstreams, "upstream", "the http url(s) of the upstream endpoint or file:// paths for static files. Routing is based on the path")
44+
flagSet.Var(upstreams, "upstream", "the http url(s) of the upstream endpoint or file:// paths for static files. Routing is based on the path")
4545
flagSet.Bool("pass-basic-auth", true, "pass HTTP Basic Auth, X-Forwarded-User and X-Forwarded-Email information to upstream")
4646
flagSet.Bool("pass-user-headers", true, "pass X-Forwarded-User and X-Forwarded-Email information to upstream")
4747
flagSet.String("basic-auth-password", "", "the password to set when passing the HTTP Basic Auth header")
4848
flagSet.Bool("pass-access-token", false, "pass OAuth access_token to upstream via X-Forwarded-Access-Token header")
4949
flagSet.Bool("pass-user-bearer-token", false, "pass OAuth access token received from the client to upstream via X-Forwarded-Access-Token header")
5050
flagSet.Bool("pass-host-header", true, "pass the request Host Header to upstream")
51-
flagSet.Var(&bypassAuthExceptRegex, "bypass-auth-except-for", "provide authentication ONLY for request paths under proxy-prefix and those that match the given regex (may be given multiple times). Cannot be set with -skip-auth-regex/-bypass-auth-for")
52-
flagSet.Var(&bypassAuthRegex, "bypass-auth-for", "alias for skip-auth-regex")
53-
flagSet.Var(&skipAuthRegex, "skip-auth-regex", "bypass authentication for request paths that match (may be given multiple times). Cannot be set with -bypass-auth-except-for. Alias for -bypass-auth-for")
51+
flagSet.Var(bypassAuthExceptRegex, "bypass-auth-except-for", "provide authentication ONLY for request paths under proxy-prefix and those that match the given regex (may be given multiple times). Cannot be set with -skip-auth-regex/-bypass-auth-for")
52+
flagSet.Var(bypassAuthRegex, "bypass-auth-for", "alias for skip-auth-regex")
53+
flagSet.Var(skipAuthRegex, "skip-auth-regex", "bypass authentication for request paths that match (may be given multiple times). Cannot be set with -bypass-auth-except-for. Alias for -bypass-auth-for")
5454
flagSet.Bool("skip-provider-button", false, "will skip sign-in-page to directly reach the next step: oauth/start")
5555
flagSet.Bool("skip-auth-preflight", false, "will skip authentication for OPTIONS requests")
5656
flagSet.Bool("ssl-insecure-skip-verify", false, "skip validation of certificates presented when using HTTPS")
5757
flagSet.String("debug-address", "", "[http://]<addr>:<port> or unix://<path> to listen on for debug and requests")
5858

59-
flagSet.Var(&emailDomains, "email-domain", "authenticate emails with the specified domain (may be given multiple times). Use * to authenticate any email")
59+
flagSet.Var(emailDomains, "email-domain", "authenticate emails with the specified domain (may be given multiple times). Use * to authenticate any email")
6060
flagSet.String("client-id", "", "the OAuth Client ID: ie: \"123456.apps.googleusercontent.com\"")
6161
flagSet.String("client-secret", "", "the OAuth Client Secret")
6262
flagSet.String("client-secret-file", "", "a file containing the client-secret")
@@ -71,7 +71,7 @@ func main() {
7171
flagSet.String("openshift-group", "", "restrict logins to members of this group (or groups, if encoded as a JSON array).")
7272
flagSet.String("openshift-sar", "", "require this encoded subject access review to authorize (may be a JSON list).")
7373
flagSet.String("openshift-sar-by-host", "", "require this encoded subject access review to authorize (must be a JSON array).")
74-
flagSet.Var(&openshiftCAs, "openshift-ca", "paths to CA roots for the OpenShift API (may be given multiple times, defaults to /var/run/secrets/kubernetes.io/serviceaccount/ca.crt).")
74+
flagSet.Var(openshiftCAs, "openshift-ca", "paths to CA roots for the OpenShift API (may be given multiple times, defaults to /var/run/secrets/kubernetes.io/serviceaccount/ca.crt).")
7575
flagSet.String("openshift-review-url", "", "Permission check endpoint (defaults to the subject access review endpoint)")
7676
flagSet.String("openshift-delegate-urls", "", "If set, perform delegated authorization against the OpenShift API server. Value is a JSON map of path prefixes to v1beta1.ResourceAttribute records that must be granted to the user to continue. E.g. {\"/\":{\"resource\":\"pods\",\"namespace\":\"default\",\"name\":\"test\"}} only allows users who can see the pod test in namespace default.")
7777
flagSet.String("openshift-service-account", "", "An optional name of an OpenShift service account to act as. If set, the injected service account info will be used to determine the client ID and client secret.")
@@ -98,15 +98,15 @@ func main() {
9898
flagSet.String("approval-prompt", "force", "OAuth approval_prompt")
9999

100100
flagSet.String("signature-key", "", "GAP-Signature request signature key (algorithm:secretkey)")
101-
flagSet.Var(&upstreamCAs, "upstream-ca", "paths to CA roots for the Upstream (target) Server (may be given multiple times, defaults to system trust store).")
101+
flagSet.Var(upstreamCAs, "upstream-ca", "paths to CA roots for the Upstream (target) Server (may be given multiple times, defaults to system trust store).")
102102

103103
providerOpenShift := openshift.New()
104104
providerOpenShift.Bind(flagSet)
105105

106106
flagSet.Parse(os.Args[1:])
107107

108108
providerOpenShift.SetClientCAFile(clientCA)
109-
providerOpenShift.SetReviewCAs(openshiftCAs)
109+
providerOpenShift.SetReviewCAs(openshiftCAs.Get().([]string))
110110

111111
if *showVersion {
112112
fmt.Printf("oauth2_proxy v%s (built with %s)\n", VERSION, runtime.Version())

providers/openshift/provider.go

+16-12
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727

2828
authenticationv1 "k8s.io/api/authentication/v1"
2929
authorizationv1 "k8s.io/api/authorization/v1"
30+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3031
"k8s.io/apimachinery/pkg/util/wait"
3132
"k8s.io/apiserver/pkg/authentication/authenticator"
3233
"k8s.io/apiserver/pkg/authorization/authorizer"
@@ -319,11 +320,13 @@ func (p *OpenShiftProvider) Complete(data *providers.ProviderData, reviewURL *ur
319320
// check whether we have access to perform authentication review
320321
if authenticator.TokenAccessReviewClient != nil {
321322
wait.PollImmediate(2*time.Second, 10*time.Second, func() (bool, error) {
322-
_, err := authenticator.TokenAccessReviewClient.Create(&authenticationv1.TokenReview{
323-
Spec: authenticationv1.TokenReviewSpec{
324-
Token: "TEST",
323+
_, err := authenticator.TokenAccessReviewClient.Create(context.TODO(),
324+
&authenticationv1.TokenReview{
325+
Spec: authenticationv1.TokenReviewSpec{
326+
Token: "TEST",
327+
},
325328
},
326-
})
329+
metav1.CreateOptions{})
327330
if err != nil {
328331
log.Printf("unable to retrieve authentication information for tokens: %v", err)
329332
return false, nil
@@ -339,15 +342,16 @@ func (p *OpenShiftProvider) Complete(data *providers.ProviderData, reviewURL *ur
339342
// check whether we have access to perform authentication review
340343
if authorizer.SubjectAccessReviewClient != nil {
341344
wait.PollImmediate(2*time.Second, 10*time.Second, func() (bool, error) {
342-
_, err := authorizer.SubjectAccessReviewClient.Create(&authorizationv1.SubjectAccessReview{
343-
Spec: authorizationv1.SubjectAccessReviewSpec{
344-
User: "TEST",
345-
ResourceAttributes: &authorizationv1.ResourceAttributes{
346-
Resource: "TEST",
347-
Verb: "TEST",
345+
_, err := authorizer.SubjectAccessReviewClient.Create(context.TODO(),
346+
&authorizationv1.SubjectAccessReview{
347+
Spec: authorizationv1.SubjectAccessReviewSpec{
348+
User: "TEST",
349+
ResourceAttributes: &authorizationv1.ResourceAttributes{
350+
Resource: "TEST",
351+
Verb: "TEST",
352+
},
348353
},
349-
},
350-
})
354+
}, metav1.CreateOptions{})
351355
if err != nil {
352356
log.Printf("unable to retrieve authorization information for users: %v", err)
353357
return false, nil

string_array.go

+20-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
11
package main
22

33
import (
4+
"flag"
45
"strings"
56
)
67

7-
type StringArray []string
8+
var _ flag.Getter = StringArray{}
89

9-
func (a *StringArray) Set(s string) error {
10-
*a = append(*a, s)
10+
type StringArray struct {
11+
stringArray *[]string
12+
}
13+
14+
func NewStringArray() *StringArray {
15+
return &StringArray{
16+
stringArray: &[]string{},
17+
}
18+
}
19+
20+
func (a StringArray) Get() interface{} {
21+
return *a.stringArray
22+
}
23+
24+
func (a StringArray) Set(s string) error {
25+
*a.stringArray = append(*a.stringArray, s)
1126
return nil
1227
}
1328

14-
func (a *StringArray) String() string {
15-
return strings.Join(*a, ",")
29+
func (a StringArray) String() string {
30+
return strings.Join(*a.stringArray, ",")
1631
}

string_array_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ package main
22

33
import (
44
"testing"
5+
56
"github.com/bmizerany/assert"
67
)
78

89
func TestStringArray(t *testing.T) {
9-
sa := StringArray{}
10+
sa := NewStringArray()
1011
assert.Equal(t, "", sa.String())
1112
err := sa.Set("foo")
1213
if err != nil {
@@ -18,4 +19,4 @@ func TestStringArray(t *testing.T) {
1819
t.Errorf("unexpected error %v", err)
1920
}
2021
assert.Equal(t, "foo,bar", sa.String())
21-
}
22+
}

test/e2e/proxy_test.go

+12-9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package e2e
22

33
import (
44
"bytes"
5+
"context"
56
"crypto/tls"
67
"crypto/x509"
78
"fmt"
@@ -21,6 +22,8 @@ import (
2122
)
2223

2324
func TestOAuthProxyE2E(t *testing.T) {
25+
testCtx := context.Background()
26+
2427
ns := os.Getenv("TEST_NAMESPACE")
2528
oauthProxyTests := map[string]struct {
2629
oauthProxyArgs []string
@@ -305,7 +308,7 @@ func TestOAuthProxyE2E(t *testing.T) {
305308
continue
306309
}
307310
t.Run(fmt.Sprintf("setting up e2e tests %s", tcName), func(t *testing.T) {
308-
_, err := kubeClientSet.CoreV1().ServiceAccounts(ns).Create(newOAuthProxySA())
311+
_, err := kubeClientSet.CoreV1().ServiceAccounts(ns).Create(testCtx, newOAuthProxySA(), metav1.CreateOptions{})
309312
if err != nil {
310313
t.Fatalf("setup: error creating SA: %s", err)
311314
}
@@ -333,18 +336,18 @@ func TestOAuthProxyE2E(t *testing.T) {
333336
t.Fatalf("setup: error creating upstream TLS certs: %s", err)
334337
}
335338

336-
_, err = kubeClientSet.CoreV1().Services(ns).Create(newOAuthProxyService())
339+
_, err = kubeClientSet.CoreV1().Services(ns).Create(testCtx, newOAuthProxyService(), metav1.CreateOptions{})
337340
if err != nil {
338341
t.Fatalf("setup: error creating service: %s", err)
339342
}
340343

341344
// configMap provides oauth-proxy with the certificates we created above
342-
_, err = kubeClientSet.CoreV1().ConfigMaps(ns).Create(newOAuthProxyConfigMap(ns, caPem, serviceCert, serviceKey, upstreamCA, upstreamCert, upstreamKey))
345+
_, err = kubeClientSet.CoreV1().ConfigMaps(ns).Create(testCtx, newOAuthProxyConfigMap(ns, caPem, serviceCert, serviceKey, upstreamCA, upstreamCert, upstreamKey), metav1.CreateOptions{})
343346
if err != nil {
344347
t.Fatalf("setup: error creating certificate configMap: %s", err)
345348
}
346349

347-
oauthProxyPod, err := kubeClientSet.CoreV1().Pods(ns).Create(newOAuthProxyPod(image, backendImage, tc.oauthProxyArgs, tc.backendEnvs))
350+
oauthProxyPod, err := kubeClientSet.CoreV1().Pods(ns).Create(testCtx, newOAuthProxyPod(image, backendImage, tc.oauthProxyArgs, tc.backendEnvs), metav1.CreateOptions{})
348351
if err != nil {
349352
t.Fatalf("setup: error creating oauth-proxy pod with image '%s' and args '%v': %s", image, tc.oauthProxyArgs, err)
350353
}
@@ -355,7 +358,7 @@ func TestOAuthProxyE2E(t *testing.T) {
355358
}
356359

357360
// Find the service CA for the client trust store
358-
secrets, err := kubeClientSet.CoreV1().Secrets(ns).List(metav1.ListOptions{})
361+
secrets, err := kubeClientSet.CoreV1().Secrets(ns).List(testCtx, metav1.ListOptions{})
359362
if err != nil {
360363
t.Fatalf("setup: error listing secrets: %s", err)
361364
}
@@ -393,11 +396,11 @@ func TestOAuthProxyE2E(t *testing.T) {
393396
t.Fatalf("skipping cleanup step for test '%s' and stopping on command", tcName)
394397
}
395398
t.Logf("cleaning up test %s", tcName)
396-
kubeClientSet.CoreV1().Pods(ns).Delete("proxy", nil)
397-
kubeClientSet.CoreV1().Services(ns).Delete("proxy", nil)
399+
kubeClientSet.CoreV1().Pods(ns).Delete(testCtx, "proxy", metav1.DeleteOptions{})
400+
kubeClientSet.CoreV1().Services(ns).Delete(testCtx, "proxy", metav1.DeleteOptions{})
398401
deleteTestRoute("proxy-route", ns)
399-
kubeClientSet.CoreV1().ConfigMaps(ns).Delete("proxy-certs", nil)
400-
kubeClientSet.CoreV1().ServiceAccounts(ns).Delete("proxy", nil)
402+
kubeClientSet.CoreV1().ConfigMaps(ns).Delete(testCtx, "proxy-certs", metav1.DeleteOptions{})
403+
kubeClientSet.CoreV1().ServiceAccounts(ns).Delete(testCtx, "proxy", metav1.DeleteOptions{})
401404
waitForPodDeletion(kubeClientSet, oauthProxyPod.Name, ns)
402405
execCmd("oc", []string{"adm", "policy", "remove-role-from-user", "admin", user, "-n", ns}, "")
403406
}()

test/e2e/util.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package e2e
33
import (
44
"bufio"
55
"bytes"
6+
"context"
67
"crypto/rand"
78
"crypto/rsa"
89
"crypto/tls"
@@ -22,12 +23,12 @@ import (
2223

2324
"golang.org/x/net/html"
2425

26+
corev1 "k8s.io/api/core/v1"
2527
"k8s.io/apimachinery/pkg/api/errors"
2628
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2729
"k8s.io/apimachinery/pkg/util/intstr"
2830
"k8s.io/apimachinery/pkg/util/wait"
2931
"k8s.io/client-go/kubernetes"
30-
corev1 "k8s.io/api/core/v1"
3132
"k8s.io/client-go/rest"
3233
"k8s.io/client-go/tools/clientcmd"
3334
"k8s.io/client-go/tools/clientcmd/api"
@@ -101,7 +102,7 @@ func waitForHealthzCheck(cas [][]byte, url string) error {
101102

102103
func podDeleted(c kubernetes.Interface, podName, namespace string) wait.ConditionFunc {
103104
return func() (bool, error) {
104-
_, err := c.CoreV1().Pods(namespace).Get(podName, metav1.GetOptions{})
105+
_, err := c.CoreV1().Pods(namespace).Get(context.Background(), podName, metav1.GetOptions{})
105106
if err != nil {
106107
if errors.IsNotFound(err) {
107108
return true, nil
@@ -114,7 +115,7 @@ func podDeleted(c kubernetes.Interface, podName, namespace string) wait.Conditio
114115

115116
func podRunning(c kubernetes.Interface, podName, namespace string) wait.ConditionFunc {
116117
return func() (bool, error) {
117-
pod, err := c.CoreV1().Pods(namespace).Get(podName, metav1.GetOptions{})
118+
pod, err := c.CoreV1().Pods(namespace).Get(context.Background(), podName, metav1.GetOptions{})
118119
if err != nil {
119120
return false, err
120121
}

vendor/github.com/cespare/xxhash/v2/.travis.yml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/cespare/xxhash/v2/LICENSE.txt

+22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)