From 1b30ca3396436ec0408ffdb0425aed5e78d3aac6 Mon Sep 17 00:00:00 2001 From: Gregor Noczinski Date: Sat, 24 Aug 2024 14:40:33 +0200 Subject: [PATCH] Added also linting and more rules to deal better with several platforms --- .editorconfig | 15 +++ .gitattributes | 7 ++ .github/workflows/ci.yml | 3 +- .github/workflows/lint.yml | 28 +++++ .golangci.yml | 30 +++++ .idea/.gitignore | 3 + .idea/codeStyles/Project.xml | 28 +++++ .idea/codeStyles/codeStyleConfig.xml | 5 + .idea/inspectionProfiles/Project_Default.xml | 7 ++ .idea/watcherTasks.xml | 53 +++++++++ cmd/bifroest/dummy-server.go | 12 +- cmd/bifroest/sftp-server.go | 6 +- cmd/bifroest/version.go | 10 +- internal/text/template/exec_test.go | 2 +- pkg/authorization/authorization.go | 4 +- pkg/authorization/authorizer.go | 4 +- pkg/authorization/facade-authorizer.go | 3 +- pkg/authorization/htpasswd-authorizer.go | 9 +- pkg/authorization/htpasswd.go | 4 +- pkg/authorization/local-authorizer.go | 18 ++- .../local-authorizer_with_pam.go | 4 +- .../local-authorizer_without_pam.go | 1 + pkg/authorization/local.go | 4 +- .../oidc-device-auth-authorizer.go | 6 +- pkg/authorization/oidc.go | 8 +- pkg/authorization/request.go | 20 +--- pkg/authorization/simple-authorizer.go | 6 +- pkg/authorization/simple.go | 4 +- pkg/configuration/authorization-htpasswd.go | 3 +- pkg/configuration/authorization-local.go | 3 +- .../authorization-local_without_pam.go | 2 +- pkg/configuration/authorization-oidc-auth.go | 3 +- pkg/configuration/authorization.go | 3 +- pkg/configuration/authorization_test.go | 3 +- pkg/configuration/configuration-ref.go | 5 +- pkg/configuration/configuration.go | 8 +- ...on_test.go => configuration_linux_test.go} | 2 + .../configuration_windows_test.go | 104 ++++++++++++++++++ pkg/configuration/environment-local.go | 3 +- pkg/configuration/environment.go | 3 +- pkg/configuration/housekeeping.go | 6 +- pkg/configuration/keys.go | 6 +- pkg/configuration/password-properties.go | 3 +- pkg/configuration/requirement.go | 3 +- pkg/configuration/session-fs.go | 3 +- pkg/configuration/session.go | 11 +- pkg/configuration/ssh.go | 6 +- pkg/configuration/support.go | 4 +- pkg/configuration/support_test.go | 5 +- .../user-requirement-template_windows.go | 2 +- pkg/crypto/authorized-keys-file.go | 6 +- pkg/crypto/authorized-keys-file_test.go | 3 +- pkg/crypto/authorized-keys-option.go | 3 +- pkg/crypto/authorized-keys.go | 5 +- pkg/crypto/authorized-keys_test.go | 11 +- pkg/crypto/dsa-restriction.go | 3 +- pkg/crypto/ecdsa-restriction.go | 3 +- pkg/crypto/ed25519-restriction.go | 3 +- pkg/crypto/htpasswd.go | 1 + pkg/crypto/key-requirement.go | 6 +- pkg/crypto/key.go | 8 +- pkg/crypto/password-bcrypt.go | 3 +- pkg/crypto/rsa-restriction.go | 3 +- pkg/crypto/ssh.go | 6 +- pkg/crypto/unix/password/apr1.go | 1 + pkg/crypto/unix/password/crypt.go | 3 +- pkg/crypto/unix/password/md5.go | 1 + pkg/crypto/unix/password/sha256.go | 1 + pkg/crypto/unix/password/sha512.go | 1 + pkg/environment/environment.go | 3 +- pkg/environment/facade-repository.go | 3 +- pkg/environment/local-repository.go | 2 + pkg/environment/local-token_windows.go | 1 + pkg/environment/local.go | 22 ++-- pkg/environment/local_linux.go | 12 +- pkg/environment/local_windows.go | 10 +- pkg/environment/repository.go | 4 +- pkg/environment/request.go | 3 +- pkg/environment/task.go | 1 + pkg/service/connection.go | 14 ++- pkg/service/context.go | 8 +- pkg/service/housekeeper.go | 25 +++-- pkg/service/service-authorization.go | 5 +- pkg/service/service-direct-tcp-ip.go | 12 +- pkg/service/service-messages.go | 6 +- pkg/service/service-session.go | 8 +- pkg/service/service.go | 16 +-- pkg/service/service_linux.go | 6 +- pkg/service/service_windows.go | 6 +- pkg/session/common.go | 3 +- pkg/session/common_test.go | 5 +- pkg/session/connection-interceptor.go | 5 +- pkg/session/facade-repository.go | 3 +- pkg/session/fs-connection-interceptor.go | 10 +- pkg/session/fs-created.go | 5 +- pkg/session/fs-info.go | 8 +- pkg/session/fs-lastaccessed.go | 5 +- pkg/session/fs-repository.go | 23 ++-- pkg/session/fs.go | 12 +- pkg/session/info.go | 6 +- pkg/session/predicates.go | 3 +- pkg/session/repository.go | 8 +- pkg/session/session.go | 6 +- pkg/sftp/server.go | 15 +-- pkg/template/bool.go | 3 +- pkg/template/bool_test.go | 3 +- pkg/template/funcs.go | 12 +- pkg/template/string.go | 3 +- pkg/template/string_test.go | 3 +- pkg/template/text-marshaller.go | 3 +- pkg/template/uint64.go | 3 +- pkg/template/uint64_test.go | 3 +- pkg/user/common_test.go | 11 +- pkg/user/ensure.go | 4 +- pkg/user/etc-colon-entry_test.go | 7 +- pkg/user/etc-colon-repository-handle.go | 3 +- pkg/user/etc-colon-repository-handles.go | 5 +- pkg/user/etc-colon-repository.go | 18 +-- pkg/user/etc-colon-repository_test.go | 48 ++++---- pkg/user/etc-group_test.go | 3 +- pkg/user/etc-passwd_test.go | 3 +- pkg/user/etc-shadow.go | 3 +- pkg/user/etc-shadow_test.go | 3 +- pkg/user/group_windows.go | 2 +- pkg/user/repository.go | 5 +- pkg/user/requirement_windows.go | 11 -- pkg/user/user_windows.go | 2 +- pkg/user/windows_repository.go | 6 +- 128 files changed, 718 insertions(+), 299 deletions(-) create mode 100644 .editorconfig create mode 100644 .gitattributes create mode 100644 .github/workflows/lint.yml create mode 100644 .golangci.yml create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/codeStyles/codeStyleConfig.xml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/watcherTasks.xml rename pkg/configuration/{configuration_test.go => configuration_linux_test.go} (99%) create mode 100644 pkg/configuration/configuration_windows_test.go diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..c678f1d --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true +charset = utf-8 +trim_trailing_whitespace = true + +[*.{go,go.tmpl}] +indent_style = tab +indent_size = 4 + +[*.{yaml,yml}] +indent_style = space +indent_size = 2 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..46ee6db --- /dev/null +++ b/.gitattributes @@ -0,0 +1,7 @@ +*.go text eol=lf +*.yaml text eol=lf +*.yml text eol=lf +*.json text eol=lf +*.sh text eol=lf +*.md text eol=lf + diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f076788..23b9cee 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,5 +1,4 @@ name: Continuous Integration - on: push: @@ -13,7 +12,7 @@ jobs: name: Tests strategy: matrix: - os: [ ubuntu-latest ] + os: [ ubuntu-latest, windows-latest ] runs-on: ${{ matrix.os }} steps: - name: Install Go diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..480d633 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,28 @@ +name: Lint +on: + push: + + pull_request: + types: + - opened + - reopened + +permissions: + contents: read + +jobs: + golangci: + name: "golangci-lint" + strategy: + matrix: + os: [ ubuntu-latest, windows-latest ] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: stable + - name: golangci-lint + uses: golangci/golangci-lint-action@v6 + with: + version: v1.60 diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..b436c0d --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,30 @@ +run: + timeout: 20m + +linters: + enable: + - asasalint + - asciicheck + - bidichk + - misspell + disable: + - ineffassign + +linters-settings: + misspell: + locale: US + ignore-words: + - engity + - bifröst + - bifroest + +issues: + exclude-dirs: + - internal/fmtsort + - internal/text + exclude: + - S1002 + - S1016 + - SA1012 + - S1031 + - SA1019 diff --git a/.idea/.gitignore b/.idea/.gitignore index 1659f91..3d2aaca 100644 --- a/.idea/.gitignore +++ b/.idea/.gitignore @@ -1,3 +1,6 @@ * !/.gitignore !/icon.svg +!/inspectionProfiles +!/codeStyles +!/watcherTasks.xml diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..2cbddaf --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,28 @@ + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..79ee123 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..995b277 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/.idea/watcherTasks.xml b/.idea/watcherTasks.xml new file mode 100644 index 0000000..5d92fce --- /dev/null +++ b/.idea/watcherTasks.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/cmd/bifroest/dummy-server.go b/cmd/bifroest/dummy-server.go index 045982a..09e0adb 100644 --- a/cmd/bifroest/dummy-server.go +++ b/cmd/bifroest/dummy-server.go @@ -3,16 +3,18 @@ package main import ( "context" "fmt" - "github.com/alecthomas/kingpin" - log "github.com/echocat/slf4g" - "github.com/engity-com/bifroest/pkg/common" - "github.com/engity-com/bifroest/pkg/errors" "net" "net/http" "os" "os/signal" "strings" "syscall" + + "github.com/alecthomas/kingpin" + log "github.com/echocat/slf4g" + + "github.com/engity-com/bifroest/pkg/common" + "github.com/engity-com/bifroest/pkg/errors" ) var ( @@ -83,7 +85,7 @@ func dummyServerHandleIndex(w http.ResponseWriter, r *http.Request) { if r.Method == http.MethodHead { return } - _, err = fmt.Fprintf(w, `Hello from a dummy-server! + _, _ = fmt.Fprintf(w, `Hello from a dummy-server! Called URI: %v Method: %v diff --git a/cmd/bifroest/sftp-server.go b/cmd/bifroest/sftp-server.go index 42f8164..a620c6a 100644 --- a/cmd/bifroest/sftp-server.go +++ b/cmd/bifroest/sftp-server.go @@ -1,9 +1,11 @@ package main import ( + "os" + "github.com/alecthomas/kingpin" + "github.com/engity-com/bifroest/pkg/sftp" - "os" ) var ( @@ -53,7 +55,7 @@ func (this *stdpipe) Close() (rErr error) { rErr = err } if err := os.Stdout.Close(); err != nil && rErr == nil { - rErr = err + rErr = err //nolint:golint,staticcheck } return nil } diff --git a/cmd/bifroest/version.go b/cmd/bifroest/version.go index b417bbd..4713a48 100644 --- a/cmd/bifroest/version.go +++ b/cmd/bifroest/version.go @@ -2,12 +2,14 @@ package main import ( "fmt" - "github.com/alecthomas/kingpin" - "github.com/engity-com/bifroest/pkg/common" "os" "runtime" "strings" "time" + + "github.com/alecthomas/kingpin" + + "github.com/engity-com/bifroest/pkg/common" ) var ( @@ -95,9 +97,7 @@ func (this versionT) Vendor() string { } func (this versionT) GoVersion() string { - v := runtime.Version() - strings.TrimPrefix(v, "go") - return v + return strings.TrimPrefix(runtime.Version(), "go") } func (this versionT) Platform() string { diff --git a/internal/text/template/exec_test.go b/internal/text/template/exec_test.go index e607fd3..978f759 100644 --- a/internal/text/template/exec_test.go +++ b/internal/text/template/exec_test.go @@ -820,7 +820,7 @@ func testExecute(execTests []execTest, template *Template, t *testing.T) { fmt.Printf("%s: %s\n\t%s\n", test.name, test.input, err) } } - result := b.String() + result := strings.ReplaceAll(b.String(), "\r\n", "\n") if result != test.output { t.Errorf("%s: expected\n\t%q\ngot\n\t%q", test.name, test.output, result) } diff --git a/pkg/authorization/authorization.go b/pkg/authorization/authorization.go index 348f1d0..4d3217b 100644 --- a/pkg/authorization/authorization.go +++ b/pkg/authorization/authorization.go @@ -2,11 +2,13 @@ package authorization import ( "context" + + "golang.org/x/crypto/ssh" + "github.com/engity-com/bifroest/pkg/common" "github.com/engity-com/bifroest/pkg/configuration" "github.com/engity-com/bifroest/pkg/session" "github.com/engity-com/bifroest/pkg/sys" - "golang.org/x/crypto/ssh" ) type Authorization interface { diff --git a/pkg/authorization/authorizer.go b/pkg/authorization/authorizer.go index 5f3cbd1..ea3a66b 100644 --- a/pkg/authorization/authorizer.go +++ b/pkg/authorization/authorizer.go @@ -3,9 +3,11 @@ package authorization import ( "context" "errors" + "io" + log "github.com/echocat/slf4g" + "github.com/engity-com/bifroest/pkg/session" - "io" ) var ( diff --git a/pkg/authorization/facade-authorizer.go b/pkg/authorization/facade-authorizer.go index 600ad64..daf9d0f 100644 --- a/pkg/authorization/facade-authorizer.go +++ b/pkg/authorization/facade-authorizer.go @@ -3,11 +3,12 @@ package authorization import ( "context" "fmt" + "reflect" + "github.com/engity-com/bifroest/pkg/common" "github.com/engity-com/bifroest/pkg/configuration" "github.com/engity-com/bifroest/pkg/errors" "github.com/engity-com/bifroest/pkg/session" - "reflect" ) func NewAuthorizerFacade(ctx context.Context, flows *configuration.Flows) (*AuthorizerFacade, error) { diff --git a/pkg/authorization/htpasswd-authorizer.go b/pkg/authorization/htpasswd-authorizer.go index 8b6ff5d..f920873 100644 --- a/pkg/authorization/htpasswd-authorizer.go +++ b/pkg/authorization/htpasswd-authorizer.go @@ -4,7 +4,9 @@ import ( "context" "encoding/json" "fmt" + log "github.com/echocat/slf4g" + "github.com/engity-com/bifroest/pkg/configuration" "github.com/engity-com/bifroest/pkg/errors" "github.com/engity-com/bifroest/pkg/session" @@ -244,10 +246,3 @@ func (this *HtpasswdAuthorizer) RestoreFromSession(ctx context.Context, sess ses func (this *HtpasswdAuthorizer) Close() error { return nil } - -func (this *HtpasswdAuthorizer) logger() log.Logger { - if v := this.Logger; v != nil { - return v - } - return log.GetLogger("authorizer") -} diff --git a/pkg/authorization/htpasswd.go b/pkg/authorization/htpasswd.go index d34bbd5..607cfb1 100644 --- a/pkg/authorization/htpasswd.go +++ b/pkg/authorization/htpasswd.go @@ -3,11 +3,13 @@ package authorization import ( "context" "fmt" + + "golang.org/x/crypto/ssh" + "github.com/engity-com/bifroest/pkg/common" "github.com/engity-com/bifroest/pkg/configuration" "github.com/engity-com/bifroest/pkg/session" "github.com/engity-com/bifroest/pkg/sys" - "golang.org/x/crypto/ssh" ) type htpasswd struct { diff --git a/pkg/authorization/local-authorizer.go b/pkg/authorization/local-authorizer.go index 6b901a6..1ca0cd1 100644 --- a/pkg/authorization/local-authorizer.go +++ b/pkg/authorization/local-authorizer.go @@ -7,7 +7,10 @@ import ( "context" "encoding/json" "fmt" + log "github.com/echocat/slf4g" + "golang.org/x/crypto/ssh" + "github.com/engity-com/bifroest/pkg/common" "github.com/engity-com/bifroest/pkg/configuration" "github.com/engity-com/bifroest/pkg/crypto" @@ -16,7 +19,6 @@ import ( "github.com/engity-com/bifroest/pkg/sys" "github.com/engity-com/bifroest/pkg/template" "github.com/engity-com/bifroest/pkg/user" - "golang.org/x/crypto/ssh" ) var ( @@ -163,6 +165,20 @@ func (this *LocalAuthorizer) isAuthorizedViaPublicKey(req PublicKeyRequest, u *u return true, nil } +type userEnabledRequest struct { + Request + user *user.User +} + +func (this *userEnabledRequest) GetField(name string) (any, bool) { + switch name { + case "user": + return this.user, true + default: + return nil, false + } +} + func (this *LocalAuthorizer) getAuthorizedKeysFilesOf(req PublicKeyRequest, u *user.User) ([]string, error) { ctx := userEnabledRequest{req, u} return common.MapSliceErr(this.conf.AuthorizedKeys, func(tmpl template.String) (string, error) { diff --git a/pkg/authorization/local-authorizer_with_pam.go b/pkg/authorization/local-authorizer_with_pam.go index b558490..b8db22c 100644 --- a/pkg/authorization/local-authorizer_with_pam.go +++ b/pkg/authorization/local-authorizer_with_pam.go @@ -4,8 +4,10 @@ package authorization import ( "errors" - "github.com/engity-com/bifroest/pkg/sys" + "github.com/msteinert/pam/v2" + + "github.com/engity-com/bifroest/pkg/sys" ) func (this *LocalAuthorizer) checkPassword(req PasswordRequest, requestedUsername string, validatePassword func(string, Request) (bool, error)) (username string, env sys.EnvVars, success bool, rErr error) { diff --git a/pkg/authorization/local-authorizer_without_pam.go b/pkg/authorization/local-authorizer_without_pam.go index 1d12343..7d72393 100644 --- a/pkg/authorization/local-authorizer_without_pam.go +++ b/pkg/authorization/local-authorizer_without_pam.go @@ -4,6 +4,7 @@ package authorization import ( "fmt" + "github.com/engity-com/bifroest/pkg/sys" ) diff --git a/pkg/authorization/local.go b/pkg/authorization/local.go index 7fbbdc8..41b837b 100644 --- a/pkg/authorization/local.go +++ b/pkg/authorization/local.go @@ -5,12 +5,14 @@ package authorization import ( "context" "fmt" + + "golang.org/x/crypto/ssh" + "github.com/engity-com/bifroest/pkg/common" "github.com/engity-com/bifroest/pkg/configuration" "github.com/engity-com/bifroest/pkg/session" "github.com/engity-com/bifroest/pkg/sys" "github.com/engity-com/bifroest/pkg/user" - "golang.org/x/crypto/ssh" ) type local struct { diff --git a/pkg/authorization/oidc-device-auth-authorizer.go b/pkg/authorization/oidc-device-auth-authorizer.go index ae75416..b0f3e0c 100644 --- a/pkg/authorization/oidc-device-auth-authorizer.go +++ b/pkg/authorization/oidc-device-auth-authorizer.go @@ -4,12 +4,14 @@ import ( "context" "encoding/json" "fmt" + coidc "github.com/coreos/go-oidc/v3/oidc" log "github.com/echocat/slf4g" + "golang.org/x/oauth2" + "github.com/engity-com/bifroest/pkg/configuration" "github.com/engity-com/bifroest/pkg/errors" "github.com/engity-com/bifroest/pkg/session" - "golang.org/x/oauth2" ) var ( @@ -359,7 +361,7 @@ func (this *OidcDeviceAuthAuthorizer) retrieveDeviceAuthToken(ctx context.Contex return failf(errors.User, "authorize of device timed out") } if errors.Is(err, context.Canceled) { - return failf(errors.User, "authorize cancelled by user") + return failf(errors.User, "authorize canceled by user") } var oaErr *oauth2.RetrieveError if errors.As(err, &oaErr) && oaErr.ErrorCode == "expired_token" { diff --git a/pkg/authorization/oidc.go b/pkg/authorization/oidc.go index e5e0db5..fc7e2b8 100644 --- a/pkg/authorization/oidc.go +++ b/pkg/authorization/oidc.go @@ -3,14 +3,16 @@ package authorization import ( "context" "fmt" + "sync" + coidc "github.com/coreos/go-oidc/v3/oidc" + "golang.org/x/crypto/ssh" + "golang.org/x/oauth2" + "github.com/engity-com/bifroest/pkg/common" "github.com/engity-com/bifroest/pkg/configuration" "github.com/engity-com/bifroest/pkg/session" "github.com/engity-com/bifroest/pkg/sys" - "golang.org/x/crypto/ssh" - "golang.org/x/oauth2" - "sync" ) type oidc struct { diff --git a/pkg/authorization/request.go b/pkg/authorization/request.go index 46cef2f..f60ee26 100644 --- a/pkg/authorization/request.go +++ b/pkg/authorization/request.go @@ -2,11 +2,11 @@ package authorization import ( "github.com/echocat/slf4g" - "github.com/engity-com/bifroest/pkg/common" - "github.com/engity-com/bifroest/pkg/session" - "github.com/engity-com/bifroest/pkg/user" "github.com/gliderlabs/ssh" gssh "golang.org/x/crypto/ssh" + + "github.com/engity-com/bifroest/pkg/common" + "github.com/engity-com/bifroest/pkg/session" ) type Request interface { @@ -33,17 +33,3 @@ type InteractiveRequest interface { SendError(string) error Prompt(msg string, echoOn bool) (string, error) } - -type userEnabledRequest struct { - Request - user *user.User -} - -func (this *userEnabledRequest) GetField(name string) (any, bool) { - switch name { - case "user": - return this.user, true - default: - return nil, false - } -} diff --git a/pkg/authorization/simple-authorizer.go b/pkg/authorization/simple-authorizer.go index 34e0ca2..5a4a96b 100644 --- a/pkg/authorization/simple-authorizer.go +++ b/pkg/authorization/simple-authorizer.go @@ -5,13 +5,15 @@ import ( "context" "encoding/json" "fmt" + "strings" + log "github.com/echocat/slf4g" + "golang.org/x/crypto/ssh" + "github.com/engity-com/bifroest/pkg/configuration" "github.com/engity-com/bifroest/pkg/crypto" "github.com/engity-com/bifroest/pkg/errors" "github.com/engity-com/bifroest/pkg/session" - "golang.org/x/crypto/ssh" - "strings" ) var ( diff --git a/pkg/authorization/simple.go b/pkg/authorization/simple.go index 5300025..6511432 100644 --- a/pkg/authorization/simple.go +++ b/pkg/authorization/simple.go @@ -3,11 +3,13 @@ package authorization import ( "context" "fmt" + + "golang.org/x/crypto/ssh" + "github.com/engity-com/bifroest/pkg/common" "github.com/engity-com/bifroest/pkg/configuration" "github.com/engity-com/bifroest/pkg/session" "github.com/engity-com/bifroest/pkg/sys" - "golang.org/x/crypto/ssh" ) type simple struct { diff --git a/pkg/configuration/authorization-htpasswd.go b/pkg/configuration/authorization-htpasswd.go index c7dd251..85ac114 100644 --- a/pkg/configuration/authorization-htpasswd.go +++ b/pkg/configuration/authorization-htpasswd.go @@ -1,9 +1,10 @@ package configuration import ( + "gopkg.in/yaml.v3" + "github.com/engity-com/bifroest/pkg/crypto" "github.com/engity-com/bifroest/pkg/sys" - "gopkg.in/yaml.v3" ) var ( diff --git a/pkg/configuration/authorization-local.go b/pkg/configuration/authorization-local.go index eab25d4..5a11c5a 100644 --- a/pkg/configuration/authorization-local.go +++ b/pkg/configuration/authorization-local.go @@ -3,8 +3,9 @@ package configuration import ( - "github.com/engity-com/bifroest/pkg/template" "gopkg.in/yaml.v3" + + "github.com/engity-com/bifroest/pkg/template" ) var ( diff --git a/pkg/configuration/authorization-local_without_pam.go b/pkg/configuration/authorization-local_without_pam.go index 642b236..e56b55f 100644 --- a/pkg/configuration/authorization-local_without_pam.go +++ b/pkg/configuration/authorization-local_without_pam.go @@ -3,7 +3,7 @@ package configuration var ( - defaultAuthorizationLocalPamService = "" + defaultAuthorizationLocalPamService = "" //nolint:golint,unused ) func IsPamSupported() bool { diff --git a/pkg/configuration/authorization-oidc-auth.go b/pkg/configuration/authorization-oidc-auth.go index 6bef856..4f8ee21 100644 --- a/pkg/configuration/authorization-oidc-auth.go +++ b/pkg/configuration/authorization-oidc-auth.go @@ -1,9 +1,10 @@ package configuration import ( + "slices" + "github.com/coreos/go-oidc/v3/oidc" "gopkg.in/yaml.v3" - "slices" ) var ( diff --git a/pkg/configuration/authorization.go b/pkg/configuration/authorization.go index f3a191d..389ef8e 100644 --- a/pkg/configuration/authorization.go +++ b/pkg/configuration/authorization.go @@ -2,8 +2,9 @@ package configuration import ( "fmt" - "gopkg.in/yaml.v3" "strings" + + "gopkg.in/yaml.v3" ) type Authorization struct { diff --git a/pkg/configuration/authorization_test.go b/pkg/configuration/authorization_test.go index 18d0472..7cb3bf7 100644 --- a/pkg/configuration/authorization_test.go +++ b/pkg/configuration/authorization_test.go @@ -1,8 +1,9 @@ package configuration import ( - "github.com/echocat/slf4g/sdk/testlog" "testing" + + "github.com/echocat/slf4g/sdk/testlog" ) func TestAuthorization_UnmarshalYAML(t *testing.T) { diff --git a/pkg/configuration/configuration-ref.go b/pkg/configuration/configuration-ref.go index 461cba7..97b959a 100644 --- a/pkg/configuration/configuration-ref.go +++ b/pkg/configuration/configuration-ref.go @@ -1,9 +1,8 @@ package configuration type ConfigurationRef struct { - v Configuration - fn string - loadErr error + v Configuration + fn string } func (this ConfigurationRef) IsZero() bool { diff --git a/pkg/configuration/configuration.go b/pkg/configuration/configuration.go index 01b5787..a2f3ce1 100644 --- a/pkg/configuration/configuration.go +++ b/pkg/configuration/configuration.go @@ -1,12 +1,14 @@ package configuration import ( + "io" + "os" + + "gopkg.in/yaml.v3" + "github.com/engity-com/bifroest/pkg/common" "github.com/engity-com/bifroest/pkg/errors" "github.com/engity-com/bifroest/pkg/sys" - "gopkg.in/yaml.v3" - "io" - "os" ) type Configuration struct { diff --git a/pkg/configuration/configuration_test.go b/pkg/configuration/configuration_linux_test.go similarity index 99% rename from pkg/configuration/configuration_test.go rename to pkg/configuration/configuration_linux_test.go index df12824..c505342 100644 --- a/pkg/configuration/configuration_test.go +++ b/pkg/configuration/configuration_linux_test.go @@ -1,3 +1,5 @@ +//go:build linux + package configuration import ( diff --git a/pkg/configuration/configuration_windows_test.go b/pkg/configuration/configuration_windows_test.go new file mode 100644 index 0000000..6b04186 --- /dev/null +++ b/pkg/configuration/configuration_windows_test.go @@ -0,0 +1,104 @@ +//go:build windows + +package configuration + +import ( + "github.com/echocat/slf4g/sdk/testlog" + "github.com/engity-com/bifroest/pkg/common" + "github.com/engity-com/bifroest/pkg/crypto" + "github.com/engity-com/bifroest/pkg/template" + "testing" +) + +func TestConfiguration_UnmarshalYAML(t *testing.T) { + testlog.Hook(t) + + runUnmarshalYamlTests(t, + unmarshalYamlTestCase[Configuration]{ + name: "empty", + yaml: ``, + expectedError: `EOF`, + }, + unmarshalYamlTestCase[Configuration]{ + name: "flows-missing", + yaml: `{}`, + expectedError: `[flows] required but absent`, + }, + unmarshalYamlTestCase[Configuration]{ + name: "flows-empty", + yaml: `flows: []`, + expectedError: `[flows] required but absent`, + }, + unmarshalYamlTestCase[Configuration]{ + name: "required-set", + yaml: `flows: +- name: foo + authorization: + type: oidcDeviceAuth + issuer: https://foo-bar + clientId: anId + clientSecret: aSecret + environment: + type: local + name: foo`, + expected: Configuration{ + Ssh: Ssh{ + Addresses: DefaultSshAddresses, + Keys: Keys{ + HostKeys: DefaultHostKeyLocations, + RsaRestriction: crypto.DefaultRsaRestriction, + DsaRestriction: crypto.DefaultDsaRestriction, + EcdsaRestriction: crypto.DefaultEcdsaRestriction, + Ed25519Restriction: crypto.DefaultEd25519Restriction, + RememberMeNotification: DefaultRememberMeNotification, + }, + IdleTimeout: DefaultSshIdleTimeout, + MaxTimeout: DefaultSshMaxTimeout, + MaxAuthTries: DefaultSshMaxAuthTries, + MaxConnections: DefaultSshMaxConnections, + Banner: DefaultSshBanner, + }, + Session: Session{&SessionFs{ + IdleTimeout: DefaultSessionIdleTimeout, + MaxTimeout: DefaultSessionMaxTimeout, + MaxConnections: DefaultSessionMaxConnections, + Storage: DefaultSessionFsStorage, + FileMode: DefaultSessionFsFileMode, + }}, + Flows: []Flow{{ + Name: "foo", + Requirement: Requirement{ + IncludedRequestingName: common.MustNewRegexp(""), + ExcludedRequestingName: common.MustNewRegexp(""), + }, + Authorization: Authorization{&AuthorizationOidcDeviceAuth{ + Issuer: "https://foo-bar", + ClientId: "anId", + ClientSecret: "aSecret", + Scopes: DefaultAuthorizationOidcScopes, + RetrieveIdToken: DefaultAuthorizationOidcRetrieveIdToken, + RetrieveUserInfo: DefaultAuthorizationOidcRetrieveUserInfo, + }}, + Environment: Environment{&EnvironmentLocal{ + User: UserRequirementTemplate{ + Name: template.MustNewString("foo"), + Shell: DefaultUserRequirementShell, + }, + LoginAllowed: DefaultEnvironmentLocalLoginAllowed, + CreateIfAbsent: DefaultEnvironmentLocalCreateIfAbsent, + UpdateIfDifferent: DefaultEnvironmentLocalUpdateIfDifferent, + Dispose: EnvironmentLocalDispose{}, + Banner: DefaultEnvironmentLocalBanner, + PortForwardingAllowed: DefaultEnvironmentLocalPortForwardingAllowed, + }}, + }}, + HouseKeeping: HouseKeeping{ + Every: DefaultHouseKeepingEvery, + InitialDelay: DefaultHouseKeepingInitialDelay, + AutoRepair: DefaultHouseKeepingAutoRepair, + KeepExpiredFor: DefaultHouseKeepingKeepExpiredFor, + }, + }, + }, + ) +} diff --git a/pkg/configuration/environment-local.go b/pkg/configuration/environment-local.go index 0aff0b2..9f60a7c 100644 --- a/pkg/configuration/environment-local.go +++ b/pkg/configuration/environment-local.go @@ -1,8 +1,9 @@ package configuration import ( - "github.com/engity-com/bifroest/pkg/template" "gopkg.in/yaml.v3" + + "github.com/engity-com/bifroest/pkg/template" ) var ( diff --git a/pkg/configuration/environment.go b/pkg/configuration/environment.go index 732b123..7af0a89 100644 --- a/pkg/configuration/environment.go +++ b/pkg/configuration/environment.go @@ -2,8 +2,9 @@ package configuration import ( "fmt" - "gopkg.in/yaml.v3" "strings" + + "gopkg.in/yaml.v3" ) type Environment struct { diff --git a/pkg/configuration/housekeeping.go b/pkg/configuration/housekeeping.go index fafc81d..9fe9651 100644 --- a/pkg/configuration/housekeeping.go +++ b/pkg/configuration/housekeeping.go @@ -1,9 +1,11 @@ package configuration import ( - "github.com/engity-com/bifroest/pkg/common" - "gopkg.in/yaml.v3" "time" + + "gopkg.in/yaml.v3" + + "github.com/engity-com/bifroest/pkg/common" ) var ( diff --git a/pkg/configuration/keys.go b/pkg/configuration/keys.go index 2fe2f39..7918e86 100644 --- a/pkg/configuration/keys.go +++ b/pkg/configuration/keys.go @@ -1,10 +1,12 @@ package configuration import ( + "slices" + + "gopkg.in/yaml.v3" + "github.com/engity-com/bifroest/pkg/crypto" "github.com/engity-com/bifroest/pkg/template" - "gopkg.in/yaml.v3" - "slices" ) var ( diff --git a/pkg/configuration/password-properties.go b/pkg/configuration/password-properties.go index 7289ee4..a71f18e 100644 --- a/pkg/configuration/password-properties.go +++ b/pkg/configuration/password-properties.go @@ -1,8 +1,9 @@ package configuration import ( - "github.com/engity-com/bifroest/pkg/template" "gopkg.in/yaml.v3" + + "github.com/engity-com/bifroest/pkg/template" ) var ( diff --git a/pkg/configuration/requirement.go b/pkg/configuration/requirement.go index 16752de..6f1742a 100644 --- a/pkg/configuration/requirement.go +++ b/pkg/configuration/requirement.go @@ -1,8 +1,9 @@ package configuration import ( - "github.com/engity-com/bifroest/pkg/common" "gopkg.in/yaml.v3" + + "github.com/engity-com/bifroest/pkg/common" ) var ( diff --git a/pkg/configuration/session-fs.go b/pkg/configuration/session-fs.go index 01ff86b..26c4495 100644 --- a/pkg/configuration/session-fs.go +++ b/pkg/configuration/session-fs.go @@ -1,9 +1,10 @@ package configuration import ( + "gopkg.in/yaml.v3" + "github.com/engity-com/bifroest/pkg/common" "github.com/engity-com/bifroest/pkg/sys" - "gopkg.in/yaml.v3" ) var ( diff --git a/pkg/configuration/session.go b/pkg/configuration/session.go index 358d37d..85fa3f0 100644 --- a/pkg/configuration/session.go +++ b/pkg/configuration/session.go @@ -2,10 +2,12 @@ package configuration import ( "fmt" - "github.com/engity-com/bifroest/pkg/common" - "gopkg.in/yaml.v3" "strings" "time" + + "gopkg.in/yaml.v3" + + "github.com/engity-com/bifroest/pkg/common" ) var ( @@ -52,7 +54,10 @@ func RegisterSessionV(factory SessionVFactory) SessionVFactory { } func (this *Session) SetDefaults() error { - *this = Session{} + *this = Session{&SessionFs{}} + if err := this.V.SetDefaults(); err != nil { + return err + } return nil } diff --git a/pkg/configuration/ssh.go b/pkg/configuration/ssh.go index 57041a1..4ee1ae3 100644 --- a/pkg/configuration/ssh.go +++ b/pkg/configuration/ssh.go @@ -1,11 +1,13 @@ package configuration import ( + "time" + + "gopkg.in/yaml.v3" + "github.com/engity-com/bifroest/pkg/common" "github.com/engity-com/bifroest/pkg/net" "github.com/engity-com/bifroest/pkg/template" - "gopkg.in/yaml.v3" - "time" ) var ( diff --git a/pkg/configuration/support.go b/pkg/configuration/support.go index 649bb29..6c40c66 100644 --- a/pkg/configuration/support.go +++ b/pkg/configuration/support.go @@ -3,9 +3,10 @@ package configuration import ( "errors" "fmt" - "gopkg.in/yaml.v3" "slices" "strings" + + "gopkg.in/yaml.v3" ) type defaulter interface { @@ -319,6 +320,7 @@ func isEqual[T equaler](left, right *T) bool { return (*left).IsEqualTo(*right) } +//nolint:golint,unused func isEqualSlice[T equaler](left, right *[]T) bool { if left == nil && right == nil { return true diff --git a/pkg/configuration/support_test.go b/pkg/configuration/support_test.go index 313b66b..1940f26 100644 --- a/pkg/configuration/support_test.go +++ b/pkg/configuration/support_test.go @@ -2,10 +2,11 @@ package configuration import ( "fmt" - "github.com/stretchr/testify/assert" - "gopkg.in/yaml.v3" "strings" "testing" + + "github.com/stretchr/testify/assert" + "gopkg.in/yaml.v3" ) type unmarshalYamlTestCase[T equaler] struct { diff --git a/pkg/configuration/user-requirement-template_windows.go b/pkg/configuration/user-requirement-template_windows.go index fec47e8..e0d95bd 100644 --- a/pkg/configuration/user-requirement-template_windows.go +++ b/pkg/configuration/user-requirement-template_windows.go @@ -82,5 +82,5 @@ func (this UserRequirementTemplate) IsEqualTo(other any) bool { func (this UserRequirementTemplate) isEqualTo(other *UserRequirementTemplate) bool { return isEqual(&this.Name, &other.Name) && - isEqual(&this.Uid, &other.Uid) + isEqual(this.Uid, other.Uid) } diff --git a/pkg/crypto/authorized-keys-file.go b/pkg/crypto/authorized-keys-file.go index e2a82fb..e0fce38 100644 --- a/pkg/crypto/authorized-keys-file.go +++ b/pkg/crypto/authorized-keys-file.go @@ -1,9 +1,11 @@ package crypto import ( - "github.com/engity-com/bifroest/pkg/common" - "golang.org/x/crypto/ssh" "os" + + "golang.org/x/crypto/ssh" + + "github.com/engity-com/bifroest/pkg/common" ) type AuthorizedKeysFile string diff --git a/pkg/crypto/authorized-keys-file_test.go b/pkg/crypto/authorized-keys-file_test.go index db077e9..001d131 100644 --- a/pkg/crypto/authorized-keys-file_test.go +++ b/pkg/crypto/authorized-keys-file_test.go @@ -2,9 +2,10 @@ package crypto import ( "fmt" + "testing" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "testing" ) func TestAuthorizedKeysFile_Get(t *testing.T) { diff --git a/pkg/crypto/authorized-keys-option.go b/pkg/crypto/authorized-keys-option.go index 3f08a25..69fc155 100644 --- a/pkg/crypto/authorized-keys-option.go +++ b/pkg/crypto/authorized-keys-option.go @@ -4,8 +4,9 @@ import ( "bytes" "errors" "fmt" - "golang.org/x/crypto/ssh" "strconv" + + "golang.org/x/crypto/ssh" ) var ( diff --git a/pkg/crypto/authorized-keys.go b/pkg/crypto/authorized-keys.go index 0c2540c..658bec3 100644 --- a/pkg/crypto/authorized-keys.go +++ b/pkg/crypto/authorized-keys.go @@ -6,9 +6,10 @@ import ( "encoding/base64" "errors" "fmt" - "golang.org/x/crypto/ssh" "io" "strings" + + "golang.org/x/crypto/ssh" ) var ( @@ -129,7 +130,7 @@ func parseAuthorizedKey(line []byte) (out ssh.PublicKey, comment string, options var algo string algo, line = cutOffSshKeyAlgo(line) if algo == "" { - // No key type recognised. Maybe there's an options field at the beginning. + // No key type recognized. Maybe there's an options field at the beginning. var b byte inQuote := false optionStart := 0 diff --git a/pkg/crypto/authorized-keys_test.go b/pkg/crypto/authorized-keys_test.go index b1862bd..5c78a16 100644 --- a/pkg/crypto/authorized-keys_test.go +++ b/pkg/crypto/authorized-keys_test.go @@ -2,16 +2,19 @@ package crypto import ( "fmt" - "github.com/engity-com/bifroest/pkg/common" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "golang.org/x/crypto/ssh" "os" "path/filepath" "strings" "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "golang.org/x/crypto/ssh" + + "github.com/engity-com/bifroest/pkg/common" ) +//nolint:golint,unused var ( dsa1Pub, dsa1Fn = mustSshPublicKey("dsa-1") ecdsa1Pub, ecdsa1Fn = mustSshPublicKey("ecdsa-1") diff --git a/pkg/crypto/dsa-restriction.go b/pkg/crypto/dsa-restriction.go index b46f0a1..9e2d817 100644 --- a/pkg/crypto/dsa-restriction.go +++ b/pkg/crypto/dsa-restriction.go @@ -3,8 +3,9 @@ package crypto import ( "crypto/dsa" "fmt" - "golang.org/x/crypto/ssh" "strings" + + "golang.org/x/crypto/ssh" ) type DsaRestriction uint8 diff --git a/pkg/crypto/ecdsa-restriction.go b/pkg/crypto/ecdsa-restriction.go index 85dbfe1..bf5d92b 100644 --- a/pkg/crypto/ecdsa-restriction.go +++ b/pkg/crypto/ecdsa-restriction.go @@ -3,8 +3,9 @@ package crypto import ( "crypto/ecdsa" "fmt" - "golang.org/x/crypto/ssh" "strings" + + "golang.org/x/crypto/ssh" ) type EcdsaRestriction uint8 diff --git a/pkg/crypto/ed25519-restriction.go b/pkg/crypto/ed25519-restriction.go index fa3f0bf..53c3ad9 100644 --- a/pkg/crypto/ed25519-restriction.go +++ b/pkg/crypto/ed25519-restriction.go @@ -3,8 +3,9 @@ package crypto import ( "crypto/ed25519" "fmt" - "golang.org/x/crypto/ssh" "strings" + + "golang.org/x/crypto/ssh" ) type Ed25519Restriction uint8 diff --git a/pkg/crypto/htpasswd.go b/pkg/crypto/htpasswd.go index 3eedbe0..3a137bb 100644 --- a/pkg/crypto/htpasswd.go +++ b/pkg/crypto/htpasswd.go @@ -2,6 +2,7 @@ package crypto import ( "bytes" + "github.com/tg123/go-htpasswd" ) diff --git a/pkg/crypto/key-requirement.go b/pkg/crypto/key-requirement.go index faf0871..f79be3c 100644 --- a/pkg/crypto/key-requirement.go +++ b/pkg/crypto/key-requirement.go @@ -8,10 +8,11 @@ import ( crand "crypto/rand" "crypto/rsa" "fmt" - "github.com/engity-com/bifroest/pkg/common" "io" "os" "path/filepath" + + "github.com/engity-com/bifroest/pkg/common" ) const ( @@ -41,6 +42,9 @@ func (this KeyRequirement) CreateFile(rand io.Reader, fn string) (crypto.Signer, _ = os.MkdirAll(filepath.Dir(fn), 0700) f, err := os.OpenFile(fn, os.O_CREATE|os.O_WRONLY, 0400) + if err != nil { + return nil, err + } defer common.IgnoreCloseError(f) if err := WriteSshPrivateKey(pk, f); err != nil { diff --git a/pkg/crypto/key.go b/pkg/crypto/key.go index 404512a..b93a867 100644 --- a/pkg/crypto/key.go +++ b/pkg/crypto/key.go @@ -5,12 +5,14 @@ import ( "crypto/dsa" "encoding/pem" "fmt" - "github.com/engity-com/bifroest/pkg/sys" + "io" + "os" + "github.com/mikesmitty/edkey" "golang.org/x/crypto/ed25519" "golang.org/x/crypto/ssh" - "io" - "os" + + "github.com/engity-com/bifroest/pkg/sys" ) func EnsureKeyFile(fn string, reqOnAbsence *KeyRequirement, rand io.Reader) (crypto.Signer, error) { diff --git a/pkg/crypto/password-bcrypt.go b/pkg/crypto/password-bcrypt.go index e89e541..1476347 100644 --- a/pkg/crypto/password-bcrypt.go +++ b/pkg/crypto/password-bcrypt.go @@ -1,8 +1,9 @@ package crypto import ( - "github.com/engity-com/bifroest/pkg/errors" "golang.org/x/crypto/bcrypt" + + "github.com/engity-com/bifroest/pkg/errors" ) func (this PasswordType) encodeBcrypt(password []byte) ([]byte, error) { diff --git a/pkg/crypto/rsa-restriction.go b/pkg/crypto/rsa-restriction.go index 5f41834..224d620 100644 --- a/pkg/crypto/rsa-restriction.go +++ b/pkg/crypto/rsa-restriction.go @@ -3,8 +3,9 @@ package crypto import ( "crypto/rsa" "fmt" - "golang.org/x/crypto/ssh" "strings" + + "golang.org/x/crypto/ssh" ) type RsaRestriction uint8 diff --git a/pkg/crypto/ssh.go b/pkg/crypto/ssh.go index afd2805..233da7f 100644 --- a/pkg/crypto/ssh.go +++ b/pkg/crypto/ssh.go @@ -2,9 +2,11 @@ package crypto import ( "fmt" - "github.com/engity-com/bifroest/pkg/sys" - "golang.org/x/crypto/ssh" "os" + + "golang.org/x/crypto/ssh" + + "github.com/engity-com/bifroest/pkg/sys" ) func DoWithEachAuthorizedKey[R any](requireExistence bool, callback func(ssh.PublicKey) (result R, canContinue bool, err error), files ...string) (result R, err error) { diff --git a/pkg/crypto/unix/password/apr1.go b/pkg/crypto/unix/password/apr1.go index 47d9ccd..2d3edd0 100644 --- a/pkg/crypto/unix/password/apr1.go +++ b/pkg/crypto/unix/password/apr1.go @@ -3,6 +3,7 @@ package password import ( "github.com/GehirnInc/crypt" "github.com/GehirnInc/crypt/apr1_crypt" + "github.com/engity-com/bifroest/pkg/errors" ) diff --git a/pkg/crypto/unix/password/crypt.go b/pkg/crypto/unix/password/crypt.go index 0dc9a56..43d6122 100644 --- a/pkg/crypto/unix/password/crypt.go +++ b/pkg/crypto/unix/password/crypt.go @@ -2,8 +2,9 @@ package password import ( "bytes" - "github.com/engity-com/bifroest/pkg/errors" "sort" + + "github.com/engity-com/bifroest/pkg/errors" ) var ( diff --git a/pkg/crypto/unix/password/md5.go b/pkg/crypto/unix/password/md5.go index 5536e22..1f9cf35 100644 --- a/pkg/crypto/unix/password/md5.go +++ b/pkg/crypto/unix/password/md5.go @@ -3,6 +3,7 @@ package password import ( "github.com/GehirnInc/crypt" "github.com/GehirnInc/crypt/md5_crypt" + "github.com/engity-com/bifroest/pkg/errors" ) diff --git a/pkg/crypto/unix/password/sha256.go b/pkg/crypto/unix/password/sha256.go index 9c3dbeb..b6a72ad 100644 --- a/pkg/crypto/unix/password/sha256.go +++ b/pkg/crypto/unix/password/sha256.go @@ -3,6 +3,7 @@ package password import ( "github.com/GehirnInc/crypt" "github.com/GehirnInc/crypt/sha256_crypt" + "github.com/engity-com/bifroest/pkg/errors" ) diff --git a/pkg/crypto/unix/password/sha512.go b/pkg/crypto/unix/password/sha512.go index afa89e5..cf8790d 100644 --- a/pkg/crypto/unix/password/sha512.go +++ b/pkg/crypto/unix/password/sha512.go @@ -3,6 +3,7 @@ package password import ( "github.com/GehirnInc/crypt" "github.com/GehirnInc/crypt/sha512_crypt" + "github.com/engity-com/bifroest/pkg/errors" ) diff --git a/pkg/environment/environment.go b/pkg/environment/environment.go index b2b764f..223a82c 100644 --- a/pkg/environment/environment.go +++ b/pkg/environment/environment.go @@ -2,8 +2,9 @@ package environment import ( "context" - "github.com/engity-com/bifroest/pkg/session" "io" + + "github.com/engity-com/bifroest/pkg/session" ) type Environment interface { diff --git a/pkg/environment/facade-repository.go b/pkg/environment/facade-repository.go index 4fe9804..dc96963 100644 --- a/pkg/environment/facade-repository.go +++ b/pkg/environment/facade-repository.go @@ -3,11 +3,12 @@ package environment import ( "context" "fmt" + "reflect" + "github.com/engity-com/bifroest/pkg/common" "github.com/engity-com/bifroest/pkg/configuration" "github.com/engity-com/bifroest/pkg/errors" "github.com/engity-com/bifroest/pkg/session" - "reflect" ) func NewRepositoryFacade(ctx context.Context, flows *configuration.Flows) (*RepositoryFacade, error) { diff --git a/pkg/environment/local-repository.go b/pkg/environment/local-repository.go index 10c5ba2..6434fc2 100644 --- a/pkg/environment/local-repository.go +++ b/pkg/environment/local-repository.go @@ -4,7 +4,9 @@ import ( "context" "encoding/json" "fmt" + log "github.com/echocat/slf4g" + "github.com/engity-com/bifroest/pkg/configuration" "github.com/engity-com/bifroest/pkg/errors" "github.com/engity-com/bifroest/pkg/session" diff --git a/pkg/environment/local-token_windows.go b/pkg/environment/local-token_windows.go index 9e4fddc..f31e12b 100644 --- a/pkg/environment/local-token_windows.go +++ b/pkg/environment/local-token_windows.go @@ -4,6 +4,7 @@ package environment import ( "fmt" + "github.com/engity-com/bifroest/pkg/common" "github.com/engity-com/bifroest/pkg/user" ) diff --git a/pkg/environment/local.go b/pkg/environment/local.go index c39c74b..d0fc8e1 100644 --- a/pkg/environment/local.go +++ b/pkg/environment/local.go @@ -3,15 +3,6 @@ package environment import ( "context" "fmt" - "github.com/creack/pty" - log "github.com/echocat/slf4g" - "github.com/echocat/slf4g/level" - "github.com/engity-com/bifroest/pkg/common" - "github.com/engity-com/bifroest/pkg/errors" - "github.com/engity-com/bifroest/pkg/session" - "github.com/engity-com/bifroest/pkg/sys" - "github.com/gliderlabs/ssh" - "github.com/kardianos/osext" "io" "net" "os" @@ -20,6 +11,17 @@ import ( "strings" "sync" "syscall" + + "github.com/creack/pty" + log "github.com/echocat/slf4g" + "github.com/echocat/slf4g/level" + "github.com/gliderlabs/ssh" + "github.com/kardianos/osext" + + "github.com/engity-com/bifroest/pkg/common" + "github.com/engity-com/bifroest/pkg/errors" + "github.com/engity-com/bifroest/pkg/session" + "github.com/engity-com/bifroest/pkg/sys" ) func (this *local) Session() session.Session { @@ -117,7 +119,7 @@ func (this *local) Run(t Task) (exitCode int, rErr error) { if !ok { return } - size := pty.Winsize{uint16(win.Height), uint16(win.Width), 0, 0} + size := pty.Winsize{Rows: uint16(win.Height), Cols: uint16(win.Width)} if err := pty.Setsize(fPty, &size); err != nil { l.WithError(err).Warn("cannot set winsize; ignoring") } diff --git a/pkg/environment/local_linux.go b/pkg/environment/local_linux.go index 4eb0b0a..46e1b26 100644 --- a/pkg/environment/local_linux.go +++ b/pkg/environment/local_linux.go @@ -4,17 +4,19 @@ package environment import ( "context" + "os" + "os/exec" + "path/filepath" + "syscall" + log "github.com/echocat/slf4g" + "github.com/gliderlabs/ssh" + "github.com/engity-com/bifroest/pkg/common" "github.com/engity-com/bifroest/pkg/errors" "github.com/engity-com/bifroest/pkg/session" "github.com/engity-com/bifroest/pkg/sys" "github.com/engity-com/bifroest/pkg/user" - "github.com/gliderlabs/ssh" - "os" - "os/exec" - "path/filepath" - "syscall" ) type local struct { diff --git a/pkg/environment/local_windows.go b/pkg/environment/local_windows.go index f4eeb1b..e49c694 100644 --- a/pkg/environment/local_windows.go +++ b/pkg/environment/local_windows.go @@ -4,15 +4,17 @@ package environment import ( "context" + "os" + "os/exec" + "syscall" + log "github.com/echocat/slf4g" + "github.com/gliderlabs/ssh" + "github.com/engity-com/bifroest/pkg/errors" "github.com/engity-com/bifroest/pkg/session" "github.com/engity-com/bifroest/pkg/sys" "github.com/engity-com/bifroest/pkg/user" - "github.com/gliderlabs/ssh" - "os" - "os/exec" - "syscall" ) type local struct { diff --git a/pkg/environment/repository.go b/pkg/environment/repository.go index c7ebf7c..0ebd509 100644 --- a/pkg/environment/repository.go +++ b/pkg/environment/repository.go @@ -3,9 +3,11 @@ package environment import ( "context" "errors" + "io" + log "github.com/echocat/slf4g" + "github.com/engity-com/bifroest/pkg/session" - "io" ) var ( diff --git a/pkg/environment/request.go b/pkg/environment/request.go index 0863baf..a353d06 100644 --- a/pkg/environment/request.go +++ b/pkg/environment/request.go @@ -2,9 +2,10 @@ package environment import ( log "github.com/echocat/slf4g" + "github.com/gliderlabs/ssh" + "github.com/engity-com/bifroest/pkg/authorization" "github.com/engity-com/bifroest/pkg/common" - "github.com/gliderlabs/ssh" ) type Request interface { diff --git a/pkg/environment/task.go b/pkg/environment/task.go index d0055b3..f2b3de1 100644 --- a/pkg/environment/task.go +++ b/pkg/environment/task.go @@ -2,6 +2,7 @@ package environment import ( "fmt" + "github.com/gliderlabs/ssh" ) diff --git a/pkg/service/connection.go b/pkg/service/connection.go index f444881..ec78201 100644 --- a/pkg/service/connection.go +++ b/pkg/service/connection.go @@ -2,17 +2,19 @@ package service import ( "fmt" - log "github.com/echocat/slf4g" - "github.com/echocat/slf4g/fields" - "github.com/engity-com/bifroest/pkg/authorization" - "github.com/engity-com/bifroest/pkg/errors" - "github.com/engity-com/bifroest/pkg/session" - "github.com/gliderlabs/ssh" "net" "os" "strconv" "sync/atomic" "time" + + log "github.com/echocat/slf4g" + "github.com/echocat/slf4g/fields" + "github.com/gliderlabs/ssh" + + "github.com/engity-com/bifroest/pkg/authorization" + "github.com/engity-com/bifroest/pkg/errors" + "github.com/engity-com/bifroest/pkg/session" ) func (this *service) onNewConnConnection(ctx ssh.Context, orig net.Conn) net.Conn { diff --git a/pkg/service/context.go b/pkg/service/context.go index fccf5fa..e2663e7 100644 --- a/pkg/service/context.go +++ b/pkg/service/context.go @@ -2,15 +2,17 @@ package service import ( "fmt" + "io" + log "github.com/echocat/slf4g" + "github.com/gliderlabs/ssh" + gssh "golang.org/x/crypto/ssh" + "github.com/engity-com/bifroest/pkg/authorization" "github.com/engity-com/bifroest/pkg/common" "github.com/engity-com/bifroest/pkg/environment" "github.com/engity-com/bifroest/pkg/net" "github.com/engity-com/bifroest/pkg/session" - "github.com/gliderlabs/ssh" - gssh "golang.org/x/crypto/ssh" - "io" ) type remote struct { diff --git a/pkg/service/housekeeper.go b/pkg/service/housekeeper.go index f2e7532..af39f12 100644 --- a/pkg/service/housekeeper.go +++ b/pkg/service/housekeeper.go @@ -2,14 +2,17 @@ package service import ( "context" + "fmt" + "sync/atomic" + "time" + log "github.com/echocat/slf4g" + "github.com/engity-com/bifroest/pkg/authorization" "github.com/engity-com/bifroest/pkg/common" "github.com/engity-com/bifroest/pkg/environment" "github.com/engity-com/bifroest/pkg/errors" "github.com/engity-com/bifroest/pkg/session" - "sync/atomic" - "time" ) type houseKeeper struct { @@ -71,15 +74,15 @@ func (this *houseKeeper) checkedRun(ctx context.Context) (nextRunIn time.Duratio } }() - //defer func() { - // if v := recover(); v != nil { - // if err, ok := v.(error); ok { - // rErr = err - // } else { - // rErr = fmt.Errorf("panic while housekeeping occured: %v", v) - // } - // } - //}() + defer func() { + if v := recover(); v != nil { + if err, ok := v.(error); ok { + rErr = err + } else { + rErr = fmt.Errorf("panic while housekeeping occurred: %v", v) + } + } + }() l.Debug("housekeeping run started") diff --git a/pkg/service/service-authorization.go b/pkg/service/service-authorization.go index 8269305..c5322b6 100644 --- a/pkg/service/service-authorization.go +++ b/pkg/service/service-authorization.go @@ -1,11 +1,12 @@ package service import ( + "github.com/gliderlabs/ssh" + gssh "golang.org/x/crypto/ssh" + "github.com/engity-com/bifroest/pkg/authorization" "github.com/engity-com/bifroest/pkg/errors" "github.com/engity-com/bifroest/pkg/session" - "github.com/gliderlabs/ssh" - gssh "golang.org/x/crypto/ssh" ) func (this *service) handlePublicKey(ctx ssh.Context, key ssh.PublicKey) bool { diff --git a/pkg/service/service-direct-tcp-ip.go b/pkg/service/service-direct-tcp-ip.go index 19ad7f2..3a0ef32 100644 --- a/pkg/service/service-direct-tcp-ip.go +++ b/pkg/service/service-direct-tcp-ip.go @@ -1,14 +1,16 @@ package service import ( - "github.com/engity-com/bifroest/pkg/common" - "github.com/engity-com/bifroest/pkg/environment" - "github.com/gliderlabs/ssh" - gssh "golang.org/x/crypto/ssh" "io" "sync" "sync/atomic" "time" + + "github.com/gliderlabs/ssh" + gssh "golang.org/x/crypto/ssh" + + "github.com/engity-com/bifroest/pkg/common" + "github.com/engity-com/bifroest/pkg/environment" ) type localForwardChannelData struct { @@ -96,7 +98,7 @@ func (this *service) handleNewDirectTcpIp(_ *ssh.Server, _ *gssh.ServerConn, new if direction != "" { ld = ld.With("direction", direction) } - ld.WithError(rErr).Error("cannot successful handle port forwarding request; cancelling...") + ld.WithError(rErr).Error("cannot successful handle port forwarding request; canceling...") } else { ld.Info("port forwarding finished") } diff --git a/pkg/service/service-messages.go b/pkg/service/service-messages.go index 713593e..27e0e20 100644 --- a/pkg/service/service-messages.go +++ b/pkg/service/service-messages.go @@ -1,11 +1,13 @@ package service import ( + "io" + + "github.com/gliderlabs/ssh" + "github.com/engity-com/bifroest/pkg/authorization" "github.com/engity-com/bifroest/pkg/errors" "github.com/engity-com/bifroest/pkg/session" - "github.com/gliderlabs/ssh" - "io" ) func (this *service) handleBanner(ctx ssh.Context) string { diff --git a/pkg/service/service-session.go b/pkg/service/service-session.go index 0de5ef2..5b9566f 100644 --- a/pkg/service/service-session.go +++ b/pkg/service/service-session.go @@ -2,12 +2,14 @@ package service import ( "context" + "io" + + "github.com/gliderlabs/ssh" + gssh "golang.org/x/crypto/ssh" + "github.com/engity-com/bifroest/pkg/common" "github.com/engity-com/bifroest/pkg/environment" "github.com/engity-com/bifroest/pkg/errors" - "github.com/gliderlabs/ssh" - gssh "golang.org/x/crypto/ssh" - "io" ) func (this *service) handleNewSshSession(srv *ssh.Server, conn *gssh.ServerConn, newChan gssh.NewChannel, ctx ssh.Context) { diff --git a/pkg/service/service.go b/pkg/service/service.go index 372f17f..4d71a0b 100644 --- a/pkg/service/service.go +++ b/pkg/service/service.go @@ -3,8 +3,17 @@ package service import ( "context" "fmt" + "io" + "net" + "sync" + "sync/atomic" + "syscall" + log "github.com/echocat/slf4g" "github.com/echocat/slf4g/fields" + "github.com/gliderlabs/ssh" + gssh "golang.org/x/crypto/ssh" + "github.com/engity-com/bifroest/pkg/authorization" "github.com/engity-com/bifroest/pkg/common" "github.com/engity-com/bifroest/pkg/configuration" @@ -13,13 +22,6 @@ import ( "github.com/engity-com/bifroest/pkg/errors" bnet "github.com/engity-com/bifroest/pkg/net" "github.com/engity-com/bifroest/pkg/session" - "github.com/gliderlabs/ssh" - gssh "golang.org/x/crypto/ssh" - "io" - "net" - "sync" - "sync/atomic" - "syscall" ) var ( diff --git a/pkg/service/service_linux.go b/pkg/service/service_linux.go index 6b369e1..327dad3 100644 --- a/pkg/service/service_linux.go +++ b/pkg/service/service_linux.go @@ -3,9 +3,11 @@ package service import ( - "github.com/engity-com/bifroest/pkg/errors" - "github.com/gliderlabs/ssh" "syscall" + + "github.com/gliderlabs/ssh" + + "github.com/engity-com/bifroest/pkg/errors" ) func (this *service) isAcceptableNewConnectionError(err error) bool { diff --git a/pkg/service/service_windows.go b/pkg/service/service_windows.go index 3e87d45..a06a451 100644 --- a/pkg/service/service_windows.go +++ b/pkg/service/service_windows.go @@ -3,9 +3,11 @@ package service import ( - "github.com/engity-com/bifroest/pkg/errors" - "github.com/gliderlabs/ssh" "syscall" + + "github.com/gliderlabs/ssh" + + "github.com/engity-com/bifroest/pkg/errors" ) func (this *service) isAcceptableNewConnectionError(err error) bool { diff --git a/pkg/session/common.go b/pkg/session/common.go index eddb883..a6efacb 100644 --- a/pkg/session/common.go +++ b/pkg/session/common.go @@ -2,8 +2,9 @@ package session import ( "bytes" - "github.com/engity-com/bifroest/pkg/errors" "io" + + "github.com/engity-com/bifroest/pkg/errors" ) func isReaderEqualToBytes(left io.Reader, right []byte) (bool, error) { diff --git a/pkg/session/common_test.go b/pkg/session/common_test.go index a8076cb..b38ae4d 100644 --- a/pkg/session/common_test.go +++ b/pkg/session/common_test.go @@ -3,10 +3,11 @@ package session import ( "bytes" "fmt" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "math/rand" "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func Test_isReaderEqualToBytes(t *testing.T) { diff --git a/pkg/session/connection-interceptor.go b/pkg/session/connection-interceptor.go index 2983b52..93959df 100644 --- a/pkg/session/connection-interceptor.go +++ b/pkg/session/connection-interceptor.go @@ -1,11 +1,12 @@ package session import ( - log "github.com/echocat/slf4g" - "github.com/gliderlabs/ssh" "io" "net" "time" + + log "github.com/echocat/slf4g" + "github.com/gliderlabs/ssh" ) type ConnectionInterceptor interface { diff --git a/pkg/session/facade-repository.go b/pkg/session/facade-repository.go index 2dffe26..46e3470 100644 --- a/pkg/session/facade-repository.go +++ b/pkg/session/facade-repository.go @@ -3,9 +3,10 @@ package session import ( "context" "fmt" + "reflect" + "github.com/engity-com/bifroest/pkg/configuration" "github.com/engity-com/bifroest/pkg/errors" - "reflect" ) func NewFacadeRepository(ctx context.Context, conf *configuration.Session) (*FacadeRepository, error) { diff --git a/pkg/session/fs-connection-interceptor.go b/pkg/session/fs-connection-interceptor.go index e9ef7da..f6c21fb 100644 --- a/pkg/session/fs-connection-interceptor.go +++ b/pkg/session/fs-connection-interceptor.go @@ -3,13 +3,15 @@ package session import ( "context" "fmt" - log "github.com/echocat/slf4g" - "github.com/engity-com/bifroest/pkg/configuration" - "github.com/gliderlabs/ssh" - "github.com/google/uuid" "net" "sync/atomic" "time" + + log "github.com/echocat/slf4g" + "github.com/gliderlabs/ssh" + "github.com/google/uuid" + + "github.com/engity-com/bifroest/pkg/configuration" ) func (this *fs) ConnectionInterceptor(context.Context) (ConnectionInterceptor, error) { diff --git a/pkg/session/fs-created.go b/pkg/session/fs-created.go index 022b98a..bade094 100644 --- a/pkg/session/fs-created.go +++ b/pkg/session/fs-created.go @@ -2,10 +2,11 @@ package session import ( "fmt" - "github.com/engity-com/bifroest/pkg/common" - "github.com/engity-com/bifroest/pkg/net" "strings" "time" + + "github.com/engity-com/bifroest/pkg/common" + "github.com/engity-com/bifroest/pkg/net" ) type fsCreated struct { diff --git a/pkg/session/fs-info.go b/pkg/session/fs-info.go index 314f351..aeababa 100644 --- a/pkg/session/fs-info.go +++ b/pkg/session/fs-info.go @@ -4,12 +4,14 @@ import ( "context" "encoding/json" "fmt" + "os" + "time" + + "github.com/google/uuid" + "github.com/engity-com/bifroest/pkg/common" "github.com/engity-com/bifroest/pkg/configuration" "github.com/engity-com/bifroest/pkg/net" - "github.com/google/uuid" - "os" - "time" ) type fsInfo struct { diff --git a/pkg/session/fs-lastaccessed.go b/pkg/session/fs-lastaccessed.go index 9bd9853..17bbdc3 100644 --- a/pkg/session/fs-lastaccessed.go +++ b/pkg/session/fs-lastaccessed.go @@ -4,11 +4,12 @@ import ( "context" "encoding/json" "fmt" - "github.com/engity-com/bifroest/pkg/common" - "github.com/engity-com/bifroest/pkg/net" "os" "strings" "time" + + "github.com/engity-com/bifroest/pkg/common" + "github.com/engity-com/bifroest/pkg/net" ) type fsLastAccessed struct { diff --git a/pkg/session/fs-repository.go b/pkg/session/fs-repository.go index c2be265..5a110a5 100644 --- a/pkg/session/fs-repository.go +++ b/pkg/session/fs-repository.go @@ -8,19 +8,21 @@ import ( "encoding/base64" "encoding/json" "fmt" - log "github.com/echocat/slf4g" - "github.com/engity-com/bifroest/pkg/common" - "github.com/engity-com/bifroest/pkg/configuration" - "github.com/engity-com/bifroest/pkg/errors" - "github.com/engity-com/bifroest/pkg/sys" - "github.com/google/uuid" - "github.com/mr-tron/base58" - "golang.org/x/crypto/ssh" "os" "path/filepath" "strings" "sync" "time" + + log "github.com/echocat/slf4g" + "github.com/google/uuid" + "github.com/mr-tron/base58" + "golang.org/x/crypto/ssh" + + "github.com/engity-com/bifroest/pkg/common" + "github.com/engity-com/bifroest/pkg/configuration" + "github.com/engity-com/bifroest/pkg/errors" + "github.com/engity-com/bifroest/pkg/sys" ) const ( @@ -432,7 +434,6 @@ func (this *FsRepository) doFindAutoCleanIfAllowed(ctx context.Context, flow con Warn(successMessage) } } - return } func (this *FsRepository) doAutoCleanUnexpectedFilesIfAllowed(_ context.Context, sess *fs, opts *FindOpts) { @@ -521,7 +522,6 @@ func (this *FsRepository) doFindAutoCleanFlowContentIfAllowed(_ context.Context, Warn(successMessage) } } - return } func (this *FsRepository) doFindAutoCleanRootContentIfAllowed(_ context.Context, fn string, opts *FindOpts, successMessage string, cause error) { @@ -541,7 +541,6 @@ func (this *FsRepository) doFindAutoCleanRootContentIfAllowed(_ context.Context, Warn(successMessage) } } - return } func (this *FsRepository) Delete(ctx context.Context, s Session) error { @@ -684,7 +683,7 @@ func (this *FsRepository) findPublicKeyIn(ctx context.Context, flow configuratio line := scanner.Bytes() lineN++ if len(line) == 0 { - //Skip empty lines... + // Skip empty lines... continue } keyBytes, err := base64.StdEncoding.DecodeString(string(line)) diff --git a/pkg/session/fs.go b/pkg/session/fs.go index 9bc2949..c949e03 100644 --- a/pkg/session/fs.go +++ b/pkg/session/fs.go @@ -3,14 +3,16 @@ package session import ( "context" "fmt" - "github.com/engity-com/bifroest/pkg/common" - "github.com/engity-com/bifroest/pkg/configuration" - "github.com/engity-com/bifroest/pkg/sys" - "github.com/google/uuid" - "golang.org/x/crypto/ssh" "io" "os" "time" + + "github.com/google/uuid" + "golang.org/x/crypto/ssh" + + "github.com/engity-com/bifroest/pkg/common" + "github.com/engity-com/bifroest/pkg/configuration" + "github.com/engity-com/bifroest/pkg/sys" ) const ( diff --git a/pkg/session/info.go b/pkg/session/info.go index 662970c..ed3658a 100644 --- a/pkg/session/info.go +++ b/pkg/session/info.go @@ -2,10 +2,12 @@ package session import ( "context" + "time" + + "github.com/google/uuid" + "github.com/engity-com/bifroest/pkg/common" "github.com/engity-com/bifroest/pkg/configuration" - "github.com/google/uuid" - "time" ) type Info interface { diff --git a/pkg/session/predicates.go b/pkg/session/predicates.go index 7edb857..321c738 100644 --- a/pkg/session/predicates.go +++ b/pkg/session/predicates.go @@ -2,8 +2,9 @@ package session import ( "context" - "github.com/engity-com/bifroest/pkg/configuration" "time" + + "github.com/engity-com/bifroest/pkg/configuration" ) type Predicate func(context.Context, Session) (bool, error) diff --git a/pkg/session/repository.go b/pkg/session/repository.go index c5f4289..f7ebcf0 100644 --- a/pkg/session/repository.go +++ b/pkg/session/repository.go @@ -3,12 +3,14 @@ package session import ( "context" "errors" + "io" + log "github.com/echocat/slf4g" - "github.com/engity-com/bifroest/pkg/common" - "github.com/engity-com/bifroest/pkg/configuration" "github.com/google/uuid" "golang.org/x/crypto/ssh" - "io" + + "github.com/engity-com/bifroest/pkg/common" + "github.com/engity-com/bifroest/pkg/configuration" ) var ( diff --git a/pkg/session/session.go b/pkg/session/session.go index 37f5dd2..ca989d9 100644 --- a/pkg/session/session.go +++ b/pkg/session/session.go @@ -2,11 +2,13 @@ package session import ( "context" + + "github.com/google/uuid" + "golang.org/x/crypto/ssh" + "github.com/engity-com/bifroest/pkg/common" "github.com/engity-com/bifroest/pkg/configuration" "github.com/engity-com/bifroest/pkg/errors" - "github.com/google/uuid" - "golang.org/x/crypto/ssh" ) var ( diff --git a/pkg/sftp/server.go b/pkg/sftp/server.go index 11ce9c5..65a59d5 100644 --- a/pkg/sftp/server.go +++ b/pkg/sftp/server.go @@ -3,12 +3,14 @@ package sftp import ( "errors" "fmt" + "io" + "os" + log "github.com/echocat/slf4g" "github.com/echocat/slf4g/level" - "github.com/engity-com/bifroest/pkg/common" "github.com/pkg/sftp" - "io" - "os" + + "github.com/engity-com/bifroest/pkg/common" ) type Server struct { @@ -42,13 +44,6 @@ func (this *Server) debugLogWriter() io.Writer { } } -func (this *Server) logger() log.Logger { - if v := this.Logger; v != nil { - return v - } - return log.GetRootLogger() -} - func (this *Server) workingDir() string { if v := this.WorkingDir; v != "" { return v diff --git a/pkg/template/bool.go b/pkg/template/bool.go index cbe670c..c10558d 100644 --- a/pkg/template/bool.go +++ b/pkg/template/bool.go @@ -2,8 +2,9 @@ package template import ( "fmt" - "github.com/engity-com/bifroest/internal/text/template" "strings" + + "github.com/engity-com/bifroest/internal/text/template" ) func NewBool(plain string) (Bool, error) { diff --git a/pkg/template/bool_test.go b/pkg/template/bool_test.go index 6b12658..65e163f 100644 --- a/pkg/template/bool_test.go +++ b/pkg/template/bool_test.go @@ -3,8 +3,9 @@ package template import ( "errors" "fmt" - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) func TestBool(t *testing.T) { diff --git a/pkg/template/funcs.go b/pkg/template/funcs.go index 42a8e63..22af3cf 100644 --- a/pkg/template/funcs.go +++ b/pkg/template/funcs.go @@ -5,11 +5,6 @@ import ( "crypto/sha256" "encoding/base64" "fmt" - "github.com/Masterminds/sprig/v3" - "github.com/engity-com/bifroest/internal/text/template" - "github.com/engity-com/bifroest/pkg/common" - "github.com/engity-com/bifroest/pkg/sys" - "golang.org/x/crypto/ssh" "io" "io/fs" "os" @@ -18,6 +13,13 @@ import ( "reflect" "strings" "time" + + "github.com/Masterminds/sprig/v3" + "golang.org/x/crypto/ssh" + + "github.com/engity-com/bifroest/internal/text/template" + "github.com/engity-com/bifroest/pkg/common" + "github.com/engity-com/bifroest/pkg/sys" ) const ( diff --git a/pkg/template/string.go b/pkg/template/string.go index abbd1b0..d34f31b 100644 --- a/pkg/template/string.go +++ b/pkg/template/string.go @@ -2,9 +2,10 @@ package template import ( "fmt" - "github.com/engity-com/bifroest/internal/text/template" "strings" "text/template/parse" + + "github.com/engity-com/bifroest/internal/text/template" ) func NewString(plain string) (String, error) { diff --git a/pkg/template/string_test.go b/pkg/template/string_test.go index b2ebcfb..a0016aa 100644 --- a/pkg/template/string_test.go +++ b/pkg/template/string_test.go @@ -2,8 +2,9 @@ package template import ( "fmt" - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) func TestString(t *testing.T) { diff --git a/pkg/template/text-marshaller.go b/pkg/template/text-marshaller.go index bdcda3d..f2bf60f 100644 --- a/pkg/template/text-marshaller.go +++ b/pkg/template/text-marshaller.go @@ -3,8 +3,9 @@ package template import ( "encoding" "fmt" - "github.com/engity-com/bifroest/internal/text/template" "strings" + + "github.com/engity-com/bifroest/internal/text/template" ) func NewTextMarshaller[T TextMarshallerArgument, PT TextMarshallerArgumentP[T]](plain string) (TextMarshaller[T, PT], error) { diff --git a/pkg/template/uint64.go b/pkg/template/uint64.go index 8178dfb..fb37f40 100644 --- a/pkg/template/uint64.go +++ b/pkg/template/uint64.go @@ -2,9 +2,10 @@ package template import ( "fmt" - "github.com/engity-com/bifroest/internal/text/template" "strconv" "strings" + + "github.com/engity-com/bifroest/internal/text/template" ) func NewUint64(plain string) (Uint64, error) { diff --git a/pkg/template/uint64_test.go b/pkg/template/uint64_test.go index 7824b06..95fa64e 100644 --- a/pkg/template/uint64_test.go +++ b/pkg/template/uint64_test.go @@ -3,8 +3,9 @@ package template import ( "errors" "fmt" - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) func TestUint64(t *testing.T) { diff --git a/pkg/user/common_test.go b/pkg/user/common_test.go index e36316c..35ffb1b 100644 --- a/pkg/user/common_test.go +++ b/pkg/user/common_test.go @@ -1,20 +1,23 @@ +//nolint:golint,unused package user import ( "bytes" "fmt" - "github.com/engity-com/bifroest/pkg/sys" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "io" "os" "path/filepath" "strings" "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/engity-com/bifroest/pkg/sys" ) var ( - keepPkgUserFiles = os.Getenv("KEEP_PKG_USER_TEST_FILES") == "yes" + keepPkgUserFiles = os.Getenv("KEEP_PKG_USER_TEST_FILES") == "yes" //nolint:golint,unused ) func b(in string) []byte { diff --git a/pkg/user/ensure.go b/pkg/user/ensure.go index 9a2be5f..7723cf2 100644 --- a/pkg/user/ensure.go +++ b/pkg/user/ensure.go @@ -10,11 +10,11 @@ import ( var ( // ErrUserDoesNotFulfilRequirement indicates that a User does not // meet the provided Requirement. - ErrUserDoesNotFulfilRequirement = errors.New("user does not fulfil requirement") + ErrUserDoesNotFulfilRequirement = errors.New("user does not fulfill requirement") // ErrGroupDoesNotFulfilRequirement indicates that a Group does not // meet the provided GroupRequirement. - ErrGroupDoesNotFulfilRequirement = errors.New("group does not fulfil requirement") + ErrGroupDoesNotFulfilRequirement = errors.New("group does not fulfill requirement") ) // Ensurer ensures that a User or Group meets the provided requirements. diff --git a/pkg/user/etc-colon-entry_test.go b/pkg/user/etc-colon-entry_test.go index c9ce43f..96a4313 100644 --- a/pkg/user/etc-colon-entry_test.go +++ b/pkg/user/etc-colon-entry_test.go @@ -1,11 +1,14 @@ +//go:build test + package user import ( "bytes" - "github.com/echocat/slf4g/sdk/testlog" - "github.com/stretchr/testify/require" "strings" "testing" + + "github.com/echocat/slf4g/sdk/testlog" + "github.com/stretchr/testify/require" ) func Test_etcColonEntry_decode(t *testing.T) { diff --git a/pkg/user/etc-colon-repository-handle.go b/pkg/user/etc-colon-repository-handle.go index e62724d..b7a981e 100644 --- a/pkg/user/etc-colon-repository-handle.go +++ b/pkg/user/etc-colon-repository-handle.go @@ -4,11 +4,12 @@ package user import ( "fmt" - "github.com/engity-com/bifroest/pkg/common" "io" "os" "path/filepath" "syscall" + + "github.com/engity-com/bifroest/pkg/common" ) type etcColonRepositoryHandle[T any, PT etcColonEntryValue[T]] struct { diff --git a/pkg/user/etc-colon-repository-handles.go b/pkg/user/etc-colon-repository-handles.go index 696feab..bb26edf 100644 --- a/pkg/user/etc-colon-repository-handles.go +++ b/pkg/user/etc-colon-repository-handles.go @@ -4,11 +4,12 @@ package user import ( "fmt" - "github.com/engity-com/bifroest/pkg/common" - "github.com/engity-com/bifroest/pkg/sys" "os" "path/filepath" "syscall" + + "github.com/engity-com/bifroest/pkg/common" + "github.com/engity-com/bifroest/pkg/sys" ) type etcColonRepositoryHandles struct { diff --git a/pkg/user/etc-colon-repository.go b/pkg/user/etc-colon-repository.go index 536f53f..892aa12 100644 --- a/pkg/user/etc-colon-repository.go +++ b/pkg/user/etc-colon-repository.go @@ -6,14 +6,6 @@ import ( "bytes" "context" "fmt" - log "github.com/echocat/slf4g" - "github.com/echocat/slf4g/fields" - "github.com/engity-com/bifroest/pkg/common" - "github.com/engity-com/bifroest/pkg/errors" - "github.com/engity-com/bifroest/pkg/sys" - "github.com/fsnotify/fsnotify" - "github.com/otiai10/copy" - "github.com/shirou/gopsutil/process" "io/fs" "os" "path/filepath" @@ -23,6 +15,16 @@ import ( "sync/atomic" "time" "unsafe" + + log "github.com/echocat/slf4g" + "github.com/echocat/slf4g/fields" + "github.com/fsnotify/fsnotify" + "github.com/otiai10/copy" + "github.com/shirou/gopsutil/process" + + "github.com/engity-com/bifroest/pkg/common" + "github.com/engity-com/bifroest/pkg/errors" + "github.com/engity-com/bifroest/pkg/sys" ) var ( diff --git a/pkg/user/etc-colon-repository_test.go b/pkg/user/etc-colon-repository_test.go index 476d773..cae7523 100644 --- a/pkg/user/etc-colon-repository_test.go +++ b/pkg/user/etc-colon-repository_test.go @@ -4,20 +4,22 @@ package user import ( "context" - errors "errors" - log "github.com/echocat/slf4g" - "github.com/echocat/slf4g/level" - "github.com/echocat/slf4g/sdk/testlog" - "github.com/echocat/slf4g/testing/recording" - "github.com/engity-com/bifroest/pkg/common" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "errors" "io/fs" "maps" "os" "path/filepath" "testing" "time" + + log "github.com/echocat/slf4g" + "github.com/echocat/slf4g/level" + "github.com/echocat/slf4g/sdk/testlog" + "github.com/echocat/slf4g/testing/recording" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/engity-com/bifroest/pkg/common" ) func Test_EtcColonRepository_Init(t *testing.T) { @@ -43,7 +45,7 @@ func Test_EtcColonRepository_Init(t *testing.T) { { name: "all-content", passwd: `root:x:0:0:root:/root:/bin/sh -foo:abc:1:2:Foo Name:/home/foo:/bin/foosh +foo:abc:1:2:Foo Name:/home/foo:/bin/foosh bar::11:12::/home/bar:/bin/barsh`, group: `root:x:0: foo:abc:1:foo,bbb @@ -72,7 +74,7 @@ bar:XbarX:20453:10:100:::20818:`, { name: "fail-with-bad-name-in-passwd", passwd: `root:x:0:0:root:/root:/bin/sh -foo@:abc:1:2:Foo Name:/home/foo:/bin/foosh +foo@:abc:1:2:Foo Name:/home/foo:/bin/foosh bar::11:12::/home/bar:/bin/barsh`, group: `root:x:0: foo:abc:1:aaa,bbb @@ -85,7 +87,7 @@ bar:XbarX:20453:10:100:::20818:`, { name: "fail-with-bad-name-in-group", passwd: `root:x:0:0:root:/root:/bin/sh -foo:abc:1:2:Foo Name:/home/foo:/bin/foosh +foo:abc:1:2:Foo Name:/home/foo:/bin/foosh bar::11:12::/home/bar:/bin/barsh`, group: `root:x:0: foo@:abc:1:aaa,bbb @@ -98,7 +100,7 @@ bar:XbarX:20453:10:100:::20818:`, { name: "fail-with-bad-name-in-shadow", passwd: `root:x:0:0:root:/root:/bin/sh -foo:abc:1:2:Foo Name:/home/foo:/bin/foosh +foo:abc:1:2:Foo Name:/home/foo:/bin/foosh bar::11:12::/home/bar:/bin/barsh`, group: `root:x:0: foo:abc:1:aaa,bbb @@ -114,7 +116,7 @@ bar:XbarX:20453:10:100:::20818:`, name: "allow-bad-name-in-passwd", allowBadName: true, passwd: `root:x:0:0:root:/root:/bin/sh -foo@:abc:1:2:Foo Name:/home/foo:/bin/foosh +foo@:abc:1:2:Foo Name:/home/foo:/bin/foosh bar::11:12::/home/bar:/bin/barsh`, group: `root:x:0: foo:abc:1:aaa,bbb @@ -142,7 +144,7 @@ bar:XbarX:20453:10:100:::20818:`, name: "allow-bad-name-in-group", allowBadName: true, passwd: `root:x:0:0:root:/root:/bin/sh -foo:abc:1:2:Foo Name:/home/foo:/bin/foosh +foo:abc:1:2:Foo Name:/home/foo:/bin/foosh bar::11:12::/home/bar:/bin/barsh`, group: `root:x:0: foo@:abc:1:aaa,bbb @@ -170,7 +172,7 @@ bar:XbarX:20453:10:100:::20818:`, name: "allow-bad-name-in-shadow", allowBadName: true, passwd: `root:x:0:0:root:/root:/bin/sh -foo:abc:1:2:Foo Name:/home/foo:/bin/foosh +foo:abc:1:2:Foo Name:/home/foo:/bin/foosh bar::11:12::/home/bar:/bin/barsh`, group: `root:x:0: foo:abc:1:aaa,bbb @@ -199,7 +201,7 @@ bar:XbarX:20453:10:100:::20818:`, { name: "fail-with-line-in-passwd", passwd: `root:x:0:0:root:/root:/bin/sh -foo:abc:1:2:Foo Name:/home/foo:/bin/foosh: +foo:abc:1:2:Foo Name:/home/foo:/bin/foosh: bar::11:12::/home/bar:/bin/barsh`, group: `root:x:0: foo:abc:1:aaa,bbb @@ -269,7 +271,7 @@ bar:XbarX:20453:10:100:::20818:`, name: "allow-bad-lines-in-group", allowBadLine: true, passwd: `root:x:0:0:root:/root:/bin/sh -foo:abc:1:2:Foo Name:/home/foo:/bin/foosh +foo:abc:1:2:Foo Name:/home/foo:/bin/foosh bar::11:12::/home/bar:/bin/barsh`, group: `root:x:0: foo:abc:1:aaa,bbb: @@ -297,7 +299,7 @@ bar:XbarX:20453:10:100:::20818:`, name: "allow-bad-lines-in-shadow", allowBadLine: true, passwd: `root:x:0:0:root:/root:/bin/sh -foo:abc:1:2:Foo Name:/home/foo:/bin/foosh +foo:abc:1:2:Foo Name:/home/foo:/bin/foosh bar::11:12::/home/bar:/bin/barsh`, group: `root:x:0: foo:abc:1:aaa,bbb @@ -327,7 +329,7 @@ bar:XbarX:20453:10:100:::20818:`, name: "allow-bad-lines-in-passwd-by-bad-names", allowBadLine: true, passwd: `root:x:0:0:root:/root:/bin/sh -foo@:abc:1:2:Foo Name:/home/foo:/bin/foosh +foo@:abc:1:2:Foo Name:/home/foo:/bin/foosh bar::11:12::/home/bar:/bin/barsh`, group: `root:x:0: foo:abc:1:aaa,bbb @@ -355,7 +357,7 @@ bar:XbarX:20453:10:100:::20818:`, name: "allow-bad-lines-in-group-by-bad-names", allowBadLine: true, passwd: `root:x:0:0:root:/root:/bin/sh -foo:abc:1:2:Foo Name:/home/foo:/bin/foosh +foo:abc:1:2:Foo Name:/home/foo:/bin/foosh bar::11:12::/home/bar:/bin/barsh`, group: `root:x:0: foo@:abc:1:aaa,bbb @@ -383,7 +385,7 @@ bar:XbarX:20453:10:100:::20818:`, name: "allow-bad-lines-in-shadow-by-bad-names", allowBadLine: true, passwd: `root:x:0:0:root:/root:/bin/sh -foo:abc:1:2:Foo Name:/home/foo:/bin/foosh +foo:abc:1:2:Foo Name:/home/foo:/bin/foosh bar::11:12::/home/bar:/bin/barsh`, group: `root:x:0: foo:abc:1:aaa,bbb @@ -479,7 +481,7 @@ func Test_EtcColonRepository_onFsEvents(t *testing.T) { dir := newTestDir(t) passwdFile := dir.file("passwd").setContent(`root:x:0:0:root:/root:/bin/sh -foo:abc:1:2:Foo Name:/home/foo:/bin/foosh +foo:abc:1:2:Foo Name:/home/foo:/bin/foosh bar::11:12::/home/bar:/bin/barsh`) groupFile := dir.file("group").setContent(`root:x:0: foo:abc:1:aaa,bbb @@ -515,7 +517,7 @@ bar:XbarX:20453:10:100:::20818:`) { name: "modify-entry", passwd: `root:x:0:0:root:/root:/bin/sh -foos:abc:1:2:Foo Name:/home/foo:/bin/foosh +foos:abc:1:2:Foo Name:/home/foo:/bin/foosh bar::11:12::/home/bar:/bin/barsh`, group: `root:x:0: foos:abc:1:aaa,bbb diff --git a/pkg/user/etc-group_test.go b/pkg/user/etc-group_test.go index a034dae..34355b7 100644 --- a/pkg/user/etc-group_test.go +++ b/pkg/user/etc-group_test.go @@ -3,9 +3,10 @@ package user import ( + "testing" + "github.com/echocat/slf4g/sdk/testlog" "github.com/stretchr/testify/require" - "testing" ) func Test_etcGroupEntry_decode(t *testing.T) { diff --git a/pkg/user/etc-passwd_test.go b/pkg/user/etc-passwd_test.go index e1cdde8..8048742 100644 --- a/pkg/user/etc-passwd_test.go +++ b/pkg/user/etc-passwd_test.go @@ -3,9 +3,10 @@ package user import ( + "testing" + "github.com/echocat/slf4g/sdk/testlog" "github.com/stretchr/testify/require" - "testing" ) func Test_etcPasswdEntry_decode(t *testing.T) { diff --git a/pkg/user/etc-shadow.go b/pkg/user/etc-shadow.go index e48d8a4..85ef52b 100644 --- a/pkg/user/etc-shadow.go +++ b/pkg/user/etc-shadow.go @@ -5,9 +5,10 @@ package user import ( "bytes" "errors" - "github.com/engity-com/bifroest/pkg/crypto/unix/password" "strconv" "time" + + "github.com/engity-com/bifroest/pkg/crypto/unix/password" ) const ( diff --git a/pkg/user/etc-shadow_test.go b/pkg/user/etc-shadow_test.go index afa7e3a..373a514 100644 --- a/pkg/user/etc-shadow_test.go +++ b/pkg/user/etc-shadow_test.go @@ -3,8 +3,9 @@ package user import ( - "github.com/stretchr/testify/require" "testing" + + "github.com/stretchr/testify/require" ) func Test_etcShadowEntry_decode(t *testing.T) { diff --git a/pkg/user/group_windows.go b/pkg/user/group_windows.go index a635fd7..96887bd 100644 --- a/pkg/user/group_windows.go +++ b/pkg/user/group_windows.go @@ -23,7 +23,7 @@ func (this Group) GetField(name string) (any, bool, error) { } func (this Group) String() string { - return fmt.Sprintf("%d(%s)", this.Gid, this.Name) + return fmt.Sprintf("%v(%s)", this.Gid, this.Name) } func (this Group) IsEqualTo(other any) bool { diff --git a/pkg/user/repository.go b/pkg/user/repository.go index ebc2885..068ca57 100644 --- a/pkg/user/repository.go +++ b/pkg/user/repository.go @@ -2,9 +2,10 @@ package user import ( "context" - "github.com/engity-com/bifroest/pkg/errors" "io" "sync" + + "github.com/engity-com/bifroest/pkg/errors" ) var ( @@ -89,7 +90,7 @@ type SharedRepositoryProvider[T interface { Init(context.Context) error }] struct { V T - usages uint16 + usages int16 mutex sync.Mutex } diff --git a/pkg/user/requirement_windows.go b/pkg/user/requirement_windows.go index 3027ace..f1c11f6 100644 --- a/pkg/user/requirement_windows.go +++ b/pkg/user/requirement_windows.go @@ -52,14 +52,3 @@ func (this Requirement) String() string { return "" } } - -func (this Requirement) name() string { - name := strings.Clone(this.Name) - if len(name) > 0 { - return name - } - if uid := this.Uid; uid != nil { - return fmt.Sprintf("u%d", uid) - } - return "" -} diff --git a/pkg/user/user_windows.go b/pkg/user/user_windows.go index fca6473..e99c92d 100644 --- a/pkg/user/user_windows.go +++ b/pkg/user/user_windows.go @@ -31,7 +31,7 @@ func (this User) GetField(name string) (any, bool, error) { } func (this User) String() string { - return fmt.Sprintf("%d(%s)", this.Uid, this.Name) + return fmt.Sprintf("%v(%s)", this.Uid, this.Name) } func (this User) IsEqualTo(other any) bool { diff --git a/pkg/user/windows_repository.go b/pkg/user/windows_repository.go index f3f699c..7c19d15 100644 --- a/pkg/user/windows_repository.go +++ b/pkg/user/windows_repository.go @@ -5,9 +5,11 @@ package user import ( "context" "fmt" - "github.com/engity-com/bifroest/pkg/errors" - "golang.org/x/sys/windows" "os/user" + + "golang.org/x/sys/windows" + + "github.com/engity-com/bifroest/pkg/errors" ) func init() {