Skip to content

Commit

Permalink
Add meta tags. Set up deployment pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugene Dementiev committed Apr 7, 2020
1 parent eef87db commit 4f2f9a8
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 16 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
vendor/
Dockerfile
build.sh
*.git
29 changes: 29 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Build and publish aws-ssh
on:
push:
tags:
- '*'
jobs:
build_and_deploy:
name: build and deploy aws-ssh
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Unshallow to restore tags
run: git fetch --prune --unshallow
-
name: Set up Go
uses: actions/setup-go@v1
with:
go-version: 1.13.x
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v1
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ aws-ssh
*.log
dist/
vendor/
*.swp
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.11-alpine as build
FROM golang:1.13-alpine as build

RUN apk update && apk add git

Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
### What it is

This program goes through all available AWS accounts in parallel and determines

IP addresses of ec2 instances. It also detects so-called "bastion" instances.

If a bastion instance has tag "Global" with value "yes", "true" or "1", then aws-ssh decides it can be
used across multiple VPCs. If there are multiple bastion instances, it chooses the instance that has the most common match in name.
There are the following EC2 instance tags that change behaviour:

1. (Deprecated) If a bastion instance has tag "Global" with value "yes", "true" or "1", then aws-ssh will use it for all VPCs. If there are multiple bastion instances, it chooses the instance that has the most common match in name.
2. "x-aws-ssh-global" - same as the above
3. "x-aws-ssh-user" - sets the ssh username in the config.

Any comments and especially pull requests are highly appreciated.

Expand All @@ -28,5 +32,5 @@ Use "aws-ssh [command] --help" for more information about a command.

### Build

You'll need go>=1.11. Note that this project uses `go.mod`, so the project has to be cloned somewhere outside of the `GOPATH` directory.
You'll need go>=1.13. Note that this project uses `go.mod`, so the project has to be cloned somewhere outside of the `GOPATH` directory.
Or just use provided `Dockerfile`.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ require (
gopkg.in/ahmetb/go-linq.v3 v3.0.0
gopkg.in/ini.v1 v1.41.0 // indirect
)

go 1.13
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
github.com/apex/log v1.1.0 h1:J5rld6WVFi6NxA6m8GJ1LJqu3+GiTFIt3mYv27gdQWI=
github.com/apex/log v1.1.0/go.mod h1:yA770aXIDQrhVOIGurT/pVdfCpSq1GQV/auzMN5fzvY=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/aws/aws-sdk-go v1.16.26 h1:GWkl3rkRO/JGRTWoLLIqwf7AWC4/W/1hMOUZqmX0js4=
github.com/aws/aws-sdk-go v1.16.26/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/aws/aws-sdk-go v1.25.23 h1:EJx1uSb8E/HRkDa02pOb0r/73bkDbds7qg74s57qYgs=
github.com/aws/aws-sdk-go v1.25.23/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
Expand All @@ -16,8 +14,6 @@ github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/go-ini/ini v1.41.0 h1:526aoxDtxRHFQKMZfcX2OG9oOI8TJ5yPLM0Mkno/uTY=
github.com/go-ini/ini v1.41.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
github.com/go-ini/ini v1.48.0 h1:TvO60hO/2xgaaTWp2P0wUe4CFxwdMzfbkv3+343Xzqw=
github.com/go-ini/ini v1.48.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e h1:JKmoR8x90Iww1ks85zJ1lfDGgIiMDuIptTOhJq+zKyg=
Expand Down
12 changes: 11 additions & 1 deletion lib/reconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type SSHEntry struct {
InstanceID,
Name,
ProxyJump,
User,
Profile string
}

Expand All @@ -28,6 +29,9 @@ func (e SSHEntry) ConfigFormat() string {
var output = []string{
fmt.Sprintf("Host %s %s %s.%s", e.Name, e.InstanceID, e.Address, e.Profile),
}
if e.User != "" {
output = append(output, fmt.Sprintf(" User %s", e.User))
}
if e.ProxyJump != "" {
output = append(output, fmt.Sprintf(" ProxyJump %s", e.ProxyJump))
}
Expand Down Expand Up @@ -121,12 +125,18 @@ func Reconf(profiles []string, filename string) {
}
entry.Address = aws.StringValue(instance.PrivateIpAddress) // get the private address first as we always have one
if bastion != nil { // get private address and add proxyhost, which is the bastion ip
entry.ProxyJump = aws.StringValue(bastion.PublicIpAddress)
bastionUser := getTagValue("x-aws-ssh-user", bastion.Tags)
if bastionUser != "" {
entry.ProxyJump = fmt.Sprintf("%s@%s", bastionUser, aws.StringValue(bastion.PublicIpAddress))
} else {
entry.ProxyJump = aws.StringValue(bastion.PublicIpAddress)
}
} else { // get public IP if we have one
if publicIP := aws.StringValue(instance.PublicIpAddress); publicIP != "" {
entry.Address = aws.StringValue(instance.PublicIpAddress)
}
}
entry.User = getTagValue("x-aws-ssh-user", instance.Tags)
sshEntries = append(sshEntries, entry)
}
}
Expand Down
22 changes: 15 additions & 7 deletions lib/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,24 @@ const bastionCanonicalName = "bastion"

var sanitiser = regexp.MustCompile("[\\s-]+")

func getNameFromTags(tags []*ec2.Tag) string {
if len(tags) > 0 {
for _, tag := range tags {
if aws.StringValue(tag.Key) == "Name" {
return strings.ToLower(aws.StringValue(tag.Value))
}
func getTagValue(tag string, tags []*ec2.Tag, caseInsensitive ...bool) string {
if len(caseInsensitive) > 0 {
if caseInsensitive[0] {
tag = strings.ToLower(tag)
}
}

for _, subTag := range tags {
if aws.StringValue(subTag.Key) == tag {
return aws.StringValue(subTag.Value)
}
}

return ""

}
func getNameFromTags(tags []*ec2.Tag) string {
return strings.ToLower(getTagValue("Name", tags))
}

func isBastionFromTags(tags []*ec2.Tag, checkGlobal bool) bool {
Expand All @@ -34,7 +42,7 @@ func isBastionFromTags(tags []*ec2.Tag, checkGlobal bool) bool {
switch aws.StringValue(tag.Key) {
case "Name":
name = strings.ToLower(aws.StringValue(tag.Value))
case "Global":
case "Global", "x-aws-ssh-global":
{
value := strings.ToLower(aws.StringValue(tag.Value))
if value == "yes" || value == "true" || value == "1" {
Expand Down
3 changes: 3 additions & 0 deletions modd.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**/*.go {
prep: go build
}

0 comments on commit 4f2f9a8

Please sign in to comment.