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

Fix Actions being enabled accidentally #24802

Merged
merged 3 commits into from
May 19, 2023
Merged

Fix Actions being enabled accidentally #24802

merged 3 commits into from
May 19, 2023

Conversation

wolfogre
Copy link
Member

@wolfogre wolfogre commented May 19, 2023

Regression of #24536. If the user doesn't explicitly disable Actions, it will be enabled.

  1. Gitea will call loadRepositoryFrom before loadActionsFrom.
    loadRepositoryFrom(cfg)
    loadPictureFrom(cfg)
    loadPackagesFrom(cfg)
    loadActionsFrom(cfg)
  2. In loadRepositoryFrom, rootCfg.Section("actions").Key("ENABLED").MustBool(true) will set actions.ENABLED with true.
    if !rootCfg.Section("actions").Key("ENABLED").MustBool(true) {
    Repository.DisabledRepoUnits = append(Repository.DisabledRepoUnits, "repo.actions")
    }
  3. In loadActionsFrom, rootCfg.Section("actions") will get a section with Actions enabled.
    sec := rootCfg.Section("actions")
    if err := sec.MapTo(&Actions); err != nil {
    log.Fatal("Failed to map Actions settings: %v", err)
    }

Although the cause of the problem was using true by copy-paste mistake, it also surprised me that rootCfg.Section("actions").Key("ENABLED").MustBool(true) doesn't only read, but also write.

@wolfogre wolfogre added type/bug outdated/backport/v1.19 This PR should be backported to Gitea 1.19 labels May 19, 2023
@wolfogre wolfogre added this to the 1.20.0 milestone May 19, 2023
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label May 19, 2023
@pull-request-size pull-request-size bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label May 19, 2023
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels May 19, 2023
@silverwind
Copy link
Member

I'm surprised there was no such line before #24536, so action.ENABLED previously defaulted to nil?

@wolfogre
Copy link
Member Author

wolfogre commented May 19, 2023

I'm surprised there was no such line before #24536, so action.ENABLED previously defaulted to nil?

Uh ... yes:

  • actions.ENABLED defaulted to nil
  • But Actions.Enabled defaulted to false

(Not sure if it's the right way)

Actions = struct {
Storage // how the created logs should be stored
Enabled bool
DefaultActionsURL string `ini:"DEFAULT_ACTIONS_URL"`
}{
Enabled: false,
DefaultActionsURL: "https://gitea.com",
}

@silverwind
Copy link
Member

I see. I think this config system is in for an rewrite anyways, I don't like that there are two places to define a default, and the casing difference is also confusing and unnecessary.

I'd like us to use https://github.com/kelseyhightower/envconfig and map back the env vars to the config struct, but it will be a massive rewrite.

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels May 19, 2023
@lunny
Copy link
Member

lunny commented May 19, 2023

I see. I think this config system is in for an rewrite anyways, I don't like that there are two places to define a default, and the casing difference is also confusing and unnecessary.

I'd like us to use https://github.com/kelseyhightower/envconfig and map back the env vars to the config struct, but it will be a massive rewrite.

I think @silverwind is right. Maybe we should use the variable instead of the false here. @wolfogre

@silverwind
Copy link
Member

silverwind commented May 19, 2023

See #24804 for some ideas regarding config system.

@wolfogre
Copy link
Member Author

I see. I think this config system is in for an rewrite anyways, I don't like that there are two places to define a default, and the casing difference is also confusing and unnecessary.
I'd like us to use kelseyhightower/envconfig and map back the env vars to the config struct, but it will be a massive rewrite.

I think @silverwind is right. Maybe we should use the variable instead of the false here. @wolfogre

Done: 845f86e

@lunny lunny added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label May 19, 2023
@lunny lunny merged commit 7985cde into go-gitea:main May 19, 2023
GiteaBot pushed a commit to GiteaBot/gitea that referenced this pull request May 19, 2023
Regression of go-gitea#24536. If the user doesn't explicitly disable Actions, it
will be enabled.

1. Gitea will call `loadRepositoryFrom` before `loadActionsFrom`.

https://github.com/go-gitea/gitea/blob/25d4f95df25dae5226e96e813dde87b071d9155e/modules/setting/setting.go#L234-L237
2. In `loadRepositoryFrom`,
`rootCfg.Section("actions").Key("ENABLED").MustBool(true)` will set
`actions.ENABLED` with `true`.

https://github.com/go-gitea/gitea/blob/25d4f95df25dae5226e96e813dde87b071d9155e/modules/setting/repository.go#L313-L315
3. In `loadActionsFrom`, `rootCfg.Section("actions")` will get a section
with Actions enabled.

https://github.com/go-gitea/gitea/blob/25d4f95df25dae5226e96e813dde87b071d9155e/modules/setting/actions.go#L23-L26

Although the cause of the problem was using `true` by copy-paste
mistake, it also surprised me that
**`rootCfg.Section("actions").Key("ENABLED").MustBool(true)` doesn't
only read, but also write.**
@GiteaBot GiteaBot added backport/done All backports for this PR have been created and removed reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. labels May 19, 2023
silverwind pushed a commit that referenced this pull request May 19, 2023
Backport #24802 by @wolfogre

Regression of #24536. If the user doesn't explicitly disable Actions, it
will be enabled.

1. Gitea will call `loadRepositoryFrom` before `loadActionsFrom`.

https://github.com/go-gitea/gitea/blob/25d4f95df25dae5226e96e813dde87b071d9155e/modules/setting/setting.go#L234-L237
2. In `loadRepositoryFrom`,
`rootCfg.Section("actions").Key("ENABLED").MustBool(true)` will set
`actions.ENABLED` with `true`.

https://github.com/go-gitea/gitea/blob/25d4f95df25dae5226e96e813dde87b071d9155e/modules/setting/repository.go#L313-L315
3. In `loadActionsFrom`, `rootCfg.Section("actions")` will get a section
with Actions enabled.

https://github.com/go-gitea/gitea/blob/25d4f95df25dae5226e96e813dde87b071d9155e/modules/setting/actions.go#L23-L26


Although the cause of the problem was using `true` by copy-paste
mistake, it also surprised me that
**`rootCfg.Section("actions").Key("ENABLED").MustBool(true)` doesn't
only read, but also write.**

Co-authored-by: Jason Song <i@wolfogre.com>
silverwind added a commit to bl00mber/gitea that referenced this pull request May 21, 2023
* main: (90 commits)
  Refactor rename user and rename organization (go-gitea#24052)
  Use `CommentList` instead of `[]*Comment` (go-gitea#24828)
  Fix topics deleted via API not being deleted in org page (go-gitea#24825)
  Return `404` in the API if the requested webhooks were not found (go-gitea#24823)
  Decouple the different contexts from each other (go-gitea#24786)
  [skip ci] Updated translations via Crowdin
  Add RTL rendering support to Markdown (go-gitea#24816)
  [skip ci] Updated translations via Crowdin
  Update JS dependencies (go-gitea#24815)
  Fix duplicate tooltip hiding (go-gitea#24814)
  Mute repo names in dashboard repo list (go-gitea#24811)
  Rework label colors (go-gitea#24790)
  Fix max width and margin of comment box on conversation page (go-gitea#24809)
  Allow all URL schemes in Markdown links by default (go-gitea#24805)
  Some refactors for issues stats (go-gitea#24793)
  Implement actions artifacts (go-gitea#22738)
  Fix Actions being enabled accidentally (go-gitea#24802)
  Change `add_on` in `keys_ssh.tmpl` (go-gitea#24803)
  replace `drone exec` to `act_runner exec` in test README.md (go-gitea#24791)
  Fix OAuth loading state (go-gitea#24788)
  ...
Codeberg-org pushed a commit to Codeberg-org/gitea that referenced this pull request Jun 3, 2023
Backport go-gitea#24802 by @wolfogre

Regression of go-gitea#24536. If the user doesn't explicitly disable Actions, it
will be enabled.

1. Gitea will call `loadRepositoryFrom` before `loadActionsFrom`.

https://github.com/go-gitea/gitea/blob/25d4f95df25dae5226e96e813dde87b071d9155e/modules/setting/setting.go#L234-L237
2. In `loadRepositoryFrom`,
`rootCfg.Section("actions").Key("ENABLED").MustBool(true)` will set
`actions.ENABLED` with `true`.

https://github.com/go-gitea/gitea/blob/25d4f95df25dae5226e96e813dde87b071d9155e/modules/setting/repository.go#L313-L315
3. In `loadActionsFrom`, `rootCfg.Section("actions")` will get a section
with Actions enabled.

https://github.com/go-gitea/gitea/blob/25d4f95df25dae5226e96e813dde87b071d9155e/modules/setting/actions.go#L23-L26

Although the cause of the problem was using `true` by copy-paste
mistake, it also surprised me that
**`rootCfg.Section("actions").Key("ENABLED").MustBool(true)` doesn't
only read, but also write.**

Co-authored-by: Jason Song <i@wolfogre.com>
(cherry picked from commit b369ed5)
@go-gitea go-gitea locked as resolved and limited conversation to collaborators Aug 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backport/done All backports for this PR have been created lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. outdated/backport/v1.19 This PR should be backported to Gitea 1.19 size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants