Skip to content

Commit 55cf8d9

Browse files
authored
Nits and Bugfixes (#2)
1 parent 885d9c8 commit 55cf8d9

7 files changed

Lines changed: 95 additions & 43 deletions

File tree

.github/workflows/lint.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: golangci-lint
2+
on:
3+
# push:
4+
# branches:
5+
# - master
6+
pull_request:
7+
branches:
8+
- main
9+
# schedule:
10+
# # Trigger every day at 16:00 UTC
11+
# - cron: '0 16 * * *'
12+
jobs:
13+
golangci-pr:
14+
if: github.ref != 'refs/heads/main'
15+
name: lint-pr-changes
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/setup-go@v3
19+
- uses: actions/checkout@v3
20+
- name: golangci-lint
21+
uses: golangci/golangci-lint-action@v3
22+
with:
23+
version: v1.48.0
24+
only-new-issues: true
25+
26+
# golangci-main:
27+
# if: github.ref == 'refs/heads/main'
28+
# name: lint-main-all
29+
# runs-on: ubuntu-latest
30+
# steps:
31+
# - uses: actions/setup-go@v3
32+
# - uses: actions/checkout@v3
33+
# - name: golangci-lint
34+
# uses: golangci/golangci-lint-action@v3
35+
# with:
36+
# version: v1.48.0
37+
# only-new-issues: true
38+
# args: --issues-exit-code=0

.github/workflows/main.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,18 @@ on:
1111
pull_request:
1212

1313
jobs:
14-
build:
14+
test:
1515
runs-on: ubuntu-latest
1616

17-
strategy:
18-
matrix:
19-
go-version: ['1.19']
20-
2117
steps:
2218

2319
- name: Checkout
2420
uses: actions/checkout@v3
2521

26-
- name: Set up Go ${{ matrix.go-version }}
22+
- name: Set up Go 1.19
2723
uses: actions/setup-go@v3
2824
with:
29-
go-version: ${{ matrix.go-version }}
25+
go-version: 1.19
3026
cache: true
3127

3228
- name: Display Go Version

Makefile

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,49 @@
1+
AWS_ACCOUNTID=$$(aws sts get-caller-identity --query Account --output text)
2+
3+
.PHONY: build
14
build:
2-
docker build --progress plain -t webdestroya/remote-shell:latest -f docker/Dockerfile .
5+
docker build --progress plain -t ghcr.io/webdestroya/remote-shell:latest -f docker/Dockerfile .
36

7+
.PHONY: buildtest
48
buildtest:
59
docker build -t shelltest:latest -f docker/Dockerfile.usage .
610

7-
runtest:
8-
docker run --rm -p 8722:8722 --privileged cloud87/shelltest:latest /cloud87/bin/remote-shell -user webdestroya
9-
10-
runversion:
11-
docker run --rm shelltest:latest /cloud87/bin/remote-shell -version
12-
13-
compile:
11+
.PHONY: clean
12+
clean:
1413
rm -f remote-shell
15-
go build -a -o remote-shell
1614

17-
compile-version:
18-
go build -ldflags="-X 'main.buildVersion=v1'" -a -o remote-shell
15+
.PHONY: compile
16+
compile: clean
17+
go build -a -o remote-shell
1918

20-
gomod:
19+
.PHONY: tidy
20+
tidy:
21+
go mod verify
2122
go mod tidy
23+
@if ! git diff --quiet go.mod go.sum; then \
24+
echo "please run go mod tidy and check in changes, you might have to use the same version of Go as the CI"; \
25+
exit 1; \
26+
fi
27+
28+
# lint:
29+
# docker run --rm -v $$(pwd):/app -w /app golangci/golangci-lint:v1.49.0 golangci-lint run -v
2230

31+
.PHONY: lint-install
32+
lint-install:
33+
@echo "Installing golangci-lint"
34+
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.46.2
35+
36+
.PHONY: lint
2337
lint:
24-
docker run --rm -v $$(pwd):/app -w /app golangci/golangci-lint:v1.49.0 golangci-lint run -v
38+
@which golangci-lint >/dev/null 2>&1 || { \
39+
echo "golangci-lint not found, please run: make lint-install"; \
40+
exit 1; \
41+
}
42+
golangci-lint run
43+
44+
# This is for easy testing
45+
.PHONY: pushtest
46+
pushtest: build buildtest
47+
aws ecr get-login-password | docker login --username AWS --password-stdin $(AWS_ACCOUNTID).dkr.ecr.us-east-1.amazonaws.com
48+
docker tag shelltest:latest $(AWS_ACCOUNTID).dkr.ecr.us-east-1.amazonaws.com/cloud87/remote-shell-test:latest
49+
docker push $(AWS_ACCOUNTID).dkr.ecr.us-east-1.amazonaws.com/cloud87/remote-shell-test:latest

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ This will pull your public keys from GitHub and use those for SSH authentication
1212
## Configuration
1313
| Flag | Description |
1414
| ------------- | ------------- |
15-
| `-user` | The GitHub user to pull keys for<br>**Required** |
16-
| `-port` | The remote port for the SSH server<br>Default: `8722` |
17-
| `-shell` | The shell command to execute.<br>Default: `/bin/bash` or `/bin/sh` |
18-
| `-idletime` | If the connection is idle for more than X seconds, terminate the connection. Setting to `0` disables.<br>Default: `0` (disabled) |
19-
| `-maxtime` | Maximum duration of a session.<br>Default: `12h` |
20-
| `-grace` | How long to wait for a connection before we just terminate.<br>Default: `30m` |
21-
| `-insecure` | If you do not have CA Certificates installed, you can bypass SSL verification.<br>Not Recommended in production<br>Default: `false`
15+
| `user` | The GitHub user to pull keys for<br>**Required** |
16+
| `port` | The remote port for the SSH server<br>Default: `8722` |
17+
| `shell` | The shell command to execute.<br>Default: `/bin/bash` or `/bin/sh` |
18+
| `idletime` | If the connection is idle for more than X seconds, terminate the connection. Setting to `0` disables.<br>Default: `0` (disabled) |
19+
| `maxtime` | Maximum duration of a session.<br>Default: `12h` |
20+
| `grace` | How long to wait for a connection before we just terminate.<br>Default: `30m` |
21+
| `insecure` | If you do not have CA Certificates installed, you can bypass SSL verification.<br>Not Recommended in production<br>Default: `false`
2222

2323
> Note: Any of the arguments can be provided using environment variables by prefixing the flag with `C87RS_` (i.e. `C87RS_PORT`)
2424
@@ -46,7 +46,7 @@ This image contains a binary that was built on Alpine Linux. If you are using an
4646

4747
In your `Dockerfile`:
4848

49-
```docker
49+
```dockerfile
5050
FROM anything
5151
# ...
5252

@@ -57,12 +57,12 @@ COPY --from=ghrc.io/webdestroya/remote-shell:latest /cloud87 /cloud87
5757
Then you can launch the container:
5858

5959
```
60-
$ docker run --rm -p 8722:8722 myapp:latest /cloud87/bin/remote-shell -user your-github-username
60+
$ docker run -p 8722:8722 myapp:latest /cloud87/bin/remote-shell -user your-github-username
6161
```
6262

6363
And connect to it on your client:
6464

65-
```
65+
```sh
6666
ssh -p 8722 \
6767
-o StrictHostKeyChecking=no \
6868
-o "UserKnownHostsFile=/dev/null" \

docker/Dockerfile.usage

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
FROM ubuntu
22

3-
43
# You don't need to install all this, it's just helpful for debugging
54
RUN apt-get update \
65
&& apt-get install -y --no-install-recommends \
7-
curl \
86
ca-certificates \
9-
vim \
107
strace \
118
\
129
&& rm -rf /var/lib/apt/lists/*
1310

14-
COPY --from=cloud87/remote-shell:latest /cloud87 /cloud87
15-
COPY --from=cloud87/remote-shell:latest /cloud87-alpine /cloud87-alpine
16-
11+
COPY --from=ghcr.io/webdestroya/remote-shell:latest /cloud87 /cloud87
1712

options.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"log"
77
"os"
88
"os/exec"
9-
"os/user"
109
"path/filepath"
1110
"time"
1211
)
@@ -27,7 +26,7 @@ type RemoteShellOptions struct {
2726
// TODO: should we allow multiple sessions?
2827
allowMultipleSessions bool
2928

30-
currentUser *user.User
29+
currentUserName string
3130
}
3231

3332
func determineDefaultShell() string {
@@ -106,8 +105,7 @@ func parseCommandFlags() RemoteShellOptions {
106105
shellCommand, err := exec.LookPath(shellCommandFlag)
107106
check(err)
108107

109-
curUser, err := user.Current()
110-
check(err)
108+
curUserName := fetchEnvValue("USER", fetchEnvValue("LOGNAME", "root"))
111109

112110
return RemoteShellOptions{
113111
username: usernameFlag,
@@ -119,6 +117,6 @@ func parseCommandFlags() RemoteShellOptions {
119117
connectionGrace: graceFlag,
120118
insecureMode: insecureModeFlag,
121119
allowMultipleSessions: false,
122-
currentUser: curUser,
120+
currentUserName: curUserName,
123121
}
124122
}

ssh.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ func sessionHandler(options *RemoteShellOptions, notify chan bool, s ssh.Session
5555
cmd.Env = append(filteredEnvironmentVars(),
5656
fmt.Sprintf("TERM=%s", ptyReq.Term),
5757
fmt.Sprintf("HOME=%s", options.homeDir),
58-
fmt.Sprintf("USER=%s", options.currentUser.Username),
59-
fmt.Sprintf("LOGNAME=%s", options.currentUser.Username),
58+
fmt.Sprintf("USER=%s", options.currentUserName),
59+
fmt.Sprintf("LOGNAME=%s", options.currentUserName),
6060
fmt.Sprintf("SHELL=%s", options.shellCommand),
6161
fmt.Sprintf("C87RS_SESSIONID=%s", s.Context().SessionID()),
6262
)

0 commit comments

Comments
 (0)