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

Introduce authentication to the broker #308

Merged
merged 25 commits into from Aug 4, 2017
Merged

Introduce authentication to the broker #308

merged 25 commits into from Aug 4, 2017

Conversation

jmrodri
Copy link
Contributor

@jmrodri jmrodri commented Jul 27, 2017

Currently supports just basic auth but it's structured to allow extension for additional auth backends.

Copy link
Contributor

@shawn-hurley shawn-hurley left a comment

Choose a reason for hiding this comment

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

I really like the structure mostly style nits but one or two functional things that I would like to discuss

ft "github.com/openshift/ansible-service-broker/pkg/fusortest"
)

func TestCreateConfig(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 🎆

pkg/auth/auth.go Outdated
return &fusa, nil
}

func (d *FileUserServiceAdapter) buildDb() error {
Copy link
Contributor

Choose a reason for hiding this comment

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

buildDB() - because Db is an acronym, it should be all uppercase or lowercase.

pkg/auth/auth.go Outdated
// userdb is probably overkill, but if we ever want to allow multiple users,
// it'll come in handy.
d.userdb = make(map[string]User)
unamestr := string(username)
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 just cast to string in struct literal? you are for password so would just like to match style IMO.

pkg/auth/auth.go Outdated

// FindByLogin - given a login name, this will return the associated User or an
// error
func (d FileUserServiceAdapter) FindByLogin(login string) (User, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be unexported?

pkg/auth/auth.go Outdated
// our backend storage. Returns fals otherwise.
func (d FileUserServiceAdapter) ValidateUser(username string, password string) bool {
user, err := d.FindByLogin(username)
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we log the error here, the user not found error above will be lost and not printed out. Could make it hard to debug.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably, I don't have the log in these structs so I removed the fmt I had. Definitely will log though. Thanks.

pkg/auth/auth.go Outdated
// Handler - does the authentication for the routes
func Handler(h http.Handler, providers []Provider) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// TODO: loop through the providers
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove todos?

fmt.Println(err.Error())
}
userpass := strings.Split(string(decodedheader), ":")
username = userpass[0]
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we check this if I pass hearder Authorization Basic I think this will panic. just thinking out loud

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I tried quite a few things in tests, all are Authorization Basic with different encoded values:

  1. just the username "admin"
  2. just the password ":password"
  3. empty string

all are handled correctly no panic on this line. strings.Split always returns a slice of at least one item even if that item is empty string.

@@ -84,6 +85,7 @@ func (h handler) bootstrap(w http.ResponseWriter, r *http.Request, params map[st
}

func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
fmt.Println("entered handler.ServeHTTP")
Copy link
Contributor

Choose a reason for hiding this comment

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

debug statement

@rthallisey
Copy link
Contributor

@jmrodri Can you try rebasing to see if it makes travis happier?

@jmrodri jmrodri force-pushed the authimpl branch 2 times, most recently from 9522f0c to 16484df Compare August 2, 2017 21:17
@jmrodri
Copy link
Contributor Author

jmrodri commented Aug 3, 2017

@shawn-hurley authHandler now returns json.

$ curl -k -X GET -u admin:admin https://asb-1338-ansible-service-broker.172.17.0.1.nip.io/v2/catalog
{
  "description": "invalid credentials"
}

@jmrodri
Copy link
Contributor Author

jmrodri commented Aug 3, 2017

TEST

First build a new broker image for testing. NOTE: make run won't work. There's a trello card and an issue for it.

  1. checkout branch
git checkout authimpl
  1. build broker
make build
  1. build image
make build-image ORG=jmrodri TAG=authimpl
  1. push image
docker push docker.io/jmrodri/ansible-service-broker:authimpl

Next, using the authimpl branch of catasb: fusor/catasb#105 this PR contains the broker configuration secret when creating the broker instance on the service-catalog.

  1. Configure catasb to read the deployment template FROM YOUR LOCAL BROKER REPO
    change asb_template_url in ansible/group_vars/all.yml b/ansible/group_vars/all.yml
-asb_template_url: https://raw.githubusercontent.com/openshift/ansible-service-broker/master/templates/deploy-ansible-service-broker.template.yaml
+asb_template_url: file:///home/jesusr/dev/src/github.com/openshift/ansible-service-broker/templates/deploy-ansible-service-broker.template.yaml
  1. Configure catasb to use YOUR newly built docker images from step 4 above. Set broker_tag to authimpl and set broker_image_name to docker.io/jmrodri/ansible-service-broker. Be sure to use the appropriate values you used when building your own images.
-broker_tag: "latest"
+broker_tag: "authimpl"
 
-broker_image_name: docker.io/ansibleplaybookbundle/ansible-service-broker
+broker_image_name: docker.io/jmrodri/ansible-service-broker
  1. Run catasb stock or with coalmine enabled.
  2. Things should startup normally. To verify auth is being used look at the asb logs for some debug logs:
^[[36m[2017-08-02T18:11:29.42Z] [DEBUG] user found, returning true^[[0m
^[[36m[2017-08-02T18:11:29.42Z] [DEBUG] We found one. HOORAY!^[[0m

@jmrodri
Copy link
Contributor Author

jmrodri commented Aug 3, 2017

TROUBLESHOOTING

If you see no route to host in the controller-manager logs when talking to the broker, check your firewall!

@jmrodri jmrodri changed the title [WIP] Introduce authentication to the broker Introduce authentication to the broker Aug 3, 2017
@jmrodri jmrodri requested a review from rthallisey August 3, 2017 04:55
name: asb-auth-secret
namespace: ansible-service-broker
data:
username: YnJva2VyLWFkbWlu
Copy link
Member

Choose a reason for hiding this comment

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

Let's introduce 2 params for the auth username/password in the parameters section

BASIC_AUTH_USER_NAME=YnJva2VyLWFkbWlu
BASIC_AUTH_USER_PASSWORD=TFl0SU5lc0hBZw==

Then refer to them here so it's easier to adjust the username/password on deploying.

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.

Let's add params for the basic auth username/password to the template.

Copy link
Contributor

@rthallisey rthallisey left a comment

Choose a reason for hiding this comment

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


// GetType - returns the type of Principal. This is a user principal.
func (u User) GetType() string {
return "user"
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be const variable instead?


// FileUserServiceAdapter - a file based UserServiceAdapter which seeds its
// users from a file.
type FileUserServiceAdapter struct {
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 the structs at the top of the file or add them all to a type.go?

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 prefer to keep the methods of the struct near the struct definition. What I did do was move the NewFileUser ctor method further down so that the structs methods are below the struct.

@shawn-hurley
Copy link
Contributor

ACK

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.

Looks good! I like the interfaces and tests. One update would be the template params @jwmatthews mentioned.

auth:
- type: basic
enabled: true
- type: oauth
Copy link
Contributor

Choose a reason for hiding this comment

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

Spoke with @jmrodri, comment out or delete, up to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

deleted the oauth lines.

pkg/auth/auth.go Outdated
)

// ConfigEntry - Configuration for authentication
type ConfigEntry struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Think the other packages take the pattern of naming this Config for each section, so it's referenced as Config within the package, and auth.Config outside.

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 was conflicted about this because it is a list of auth definitions.

auth:
  - type: basic
    enabled: true
  - type: oauth
    enabled: true
  - type: cert
    enabled: true

So each type is a config entry. I guess we could say it's an array of auth.Config.

@jmrodri
Copy link
Contributor Author

jmrodri commented Aug 4, 2017

@jwmatthews variables added to template.

@jmrodri
Copy link
Contributor Author

jmrodri commented Aug 4, 2017

@rthallisey CI build fixed. I was missing the secret but while I copied that in I put in the wrong broker url I had asb-1337... instead of asb-1338... We're green now!

@jmrodri
Copy link
Contributor Author

jmrodri commented Aug 4, 2017

@eriknelson retest please.

// an error
func (d FileUserServiceAdapter) FindByLogin(login string) (User, error) {

// TODO: add some error checking
Copy link
Contributor

Choose a reason for hiding this comment

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

Did we make a card for this?

@eriknelson
Copy link
Contributor

@jmrodri All my tests passed. Started up catasb, saw authenticated catalog requests coming from the service-catalog. Checked curl without auth fails, checked curl with bad credentials fails, checked curl with correct credentials succeeds, and verified I could disable auth editing the config value.

Think this is ready to merge unless anyone objects.

@eriknelson
Copy link
Contributor

Merging since complaints have been addressed, CI is working, and a bunch of people have tested this back to front.

@eriknelson eriknelson merged commit fdbf722 into master Aug 4, 2017
@eriknelson eriknelson deleted the authimpl branch August 4, 2017 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants