Skip to content

Commit 046f34e

Browse files
committed
Merge remote-tracking branch 'upstream/main'
* upstream/main: (26 commits) Clean up WebAuthn javascript code and remove JQuery code (go-gitea#22697) Enable all webpack sourcemaps in dev build, disable all in prod build (go-gitea#25089) Don't display `select all issues` checkbox when no issues are available (go-gitea#25086) change placeholders in actions docs change placeholders in actions docs fix "Remove stars when repo goes private go-gitea#19904" (go-gitea#25084) Introduce how to configure cache when starting a Runner with Docker (go-gitea#25077) Remove stars when repo goes private (go-gitea#19904) Use correct selector for hiding RSS icon link in the branch selector dropdown (go-gitea#25080) Fix parallelly generating index failure with Mysql (go-gitea#24567) Use git command instead of the ini package to remove the `origin` remote (go-gitea#25066) improve permission documentation (go-gitea#23942) Use RepositoryList instead of []*Repository (go-gitea#25074) Add ability to set multiple redirect URIs in OAuth application UI (go-gitea#25072) Add Progressbar to Milestone Page (go-gitea#25050) [skip ci] Updated licenses and gitignores Redesign Scoped Access Tokens (go-gitea#24767) Use a separate admin page to show global stats, remove `actions` stat (go-gitea#25062) Remove cancel button from branch protection form (go-gitea#25063) Allow for PKCE flow without client secret + add docs (go-gitea#25033) ...
2 parents 5556dd0 + 036fb78 commit 046f34e

File tree

171 files changed

+3194
-1498
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

171 files changed

+3194
-1498
lines changed

.golangci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ linters-settings:
8686
- io/ioutil: "use os or io instead"
8787
- golang.org/x/exp: "it's experimental and unreliable."
8888
- code.gitea.io/gitea/modules/git/internal: "do not use the internal package, use AddXxx function instead"
89+
- gopkg.in/ini.v1: "do not use the ini package, use gitea's config system instead"
8990

9091
issues:
9192
max-issues-per-linter: 0

build/backport-locales.go

+4-8
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"path/filepath"
1313
"strings"
1414

15-
"gopkg.in/ini.v1"
15+
"code.gitea.io/gitea/modules/setting"
1616
)
1717

1818
func main() {
@@ -22,25 +22,21 @@ func main() {
2222
os.Exit(1)
2323
}
2424

25-
ini.PrettyFormat = false
2625
mustNoErr := func(err error) {
2726
if err != nil {
2827
panic(err)
2928
}
3029
}
31-
collectInis := func(ref string) map[string]*ini.File {
32-
inis := map[string]*ini.File{}
30+
collectInis := func(ref string) map[string]setting.ConfigProvider {
31+
inis := map[string]setting.ConfigProvider{}
3332
err := filepath.WalkDir("options/locale", func(path string, d os.DirEntry, err error) error {
3433
if err != nil {
3534
return err
3635
}
3736
if d.IsDir() || !strings.HasSuffix(d.Name(), ".ini") {
3837
return nil
3938
}
40-
cfg, err := ini.LoadSources(ini.LoadOptions{
41-
IgnoreInlineComment: true,
42-
UnescapeValueCommentSymbols: true,
43-
}, path)
39+
cfg, err := setting.NewConfigProviderForLocale(path)
4440
mustNoErr(err)
4541
inis[path] = cfg
4642
fmt.Printf("collecting: %s @ %s\n", path, ref)

contrib/environment-to-ini/environment-to-ini.go

+2-13
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ import (
99

1010
"code.gitea.io/gitea/modules/log"
1111
"code.gitea.io/gitea/modules/setting"
12-
"code.gitea.io/gitea/modules/util"
1312

1413
"github.com/urfave/cli"
15-
"gopkg.in/ini.v1"
1614
)
1715

1816
// EnvironmentPrefix environment variables prefixed with this represent ini values to write
@@ -97,19 +95,10 @@ func runEnvironmentToIni(c *cli.Context) error {
9795
providedWorkPath := c.String("work-path")
9896
setting.SetCustomPathAndConf(providedCustom, providedConf, providedWorkPath)
9997

100-
cfg := ini.Empty()
101-
confFileExists, err := util.IsFile(setting.CustomConf)
98+
cfg, err := setting.NewConfigProviderFromFile(&setting.Options{CustomConf: setting.CustomConf, AllowEmpty: true})
10299
if err != nil {
103-
log.Fatal("Unable to check if %s is a file. Error: %v", setting.CustomConf, err)
100+
log.Fatal("Failed to load custom conf '%s': %v", setting.CustomConf, err)
104101
}
105-
if confFileExists {
106-
if err := cfg.Append(setting.CustomConf); err != nil {
107-
log.Fatal("Failed to load custom conf '%s': %v", setting.CustomConf, err)
108-
}
109-
} else {
110-
log.Warn("Custom config '%s' not found, ignore this if you're running first time", setting.CustomConf)
111-
}
112-
cfg.NameMapper = ini.SnackCase
113102

114103
prefixGitea := c.String("prefix") + "__"
115104
suffixFile := "__FILE"

docs/content/doc/development/oauth2-provider.en-us.md

+108-43
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
date: "2019-04-19:44:00+01:00"
2+
date: "2023-06-01T08:40:00+08:00"
33
title: "OAuth2 provider"
44
slug: "oauth2-provider"
55
weight: 41
@@ -40,64 +40,67 @@ At the moment Gitea only supports the [**Authorization Code Grant**](https://too
4040
- [Proof Key for Code Exchange (PKCE)](https://tools.ietf.org/html/rfc7636)
4141
- [OpenID Connect (OIDC)](https://openid.net/specs/openid-connect-core-1_0.html#CodeFlowAuth)
4242

43-
To use the Authorization Code Grant as a third party application it is required to register a new application via the "Settings" (`/user/settings/applications`) section of the settings.
43+
To use the Authorization Code Grant as a third party application it is required to register a new application via the "Settings" (`/user/settings/applications`) section of the settings. To test or debug you can use the web-tool https://oauthdebugger.com/.
4444

4545
## Scopes
4646

47-
Gitea supports the following scopes for tokens:
48-
49-
| Name | Description |
50-
| ---- | ----------- |
51-
| **(no scope)** | Grants read-only access to public user profile and public repositories. |
52-
| **repo** | Full control over all repositories. |
53-
|     **repo:status** | Grants read/write access to commit status in all repositories. |
54-
|     **public_repo** | Grants read/write access to public repositories only. |
55-
| **admin:repo_hook** | Grants access to repository hooks of all repositories. This is included in the `repo` scope. |
56-
|     **write:repo_hook** | Grants read/write access to repository hooks |
57-
|     **read:repo_hook** | Grants read-only access to repository hooks |
58-
| **admin:org** | Grants full access to organization settings |
59-
|     **write:org** | Grants read/write access to organization settings |
60-
|     **read:org** | Grants read-only access to organization settings |
61-
| **admin:public_key** | Grants full access for managing public keys |
62-
|     **write:public_key** | Grant read/write access to public keys |
63-
|     **read:public_key** | Grant read-only access to public keys |
64-
| **admin:org_hook** | Grants full access to organizational-level hooks |
65-
| **admin:user_hook** | Grants full access to user-level hooks |
66-
| **notification** | Grants full access to notifications |
67-
| **user** | Grants full access to user profile info |
68-
|     **read:user** | Grants read access to user's profile |
69-
|     **user:email** | Grants read access to user's email addresses |
70-
|     **user:follow** | Grants access to follow/un-follow a user |
71-
| **delete_repo** | Grants access to delete repositories as an admin |
72-
| **package** | Grants full access to hosted packages |
73-
|     **write:package** | Grants read/write access to packages |
74-
|     **read:package** | Grants read access to packages |
75-
|     **delete:package** | Grants delete access to packages |
76-
| **admin:gpg_key** | Grants full access for managing GPG keys |
77-
|     **write:gpg_key** | Grants read/write access to GPG keys |
78-
|     **read:gpg_key** | Grants read-only access to GPG keys |
79-
| **admin:application** | Grants full access to manage applications |
80-
|     **write:application** | Grants read/write access for managing applications |
81-
|     **read:application** | Grants read access for managing applications |
82-
| **sudo** | Allows to perform actions as the site admin. |
47+
Gitea supports scoped access tokens, which allow users the ability to restrict tokens to operate only on selected url routes. Scopes are grouped by high-level API routes, and further refined to the following:
48+
49+
- `read`: `GET` routes
50+
- `write`: `POST`, `PUT`, `PATCH`, and `DELETE` routes (in addition to `GET`)
51+
52+
Gitea token scopes are as follows:
53+
54+
| Name | Description |
55+
| ---- |--------------------------------------------------------------------------------------------------------------------------------------------------|
56+
| **(no scope)** | Not supported. A scope is required even for public repositories. |
57+
| **activitypub** | `activitypub` API routes: ActivityPub related operations. |
58+
|     **read:activitypub** | Grants read access for ActivityPub operations. |
59+
|     **write:activitypub** | Grants read/write/delete access for ActivityPub operations. |
60+
| **admin** | `/admin/*` API routes: Site-wide administrative operations (hidden for non-admin accounts). |
61+
|     **read:admin** | Grants read access for admin operations, such as getting cron jobs or registered user emails. |
62+
|     **write:admin** | Grants read/write/delete access for admin operations, such as running cron jobs or updating user accounts. | |
63+
| **issue** | `issues/*`, `labels/*`, `milestones/*` API routes: Issue-related operations. |
64+
|     **read:issue** | Grants read access for issues operations, such as getting issue comments, issue attachments, and milestones. |
65+
|     **write:issue** | Grants read/write/delete access for issues operations, such as posting or editing an issue comment or attachment, and updating milestones. |
66+
| **misc** | miscellaneous and settings top-level API routes. |
67+
|     **read:misc** | Grants read access to miscellaneous operations, such as getting label and gitignore templates. |
68+
|     **write:misc** | Grants read/write/delete access to miscellaneous operations, such as markup utility operations. |
69+
| **notification** | `notification/*` API routes: user notification operations. |
70+
|     **read:notification** | Grants read access to user notifications, such as which notifications users are subscribed to and read new notifications. |
71+
|     **write:notification** | Grants read/write/delete access to user notifications, such as marking notifications as read. |
72+
| **organization** | `orgs/*` and `teams/*` API routes: Organization and team management operations. |
73+
|     **read:organization** | Grants read access to org and team status, such as listing all orgs a user has visibility to, teams, and team members. |
74+
|     **write:organization** | Grants read/write/delete access to org and team status, such as creating and updating teams and updating org settings. |
75+
| **package** | `/packages/*` API routes: Packages operations |
76+
|     **read:package** | Grants read access to package operations, such as reading and downloading available packages. |
77+
|     **write:package** | Grants read/write/delete access to package operations. Currently the same as `read:package`. |
78+
| **repository** | `/repos/*` API routes except `/repos/issues/*`: Repository file, pull-request, and release operations. |
79+
|     **read:repository** | Grants read access to repository operations, such as getting repository files, releases, collaborators. |
80+
|     **write:repository** | Grants read/write/delete access to repository operations, such as getting updating repository files, creating pull requests, updating collaborators. |
81+
| **user** | `/user/*` and `/users/*` API routes: User-related operations. |
82+
|     **read:user** | Grants read access to user operations, such as getting user repo subscriptions and user settings. |
83+
|     **write:user** | Grants read/write/delete access to user operations, such as updating user repo subscriptions, followed users, and user settings. |
8384

8485
## Client types
8586

8687
Gitea supports both confidential and public client types, [as defined by RFC 6749](https://datatracker.ietf.org/doc/html/rfc6749#section-2.1).
8788

8889
For public clients, a redirect URI of a loopback IP address such as `http://127.0.0.1/` allows any port. Avoid using `localhost`, [as recommended by RFC 8252](https://datatracker.ietf.org/doc/html/rfc8252#section-8.3).
8990

90-
## Example
91+
## Examples
92+
93+
### Confidential client
9194

9295
**Note:** This example does not use PKCE.
9396

94-
1. Redirect to user to the authorization endpoint in order to get their consent for accessing the resources:
97+
1. Redirect the user to the authorization endpoint in order to get their consent for accessing the resources:
9598

9699
```curl
97100
https://[YOUR-GITEA-URL]/login/oauth/authorize?client_id=CLIENT_ID&redirect_uri=REDIRECT_URI&response_type=code&state=STATE
98101
```
99102

100-
The `CLIENT_ID` can be obtained by registering an application in the settings. The `STATE` is a random string that will be send back to your application after the user authorizes. The `state` parameter is optional but should be used to prevent CSRF attacks.
103+
The `CLIENT_ID` can be obtained by registering an application in the settings. The `STATE` is a random string that will be sent back to your application after the user authorizes. The `state` parameter is optional, but should be used to prevent CSRF attacks.
101104

102105
![Authorization Page](/authorize.png)
103106

@@ -107,7 +110,7 @@ For public clients, a redirect URI of a loopback IP address such as `http://127.
107110
https://[REDIRECT_URI]?code=RETURNED_CODE&state=STATE
108111
```
109112

110-
2. Using the provided `code` from the redirect, you can request a new application and refresh token. The access token endpoints accepts POST requests with `application/json` and `application/x-www-form-urlencoded` body, for example:
113+
2. Using the provided `code` from the redirect, you can request a new application and refresh token. The access token endpoint accepts POST requests with `application/json` and `application/x-www-form-urlencoded` body, for example:
111114

112115
```curl
113116
POST https://[YOUR-GITEA-URL]/login/oauth/access_token
@@ -134,7 +137,69 @@ For public clients, a redirect URI of a loopback IP address such as `http://127.
134137
}
135138
```
136139

137-
The `CLIENT_SECRET` is the unique secret code generated for this application. Please note that the secret will only be visible after you created/registered the application with Gitea and cannot be recovered. If you lose the secret you must regenerate the secret via the application's settings.
140+
The `CLIENT_SECRET` is the unique secret code generated for this application. Please note that the secret will only be visible after you created/registered the application with Gitea and cannot be recovered. If you lose the secret, you must regenerate the secret via the application's settings.
141+
142+
The `REDIRECT_URI` in the `access_token` request must match the `REDIRECT_URI` in the `authorize` request.
143+
144+
3. Use the `access_token` to make [API requests](https://docs.gitea.io/en-us/api-usage#oauth2) to access the user's resources.
145+
146+
### Public client (PKCE)
147+
148+
PKCE (Proof Key for Code Exchange) is an extension to the OAuth flow which allows for a secure credential exchange without the requirement to provide a client secret.
149+
150+
**Note**: Please ensure you have registered your OAuth application as a public client.
151+
152+
To achieve this, you have to provide a `code_verifier` for every authorization request. A `code_verifier` has to be a random string with a minimum length of 43 characters and a maximum length of 128 characters. It can contain alphanumeric characters as well as the characters `-`, `.`, `_` and `~`.
153+
154+
Using this `code_verifier` string, a new one called `code_challenge` is created by using one of two methods:
155+
156+
- If you have the required functionality on your client, set `code_challenge` to be a URL-safe base64-encoded string of the SHA256 hash of `code_verifier`. In that case, your `code_challenge_method` becomes `S256`.
157+
- If you are unable to do so, you can provide your `code_verifier` as a plain string to `code_challenge`. Then you have to set your `code_challenge_method` as `plain`.
158+
159+
After you have generated this values, you can continue with your request.
160+
161+
1. Redirect the user to the authorization endpoint in order to get their consent for accessing the resources:
162+
163+
```curl
164+
https://[YOUR-GITEA-URL]/login/oauth/authorize?client_id=CLIENT_ID&redirect_uri=REDIRECT_URI&response_type=code&code_challenge_method=CODE_CHALLENGE_METHOD&code_challenge=CODE_CHALLENGE&state=STATE
165+
```
166+
167+
The `CLIENT_ID` can be obtained by registering an application in the settings. The `STATE` is a random string that will be sent back to your application after the user authorizes. The `state` parameter is optional, but should be used to prevent CSRF attacks.
168+
169+
![Authorization Page](/authorize.png)
170+
171+
The user will now be asked to authorize your application. If they authorize it, the user will be redirected to the `REDIRECT_URL`, for example:
172+
173+
```curl
174+
https://[REDIRECT_URI]?code=RETURNED_CODE&state=STATE
175+
```
176+
177+
2. Using the provided `code` from the redirect, you can request a new application and refresh token. The access token endpoint accepts POST requests with `application/json` and `application/x-www-form-urlencoded` body, for example:
178+
179+
```curl
180+
POST https://[YOUR-GITEA-URL]/login/oauth/access_token
181+
```
182+
183+
```json
184+
{
185+
"client_id": "YOUR_CLIENT_ID",
186+
"code": "RETURNED_CODE",
187+
"grant_type": "authorization_code",
188+
"redirect_uri": "REDIRECT_URI",
189+
"code_verifier": "CODE_VERIFIER",
190+
}
191+
```
192+
193+
Response:
194+
195+
```json
196+
{
197+
"access_token": "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJnbnQiOjIsInR0IjowLCJleHAiOjE1NTUxNzk5MTIsImlhdCI6MTU1NTE3NjMxMn0.0-iFsAwBtxuckA0sNZ6QpBQmywVPz129u75vOM7wPJecw5wqGyBkmstfJHAjEOqrAf_V5Z-1QYeCh_Cz4RiKug",
198+
"token_type": "bearer",
199+
"expires_in": 3600,
200+
"refresh_token": "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJnbnQiOjIsInR0IjoxLCJjbnQiOjEsImV4cCI6MTU1NzgwNDMxMiwiaWF0IjoxNTU1MTc2MzEyfQ.S_HZQBy4q9r5SEzNGNIoFClT43HPNDbUdHH-GYNYYdkRfft6XptJBkUQscZsGxOW975Yk6RbgtGvq1nkEcklOw"
201+
}
202+
```
138203

139204
The `REDIRECT_URI` in the `access_token` request must match the `REDIRECT_URI` in the `authorize` request.
140205

docs/content/doc/installation/from-source.en-us.md

+2
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ If pre-built frontend files are present it is possible to only build the backend
132132
TAGS="bindata" make backend
133133
```
134134

135+
Webpack source maps are by default enabled in development builds and disabled in production builds. They can be enabled by setting the `ENABLE_SOURCEMAP=true` environment variable.
136+
135137
## Test
136138

137139
After following the steps above, a `gitea` binary will be available in the working directory.

docs/content/doc/usage/actions/act-runner.en-us.md

+34
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,40 @@ It is because the act runner will run jobs in docker containers, so it needs to
172172
As mentioned, you can remove it if you want to run jobs in the host directly.
173173
To be clear, the "host" actually means the container which is running the act runner now, instead of the host machine.
174174

175+
### Configuring cache when starting a Runner using docker image
176+
177+
If you do not intend to use `actions/cache` in workflow, you can ignore this section.
178+
179+
If you use `actions/cache` without any additional configuration, it will return the following error:
180+
> Failed to restore: getCacheEntry failed: connect ETIMEDOUT IP:PORT
181+
182+
The error occurs because the runner container and job container are on different networks, so the job container cannot access the runner container.
183+
184+
Therefore, it is essential to configure the cache action to ensure its proper functioning. Follow these steps:
185+
186+
- 1.Obtain the LAN IP address of the host machine where the runner container is running.
187+
- 2.Find an available port number on the host machine where the runner container is running.
188+
- 3.Configure the following settings in the configuration file:
189+
190+
```yaml
191+
cache:
192+
enabled: true
193+
dir: ""
194+
# Use the LAN IP obtained in step 1
195+
host: "192.168.8.17"
196+
# Use the port number obtained in step 2
197+
port: 8088
198+
```
199+
200+
- 4.When starting the container, map the cache port to the host machine:
201+
202+
```bash
203+
docker run \
204+
--name gitea-docker-runner \
205+
-p 8088:8088 \
206+
-d gitea/act_runner:nightly
207+
```
208+
175209
### Labels
176210

177211
The labels of a runner are used to determine which jobs the runner can run, and how to run them.

0 commit comments

Comments
 (0)