Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Test
name: Code Check

on:
push:
pull_request:

jobs:
Expand All @@ -20,7 +21,6 @@ jobs:
- name: Get dependencies
run: |
go get -v -t -d ./...

- name: go test
run: go test -v -covermode=count -coverprofile=coverage.out ./...

Expand All @@ -32,7 +32,6 @@ jobs:
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: coverage.lcov
flag-name: Unit Test

vet:
name: go vet and lint
Expand Down Expand Up @@ -67,4 +66,4 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.40.1
version: v1.37.0
71 changes: 60 additions & 11 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ run:
linters-settings:
goimports:
local-prefixes: github.com/omegion/go-vault-ssh
gci:
local-prefixes: github.com/omegion/go-vault-ssh
golint:
min-confidence: 0
govet:
check-shadowing: true
misspell:
Expand All @@ -18,8 +18,6 @@ linters-settings:
allow-unused: false
require-explanation: true
require-specific: false
funlen:
lines: 80

issues:
exclude-rules:
Expand All @@ -31,13 +29,64 @@ issues:
- gosec
- dupl
- funlen
- scopelint
- testpackage
- ifshort
- paralleltest

linters:
disable-all: false
enable-all: true
disable:
- exhaustivestruct
- wrapcheck
disable-all: true
enable:
- deadcode
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- structcheck
- typecheck
- unused
- varcheck
- asciicheck
- bodyclose
- depguard
- dogsled
- dupl
- exportloopref
- funlen
- gochecknoglobals
- gochecknoinits
- gocognit
- goconst
- gocritic
- gocyclo
- godot
- godox
- goerr113
- gofmt
- gofumpt
- goimports
- golint
- gomnd
- gomodguard
- goprintffuncname
- gosec
- interfacer
- lll
- maligned
- misspell
- nakedret
- nestif
- noctx
- nolintlint
- prealloc
- rowserrcheck
- scopelint
- sqlclosecheck
- stylecheck
- unconvert
- unparam
- whitespace
- wsl
- tparallel
# don't enable:
# - go-header
# - testpackage
11 changes: 4 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
ARG GO_VERSION=1.16-alpine3.12
ARG FROM_IMAGE=alpine:3.12

FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} AS builder

ARG TARGETOS
ARG TARGETARCH
FROM golang:${GO_VERSION} AS builder

LABEL org.opencontainers.image.source="https://github.com/omegion/vault-ssh"

Expand All @@ -13,15 +10,15 @@ WORKDIR /app
COPY ./ /app

RUN apk update && \
apk add ca-certificates gettext git make && \
apk add ca-certificates gettext git make curl unzip && \
rm -rf /tmp/* && \
rm -rf /var/cache/apk/* && \
rm -rf /var/tmp/*

RUN make build TARGETOS=$TARGETOS TARGETARCH=$TARGETARCH
RUN make build-for-container

FROM ${FROM_IMAGE}

COPY --from=builder /app/dist/vault-ssh /bin/vault-ssh
COPY --from=builder /app/dist/vault-ssh-linux /bin/vault-ssh

ENTRYPOINT ["vault-ssh"]
30 changes: 13 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
export PATH := $(abspath ./vendor/bin):$(PATH)

BASE_PACKAGE_NAME = github.com/omegion/vault-ssh
GIT_VERSION = $(shell git describe --tags --always 2> /dev/null || echo 0.0.0)
LDFLAGS = -ldflags "-X $(BASE_PACKAGE_NAME)/internal/info.Version=$(GIT_VERSION)"
BUFFER := $(shell mktemp)
REPORT_DIR = dist/report
COVER_PROFILE = $(REPORT_DIR)/coverage.out
TARGETOS = "darwin"
TARGETARCH = "amd64"
BASE_PACKAGE_NAME = github.com/omegion/vault-ssh
GIT_VERSION = $(shell git describe --tags --always 2> /dev/null || echo 0.0.0)
LDFLAGS = -ldflags "-X $(BASE_PACKAGE_NAME)/pkg/info.Version=$(GIT_VERSION)"
BUFFER := $(shell mktemp)
REPORT_DIR = dist/report
COVER_PROFILE = $(REPORT_DIR)/coverage.out

.PHONY: build
build:
CGO_ENABLED=0 GOOS=$(TARGETOS) GOARCH=$(TARGETARCH) go build $(LDFLAGS) -a -installsuffix cgo -o dist/vault-ssh main.go
CGO_ENABLED=0 go build $(LDFLAGS) -installsuffix cgo -o dist/vault-ssh main.go

build-for-container:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -a -installsuffix cgo -o dist/vault-ssh-linux main.go

.PHONY: lint
lint:
@echo "Checking code style"
gofmt -l . | tee $(BUFFER)
@! test -s $(BUFFER)
go vet ./...
go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.40.1
go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.37.1
@golangci-lint --version
golangci-lint run --fix
golangci-lint run
go get -u golang.org/x/lint/golint
golint -set_exit_status ./...

Expand All @@ -39,13 +40,8 @@ cut-tag:
git push origin $(version)

.PHONY: release
release: build
release: build-for-container
@echo "Releasing $(GIT_VERSION)"
docker build -t vault-ssh .
docker tag vault-ssh:latest omegion/vault-ssh:$(GIT_VERSION)
docker push omegion/vault-ssh:$(GIT_VERSION)

.PHONY: docker-image
docker-image:
@echo "Building Docker Image"
docker buildx build -t vault-ssh --platform linux/amd64,linux/arm64 . --output=type=docker
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ vault-ssh certificate create --engine my-ssh-signer
3. Read created certificate to put on your server.

```shell
vault-ssh certificate get --engine my-ssh-signer
vault-ssh certificate read --engine my-ssh-signer
```

4. Create a role for the engine.
Expand Down
15 changes: 12 additions & 3 deletions cmd/certificate/create.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package certificate

import (
"github.com/omegion/vault-ssh/internal/controller"
"github.com/omegion/vault-ssh/internal/vault"
"fmt"

"github.com/omegion/vault-ssh/pkg/vault"

"github.com/spf13/cobra"
)

Expand All @@ -19,7 +21,14 @@ func Create() *cobra.Command {
return err
}

return controller.NewController(api).CreateCACertificate(engineName)
err = api.CreateCACertificate(engineName)
if err != nil {
return err
}

fmt.Printf("Certificate created for SSH Engine \"%s\".\n", engineName)

return nil
},
}

Expand Down
11 changes: 6 additions & 5 deletions cmd/certificate/get.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package certificate

import (
"github.com/omegion/vault-ssh/internal/controller"
"github.com/omegion/vault-ssh/internal/vault"
log "github.com/sirupsen/logrus"
"fmt"

"github.com/omegion/vault-ssh/pkg/vault"

"github.com/spf13/cobra"
)

Expand All @@ -20,12 +21,12 @@ func Get() *cobra.Command {
return err
}

publicKey, err := controller.NewController(api).GetCACertificate(engineName)
publicKey, err := api.GetCACertificate(engineName)
if err != nil {
return err
}

log.Infoln(publicKey)
fmt.Printf("%s\n", publicKey)

return nil
},
Expand Down
22 changes: 18 additions & 4 deletions cmd/enable.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
package cmd

import (
"github.com/omegion/vault-ssh/internal/controller"
"github.com/omegion/vault-ssh/internal/vault"
"fmt"

"github.com/omegion/vault-ssh/pkg/vault"

"github.com/spf13/cobra"
)

// setupAddCommand sets default flags.
func setupGetCommand(cmd *cobra.Command) {
cmd.Flags().String("path", vault.SSHEngineDefaultName, "SSH engine path")
}

// Enable enables SSH engine.
func Enable() *cobra.Command {
cmd := &cobra.Command{
Expand All @@ -19,11 +26,18 @@ func Enable() *cobra.Command {
return err
}

return controller.NewController(api).EnableSSHEngine(path)
err = api.EnableSSHEngine(path)
if err != nil {
return err
}

fmt.Printf("\"%s\" SSH Engine enabled.\n", path)

return nil
},
}

cmd.Flags().String("path", vault.SSHEngineDefaultName, "SSH engine path")
setupGetCommand(cmd)

return cmd
}
1 change: 0 additions & 1 deletion cmd/fixtures/public-key.pem

This file was deleted.

17 changes: 17 additions & 0 deletions cmd/helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package cmd

import (
"bytes"

"github.com/spf13/cobra"
)

func executeCommand(root *cobra.Command, args ...string) (output string, err error) {
buf := new(bytes.Buffer)
root.SetOut(buf)
root.SetErr(buf)
root.SetArgs(args)
_, err = root.ExecuteC()

return buf.String(), err
}
15 changes: 12 additions & 3 deletions cmd/role/create.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package role

import (
"github.com/omegion/vault-ssh/internal/controller"
"github.com/omegion/vault-ssh/internal/vault"
"fmt"

"github.com/omegion/vault-ssh/pkg/vault"

"github.com/spf13/cobra"
)

Expand All @@ -20,7 +22,14 @@ func Create() *cobra.Command {
return err
}

return controller.NewController(api).CreateRole(engineName, roleName)
err = api.CreateRole(engineName, roleName)
if err != nil {
return err
}

fmt.Printf("\"%s\" created for SSH Engine \"%s\" enabled.\n", roleName, engineName)

return nil
},
}

Expand Down
Loading