-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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 black list and white list support for migrating repositories #8040
Conversation
WHITELISTED_DOMAINS = | ||
; Blacklist for migrating, default is blank. Multiple domains could be separated by commas. | ||
; When WHITELISTED_DOMAINS is not blank, this option will be ignored. | ||
BLACKLISTED_DOMAINS = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing EOL
return false, err | ||
} | ||
|
||
if strings.EqualFold(u.Scheme, "http") || strings.EqualFold(u.Scheme, "https") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why check the protocol? This will let ftp:
, git:
and ssh:
pass if one day they are supported. Perhaps it's better to check if the url is local and make any other protocol go through whitelisting/blacklisting.
if strings.EqualFold(u.Scheme, "http") || strings.EqualFold(u.Scheme, "https") { | ||
if len(setting.Migration.WhitelistedDomains) > 0 { | ||
if !whitelist.Match(u.Host) { | ||
return false, fmt.Errorf("Migrate from %v is not allowed", u.Host) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps a translatable error should be better?
var err error | ||
whitelist, err = matchlist.NewMatchlist(setting.Migration.WhitelistedDomains...) | ||
if err != nil { | ||
return fmt.Errorf("Init migration whitelist domains failed: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error will show up when the instance starts, right? I mean, the admin needs to see the errors as soon as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. It will display when gitea start.
47936c5
to
63a2947
Compare
A new rebase + make fmt to pick up the latest changes? |
63a2947
to
cdff51c
Compare
Codecov Report
@@ Coverage Diff @@
## master #8040 +/- ##
==========================================
+ Coverage 41.81% 41.81% +<.01%
==========================================
Files 482 484 +2
Lines 64557 64615 +58
==========================================
+ Hits 26993 27018 +25
- Misses 34095 34121 +26
- Partials 3469 3476 +7
Continue to review full report at Codecov.
|
@guillep2k done. |
} | ||
|
||
for _, rule := range list.rules { | ||
rg, err := glob.Compile(rule) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rg, err := glob.Compile(rule) | |
rg, err := glob.Compile(rule,[]string{".","/"}) |
I think that separators should work better if specified, so the tokenization is aware of the different parts of the glob.
} | ||
|
||
for _, rule := range list.rules { | ||
rg, err := glob.Compile(rule) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some case normalization should be used. For instance, if I black list: "google.com", someone could work around that by using "GOOGLE.COM".
Thinking about it, I can set up a DNS of mine pointing to whatever site I want and make it work around the domain blacklist. For example, the administrator wants to blacklist
|
@guillep2k in this PR there is also support for whitelist |
@lafriks Yes. The whitelist part is OK. The blacklist part has some holes, as noted above. I think they require some rework. |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 months. Thank you for your contributions. |
I maintain awesome-humane-tech and was advised to use ‘blocklist’ and ‘allowlist’ terminology instead (from a better inclusion / diversity perspective), and I wonder whether that would be better here too. From WikiDiff:
(and see also: http://garysaid.com/are-the-terms-whitelist-and-blacklist-racist/ ) Edit: See also IETF Recommendation (draft) |
@lunny do you work on this or should I catch it up? |
@6543 Please pick it up. |
follow up pull: #13610 |
Thank you for switching terminology, much appreciated 🙏 |
This PR will add two options
blacklist
andwhitelist
for migrating repositories from external URLs.When you set
whitelist
thenblacklist
will be ignored and all users on this gitea instance could only migrate repositories from thedomains
onwhitelist
.When
whitelist
is empty and you have domains onblacklist
, all users on this gitea instance could migrate repositories any domain except thedomains
onblacklist
.