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 basic auth middleware for basic protection of web ui #113

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

cinemast
Copy link

@cinemast cinemast commented Aug 23, 2024

This should fix #111 in a very simple way.

  • Adds new ENV variables for BASIC_AUTH_USER and BASIC_AUTH_PASSWORD which both need to be defined, otherwise Basic Auth middleware will not be enabled.
  • Documents existing found ENV variables

@cinemast cinemast mentioned this pull request Aug 23, 2024
Copy link
Collaborator

@brandur brandur left a comment

Choose a reason for hiding this comment

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

Thanks!

Logger: logger,
Prefix: pathPrefix,
BasicAuthUser: os.Getenv("BASIC_AUTH_USER"),
BasicAuthPassword: os.Getenv("BASIC_AUTH_PASSWORD"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

You use "user" here, but "username" below.

Do you want to change all references to user/pass/BASIC_AUTH_USER/BASIC_AUTH_PASS? The symmetry in length appeals to me, and it's a little shorter.

Also, can you keep this list alphabetized?

- `RIVER_DEBUG=true` - enable debugging logs
- `CORS_ORIGINS=url1,url2` - define allowed CORS origins
- `OTEL_ENABLED=true` - enable OTEL integration
- `BASIC_AUTH_USER=admin`, `BASIC_AUTH_PASSWORD=changeme` - enable basic auth username/password
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good idea on some basic documentation for this stuff.

Can you sort this list? Better if there's some sort of scheme in how things like this are organized.

return
}

data, err := base64.StdEncoding.DecodeString(basicAuthHeader[len("Basic "):])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you know about Request.BasicAuth? Probably better to use that than implement it yourself.

}
next.ServeHTTP(w, r)
})
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you think you could take a stab at a basic couple of tests for this middleware? I know the project is hit or miss testing wise, but we're trying to shore that up.

@bgentry
Copy link
Contributor

bgentry commented Aug 28, 2024

@cinemast whether or not you pick up on the fixes to this PR, you may also be interested in this prerelease v0.5.0-pre3 which allows you to use River UI via an http.Handler in your own app: #107 (comment)

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.

Authentication
3 participants