Skip to content
This repository was archived by the owner on Apr 2, 2024. It is now read-only.

Add cmd flag to skip http paths from authentication #1637

Merged
merged 2 commits into from
Sep 15, 2022

Conversation

arajkumar
Copy link
Member

@arajkumar arajkumar commented Sep 12, 2022

Signed-off-by: Arunprasad Rajkumar [email protected]

Description

This PR adds a flag named --web.auth.ignore-path which takes a http path and passed path would be ignored from authentication. The flag shall be repeated to pass array of ignored paths.

e.g.

# skips authn for heathz and api/query_range endpoints.
./dist/promscale --web.auth.ignore-path=/heathz --web.auth.ignore-path=/api/query_range

Fixes #1636

Code changes are inspired from https://github.com/brancz/kube-rbac-proxy/blob/fc1ca4f969941340a8adb66932bd64dc5773d37a/main.go#L298-L321

Merge requirements

Please take into account the following non-code changes that you may need to make with your PR:

  • CHANGELOG entry for user-facing changes
  • Updated the relevant documentation

@arajkumar arajkumar force-pushed the skip-auth branch 2 times, most recently from 328090a to bceb05e Compare September 12, 2022 08:44
@@ -163,8 +164,22 @@ func authHandler(cfg *Config, handler http.Handler) http.Handler {
return handler
}

isIgnoredPath := func(r *http.Request) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can add this as a method to Auth?

Copy link
Member

Choose a reason for hiding this comment

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

I agree, this is getting into too much auth logic for the router file. It should probably go into the common.go file, have the Auth method encapsulate all this internal logic about authorization methods and ignored paths.

Copy link
Member

Choose a reason for hiding this comment

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

Might even make sense to break it up into its own auth file since its kinda overgrown the common file.

Copy link
Member

@antekresic antekresic left a comment

Choose a reason for hiding this comment

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

Overall looks good, a bit of organization would benefit us here with the rise of complexity in the auth code.

@@ -163,8 +164,22 @@ func authHandler(cfg *Config, handler http.Handler) http.Handler {
return handler
}

isIgnoredPath := func(r *http.Request) bool {
Copy link
Member

Choose a reason for hiding this comment

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

I agree, this is getting into too much auth logic for the router file. It should probably go into the common.go file, have the Auth method encapsulate all this internal logic about authorization methods and ignored paths.

@@ -163,8 +164,22 @@ func authHandler(cfg *Config, handler http.Handler) http.Handler {
return handler
}

isIgnoredPath := func(r *http.Request) bool {
Copy link
Member

Choose a reason for hiding this comment

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

Might even make sense to break it up into its own auth file since its kinda overgrown the common file.

@arajkumar arajkumar force-pushed the skip-auth branch 2 times, most recently from 9f48f88 to a28b24f Compare September 13, 2022 16:22
@Harkishen-Singh
Copy link
Member

I will pass this review to other reviewers.

Copy link
Member

@antekresic antekresic left a comment

Choose a reason for hiding this comment

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

Approved with a small ask to add a TODO for some future refactoring.

@@ -29,7 +28,7 @@ import (
"github.com/timescale/promscale/pkg/telemetry"
)

func GenerateRouter(apiConf *Config, promqlConf *query.Config, client *pgclient.Client, store *jaegerStore.Store, reload func() error) (*mux.Router, error) {
func GenerateRouter(apiConf *Config, promqlConf *query.Config, client *pgclient.Client, store *jaegerStore.Store, authWrapper mux.MiddlewareFunc, reload func() error) (*mux.Router, error) {
Copy link
Member

Choose a reason for hiding this comment

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

This is obviously a smell, having so many input parameters on a function. The function itself is too big as well.

Lets put a TODO on this to refactor it in the future so when somebody goes to add another parameter, they can see it and not do it 😃

This commit adds a flag `--web.auth.ignore-path` which takes a http path and passed path would be ignored from authentication. The flag shall be repeated to pass array of ignored paths.

e.g.
```
./dist/promscale --web.auth.ignore-path=/heathz --web.auth.ignore-path=/api/query_range
```

Fixes timescale#1636

Signed-off-by: Arunprasad Rajkumar <[email protected]>
@arajkumar arajkumar merged commit b6c4e6c into timescale:master Sep 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ignore HTTP AUTH for /healthz
4 participants