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

Allow custom SSH user in UI for built-in SSH server (#2617) #2678

Merged
merged 7 commits into from
Oct 14, 2017
Merged

Allow custom SSH user in UI for built-in SSH server (#2617) #2678

merged 7 commits into from
Oct 14, 2017

Conversation

pgaskin
Copy link
Contributor

@pgaskin pgaskin commented Oct 8, 2017

This allows a custom username to be set for the built-in SSH server.

It adds the config option BUILTIN_SSH_USER in the [server] section. If this option is missing or empty, it defaults to the RUN_USER (which was the default before), and it it is present and the built-in SSH server is enabled, then it uses the custom user for the built-in SSH server.

This does not introduce any compatibility issues with old versions.

I have tested this feature.

See issue #2617

@codecov-io
Copy link

codecov-io commented Oct 8, 2017

Codecov Report

Merging #2678 into master will decrease coverage by <.01%.
The diff coverage is 28.57%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2678      +/-   ##
==========================================
- Coverage   27.38%   27.38%   -0.01%     
==========================================
  Files          86       86              
  Lines       17010    17014       +4     
==========================================
+ Hits         4658     4659       +1     
- Misses      11673    11675       +2     
- Partials      679      680       +1
Impacted Files Coverage Δ
models/repo.go 13.17% <28.57%> (+0.02%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 514006a...9706d5b. Read the comment docs.

@tboerger tboerger added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Oct 8, 2017
@lafriks
Copy link
Member

lafriks commented Oct 8, 2017

LGTM

@tboerger tboerger 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 Oct 8, 2017
@lafriks lafriks added the type/enhancement An improvement of existing functionality label Oct 8, 2017
@lafriks lafriks added this to the 1.3.0 milestone Oct 8, 2017
@lunny
Copy link
Member

lunny commented Oct 9, 2017

It's not format well

@pgaskin
Copy link
Contributor Author

pgaskin commented Oct 9, 2017

@lunny You mean I need to run gofmt?

@daviian
Copy link
Member

daviian commented Oct 9, 2017

@geek1011 You can use make fmt too

@bkcsoft
Copy link
Member

bkcsoft commented Oct 9, 2017

Shouldn't that user be verified in the builtin ssh-server as well?

@pgaskin
Copy link
Contributor Author

pgaskin commented Oct 9, 2017

@bkcsoft no, that would introduce compatibility issues and an unnecessary check. The SSH user for the built-in SSH server has no real meaning.

@pgaskin
Copy link
Contributor Author

pgaskin commented Oct 11, 2017

I did make fmt.

@pgaskin
Copy link
Contributor Author

pgaskin commented Oct 11, 2017

Can this be merged now?

Copy link
Member

@Morlinest Morlinest left a comment

Choose a reason for hiding this comment

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

Some suggestions

@@ -720,6 +722,8 @@ func NewContext() {
SSH.StartBuiltinServer = false
}

SSH.BuiltinServerUser = sec.Key("BUILTIN_SSH_USER").MustString("")
Copy link
Member

Choose a reason for hiding this comment

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

Can this be changed to SSH.BuiltinServerUser = sec.Key("BUILTIN_SSH_USER").MustString(RunUser)?

Copy link
Contributor Author

@pgaskin pgaskin Oct 11, 2017

Choose a reason for hiding this comment

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

It is set to the runuser if blank a bit further down. I cannot combine them because this one requires the server sec variable, and the runuser is set further down. (Line 922)

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I saw that line. Can you move this setup line down as BuiltinSSHServerUser is not used between lines 725 and 922?

@@ -104,6 +105,7 @@ var (
}{
Disabled: false,
StartBuiltinServer: false,
BuiltinServerUser: "",
Copy link
Member

Choose a reason for hiding this comment

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

Why setting default string value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll remove that.

conf/app.ini Outdated
@@ -113,6 +113,8 @@ LOCAL_ROOT_URL = %(PROTOCOL)s://%(HTTP_ADDR)s:%(HTTP_PORT)s/
DISABLE_SSH = false
; Whether use builtin SSH server or not.
START_SSH_SERVER = false
; Username to use for builtin SSH server. If blank, then it is the value of RUN_USER.
BUILTIN_SSH_USER =
Copy link
Member

Choose a reason for hiding this comment

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

IMO is better to use name like BUILTIN_SSH_SERVER_USER.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I change it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have changed it.

- Renamed config to BUILTIN_SSH_SERVER_USER
- Removed unnecessary default string value for config item
@@ -915,6 +918,10 @@ func NewContext() {
}
}

if SSH.BuiltinSSHServerUser == "" {
SSH.BuiltinSSHServerUser = RunUser
Copy link
Member

Choose a reason for hiding this comment

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

Couldn't we do simply SSH.BuiltinSSHServerUser = sec.Key("BUILTIN_SSH_USER").MustString(RunUser) here ?

Copy link
Member

Choose a reason for hiding this comment

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

@sapk That's my question :D

Copy link
Member

Choose a reason for hiding this comment

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

@Morlinest sorry I haven't look at others reviews. just quickly look at it ^^

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So my code is fine?

Copy link
Member

Choose a reason for hiding this comment

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

What we suggest is that you move (and add the RunUser as default) L724 SSH.BuiltinSSHServerUser = sec.Key("BUILTIN_SSH_USER").MustString(RunUser) in place of L921-924

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sapk It cannot happen because sec is redefined in between those spots. That's why I have the two lines.

Copy link
Member

@Morlinest Morlinest Oct 12, 2017

Choose a reason for hiding this comment

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

Cfg.Section("server").Key("BUILTIN_SSH_SERVER_USER").MustString(RunUser)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Morlinest I didn't know about that one. Thanks. I'll try it.

@pgaskin
Copy link
Contributor Author

pgaskin commented Oct 12, 2017

@sapk @Morlinest I have updated according to your review.

@@ -915,6 +916,8 @@ func NewContext() {
}
}

SSH.BuiltinSSHServerUser = Cfg.Section("server").Key("BUILTIN_SSH_USER").MustString(RunUser)
Copy link
Member

Choose a reason for hiding this comment

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

BUILTIN_SSH_SERVER_USER

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops

@@ -90,6 +90,7 @@ var (
SSH = struct {
Disabled bool `ini:"DISABLE_SSH"`
StartBuiltinServer bool `ini:"START_SSH_SERVER"`
BuiltinSSHServerUser string `ini:"BUILTIN_SSH_SERVER_USER"`
Copy link
Member

Choose a reason for hiding this comment

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

Idea: What about changing BuiltinSSHServerUser to BuiltinServerUser. Then reading config inside go setting.SSH.BuiltinServerUser. Also "builtin" word can be removed so it would be more consistent with other ssh settings. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll remove the SSH from the var name. Since this user only applies to the internal server, I'll keep the Builtin

Copy link
Member

Choose a reason for hiding this comment

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

Good point. The last thing: SSH_BUILTIN_SERVER_USER instead of BUILTIN_SSH_SERVER_USER?

@pgaskin
Copy link
Contributor Author

pgaskin commented Oct 12, 2017

@Morlinest should be fixed now.

@lafriks
Copy link
Member

lafriks commented Oct 14, 2017

@Morlinest need your approval

@Morlinest
Copy link
Member

@lafriks Waiting for response (last thing), I think SSH_BUILTIN_SERVER_USER would be better than BUILTIN_SSH_SERVER_USER.

@pgaskin
Copy link
Contributor Author

pgaskin commented Oct 14, 2017

@Morlinest how many times do you have to change your mind?

@lafriks
Copy link
Member

lafriks commented Oct 14, 2017

@Morlinest I think current is better as SSH_BUILTIN_SERVER_USER does not sound correct in English

@Morlinest
Copy link
Member

Morlinest commented Oct 14, 2017

@lafriks I meant SSH_ as prefix in config. In code it translates to SSH.BuiltinServerUser.

@Morlinest
Copy link
Member

@geek1011 I was asking about another idea after accepting your opinion. I don't see anything bad on it.

@Morlinest
Copy link
Member

@lafriks Same as SSH_BACKUP_AUTHORIZED_KEYS or SSH_EXPOSE_ANONYMOUS

@lafriks
Copy link
Member

lafriks commented Oct 14, 2017

@Morlinest not really:
SSH_BUILTIN_SERVER_USER -> built-in server in ssh
BUILTIN_SSH_SERVER_USER -> built-in ssh server

@Morlinest
Copy link
Member

@lafriks OK, I accept your interpretation.

LGTM

@tboerger tboerger 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 Oct 14, 2017
@lafriks
Copy link
Member

lafriks commented Oct 14, 2017

Make LG-TM work again

@lafriks lafriks merged commit e89bb7e into go-gitea:master Oct 14, 2017
@go-gitea go-gitea locked and limited conversation to collaborators Nov 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants