Skip to content

Commit 94dbcba

Browse files
authored
Feature/authkeys (#1)
* updates * updates
1 parent 399dfa1 commit 94dbcba

File tree

10 files changed

+503
-124
lines changed

10 files changed

+503
-124
lines changed

.github/workflows/release.yml

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
2+
name: Release
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
branch:
7+
description: "The branch that will be built"
8+
required: true
9+
version:
10+
description: "The version to release (must be prefixed with 'v')"
11+
required: true
12+
13+
env:
14+
VERSION: ${{ github.event.inputs.version }}
15+
GH_TOKEN: ${{ secrets.GORELEASER_GITHUB_TOKEN }}
16+
17+
jobs:
18+
goreleaser:
19+
name: Build
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v3
25+
with:
26+
ref: ${{ github.event.inputs.branch }}
27+
28+
- name: Unshallow
29+
run: git fetch
30+
31+
- name: Set up Go
32+
uses: actions/setup-go@v3
33+
with:
34+
go-version: 1.19
35+
36+
# - name: Hook private repo
37+
# run: git config --global url."https://${{ secrets.GORELEASER_GITHUB_TOKEN }}:x-oauth-basic@github.com".insteadOf "https://github.com"
38+
39+
- name: Run GoReleaser
40+
uses: goreleaser/goreleaser-action@v3
41+
with:
42+
version: latest
43+
args: release --snapshot --rm-dist --skip-publish
44+
env:
45+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46+
47+
- name: Move build artifacts
48+
run: |
49+
mkdir ~/artifacts
50+
mv $GITHUB_WORKSPACE/dist/remote-shell_linux_amd64.tar.gz ~/artifacts/linux.tar.gz
51+
mv $GITHUB_WORKSPACE/dist/remote-shell_darwin_amd64.zip ~/artifacts/darwin.zip
52+
53+
- name: List Build Artifacts
54+
run: ls -l ~/artifacts
55+
56+
- name: Save Linux Build Artifact
57+
uses: actions/upload-artifact@v3
58+
with:
59+
name: build-artifact-linux
60+
path: ~/artifacts/linux.tar.gz
61+
if-no-files-found: error
62+
63+
- name: Save MacOS Build Artifact
64+
uses: actions/upload-artifact@v3
65+
with:
66+
name: build-artifact-darwin
67+
path: ~/artifacts/darwin.zip
68+
if-no-files-found: error
69+
70+
create_release_tag:
71+
name: Tag Release
72+
needs: [goreleaser]
73+
runs-on: ubuntu-latest
74+
steps:
75+
76+
- name: Trim asset version prefix and Validate
77+
run: |-
78+
echo $VERSION
79+
trim=${VERSION#"v"}
80+
echo $trim
81+
if [[ $trim =~ ^[0-9]+\.[0-9]+\.[0-9]+(-.+)?$ ]]; then
82+
echo "Version OK: $trim"
83+
else
84+
echo "Invalid version: $trim"
85+
exit 1
86+
fi
87+
echo "VERSION=${trim}" >> $GITHUB_ENV
88+
89+
- name: Checkout
90+
uses: actions/checkout@v3
91+
with:
92+
ref: ${{ github.event.inputs.branch }}
93+
94+
- name: Unshallow
95+
run: git fetch --prune --unshallow
96+
97+
- name: Tag Release
98+
run: |
99+
git config user.name "Cloud87 GitHub Actions Bot"
100+
git config user.email noreply@github.com
101+
git tag ${{ github.event.inputs.version }}
102+
git push origin ${{ github.event.inputs.version }}
103+
104+
ensure_branch_in_homebrew:
105+
name: Ensure branch exists in homebrew-tap
106+
needs: [create_release_tag]
107+
runs-on: ubuntu-latest
108+
steps:
109+
- name: Parse semver string
110+
id: semver_parser
111+
uses: booxmedialtd/ws-action-parse-semver@v1
112+
with:
113+
input_string: ${{ github.event.inputs.version }}
114+
115+
- name: Checkout
116+
if: steps.semver_parser.outputs.prerelease == ''
117+
uses: actions/checkout@v3
118+
with:
119+
repository: webdestroya/homebrew-tap
120+
token: ${{ secrets.GORELEASER_GITHUB_TOKEN }}
121+
ref: main
122+
123+
- name: Delete base branch if exists
124+
if: steps.semver_parser.outputs.prerelease == ''
125+
run: |
126+
git fetch --all
127+
git push origin --delete bump-brew
128+
git push origin --delete $VERSION
129+
continue-on-error: true
130+
131+
- name: Create base branch
132+
if: steps.semver_parser.outputs.prerelease == ''
133+
run: |
134+
git checkout -b bump-brew
135+
git push --set-upstream origin bump-brew
136+
137+
create_release:
138+
name: Release
139+
needs: [create_release_tag, ensure_branch_in_homebrew]
140+
runs-on: ubuntu-latest
141+
steps:
142+
- name: Checkout
143+
uses: actions/checkout@v3
144+
with:
145+
ref: ${{ github.event.inputs.version }}
146+
147+
- name: Set up Go
148+
uses: actions/setup-go@v3
149+
with:
150+
go-version: 1.19
151+
152+
- name: Run GoReleaser
153+
uses: goreleaser/goreleaser-action@v3
154+
with:
155+
version: latest
156+
args: release --rm-dist
157+
env:
158+
GITHUB_TOKEN: ${{ secrets.GORELEASER_GITHUB_TOKEN }}
159+
160+
161+
create_pr_in_homebrew:
162+
name: Create PR in homebrew-tap
163+
needs: [ensure_branch_in_homebrew, create_release]
164+
runs-on: ubuntu-latest
165+
env:
166+
Version: ${{ github.event.inputs.version }}
167+
steps:
168+
- name: Parse semver string
169+
id: semver_parser
170+
uses: booxmedialtd/ws-action-parse-semver@v1
171+
with:
172+
input_string: ${{ github.event.inputs.version }}
173+
174+
- name: Checkout
175+
if: steps.semver_parser.outputs.prerelease == ''
176+
uses: actions/checkout@v3
177+
with:
178+
repository: webdestroya/homebrew-tap
179+
token: ${{ secrets.GORELEASER_GITHUB_TOKEN }}
180+
ref: main
181+
182+
- name: Create a new branch off the base branch
183+
if: steps.semver_parser.outputs.prerelease == ''
184+
run: |
185+
git fetch --all
186+
git checkout bump-brew
187+
git checkout -b rshell/$VERSION
188+
git push --set-upstream origin rshell/$VERSION
189+
190+
- name: Close pull request if already exists
191+
if: steps.semver_parser.outputs.prerelease == ''
192+
run: |
193+
gh pr close rshell/$VERSION
194+
continue-on-error: true
195+
196+
- name: Create pull request
197+
if: steps.semver_parser.outputs.prerelease == ''
198+
run: |
199+
gh pr create --base main --head rshell/$VERSION --title "[RShell] $Version" --body "Update formula"

.goreleaser.yaml

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This is an example .goreleaser.yml file with some sensible defaults.
22
# Make sure to check the documentation at https://goreleaser.com
33

4-
project_name: remote-shell-client
4+
project_name: remote-shell
55

66
before:
77
hooks:
@@ -18,7 +18,7 @@ builds:
1818
- arm64
1919

2020
id: rshell
21-
# binary: 'remote-shell'
21+
binary: 'remote-shell'
2222
ldflags:
2323
- "-s -w -X main.buildVersion={{.Version}} -X main.buildSha={{.Commit}}"
2424

@@ -36,6 +36,7 @@ archives:
3636
- none*
3737
format: zip
3838
id: homebrew
39+
# name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}_{{ .Version }}"
3940
name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}"
4041
format_overrides:
4142
- goos: linux
@@ -49,19 +50,14 @@ release:
4950
draft: true
5051
changelog:
5152
skip: true
52-
# sort: asc
53-
# filters:
54-
# exclude:
55-
# - '^docs:'
56-
# - '^test:'
57-
53+
5854
announce:
5955
skip: true
6056

6157
brews:
6258
- ids:
6359
- homebrew
64-
name: cloud87-remote-shell
60+
name: remote-shell
6561
tap:
6662
owner: webdestroya
6763
name: homebrew-tap
@@ -71,12 +67,28 @@ brews:
7167
homepage: "https://github.com/webdestroya/remote-shell-client"
7268
description: "Allows easy remote access to containerized applications running on Fargate"
7369
skip_upload: auto
70+
license: "MIT"
7471
install: |-
7572
bin.install "remote-shell"
7673
7774
universal_binaries:
78-
-
79-
id: rshell
80-
# name_template: "{{ .ProjectName }}_{{ .Version }}"
81-
name_template: "{{ .ProjectName }}"
82-
replace: true
75+
- id: rshell
76+
# name_template: "{{ .ProjectName }}_{{ .Version }}"
77+
name_template: "{{ .ProjectName }}"
78+
replace: false
79+
80+
nfpms:
81+
- id: "rshell"
82+
builds: ['rshell']
83+
formats:
84+
- deb
85+
- rpm
86+
- apk
87+
vendor: "cloud87.io"
88+
homepage: "https://github.com/webdestroya/remote-shell-client/"
89+
maintainer: "Mitch Dempsey <webdestroya@noreply.github.com>"
90+
description: "Allows easy remote access to containerized applications running on Fargate"
91+
# file_name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}_{{ .Version }}"
92+
file_name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}"
93+
rpm:
94+
summary: "Allows easy remote access to containerized applications running on Fargate"

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ clean:
55

66
.PHONY: compile
77
compile: clean
8-
go build -a -o remote-shell-client -ldflags="-s -w"
8+
go build -o remote-shell-client -ldflags="-s -w"
99
stat remote-shell-client
1010

1111
.PHONY: tidy
@@ -29,3 +29,7 @@ lint:
2929
exit 1; \
3030
}
3131
golangci-lint run
32+
33+
.PHONY: test-release
34+
test-release:
35+
goreleaser release --skip-publish --rm-dist --snapshot

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22

33
This program makes it dead simple to launch a task using the [webdestroya/remote-shell](https://github.com/webdestroya/remote-shell) service.
44

5+
## Installation
6+
7+
8+
## Usage
9+
10+
To launch a remote shell session, you only need to know the task definition prefix. By default, it is assumed that your task definition is whatever you enter for the `app` parameter, but with `-console` appended.
11+
12+
If you do not have a console suffix, then add `-exact` to your command.
13+
14+
```
15+
remote-shell-client -app myapp
16+
```
517

618
## Task Configuration
719
To use this, you must add a docker label to your ECS Task Definition on the container that will be used for the shell.
@@ -15,10 +27,9 @@ The label must be named `cloud87.rshell` and should contain a JSON object with t
1527
| `security_groups` | Array | List of SecurityGroupIDs to use for the network interface |
1628
| `port` | Integer | The port that should be used for the SSH service |
1729
| `public` | Boolean | Whether or not this container will be given a public IP address |
30+
| `path` | String | Path to the remote-shell binary. If not provided, then `/cloud87/remote-shell` is assumed. |
1831

1932

20-
## Usage
21-
2233

2334

2435
## AWS Permissions Required

authkeys.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package main
2+
3+
import (
4+
"crypto/rand"
5+
"crypto/rsa"
6+
"strings"
7+
8+
"golang.org/x/crypto/ssh"
9+
)
10+
11+
func generateSSHKeypair(bitSize int) (ssh.Signer, string, error) {
12+
privKey, err := generatePrivateKey(bitSize)
13+
if err != nil {
14+
return nil, "", err
15+
}
16+
17+
signer, err := ssh.NewSignerFromKey(privKey)
18+
if err != nil {
19+
return nil, "", err
20+
}
21+
22+
pubKey, err := generatePublicKey(&privKey.PublicKey)
23+
if err != nil {
24+
return nil, "", err
25+
}
26+
27+
return signer, pubKey, nil
28+
29+
}
30+
31+
func generatePrivateKey(bitSize int) (*rsa.PrivateKey, error) {
32+
privateKey, err := rsa.GenerateKey(rand.Reader, bitSize)
33+
if err != nil {
34+
return nil, err
35+
}
36+
37+
err = privateKey.Validate()
38+
if err != nil {
39+
return nil, err
40+
}
41+
42+
return privateKey, nil
43+
}
44+
45+
func generatePublicKey(pubKey *rsa.PublicKey) (string, error) {
46+
publicRsaKey, err := ssh.NewPublicKey(pubKey)
47+
if err != nil {
48+
return "", err
49+
}
50+
51+
pubKeyBytes := ssh.MarshalAuthorizedKey(publicRsaKey)
52+
53+
pubKeyString := strings.TrimSuffix(string(pubKeyBytes), "\n")
54+
55+
return pubKeyString, nil
56+
}

0 commit comments

Comments
 (0)