Skip to content
This repository has been 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 ar.arunprasad@gmail.com

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

@@ -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
Contributor

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
Contributor

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
Contributor

@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.

pkg/api/common.go Outdated Show resolved Hide resolved
docs/configuration.md Outdated Show resolved Hide resolved
@@ -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.

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
Contributor

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.

@Harkishen-Singh
Copy link
Member

I will pass this review to other reviewers.

Copy link
Contributor

@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
Contributor

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 <ar.arunprasad@gmail.com>
Signed-off-by: Arunprasad Rajkumar <ar.arunprasad@gmail.com>
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