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

Bearer Token Auth via kubernetes Apiserver #445

Merged
merged 14 commits into from Sep 26, 2017
Merged

Bearer Token Auth via kubernetes Apiserver #445

merged 14 commits into from Sep 26, 2017

Conversation

shawn-hurley
Copy link
Contributor

@shawn-hurley shawn-hurley commented Sep 20, 2017

Describe what this PR does and why we need it:
Sets up ASB with the apiserver kubernetes project.
Changes proposed in this pull request

  • Serve ASB via apiserver
  • Set up delegated auth using nonResoureceURLs to control access
  • Setting servicecatalog.ServiceBroker with bearer token auth from a secret generated for a service account
  • Will generate certs if no certs are given, therefore removing insecure argument.

Does this PR depend on another PR (Use this to track when PRs should be merged)
depends-on
fusor/catasb#142

Will neeed another PR for Documentation update.

@@ -24,7 +24,7 @@ import (
"errors"

logging "github.com/op/go-logging"
restclient "k8s.io/client-go/rest"
"k8s.io/client-go/rest"

Copy link
Contributor

Choose a reason for hiding this comment

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

can you move this down with the other k8s.io imports

h := handler{
router: *mux.NewRouter(),
broker: b,
log: log,
brokerConfig: brokerConfig,
}
s := h.router.PathPrefix(prefix).Subrouter()

// TODO: Reintroduce router restriction based on API version when settled upstream
Copy link
Contributor

Choose a reason for hiding this comment

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

This covers the TODO here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

can you explain?

Copy link
Contributor

Choose a reason for hiding this comment

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

I thought 104 covered this todo. But, I think I'm confusing a Headers and a pathprefix. They aren't related.

@@ -145,14 +145,14 @@ func init() {

func TestNewHandler(t *testing.T) {
testb := MockBroker{Name: "testbroker"}
testhandler := NewHandler(testb, log, brokerConfig)
testhandler := NewHandler(testb, log, brokerConfig, "")
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be worth adding a prefix to the test.


- apiVersion: servicecatalog.k8s.io/v1alpha1
kind: ${BROKER_KIND}
metadata:
name: ansible-service-broker
spec:
url: ${ASB_SCHEME}://asb-1338-ansible-service-broker.${ROUTING_SUFFIX}
url: https://asb.ansible-service-broker.svc:1338/ansible-service-broker/
Copy link
Contributor

Choose a reason for hiding this comment

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

This makes it a requirement to use https. I'm not against that, but then ASB_SCHEME should be removed.

Another way to do this is keep ASB_SCHEME and BROKER_AUTH in place but change BROKER_AUTH to:

value: '{ "bearer": { "secretRef": { "kind": "Secret", "namespace": "ansible-service-broker", "name": "ansible-service-broker" } } }'

Copy link
Contributor

Choose a reason for hiding this comment

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

You also aren't using BROKER_URL_PREFIX

"time"

kapierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Can you organize this so that imports with a name are together and those without a name are together.

kapierrors "k8s.io/apimachinery/pkg/api/errors"
kubeversiontypes "k8s.io/apimachinery/pkg/version"
...

"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/apimachinery/pkg/util/wait"
...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

go imports organize the imports like this I would prefer to continue to use go imports.

Does anyone else have any thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's the style we've been using. I don't mind changing it.

Copy link
Contributor

Choose a reason for hiding this comment

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

we could name them all and goimports will be fine. The problem with changing it is that @shawn-hurley and myself will flip it back when we save the file again. Not sure if there's a way to configure goimports. And I'd hate to stop using it since it does so much for me automatically.

pkg/app/app.go Outdated
clusterURL = a.config.Broker.ClusterURL
}
} else {
clusterURL = ClusterURLPreFix
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Can you change ClusterURLPreFix to something like DefaultClusterURLPrefix

pkg/app/app.go Outdated
genericserver.Handler.NonGoRestfulMux.HandlePrefix(fmt.Sprintf("%v/", clusterURL), daHandler)
a.log.Notice("Listening on https://%s", genericserver.SecureServingInfo.BindAddress)

a.log.Notice("Starting apiserver")
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 we note the Broker is started here? a.log.Notice("Ansible Service Broker Started")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I mean it does not actually start until the next line and could fail. I would prefer to make it a.log.Notice("Ansible Service Broker Starting")? is that agreeable?

pkg/app/app.go Outdated
err = genericserver.PrepareRun().Run(wait.NeverStop)
a.log.Errorf("unable to wait on run - %v", err)

//TODO: Add Flag so we can still use the old way of doing this.
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't this it's necessary to also support the old way.

@@ -30,7 +30,6 @@ import (
type Args struct {
ConfigFile string `short:"c" long:"config" description:"Config File" default:"/etc/ansible-service-broker/config.yaml"`
Version bool `short:"v" long:"version" description:"Print version information"`
Insecure bool `long:"insecure" description:"Run Ansible Service Broker in insecure mode."`
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 going to require a change in catasb.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have the branch in my repo and will be posting a PR soon.

@rthallisey
Copy link
Contributor

@shawn-hurley I'm going to mess around with this a little by hand and get back to you. I also want to make sure the gate passes on this which will require #446

Copy link
Contributor

@jmrodri jmrodri left a comment

Choose a reason for hiding this comment

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

I've seen most of this code. I'm not a fan of this whole apiserver idea. I find it annoying that in order to integrate with an apiserver that serves basically as a proxy that I have to change the architecture of my application.

This is how folks want it, then so be it. Approval from me of this PR is not an acceptance consider it a ACK under Protest.

@rthallisey
Copy link
Contributor

@jmrodri How close is your alternative to working? I'd like to evaluate both options.

@jwmatthews
Copy link
Member

@rthallisey it's been decided to go with Shawn's approach for delegated auth. This is what the project needs at this point in time.

We are not pursuing the alternative approach.

@jmrodri
Copy link
Contributor

jmrodri commented Sep 20, 2017

@rthallisey like @jwmatthews mentioned it's been decided for us. I've deleted the bearerauth branch I had going.

@jmrodri
Copy link
Contributor

jmrodri commented Sep 20, 2017

@shawn-hurley does basic auth still work? because that's what the current spec supports.

@shawn-hurley
Copy link
Contributor Author

shawn-hurley commented Sep 21, 2017

@jmrodri adding the ability that if basic auth if set, then we will use that instead of bearer token auth. This makes sense because if you set both authentication types on the ServiceBroker it will honor basic auth first.

I still think that our default should be bearer token auth.

@jwmatthews
Copy link
Member

I expect default workflow will want Bearer Token Auth as well

@enj
Copy link

enj commented Sep 22, 2017

LGTM

There are some followup items but this is in line with our discussions.

Copy link
Contributor

@eriknelson eriknelson left a comment

Choose a reason for hiding this comment

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

ACK. Not my preferred path forwards but it sounds like this is simply required. Well done @shawn-hurley, no nits from me from my rudimentary skim.

pkg/app/app.go Outdated
}
daHandler := handler.NewHandler(a.broker, a.log.Logger, a.config.Broker, clusterURL)

genericserver.Handler.NonGoRestfulMux.HandlePrefix(fmt.Sprintf("%v/", clusterURL), daHandler)
a.log.Notice("Listening on https://%s", genericserver.SecureServingInfo.BindAddress)

a.log.Notice("Starting apiserver")
a.log.Notice("Ansible Serivce Broker Starting")
Copy link
Contributor

Choose a reason for hiding this comment

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

TYPO: Serivce -> Service

@rthallisey
Copy link
Contributor

rthallisey commented Sep 25, 2017

Corresponding catasb change: fusor/catasb#142

Copy link
Member

@jwmatthews jwmatthews left a comment

Choose a reason for hiding this comment

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

ACK, before merging I'd like to coordinate with some demos that are planned for 9/26, worried about merging this in and causing breakage with the template change.

@shawn-hurley shawn-hurley merged commit f1a4158 into master Sep 26, 2017
dymurray pushed a commit to dymurray/ansible-service-broker that referenced this pull request Sep 27, 2017
* apiserver work

* updated glide yaml/lock

* update vendor to match the new glide values

* Create and return genericapiserver from ApiServer method

* more stupid changes
* broker runs but does not stay up.

* add natefinch dep

* getting genericapiserver working.

* making the initialization a little cleaner.

* No support for insecure.
* if no certs given will generate its own
* ignor the folder that the certs get generated too

* Working deploy template and apiserver

* addressing pr comments.

* Still trying to remove insecure broker code.

* Adding ability for basic auth to override the bearer token auth.

* template and catasb are still defaulting for bearer token auth.

* adding temporary template to be used for a couple of days

* fixing gate build for a couple of days

* Adding ability to serve at the root url

* getting gate build working

* fixing build. going back to a single deployment template
@jmrodri jmrodri deleted the apiserver branch October 19, 2017 01:31
jianzhangbjz pushed a commit to jianzhangbjz/ansible-service-broker that referenced this pull request May 17, 2018
* apiserver work

* updated glide yaml/lock

* update vendor to match the new glide values

* Create and return genericapiserver from ApiServer method

* more stupid changes
* broker runs but does not stay up.

* add natefinch dep

* getting genericapiserver working.

* making the initialization a little cleaner.

* No support for insecure.
* if no certs given will generate its own
* ignor the folder that the certs get generated too

* Working deploy template and apiserver

* addressing pr comments.

* Still trying to remove insecure broker code.

* Adding ability for basic auth to override the bearer token auth.

* template and catasb are still defaulting for bearer token auth.

* adding temporary template to be used for a couple of days

* fixing gate build for a couple of days

* Adding ability to serve at the root url

* getting gate build working

* fixing build. going back to a single deployment template
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants