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

Add support for Application ID auth pattern #58

Merged
merged 10 commits into from
Feb 14, 2019
Merged

Conversation

philipgough
Copy link
Contributor

@philipgough philipgough commented Feb 12, 2019

Moves to 1.1 codebase

Post review/approval

  • Docs update
  • Modify sample templates

TODO - Verification Steps

  • Test User Key headers and query params
  • Test User Key headers and query params individual
  • Test APP ID headers and query params
  • Test APP ID headers and query params individual
  • Test App Id with App Key
  • Test App Id without key

These overrides are required as a fix to workaround istio/istio#11226

dep: Migrate to latest revision of istio 1.1
@codecov-io
Copy link

codecov-io commented Feb 12, 2019

Codecov Report

Merging #58 into master will increase coverage by 1.14%.
The diff coverage is 93.18%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #58      +/-   ##
==========================================
+ Coverage   85.61%   86.75%   +1.14%     
==========================================
  Files           3        3              
  Lines         438      438              
==========================================
+ Hits          375      380       +5     
+ Misses         40       37       -3     
+ Partials       23       21       -2
Impacted Files Coverage Δ
pkg/threescale/threescale.go 84.35% <93.18%> (+2.79%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 630fa40...e83a665. Read the comment docs.

@philipgough philipgough mentioned this pull request Feb 12, 2019
Copy link
Contributor

@unleashed unleashed left a comment

Choose a reason for hiding this comment

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

Check comments - since we will be detecting the authn used, we want to be lenient about existing parameters (ie. ignoring them) and use a specific priority order.

Gopkg.toml Show resolved Hide resolved
user: request.query_params["user_key"] | request.headers["x-user-key"] | request.api_key | ""
properties:
app_id: request.query_params["app_id"] | request.headers["x-app-id"] | ""
app_key: request.query_params["app_key"] | request.headers["x-app-key"] | ""
Copy link
Contributor

Choose a reason for hiding this comment

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

we've been talking about this, but just to rule out this last thought of mine out of being a bit naive: setting here a property like query: request.query_params (the whole map) does not work, does it?

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 couldn't get that to work. Thats what I thought initially. Cant seem to have nested maps. I will try out some other stuff in the mean time but it wont be hard to go from this to a working alternative.

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 be interested in knowing whether these parameters are empty or they weren't specified, perhaps we can leave out the "" and test for nil?

Copy link
Contributor

Choose a reason for hiding this comment

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

(for a bit of context, there is in 3scale, under certain conditions, a semantic difference between specifying an empty app_key to the Service Management API and simply not specifying it at all)

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 don't think that's going to be achievable with the current client. The default string value in go is "".

When we create the params, even if we don't set it it will become empty string. I think would need to go ahead and use pointers to strings in the client to get this behaviour.

Happy to create an issue on it and fix, but my suggestion is leave this as is for now, wdyt?

testdata/threescale-adapter-config.yaml Outdated Show resolved Hide resolved
server *grpc.Server
client *http.Client
conf *AdapterConfig
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if it's more idiomatic to group these together in golang, I personally prefer to have the definition next to the implementation of methods, perhaps one struct + methods per file (as in Java) to have all the information together for easy reference, but I don't have a strong opinion in this particular case (just FYI in case you didn't consider alternatives).

Copy link
Contributor Author

@philipgough philipgough Feb 12, 2019

Choose a reason for hiding this comment

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

Well this is not uncommon in go. Even the stdlib uses types.go files. The reason I have done this is looking ahead slightly.

I spoke to @jmprusi who has a use cause for decoupling the actual so I expect some refactoring, but I'm ok with putting these back where they were if you like. Once the type methods aren't spread across files I'm fine either way.

Copy link
Contributor

@unleashed unleashed Feb 12, 2019

Choose a reason for hiding this comment

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

No, it's ok this way, I just FYI'ed it. :)

Decoupling this from its context... well, it's going to cost a bit. Let @jmprusi volunteer to extract the logic out and make it available for us as a shared library. :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jmprusi has just been volunteered. Thanks @jmprusi 👍 🥇

pkg/threescale/threescale_test.go Outdated Show resolved Hide resolved
},
},
},
expect: generatedExpectedError(t, rpc.PERMISSION_DENIED, authMismatchErr),
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd say we prefer this to be "I will use user_key=MATCH and ignore app_key".
We can define this order:

  1. Presence of user_key? => process user_key, goto 3
  2. Presence of app_id? => goto 2.a
    2.a Presence of app_key? => process app_id with app_key, goto 3
    2.b Process app_id without app_key
  3. Done.

Of course, if we knew we were supposed to only be using app_id/app_key, we'd be ignoring the other steps (ie. 1).

pkg/threescale/threescale.go Outdated Show resolved Hide resolved
Value: proxyConf.Content.BackendAuthenticationValue,
}}

if request.Subject != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

if Subject == nil we can probably error out earlier, before matching rules, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, Again this is just covering a messed up config and avoiding a panic but yes, I'll move this to fail early

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

pkg/threescale/threescale.go Show resolved Hide resolved
Copy link
Contributor

@unleashed unleashed left a comment

Choose a reason for hiding this comment

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

Looking better, check comments.

Gopkg.toml Show resolved Hide resolved
pkg/threescale/threescale.go Outdated Show resolved Hide resolved
user: request.query_params["user_key"] | request.headers["x-user-key"] | request.api_key | ""
properties:
app_id: request.query_params["app_id"] | request.headers["x-app-id"] | ""
app_key: request.query_params["app_key"] | request.headers["x-app-key"] | ""
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 be interested in knowing whether these parameters are empty or they weren't specified, perhaps we can leave out the "" and test for nil?

user: request.query_params["user_key"] | request.headers["x-user-key"] | request.api_key | ""
properties:
app_id: request.query_params["app_id"] | request.headers["x-app-id"] | ""
app_key: request.query_params["app_key"] | request.headers["x-app-key"] | ""
Copy link
Contributor

Choose a reason for hiding this comment

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

(for a bit of context, there is in 3scale, under certain conditions, a semantic difference between specifying an empty app_key to the Service Management API and simply not specifying it at all)

README.md Show resolved Hide resolved
Copy link
Contributor

@unleashed unleashed 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, check comments for minor things to correct.

README.md Outdated
Now that the we have [configured the service to be managed by 3scale](#routing-service-traffic-through-the-adapter) we can decide how requests should be authenticated.
Currently there are two supported mechanisms:
1. The API Key authentication pattern
1. The Application ID authentication pattern
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably mention the "pair" of App ID and App Key, as it is referred to like this in docs. Also, this should be 2.

method: request.method | "get"
```

#### Hybrid Pattern
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Gopkg.toml Show resolved Hide resolved
@philipgough philipgough force-pushed the 1.1-migration branch 2 times, most recently from 669aced to ed3ae64 Compare February 13, 2019 16:21
This change updates the handler to support an additional authentication method.
The instance will be configured by the user and the adapter parses the request
to determine what authentication method should be used and in turn decides on the
3scale backend API which will be called.
This change alerts the operator to the fact that the config has no changed to use features
from Istio version 1.1 which becomes a prerequisite.

Also included are updates to the README to describe how to configure the various authentication patterns
and how to adjust the config to enforce various authn methods.
@philipgough philipgough merged commit 66816d2 into master Feb 14, 2019
@philipgough philipgough deleted the 1.1-migration branch February 14, 2019 08:08
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.

3 participants