Skip to content
This repository has been archived by the owner on May 6, 2022. It is now read-only.

Converting the AuthSecret field to a union AuthInfo type #877

Merged
merged 4 commits into from
Jun 7, 2017

Conversation

arschles
Copy link
Contributor

@arschles arschles commented May 18, 2017

This change will enable operators to chose different auth schemes for brokers, as the OSB API spec begins to support more in the future.

Fixes #864

@arschles arschles added this to the 0.1.0 milestone May 18, 2017
@arschles arschles requested review from pmorie, krancour and vaikas May 18, 2017 23:00
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 18, 2017
Copy link
Contributor

@pmorie pmorie left a comment

Choose a reason for hiding this comment

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

Looks like what I described in the issue - the validations have to move, of course, and there should be a new validation that if you supply auth info that you supply basic auth (which we will relax as we add other types to AuthInfo).

type BrokerAuthInfo struct {
// BasicAuthSecret is a reference to a Secret containing auth information the
// catalog should use to authenticate to this Broker using basic auth.
BasicAuthSecret *v1.ObjectReference
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the assumption that we know which one is being used because all others will be nil ?
If so, does that require a loop (or set of if-statements) to find the right one? Could we instead just make AuthInfo in the previous struct a pointer to an Object and dynamically find its type at runtime?

Copy link
Contributor

Choose a reason for hiding this comment

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

@duglin

Is the assumption that we know which one is being used because all others will be nil ?

Yes, the generic assertion is that if you provide a union type, you must provide one and only one field of that type. Since we only have basic auth right now, that collapses into 'you must provide basic auth'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@duglin in addition to what @pmorie said, only one will be set at once (as the comment above says), so only one will be non-nil at once

@arschles arschles self-assigned this May 19, 2017
allErrs = append(allErrs, field.Invalid(fldPath.Child("authSecret", "namespace"), spec.AuthSecret.Namespace, msg))
// TODO: when we start supporting additional auth schemes, this code will have to accommodate
// the new schemes
basicAuthSecret := spec.AuthInfo.BasicAuthSecret
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not nil-safe

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good call, I'll add an error if basicAuthSecret == nil

AuthSecret: &v1.ObjectReference{
Namespace: "test-ns",
Name: "test-secret",
AuthInfo: servicecatalog.BrokerAuthInfo{
Copy link
Contributor

Choose a reason for hiding this comment

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

Needs a test case for AuthInfo not nil but empty

Copy link
Contributor Author

Choose a reason for hiding this comment

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

note that AuthInfo cannot be nil because it's not a pointer. BasicAuthInfo inside of AuthInfo can be nil, though, and that needs a test.

if broker.Spec.AuthSecret == nil {
// TODO: when we start supporting additional auth schemes, this code will have to accommodate
// the new schemes
basicAuthSecret := broker.Spec.AuthInfo.BasicAuthSecret
Copy link
Contributor

Choose a reason for hiding this comment

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

also not nil-safe

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is nil-safe because AuthInfo is a BrokerAuthInfo, not a *BrokerAuthInfo, and there's a check for a nil basic auth secret (which is a *v1.ObjectReference)

@arschles
Copy link
Contributor Author

@pmorie comments addressed and changes made where appropriate. PTAL

@arschles arschles modified the milestones: 0.8.0, 0.1.0 May 22, 2017
@krancour krancour added the LGTM1 label May 23, 2017
@vaikas vaikas added the LGTM2 label May 23, 2017
@vaikas
Copy link
Contributor

vaikas commented May 24, 2017

Looks like the integration test failure is for realsies:
[Build & Unit/Integration Tests] I0523 21:04:01.468765 3764 round_trippers.go:398] curl -k -v -XGET -H "Accept: application/json, /" -H "User-Agent: integration.test/v0.0.0 (linux/amd64) kubernetes/$Format" http://localhost:23533/apis/servicecatalog.k8s.io/v1alpha1/serviceclasses?resourceVersion=0
[Build & Unit/Integration Tests] I0523 21:04:01.469412 3764 request.go:991] Response Body: {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"Broker.servicecatalog.k8s.io "test-broker" is invalid: spec.authInfo.basicAuthSecret: Required value: a basic auth secret is required","reason":"Invalid","details":{"name":"test-broker","group":"servicecatalog.k8s.io","kind":"Broker","causes":[{"reason":"FieldValueRequired","message":"Required value: a basic auth secret is required","field":"spec.authInfo.basicAuthSecret"}]},"code":422}
[Build & Unit/Integration Tests] --- FAIL: TestBasicFlows (5.07s)
[Build & Unit/Integration Tests] controller_test.go:267: controller start
[Build & Unit/Integration Tests] controller_test.go:275: informers start
[Build & Unit/Integration Tests] controller_test.go:104: error creating the broker &{{"" ""} {"test-broker" "" "" "" "" "" '\x00' "0001-01-01 00:00:00 +0000 UTC" %!q(*int64=) map[] map[] [] [] ""} {"https://example.com" {"nil"}} {[]}} ("Broker.servicecatalog.k8s.io "test-broker" is invalid: spec.authInfo.basicAuthSecret: Required value: a basic auth secret is required")
[Build & Unit/Integration Tests] framework.go:61: Shutting down server on ports: 23533 and 16738
[Build & Unit/Integration Tests] FAIL
[Build & Unit/Integration Tests] exit status 1
[Build & Unit/Integration Tests] FAIL github.com/kubernetes-incubator/s

@vaikas vaikas modified the milestones: 0.8.0, 0.1.0 May 24, 2017
Copy link
Contributor

@pmorie pmorie left a comment

Choose a reason for hiding this comment

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

LGTM; just a couple little nits (sorry), and needs rebase.

// catalog should use to authenticate to this Broker.
AuthSecret *v1.ObjectReference
// AuthInfo contains the data that the service catalog should use to authenticate
// with the Broker
Copy link
Contributor

Choose a reason for hiding this comment

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

missing period

// catalog should use to authenticate to this Broker.
AuthSecret *v1.ObjectReference `json:"authSecret,omitempty"`
// AuthInfo contains the data that the service catalog should use to authenticate
// with the Broker
Copy link
Contributor

Choose a reason for hiding this comment

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

missing period

@@ -32,6 +32,8 @@ func TestValidateBroker(t *testing.T) {
valid bool
}{
{
// covers the case where there is no AuthInfo field specified. the validator should
// ignore the field and still succeed the validation
name: "valid broker - no auth secret",
Copy link
Contributor

Choose a reason for hiding this comment

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

not a feedback on your PR, but I have had a lot of luck with a method that returns a valid resource, and then subtracting / mutating things to create objects for invalid scenarios.

This change will enable operators to chose different auth schemes for
brokers, as the OSB API spec begins to support more in the future.

Fixes kubernetes-retired#864
@pmorie pmorie added the LGTM3 label Jun 7, 2017
@pmorie
Copy link
Contributor

pmorie commented Jun 7, 2017

LGTM

@pmorie pmorie merged commit 066159d into kubernetes-retired:master Jun 7, 2017
@arschles arschles deleted the auth-info branch June 7, 2017 20:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. LGTM1 LGTM2 LGTM3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants