-
Notifications
You must be signed in to change notification settings - Fork 21
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
Basic Authentication #399
Comments
For basic auth OpenAPI only seems to concern itself with the type of authentication how credentials are transmitted.
|
components:
securitySchemes:
basicAuth:
type: "http"
description: "HTTP Basic Authentication."
scheme: "basic"
x-kusk:
path_prefix: /login #optional
auth-upstream: # upstream and redirect are mutually exclusive
host: # host and service are mutually exclusive
hostname: example.com
port: 80
service: # host and service are mutually exclusive
namespace: default
name: petstore
port: 8000 |
Could we start with not specifying any extensions for now and just validate that requests have the desired authentication? GIVEN a basic auth scheme is specified GIVEN a basic auth scheme is specified |
@kylehodgetts I'm going to leave the snippet here so we don't lose it
Sample API I used https://pastebin.com/eMtgqEYa |
The next bit is to pass the config to the fleet. |
* `pkg/options/auth.go`: Struct definition of the `auth` section. * `pkg/options/auth_test.go`: Tests that unmarshaling the `auth` section YAML works as expected. * `internal/controllers/auth.go`: This is where the configuration of envoy will take place, perhaps using an approach similar to the one defined here <envoyproxy/go-control-plane#184>. * `pkg/spec/extension_test.go`: use `require.EqualError` to match the error message. * `pkg/spec/extension.go`: Print out the input when we fail to parse `x-kusk` extension. * `Makefile`: Run `docker build` with out cache, which I'll revert in the future. * `examples/auth-basic/`: Basic auth samples. Example `auth` YAML: ```yaml x-kusk: ... auth: scheme: basic path_prefix: /login #optional auth-upstream: host: hostname: example.com port: 80 ``` See <#399> for further information.
* `pkg/options/auth.go`: Struct definition of the `auth` section. * `pkg/options/auth_test.go`: Tests that unmarshaling the `auth` section YAML works as expected. * `internal/controllers/auth.go`: This is where the configuration of envoy will take place, perhaps using an approach similar to the one defined here <envoyproxy/go-control-plane#184>. * `pkg/spec/extension_test.go`: use `require.EqualError` to match the error message. * `pkg/spec/extension.go`: Print out the input when we fail to parse `x-kusk` extension. * `Makefile`: Run `docker build` with out cache, which I'll revert in the future. * `examples/auth-basic/`: Basic auth samples. Example `auth` YAML: ```yaml x-kusk: ... auth: scheme: basic path_prefix: /login #optional auth-upstream: host: hostname: example.com port: 80 ``` See <#399> for further information.
* `pkg/options/auth.go`: Struct definition of the `auth` section. * `pkg/options/auth_test.go`: Tests that unmarshaling the `auth` section YAML works as expected. * `internal/controllers/auth.go`: This is where the configuration of envoy will take place, perhaps using an approach similar to the one defined here <envoyproxy/go-control-plane#184>. * `pkg/spec/extension_test.go`: use `require.EqualError` to match the error message. * `pkg/spec/extension.go`: Print out the input when we fail to parse `x-kusk` extension. * `Makefile`: Run `docker build` with out cache, which I'll revert in the future. * `examples/auth-basic/`: Basic auth samples. Example `auth` YAML: ```yaml x-kusk: ... auth: scheme: basic path_prefix: /login #optional auth-upstream: host: hostname: example.com port: 80 ``` See <#399> for further information.
* `internal/envoy/config/hcm.go`: Hardcode filters in `NewHCMBuilder` just for testing purposes. * Add `prototypes/auth-basic/ext_authz` that contains an envoy sample that proxies auth to an upstream service. See: <https://github.com/envoyproxy/envoy/tree/main/examples/ext_authz>. See <#399> for further information.
**WIP:** Still debugging. See <#399> for further information.
**WIP:** Still debugging. See <#399> for further information.
**WIP:** Still debugging. See <#399> for further information.
First cut at basic auth with hardcoded values and static configuration. These hardcoded values and static configuration will be removed later on. `pkg/options/options.go`, `pkg/options/auth.go` and `pkg/options/auth_test.go` ------------------------------------------------------------------------------ * Add `AuthOptions` as an optional in `SubOptions`. * Add the authentication option themselves and tests. `internal/controllers/envoyfleet_resources.go` ---------------------------------------------- * Turn on `envoy` logging - `filter:trace,ext_authz:trace` - to help tracing `ext_authz` and `filter` log lines. * Add note and commented out code on how to configure different logging levels. `internal/envoy/config/hcm.go` ------------------------------ * Create a new function called `makeHTTPExternalAuthorization` that creates the filter. * In `NewHCMBuilder` create the `HTTPExternalAuthorization` filter and add it to `httpConnectionManager.HttpFilters`. * Copy `generateClusterName` from `internal/controllers/parser.go`. See <#399> for further information.
@mbana Can you add some update here? |
The work exists in this, https://github.com/kubeshop/kusk-gateway/tree/mbana-basic-auth-prototype, branch. It works for a statically configured authentication server, i.e., if I hardcode the authentication server and cluster in the code. The last hurdle that I'm working on is to make the static configuration of the authentication server, e.g., x-kusk:
...
auth:
scheme: basic
path_prefix: /login #optional
auth-upstream:
host:
hostname: example.com
port: 80 So that in it proxies to
How to run it. Checkout the branch above and git pull
git checkout mbana-basic-auth-prototype
make create-env
kubectl port-forward service/default 8080:80 kubectl apply -f protoypes/manifests/ext-authz-http-service-api.yaml
kubectl apply -f protoypes/manifests/auth-basic-staticroute.yaml
kubectl apply -f protoypes/manifests/ext-authz-http-service.yaml Run the commands below. Notice the first one contains invalid credentials ( $ curl -L -X GET -v --user kubeshop:kubeshopx http://localhost:8080/get2
Note: Unnecessary use of -X or --request, GET is already inferred.
* Trying 127.0.0.1:8080...
* Connected to localhost (127.0.0.1) port 8080 (#0)
* Server auth using Basic with user 'kubeshop'
> GET /get2 HTTP/1.1
> Host: localhost:8080
> Authorization: Basic a3ViZXNob3A6a3ViZXNob3B4
> User-Agent: curl/7.83.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 401 Unauthorized
< x-powered-by: Express
< date: Wed, 01 Jun 2022 12:56:11 GMT
< content-length: 54
< x-envoy-upstream-service-time: 761
< content-type: text/plain
< server: envoy
<
* Connection #0 to host localhost left intact
Unauthorized - hint: credentials are kubeshop:kubeshop%
$ curl -L -X GET -v --user kubeshop:kubeshop http://localhost:8080/get2
Note: Unnecessary use of -X or --request, GET is already inferred.
* Trying 127.0.0.1:8080...
* Connected to localhost (127.0.0.1) port 8080 (#0)
* Server auth using Basic with user 'kubeshop'
> GET /get2 HTTP/1.1
> Host: localhost:8080
> Authorization: Basic a3ViZXNob3A6a3ViZXNob3A=
> User-Agent: curl/7.83.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< server: envoy
< date: Wed, 01 Jun 2022 12:56:17 GMT
< content-type: application/json
< content-length: 367
< access-control-allow-origin: *
< access-control-allow-credentials: true
< x-envoy-upstream-service-time: 32
<
{
"args": {},
"headers": {
"Accept": "*/*",
"Authorization": "Basic a3ViZXNob3A6a3ViZXNob3A=",
"Host": "localhost:8080",
"User-Agent": "curl/7.83.0",
"X-Current-User": "kubeshop",
"X-Envoy-Expected-Rq-Timeout-Ms": "15000",
"X-Envoy-Original-Path": "/get2"
},
"origin": "172.17.0.1",
"url": "http://localhost:8080/get"
}
* Connection #0 to host localhost left intact |
Make the configuration dynamic. See <#399> for further information.
Trying to figure out some issues with Validation of the manifest. |
Code review points. Add `Dockerfile` See <#399> for further information.
First cut at basic auth with hardcoded values and static configuration. These hardcoded values and static configuration will be removed later on. `pkg/options/options.go`, `pkg/options/auth.go` and `pkg/options/auth_test.go` ------------------------------------------------------------------------------ * Add `AuthOptions` as an optional in `SubOptions`. * Add the authentication option themselves and tests. `internal/controllers/envoyfleet_resources.go` ---------------------------------------------- * Turn on `envoy` logging - `filter:trace,ext_authz:trace` - to help tracing `ext_authz` and `filter` log lines. * Add note and commented out code on how to configure different logging levels. `internal/envoy/config/hcm.go` ------------------------------ * Create a new function called `makeHTTPExternalAuthorization` that creates the filter. * In `NewHCMBuilder` create the `HTTPExternalAuthorization` filter and add it to `httpConnectionManager.HttpFilters`. * Copy `generateClusterName` from `internal/controllers/parser.go`. See <#399> for further information.
Make the configuration dynamic. See <#399> for further information.
Code review points. Add `Dockerfile` See <#399> for further information.
Code review points. Fix `MIT License` comment style so it does not appear in `godoc` when previewing the docs for the repository. See <#399> for further information.
Code review points. Run `go mod tidy` and `go mod verify` See <#399> for further information.
Code review points. Push `docker.io/kubeshop/kusk-ext-authz-http-service` image. See <#399> for further information.
First cut at basic auth with hardcoded values and static configuration. These hardcoded values and static configuration will be removed later on. `pkg/options/options.go`, `pkg/options/auth.go` and `pkg/options/auth_test.go` ------------------------------------------------------------------------------ * Add `AuthOptions` as an optional in `SubOptions`. * Add the authentication option themselves and tests. `internal/controllers/envoyfleet_resources.go` ---------------------------------------------- * Turn on `envoy` logging - `filter:trace,ext_authz:trace` - to help tracing `ext_authz` and `filter` log lines. * Add note and commented out code on how to configure different logging levels. `internal/envoy/config/hcm.go` ------------------------------ * Create a new function called `makeHTTPExternalAuthorization` that creates the filter. * In `NewHCMBuilder` create the `HTTPExternalAuthorization` filter and add it to `httpConnectionManager.HttpFilters`. * Copy `generateClusterName` from `internal/controllers/parser.go`. See <#399> for further information.
Make the configuration dynamic. See <#399> for further information.
Code review points. Add `Dockerfile` See <#399> for further information.
Code review points. Fix `MIT License` comment style so it does not appear in `godoc` when previewing the docs for the repository. See <#399> for further information.
Code review points. Run `go mod tidy` and `go mod verify` See <#399> for further information.
Code review points. Push `docker.io/kubeshop/kusk-ext-authz-http-service` image. See <#399> for further information.
`pkg/options/options.go`, `pkg/options/auth.go` and `pkg/options/auth_test.go` ------------------------------------------------------------------------------ * Add `AuthOptions` as an optional in `SubOptions`. * Add the authentication option themselves and tests. `internal/controllers/envoyfleet_resources.go` ---------------------------------------------- * Turn on `envoy` logging - `filter:trace,ext_authz:trace` - to help tracing `ext_authz` and `filter` log lines. * Add note and commented out code on how to configure different logging levels. `internal/envoy/config/hcm.go` ------------------------------ * Create a new function called `makeHTTPExternalAuthorization` that creates the filter. * In `NewHCMBuilder` create the `HTTPExternalAuthorization` filter and add it to `httpConnectionManager.HttpFilters`. * Copy `generateClusterName` from `internal/controllers/parser.go`. See <#399> for further information. Signed-off-by: Mohamed Bana <mohamed@bana.io>
* Basic Authentication - #399 `pkg/options/options.go`, `pkg/options/auth.go` and `pkg/options/auth_test.go` ------------------------------------------------------------------------------ * Add `AuthOptions` as an optional in `SubOptions`. * Add the authentication option themselves and tests. `internal/controllers/envoyfleet_resources.go` ---------------------------------------------- * Turn on `envoy` logging - `filter:trace,ext_authz:trace` - to help tracing `ext_authz` and `filter` log lines. * Add note and commented out code on how to configure different logging levels. `internal/envoy/config/hcm.go` ------------------------------ * Create a new function called `makeHTTPExternalAuthorization` that creates the filter. * In `NewHCMBuilder` create the `HTTPExternalAuthorization` filter and add it to `httpConnectionManager.HttpFilters`. * Copy `generateClusterName` from `internal/controllers/parser.go`. See <#399> for further information. Signed-off-by: Mohamed Bana <mohamed@bana.io> * basic auth smokes Signed-off-by: jasmingacic <jasmin.gacic@gmail.com> * a little bit of optimization Signed-off-by: jasmingacic <jasmin.gacic@gmail.com> * removed upstream from mocked apis Signed-off-by: jasmingacic <jasmin.gacic@gmail.com> * fixing global auth disable Signed-off-by: jasmingacic <jasmin.gacic@gmail.com> * re-enabled teeardown for basic auth smokes Signed-off-by: jasmingacic <jasmin.gacic@gmail.com> * removed commented code from auth service Signed-off-by: jasmingacic <jasmin.gacic@gmail.com> Co-authored-by: Mohamed Bana <mohamed@bana.io>
Use this a guide
https://medium.com/@ricklee_10931/envoy-external-authorization-a-simple-example-d50ef2ede631
The text was updated successfully, but these errors were encountered: