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 static HTTP file server for /.well-known/ endpoint #25892

Closed
wants to merge 1 commit into from
Closed

Add static HTTP file server for /.well-known/ endpoint #25892

wants to merge 1 commit into from

Conversation

alex19srv
Copy link

First commit to implement /.well-known/security.txt endpoint (as discussed in #21942)

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jul 14, 2023
@pull-request-size pull-request-size bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jul 14, 2023
@alex19srv alex19srv changed the title add static HTTP file server for /.well-known/ endpoint Add static HTTP file server for /.well-known/ endpoint Jul 14, 2023
@denyskon denyskon added the type/feature Completely new functionality. Can only be merged if feature freeze is not active. label Jul 14, 2023
@denyskon
Copy link
Member

Could we have a test for it?

@alex19srv
Copy link
Author

Could we have a test for it?

I want to add tests, when I will add /.well-known/security.txt. Currently I can only test, if https://gitea/.well-known/ will return 404 status code (do not make directory list).

Or which tests do You want to see? I thought and did not found which tests to implement an this stage.

@@ -349,6 +349,12 @@ func registerRoutes(m *web.Route) {
m.Get("/change-password", func(ctx *context.Context) {
ctx.Redirect(setting.AppSubURL + "/user/settings/account")
})
wellKnownDir := wellKnownWebDir()
m.Get("/*", func(ctx *context.Context) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is right. Why not use m.Get("/.well-know/*",

Copy link
Author

Choose a reason for hiding this comment

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

This code inside group m.Group("/.well-known", func() { and my code works (I checked). All endpoints related to "/.well-known" is inside that group.

Copy link
Author

Choose a reason for hiding this comment

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

Moved m.Get("/.well-known/*", func(ctx *context.Context) { out of Group.

@wxiaoguang
Copy link
Contributor

Some thoughts:

  1. makeDirExist seems strange, I do not think the app needs to create the directories automatically.
    • Or, if it is necessary, should Gitea provide a default "security.txt"?
  2. After reading more code, I find there are some other files like "robots.txt" which need to be customized.
    • At the moment, the "robots.txt" is hard-coded as "CustomPath/robots.txt", it's impossible to add more files in the root directory.
    • Ideally, Gitea could support various static files in the web root or web well-known directory.
    • Maybe a more general approach could be like this:
      • Serve files in CustomPath/web-root-static/... to http://gitea-domain/....
      • For files in the root
        • CustomPath/web-root-static/robots.txt
        • CustomPath/web-root-static/the-domain-verification.txt
      • For files in the well-known
        • CustomPath/web-root-static/.well-known/security.txt
        • CustomPath/web-root-static/.well-known/the-domain-verification.txt

@alex19srv alex19srv closed this by deleting the head repository Jul 16, 2023
@wxiaoguang
Copy link
Contributor

wxiaoguang commented Jul 16, 2023

This feature is useful IMO, eg: https://discourse.gitea.io/t/well-known-path-serving-custom-files-behind-proxy/5445

I will try to propose a new PR for it.


The first step: Move public asset files to the proper directory #25907

silverwind pushed a commit that referenced this pull request Jul 18, 2023
Move `public/*` to `public/assets/*`

Some old PRs (like #15219) introduced inconsistent directory system.

For example: why the local directory "public" is accessed by
`http://site/assets`? How to serve the ".well-known" files properly in
the public directory?

For convention rules, the "public" directory is widely used for the
website's root directory. It shouldn't be an exception for Gitea.

So, this PR makes the things consistent:

* `http://site/assets/foo` means `{CustomPath}/public/assets/foo`.
* `{CustomPath}/public/.well-known` and `{CustomPath}/public/robots.txt`
can be used in the future.

This PR is also a prerequisite for a clear solution for:
* #21942
* #25892 
* discourse.gitea.io: [.well-known path serving custom files behind
proxy?](https://discourse.gitea.io/t/well-known-path-serving-custom-files-behind-proxy/5445/1)

This PR is breaking for users who have custom "public" files (CSS/JS).
After getting approvals, I will update the documents.

----

## ⚠️ BREAKING ⚠️

If you have files in your "custom/public/" folder, please move them to
"custom/public/assets/".

---------

Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: Giteabot <teabot@gitea.io>
@wxiaoguang
Copy link
Contributor

-> Add "security.txt" support, add CORS header for ".well-known" #25974

silverwind added a commit that referenced this pull request Jul 21, 2023
…der for ".well-known" (#25974)

Replace #25892

Close  #21942
Close  #25464

Major changes:

1. Serve "robots.txt" and ".well-known/security.txt" in the "public"
custom path
* All files in "public/.well-known" can be served, just like
"public/assets"
3. Add a test for ".well-known/security.txt"
4. Simplify the "FileHandlerFunc" logic, now the paths are consistent so
the code can be simpler
5. Add CORS header for ".well-known" endpoints
6. Add logs to tell users they should move some of their legacy custom
public files

```
2023/07/19 13:00:37 cmd/web.go:178:serveInstalled() [E] Found legacy public asset "img" in CustomPath. Please move it to /work/gitea/custom/public/assets/img
2023/07/19 13:00:37 cmd/web.go:182:serveInstalled() [E] Found legacy public asset "robots.txt" in CustomPath. Please move it to /work/gitea/custom/public/robots.txt
```
This PR is not breaking.

---------

Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: Giteabot <teabot@gitea.io>
@n0toose
Copy link
Contributor

n0toose commented Jul 23, 2023

This is meta, but you should seriously start providing some sort of method for people that are intending to contribute seriously and want to discuss design ideas and plans in a way that isn't a real-time platform. There are indeed too many issues but some sort of an explicitly defined "lifeline" to a contributor has to somehow continue existing.

@jolheiser
Copy link
Member

This is meta, but you should seriously start providing some sort of method for people that are intending to contribute seriously and want to discuss design ideas and plans in a way that isn't a real-time platform. There are indeed too many issues but some sort of an explicitly defined "lifeline" to a contributor has to somehow continue existing.

I'm not sure what this means? Anyone is welcome to discuss ideas in an issue, Discord, Matrix, Discourse, etc.

@wxiaoguang
Copy link
Contributor

Some people just don't want to discuss. There is a discord channel develop.

And some tasks are too difficult for new contributors. I have done my best to help them (many discussions were done by discord develop channel or private message)

@n0toose
Copy link
Contributor

n0toose commented Jul 23, 2023

Some people just don't want to discuss.

Issues are big and messy and there is an implicit expectation from the perspective of a new contributor that doesn't want to bother: Developers can't be possibly monitoring a thousand issues (which are arguably a very good place for drive-by contributors), even if notifications exist.

And some tasks are too difficult for new contributors. I have done my best to help them (many discussions were done by discord develop channel or private message)

I'm not accusing you of not trying to help and not trying to help onboard new users (I apologize if I gave off that impression), I'm saying that it would be best to bridge the gap between wanting to work on an issue and reaching out to people. If you are reachable in an issue tracker, it might be best to not let that be an unwritten rule.

@go-gitea go-gitea locked as resolved and limited conversation to collaborators Oct 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. type/feature Completely new functionality. Can only be merged if feature freeze is not active.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants