Skip to content

Commit 04fa477

Browse files
nileboxpmorie
authored andcommitted
Implementation: Support for Bearer token auth between Service Catalog and brokers (#1053)
* Support for Bearer token auth between Service Catalog and brokers * Switching back to ObjectReference
1 parent 9e46d3c commit 04fa477

17 files changed

+1089
-94
lines changed

contrib/examples/apiserver/broker.yaml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ metadata:
44
name: test-broker
55
spec:
66
url: http://beefco.de
7-
# put the basic auth for the broker in a secret, and reference the secret here.
8-
# service-catalog will use the contents of the secret. The secret should have "username"
9-
# and "password" keys
7+
# Put the basic auth for the broker in a secret, and reference the secret here.
8+
# Service Catalog will use the contents of the secret. The secret should have "username"
9+
# and "password" keys.
10+
# Alternatively you can use bearer token auth for which the secret should have a
11+
# "token" key with bearer token.
1012
authInfo:
11-
basicAuthSecret:
12-
namespace: some-namespace
13-
name: secret-name
13+
basic:
14+
secretRef:
15+
namespace: some-namespace
16+
name: secret-name

pkg/apis/servicecatalog/checksum/checksum_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,11 @@ func TestBrokerSpecChecksum(t *testing.T) {
7070
spec := servicecatalog.BrokerSpec{
7171
URL: "https://kubernetes.default.svc:443/brokers/template.k8s.io",
7272
AuthInfo: &servicecatalog.BrokerAuthInfo{
73-
BasicAuthSecret: &v1.ObjectReference{
74-
Namespace: "test-ns",
75-
Name: "test-secret",
73+
Basic: &servicecatalog.BasicAuthConfig{
74+
SecretRef: &v1.ObjectReference{
75+
Namespace: "test-ns",
76+
Name: "test-secret",
77+
},
7678
},
7779
},
7880
}

pkg/apis/servicecatalog/types.go

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,51 @@ type BrokerSpec struct {
5656
// BrokerAuthInfo is a union type that contains information on one of the authentication methods
5757
// the the service catalog and brokers may support, according to the OpenServiceBroker API
5858
// specification (https://github.com/openservicebrokerapi/servicebroker/blob/master/spec.md).
59-
//
60-
// Note that we currently restrict a single broker to have only one of these fields
61-
// set on it.
6259
type BrokerAuthInfo struct {
60+
// Basic provides configuration for basic authentication.
61+
Basic *BasicAuthConfig
62+
// BearerTokenAuthConfig provides configuration to send an opaque value as a bearer token.
63+
// The value is referenced from the 'token' field of the given secret. This value should only
64+
// contain the token value and not the `Bearer` scheme.
65+
Bearer *BearerTokenAuthConfig
66+
67+
// DEPRECATED: use `Basic` field for configuring basic authentication instead.
6368
// BasicAuthSecret is a reference to a Secret containing auth information the
6469
// catalog should use to authenticate to this Broker using basic auth.
6570
BasicAuthSecret *v1.ObjectReference
6671
}
6772

73+
// BasicAuthConfig provides config for the basic authentication.
74+
type BasicAuthConfig struct {
75+
// SecretRef is a reference to a Secret containing information the
76+
// catalog should use to authenticate to this Broker.
77+
//
78+
// Required at least one of the fields:
79+
// - Secret.Data["username"] - username used for authentication
80+
// - Secret.Data["password"] - password or token needed for authentication
81+
SecretRef *v1.ObjectReference
82+
}
83+
84+
// BearerTokenAuthConfig provides config for the bearer token authentication.
85+
type BearerTokenAuthConfig struct {
86+
// SecretRef is a reference to a Secret containing information the
87+
// catalog should use to authenticate to this Broker.
88+
//
89+
// Required field:
90+
// - Secret.Data["token"] - bearer token for authentication
91+
SecretRef *v1.ObjectReference
92+
}
93+
94+
const (
95+
// BasicAuthUsernameKey is the key of the username for SecretTypeBasicAuth secrets
96+
BasicAuthUsernameKey = "username"
97+
// BasicAuthPasswordKey is the key of the password or token for SecretTypeBasicAuth secrets
98+
BasicAuthPasswordKey = "password"
99+
100+
// BearerTokenKey is the key of the bearer token for SecretTypeBearerTokenAuth secrets
101+
BearerTokenKey = "token"
102+
)
103+
68104
// BrokerStatus represents the current status of a Broker.
69105
type BrokerStatus struct {
70106
Conditions []BrokerCondition

0 commit comments

Comments
 (0)