Codeberg/pages-server
25
366
Fork
You've already forked pages-server
52

Add Basic HTTP Auth Config #166

Open
jimafisk wants to merge 4 commits from jimafisk/pages-server:issue-163 into main
pull from: jimafisk/pages-server:issue-163
merge into: Codeberg:main
Codeberg:main
Codeberg:renovate/woodpeckerci-plugin-docker-buildx-6.x
Codeberg:renovate/golang-deps-non-major
Codeberg:git-pages-server-doc
Codeberg:pages
Codeberg:ci_user-local-acme-service
Codeberg:feat/redis-caching
Codeberg:fix/memory-problem
First-time contributor
Copy link

This PR adds basic HTTP auth per project: #163

You enable this by optionally adding a .auth file to the branch/repo for your website. The format for the contents of this file is simply username, password on a single line.

You can add multiple user/password combinations if you'd like:

user1, mypass
user2, anotherpass
This PR adds basic HTTP auth per project: https://codeberg.org/Codeberg/pages-server/issues/163 You enable this by optionally adding a `.auth` file to the branch/repo for your website. The format for the contents of this file is simply `username, password` on a single line. You can add multiple user/password combinations if you'd like: ``` user1, mypass user2, anotherpass ```
Basic HTTP Auth ( #163 ).
Some checks failed
ci/woodpecker/pr/woodpecker Pipeline failed
faeb8ae499
Contributor
Copy link

Hi, I don't understand how you can protect the password from being read?

Hi, I don't understand how you can protect the password from being read?
Author
First-time contributor
Copy link

@fsologureng - can't you serve public websites from a private repo if you're using GITEA_API_TOKEN? Or are you worried about the password being exposed in transit?

@fsologureng - can't you serve public websites from a private repo if you're using `GITEA_API_TOKEN`? Or are you worried about the password being exposed in transit?
Contributor
Copy link

@fsologureng - can't you serve public websites from a private repo if you're using GITEA_API_TOKEN? Or are you worried about the password being exposed in transit?

Ok, so this is a feature just for private repos. Now is clarified, thank you.

> @fsologureng - can't you serve public websites from a private repo if you're using `GITEA_API_TOKEN`? Or are you worried about the password being exposed in transit? Ok, so this is a feature just for private repos. Now is clarified, thank you.
Author
First-time contributor
Copy link

so this is a feature just for private repos

Yes sorry that wasn't clear. You could use it in a public repo but you'd be relying on security through obscurity. For anything too sensitive (long-term private data), I honestly would implement a more robust auth solution in your app (use https://pocketbase.io/ or something similar). For my use-case, I just wanted to be able to hide websites that I'm working on before they're launched, but have the ability to share them with clients so they can see progress.

> so this is a feature just for private repos Yes sorry that wasn't clear. You could use it in a public repo but you'd be relying on security through obscurity. For anything too sensitive (long-term private data), I honestly would implement a more robust auth solution in your app (use https://pocketbase.io/ or something similar). For my use-case, I just wanted to be able to hide websites that I'm working on before they're launched, but have the ability to share them with clients so they can see progress.
Contributor
Copy link

well for the feature itselve, i wont block it ...

... how caching is done, thats what i dislike (also as its done in the current codebase)

If you allow me to "edit the pullrequest" I'll going to push some changes next week to it.

Thanks for upstreaming :)

well for the feature itselve, i wont block it ... ... how caching is done, thats what i dislike (also as its done in the current codebase) If you allow me to "edit the pullrequest" I'll going to push some changes next week to it. Thanks for upstreaming :)
Owner
Copy link

I think this is outside the scope for Codeberg to maintain. Rather leave the patch around for people to cherry-pick.

I think this is outside the scope for Codeberg to maintain. Rather leave the patch around for people to cherry-pick.
Author
First-time contributor
Copy link

... how caching is done, thats what i dislike (also as its done in the current codebase)

I wasn't sure about this either, I was trying my best to copy the model from custom domains. Not sure if it makes sense to cache this at all, just didn't want to put extra load if was going to be a performance issue constantly reading .auth files.

If you allow me to "edit the pullrequest" I'll going to push some changes next week to it.

I'm totally fine with you making changes as you see fit. If there is something I need to do to allow this, just let me know.

I think this is outside the scope for Codeberg to maintain. Rather leave the patch around for people to cherry-pick.

That's ok if you don't want to pull this in, I know we discussed previously. I needed it for my project and I figured other folks might need it for theirs so I wanted to share it.

Note: currently it will log ERR could not read .auth of owner/repo error="not found" so if we decide to pull this in, we should clean that up since lots of repos intentionally won't have .auth files. Thanks!

> ... how caching is done, thats what i dislike (also as its done in the current codebase) I wasn't sure about this either, I was trying my best to copy the model from custom domains. Not sure if it makes sense to cache this at all, just didn't want to put extra load if was going to be a performance issue constantly reading `.auth` files. > If you allow me to "edit the pullrequest" I'll going to push some changes next week to it. I'm totally fine with you making changes as you see fit. If there is something I need to do to allow this, just let me know. > I think this is outside the scope for Codeberg to maintain. Rather leave the patch around for people to cherry-pick. That's ok if you don't want to pull this in, I know we discussed previously. I needed it for my project and I figured other folks might need it for theirs so I wanted to share it. **Note:** currently it will log `ERR could not read .auth of owner/repo error="not found"` so if we decide to pull this in, we should clean that up since lots of repos intentionally won't have `.auth` files. Thanks!
Owner
Copy link

Yeah thanks for providing the patch, it's surely interesting for others. If there is some more demand from others (even if not Codeberg but other instances), this would be fine, but in general I think it's really not a best fit for the concept of this project, but happy you were able to adapt it to your needs.

Yeah thanks for providing the patch, it's surely interesting for others. If there is some more demand from others (even if not Codeberg but other instances), this would be fine, but in general I think it's really not a best fit for the concept of this project, but happy you were able to adapt it to your needs.
Author
First-time contributor
Copy link

No problem! That makes sense, as I mentioned on another PR I think my use case is rather specific, so rather than extending this project to handle every possible scenario, it probably makes sense for me to fork the base system for my specific needs. Thanks, I'll close this out!

No problem! That makes sense, as I mentioned on [another PR](https://codeberg.org/Codeberg/pages-server/pulls/168#issuecomment-789512) I think my use case is rather specific, so rather than extending this project to handle every possible scenario, it probably makes sense for me to fork the base system for my specific needs. Thanks, I'll close this out!
jimafisk closed this pull request 2023年02月02日 20:47:10 +01:00
Member
Copy link

Consider leaving it open so other people can easily find it to cherry-pick if they want to try.

Consider leaving it open so other people can easily find it to cherry-pick if they want to try.
Author
First-time contributor
Copy link

Oops sorry. Re-opened!

Oops sorry. Re-opened!
jimafisk reopened this pull request 2023年02月02日 20:53:28 +01:00
Contributor
Copy link

@jimafisk Maybe a PR against the README of this repo pointing to your little fork would make sense to simplify access to people whose want to replicate your use case (or part of).

@jimafisk Maybe a PR against the README of this repo pointing to your little fork would make sense to simplify access to people whose want to replicate your use case (or part of).
Author
First-time contributor
Copy link

@fsologureng I'd be happy to do that if the maintainers don't think it's taking away this project.

@fsologureng I'd be happy to do that if the maintainers don't think it's taking away this project.
Contributor
Copy link

@fsologureng I'd be happy to do that if the maintainers don't think it's taking away this project.

I really don't believe so. But I am not the last word ;)

> @fsologureng I'd be happy to do that if the maintainers don't think it's taking away this project. I really don't believe so. But I am not the last word ;)
6543 added this to the v5.0 milestone 2023年02月09日 22:06:24 +01:00
6543 changed title from (削除) Basic HTTP Auth (#163). (削除ここまで) to Add Basic HTTP Auth Config 2023年02月10日 02:54:13 +01:00
Contributor
Copy link
we need some integration test and a test repo ... e.g.: [https://codeberg.org/Codeberg/pages-server/pulls/159/files#diff-bb7421cb6838f804b1a3ed4529887f274c0ee43f](https://codeberg.org/Codeberg/pages-server/pulls/159/files#diff-bb7421cb6838f804b1a3ed4529887f274c0ee43f)
Contributor
Copy link

@jimafisk please merge main into the feature branch :)

@jimafisk please merge main into the feature branch :)
Author
First-time contributor
Copy link

@6543 I force pushed, sorry if that wasn't the thing to do. Just let me know if I need to clean this up a bit. Thanks!

@6543 I force pushed, sorry if that wasn't the thing to do. Just let me know if I need to clean this up a bit. Thanks!
Contributor
Copy link

well if rebasing things works for you it's fine ...

well if rebasing things works for you it's fine ...
@ -0,0 +23,4 @@
}else{
body,err:=giteaClient.GiteaRawContent(o.TargetOwner,o.TargetRepo,o.TargetBranch,authConfig)
iferr==nil{
for_,authLine:=rangestrings.Split(string(body),"\n"){
Contributor
Copy link

move this in a unexported helper function parseAuth([]byte) []string and handling # comments might also be a good idea ...

move this in a unexported helper function `parseAuth([]byte) []string` and handling `# comments` might also be a good idea ...
@ -114,0 +127,4 @@
}
}
funcenforceBasicHTTPAuth(credentials[]string,whttp.ResponseWriter,req*http.Request)bool{
Contributor
Copy link

move to handler_auth.go ?

move to handler_auth.go ?
@ -33,1 +33,4 @@
trimmedHost:=ctx.TrimHostPort()
credentials:=handleAuth(log,ctx,giteaClient,
Contributor
Copy link
can we make this feature opt-in? https://codeberg.org/Codeberg/pages-server/src/branch/main/cmd/flags.go#L83-L85
6543 modified the milestone from v5.0 to v6.0 2023年11月15日 02:52:31 +01:00
crapStone removed this from the v6.0 milestone 2024年05月27日 23:59:20 +02:00
First-time contributor
Copy link

Any new on this feature? I also have a use case for having finer access control.
Probably something that mirrors Gitea's read rights on a repo.

Any new on this feature? I also have a use case for having finer access control. Probably something that mirrors Gitea's read rights on a repo.
This pull request has changes conflicting with the target branch.
  • cmd/main.go
  • server/handler/handler.go
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u issue-163:jimafisk-issue-163
git switch jimafisk-issue-163
Sign in to join this conversation.
No reviewers
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
6 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Codeberg/pages-server!166
Reference in a new issue
Codeberg/pages-server
No description provided.
Delete branch "jimafisk/pages-server:issue-163"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?