mirror of
https://github.com/glauth/glauth.git
synced 2026-10-27 06:26:59 +00:00
Compare commits
33 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fbef6a70fa | |||
| 48537deabd | |||
| 114b36f677 | |||
| ebab2a0910 | |||
| 7cbb176686 | |||
| f474f883d4 | |||
| 8c3fe078b2 | |||
| f65ee3d63b | |||
| 6b6a64ce6a | |||
| fad9d82e76 | |||
| 6c2ecbfcd6 | |||
| 0904a24564 | |||
| c551cab56f | |||
| aa0414f02e | |||
| 349431c6ca | |||
| 15ed058754 | |||
| 675b236328 | |||
| 75d02ee368 | |||
| 0c11325a24 | |||
| 0c7a513852 | |||
| d8398285f1 | |||
| 27c9d4cb42 | |||
| 3114106563 | |||
| 75abe08313 | |||
| 4e62b7cd89 | |||
| 498cad48b1 | |||
| 19fa5045ee | |||
| 08a89a9861 | |||
| a4450d4558 | |||
| 0b7910c03c | |||
| 944d602077 | |||
| 596d28efbd | |||
| 6a58f35b14 |
@@ -0,0 +1,27 @@
|
|||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- dev
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
pull-requests: write
|
||||||
|
|
||||||
|
name: release-please
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
release-please:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: google-github-actions/release-please-action@v3
|
||||||
|
with:
|
||||||
|
release-type: go
|
||||||
|
package-name: GLAuth
|
||||||
|
path: v2
|
||||||
|
default-branch: master
|
||||||
|
pull-request-title-pattern: "ci: release ${version}"
|
||||||
|
token: ${{ secrets.RELEASE_PLEASE_TOKEN }}
|
||||||
|
extra-files: |
|
||||||
|
v2/internal/version/const.go
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
[submodule "v2/pkg/plugins/glauth-sqlite"]
|
||||||
|
path = v2/pkg/plugins/glauth-sqlite
|
||||||
|
url = https://github.com/glauth/glauth-sqlite
|
||||||
|
[submodule "v2/pkg/plugins/glauth-mysql"]
|
||||||
|
path = v2/pkg/plugins/glauth-mysql
|
||||||
|
url = https://github.com/glauth/glauth-mysql
|
||||||
|
[submodule "v2/pkg/plugins/glauth-postgres"]
|
||||||
|
path = v2/pkg/plugins/glauth-postgres
|
||||||
|
url = https://github.com/glauth/glauth-postgres
|
||||||
|
[submodule "v2/pkg/plugins/glauth-pam"]
|
||||||
|
path = v2/pkg/plugins/glauth-pam
|
||||||
|
url = https://github.com/glauth/glauth-pam
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
## [2.3.0](https://github.com/glauth/glauth/compare/v2.2.0...v2.3.0) (2023-10-02)
|
||||||
|
|
||||||
|
|
||||||
|
### ⚠ BREAKING CHANGES
|
||||||
|
|
||||||
|
* **plugins:** Rename the groups table to ldapgroups ([#326](https://github.com/glauth/glauth/issues/326))
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* Update migration code to support table names ([#339](https://github.com/glauth/glauth/issues/339)) ([349431c](https://github.com/glauth/glauth/commit/349431c6caa0388d17ab987621eb9be5f019155e))
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* **plugins:** Rename the groups table to ldapgroups ([#326](https://github.com/glauth/glauth/issues/326)) ([675b236](https://github.com/glauth/glauth/commit/675b236328a21a65daa7876a1a3c6900b85b1964))
|
||||||
|
|
||||||
|
|
||||||
|
### Miscellaneous Chores
|
||||||
|
|
||||||
|
* release 2.3.0 ([0c11325](https://github.com/glauth/glauth/commit/0c11325a2482d5067c805a4c7ed948a5e337b8f8))
|
||||||
+40
-15
@@ -16,14 +16,21 @@ GIT_IS_TAG_COMMIT=$(shell git describe --abbrev=0 --tags > /dev/null 2> /dev/nul
|
|||||||
GIT_BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
|
GIT_BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
|
||||||
|
|
||||||
# Build variables
|
# Build variables
|
||||||
BUILD_VARS=-s -w -X main.GitCommit=${GIT_COMMIT} -X main.GitBranch=${GIT_BRANCH} -X main.BuildTime=${BUILD_TIME} -X main.GitClean=${GIT_CLEAN} -X main.LastGitTag=${LAST_GIT_TAG} -X main.GitTagIsCommit=${GIT_IS_TAG_COMMIT}
|
BUILD_VARS?=-s -w
|
||||||
BUILD_FILES=glauth.go
|
BUILD_FILES=.
|
||||||
TRIM_FLAGS=-gcflags "all=-trimpath=${PWD}" -asmflags "all=-trimpath=${PWD}"
|
TRIM_FLAGS>?=-trimpath
|
||||||
|
|
||||||
# Targets
|
# Targets
|
||||||
MAIN_TARGETS=linux/amd64,linux/386,linux/arm64,linux/arm-7,darwin/amd64,darwin/arm64,windows/amd64,windows/386
|
MAIN_TARGETS=linux/amd64,linux/386,linux/arm64,linux/arm-7,darwin/amd64,darwin/arm64,windows/amd64,windows/386
|
||||||
PLUGIN_TARGETS=linux/amd64,linux/386,linux/arm64,linux/arm-7,darwin/amd64,darwin/arm64
|
PLUGIN_TARGETS=linux/amd64,linux/386,linux/arm64,linux/arm-7,darwin/amd64,darwin/arm64
|
||||||
|
|
||||||
|
# For release process
|
||||||
|
GO_RELEASE_V=$(shell go version | { read _ _ v _; echo $${v#go}; })
|
||||||
|
|
||||||
|
# Build
|
||||||
|
GOOS?=linux
|
||||||
|
GOARCH?=amd64
|
||||||
|
|
||||||
# Plugins
|
# Plugins
|
||||||
-include pkg/plugins/*/Makefile
|
-include pkg/plugins/*/Makefile
|
||||||
|
|
||||||
@@ -74,29 +81,43 @@ format:
|
|||||||
devrun:
|
devrun:
|
||||||
go run ${BUILD_FILES} -c sample-simple.cfg
|
go run ${BUILD_FILES} -c sample-simple.cfg
|
||||||
|
|
||||||
|
mkbindir:
|
||||||
|
@echo "create directory bin/$(GOOS)$(GOARCH)"
|
||||||
|
@mkdir -p bin/$(GOOS)$(GOARCH)
|
||||||
|
.PHONY: mkbindir
|
||||||
|
|
||||||
|
build: mkbindir
|
||||||
|
@go build ${TRIM_FLAGS} -ldflags "${BUILD_VARS}" -o bin/$(GOOS)$(GOARCH)/glauth -buildvcs=false .
|
||||||
|
$(MAKE) sha256
|
||||||
|
.PHONY: build
|
||||||
|
|
||||||
|
sha256:
|
||||||
|
@sha256sum bin/$(GOOS)$(GOARCH)/glauth > bin/$(GOOS)$(GOARCH)/glauth.sha256
|
||||||
|
.PHONY: sha256
|
||||||
|
|
||||||
linux386:
|
linux386:
|
||||||
mkdir -p bin/$@ && GOOS=linux GOARCH=386 go build ${TRIM_FLAGS} -ldflags "${BUILD_VARS}" -o bin/$@/glauth ${BUILD_FILES} && cd bin/$@ && sha256sum glauth > glauth.sha256
|
GOOS=linux GOARCH=386 $(MAKE) build
|
||||||
|
|
||||||
linuxamd64:
|
linuxamd64:
|
||||||
mkdir -p bin/$@ && GOOS=linux GOARCH=amd64 go build ${TRIM_FLAGS} -ldflags "${BUILD_VARS}" -o bin/$@/glauth ${BUILD_FILES} && cd bin/$@ && sha256sum glauth > glauth.sha256
|
GOOS=linux GOARCH=amd64 $(MAKE) build
|
||||||
|
|
||||||
linuxarm:
|
linuxarm:
|
||||||
mkdir -p bin/$@ && GOOS=linux GOARCH=arm go build ${TRIM_FLAGS} -ldflags "${BUILD_VARS}" -o bin/$@/glauth ${BUILD_FILES} && cd bin/$@ && sha256sum glauth > glauth.sha256
|
GOOS=linux GOARCH=arm $(MAKE) build
|
||||||
|
|
||||||
linuxarm64:
|
linuxarm64:
|
||||||
mkdir -p bin/$@ && GOOS=linux GOARCH=arm64 go build ${TRIM_FLAGS} -ldflags "${BUILD_VARS}" -o bin/$@/glauth ${BUILD_FILES} && cd bin/$@ && sha256sum glauth > glauth.sha256
|
GOOS=linux GOARCH=arm64 $(MAKE) build
|
||||||
|
|
||||||
darwinamd64:
|
darwinamd64:
|
||||||
mkdir -p bin/$@ && GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 go build ${TRIM_FLAGS} -ldflags "${BUILD_VARS}" -o bin/$@/glauth ${BUILD_FILES} && cd bin/$@ && sha256sum glauth > glauth.sha256
|
GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 $(MAKE) build
|
||||||
|
|
||||||
darwinarm64:
|
darwinarm64:
|
||||||
mkdir -p bin/$@ && GOOS=darwin GOARCH=arm64 CGO_ENABLED=1 go build ${TRIM_FLAGS} -ldflags "${BUILD_VARS}" -o bin/$@/glauth ${BUILD_FILES} && cd bin/$@ && sha256sum glauth > glauth.sha256
|
GOOS=darwin GOARCH=arm64 CGO_ENABLED=1 $(MAKE) build
|
||||||
|
|
||||||
win386:
|
win386:
|
||||||
mkdir -p bin/$@ && GOOS=windows GOARCH=386 go build ${TRIM_FLAGS} -ldflags "${BUILD_VARS}" -o bin/$@/glauth ${BUILD_FILES} && cd bin/$@ && sha256sum glauth > glauth.sha256
|
GOOS=windows GOARCH=386 $(MAKE) build
|
||||||
|
|
||||||
winamd64:
|
winamd64:
|
||||||
mkdir -p bin/$@ && GOOS=windows GOARCH=amd64 go build ${TRIM_FLAGS} -ldflags "${BUILD_VARS}" -o bin/$@/glauth ${BUILD_FILES} && cd bin/$@ && sha256sum glauth > glauth.sha256
|
GOOS=windows GOARCH=amd64 $(MAKE) build
|
||||||
|
|
||||||
verify:
|
verify:
|
||||||
@for binary in linux386 linuxamd64 linuxarm linuxarm64 darwinamd64 darwinarm64 win386 winamd64; do cd bin/$$binary && sha256sum glauth.sha256 -c && cd ../..; done
|
@for binary in linux386 linuxamd64 linuxarm linuxarm64 darwinamd64 darwinarm64 win386 winamd64; do cd bin/$$binary && sha256sum glauth.sha256 -c && cd ../..; done
|
||||||
@@ -105,6 +126,7 @@ pull-plugin:
|
|||||||
@git submodule add $U $M && \
|
@git submodule add $U $M && \
|
||||||
(for pkg in $$(cat $$M/go.mod | awk '/^require [a-z]/{print $$2} /^\)/{rblock=0} rblock{if($$4!="indirect" && $$1!~"glauth"){print $$1}} /^require \(/{rblock=1}'); do if [ "$$(grep $$pkg go.mod &>/dev/null)" = "" ]; then go get $$pkg; fi; done)
|
(for pkg in $$(cat $$M/go.mod | awk '/^require [a-z]/{print $$2} /^\)/{rblock=0} rblock{if($$4!="indirect" && $$1!~"glauth"){print $$1}} /^require \(/{rblock=1}'); do if [ "$$(grep $$pkg go.mod &>/dev/null)" = "" ]; then go get $$pkg; fi; done)
|
||||||
|
|
||||||
|
#pull-base-plugins: @ pull plugins for local building
|
||||||
pull-base-plugins:
|
pull-base-plugins:
|
||||||
@U=https://github.com/glauth/glauth-sqlite M=pkg/plugins/glauth-sqlite make pull-plugin && \
|
@U=https://github.com/glauth/glauth-sqlite M=pkg/plugins/glauth-sqlite make pull-plugin && \
|
||||||
U=https://github.com/glauth/glauth-mysql M=pkg/plugins/glauth-mysql make pull-plugin && \
|
U=https://github.com/glauth/glauth-mysql M=pkg/plugins/glauth-mysql make pull-plugin && \
|
||||||
@@ -117,21 +139,24 @@ forget-plugin:
|
|||||||
git rm --cache $M && \
|
git rm --cache $M && \
|
||||||
go mod tidy
|
go mod tidy
|
||||||
|
|
||||||
|
#forget-plugin: @ remove plugins, restoring original file structure
|
||||||
forget-plugins:
|
forget-plugins:
|
||||||
for pkg in pkg/plugins/*/go.mod; do\
|
for pkg in pkg/plugins/*/go.mod; do\
|
||||||
P=$$(echo $$pkg | cut -d'/' -f 3) M=$$(dirname $$pkg) make forget-plugin;\
|
P=$$(echo $$pkg | cut -d'/' -f 3) M=$$(dirname $$pkg) make forget-plugin;\
|
||||||
done
|
done
|
||||||
|
|
||||||
|
#releasemain: @ build main binaries for distribution
|
||||||
releasemain:
|
releasemain:
|
||||||
@xgo -v -ldflags="${BUILD_VARS}" -trimpath -go 1.18.1 -out glauth -dest bin -buildvcs=false --targets="${MAIN_TARGETS}" .
|
@xgo -v -ldflags="${BUILD_VARS}" -trimpath -go ${GO_RELEASE_V} -out glauth -dest bin -buildvcs=false --targets="${MAIN_TARGETS}" .
|
||||||
|
|
||||||
releaseplugin:
|
releaseplugin:
|
||||||
@xgo -v -ldflags="${BUILD_VARS}" -trimpath -go 1.18.1 -out $P -dest bin -buildvcs=false -buildmode=plugin --targets="${PLUGIN_TARGETS}" --pkg $M/$P.go . && \
|
@xgo -v -ldflags="${BUILD_VARS}" -trimpath -go ${GO_RELEASE_V} -out $P -dest bin -buildvcs=false -buildmode=plugin --targets="${PLUGIN_TARGETS}" --pkg $M/$P.go . && \
|
||||||
(cd bin && for lib in $$(ls $$P-*); do mv $$lib $$lib.so; done)
|
(cd bin && for lib in $$(ls $$P-*); do sudo mv $$lib $$lib.so; done)
|
||||||
|
|
||||||
|
#releaseplugins: @ build base plugins for distribution
|
||||||
releaseplugins:
|
releaseplugins:
|
||||||
@for pkg in pkg/plugins/*/go.mod; do\
|
@for pkg in pkg/plugins/*/go.mod; do\
|
||||||
P=$$(echo $$pkg | cut -d'/' -f 3) && make release-$$P;\
|
M=pkg/plugins/$$(echo $$pkg | cut -d'/' -f 3) && P=$$(echo $$M | grep -oP 'glauth-\K\w+') && M=$$M P=$$P make releaseplugin;\
|
||||||
done
|
done
|
||||||
|
|
||||||
releasedockermain:
|
releasedockermain:
|
||||||
|
|||||||
Binary file not shown.
+47
-81
@@ -3,10 +3,20 @@ package main
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"path/filepath"
|
||||||
|
"reflect"
|
||||||
|
"strings"
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/GeertJohan/yubigo"
|
"github.com/GeertJohan/yubigo"
|
||||||
"github.com/arl/statsviz"
|
"github.com/arl/statsviz"
|
||||||
docopt "github.com/docopt/docopt-go"
|
docopt "github.com/docopt/docopt-go"
|
||||||
"github.com/fsnotify/fsnotify"
|
"github.com/fsnotify/fsnotify"
|
||||||
|
"github.com/glauth/glauth/v2/internal/version"
|
||||||
"github.com/glauth/glauth/v2/pkg/config"
|
"github.com/glauth/glauth/v2/pkg/config"
|
||||||
"github.com/glauth/glauth/v2/pkg/frontend"
|
"github.com/glauth/glauth/v2/pkg/frontend"
|
||||||
"github.com/glauth/glauth/v2/pkg/logging"
|
"github.com/glauth/glauth/v2/pkg/logging"
|
||||||
@@ -17,23 +27,8 @@ import (
|
|||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
"gopkg.in/amz.v3/aws"
|
"gopkg.in/amz.v3/aws"
|
||||||
"gopkg.in/amz.v3/s3"
|
"gopkg.in/amz.v3/s3"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"reflect"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Set with buildtime vars
|
|
||||||
var LastGitTag string
|
|
||||||
var BuildTime string
|
|
||||||
var GitCommit string
|
|
||||||
var GitClean string
|
|
||||||
var GitBranch string
|
|
||||||
var GitTagIsCommit string
|
|
||||||
|
|
||||||
const programName = "glauth"
|
const programName = "glauth"
|
||||||
|
|
||||||
var usage = `glauth: securely expose your LDAP for external auth
|
var usage = `glauth: securely expose your LDAP for external auth
|
||||||
@@ -48,6 +43,7 @@ Options:
|
|||||||
-K <aws_key_id> AWS Key ID.
|
-K <aws_key_id> AWS Key ID.
|
||||||
-S <aws_secret_key> AWS Secret Key.
|
-S <aws_secret_key> AWS Secret Key.
|
||||||
-r <aws_region> AWS Region [default: us-east-1].
|
-r <aws_region> AWS Region [default: us-east-1].
|
||||||
|
--aws_endpoint_url <url> Custom S3 endpoint.
|
||||||
--ldap <address> Listen address for the LDAP server.
|
--ldap <address> Listen address for the LDAP server.
|
||||||
--ldaps <address> Listen address for the LDAPS server.
|
--ldaps <address> Listen address for the LDAPS server.
|
||||||
--ldaps-cert <cert-file> Path to cert file for the LDAPS server.
|
--ldaps-cert <cert-file> Path to cert file for the LDAPS server.
|
||||||
@@ -65,48 +61,6 @@ var (
|
|||||||
activeConfig = &config.Config{}
|
activeConfig = &config.Config{}
|
||||||
)
|
)
|
||||||
|
|
||||||
// Reads builtime vars and returns a full string containing info about
|
|
||||||
// the currently running version of the software. Primarily used by the
|
|
||||||
// --version flag at runtime.
|
|
||||||
func getVersionString() string {
|
|
||||||
|
|
||||||
var versionstr string
|
|
||||||
|
|
||||||
versionstr = "GLauth"
|
|
||||||
|
|
||||||
// Notate the git context of the build
|
|
||||||
switch {
|
|
||||||
// If a release, use the tag
|
|
||||||
case GitClean == "1" && GitTagIsCommit == "1":
|
|
||||||
versionstr += " " + LastGitTag + "\n\n"
|
|
||||||
|
|
||||||
// If this branch had a tag before, mention the branch and the tag to give a rough idea of the base version
|
|
||||||
case len(GitBranch) > 1 && len(LastGitTag) > 1:
|
|
||||||
versionstr += "\nNon-release build from branch " + GitBranch + ", based on tag " + LastGitTag + "\n\n"
|
|
||||||
|
|
||||||
// If no previous tag specified, just mention the branch
|
|
||||||
case len(GitBranch) > 1:
|
|
||||||
versionstr += "\nNon-release build from branch " + GitBranch + "\n\n"
|
|
||||||
|
|
||||||
// Fallback message, if all else fails
|
|
||||||
default:
|
|
||||||
versionstr += "\nNon-release build\n\n"
|
|
||||||
}
|
|
||||||
|
|
||||||
// Include build time
|
|
||||||
if len(BuildTime) > 1 {
|
|
||||||
versionstr += "Build time: " + BuildTime + "\n"
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add commit hash
|
|
||||||
if GitClean == "1" && len(GitCommit) > 1 {
|
|
||||||
versionstr += "Commit: " + GitCommit + "\n"
|
|
||||||
}
|
|
||||||
|
|
||||||
return versionstr
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if err := parseArgs(); err != nil {
|
if err := parseArgs(); err != nil {
|
||||||
fmt.Println("Could not parse command-line arguments")
|
fmt.Println("Could not parse command-line arguments")
|
||||||
@@ -135,7 +89,7 @@ func main() {
|
|||||||
|
|
||||||
func startService() {
|
func startService() {
|
||||||
// stats
|
// stats
|
||||||
stats.General.Set("version", stats.Stringer(LastGitTag))
|
stats.General.Set("version", stats.Stringer(version.Version))
|
||||||
|
|
||||||
// web API
|
// web API
|
||||||
if activeConfig.API.Enabled {
|
if activeConfig.API.Enabled {
|
||||||
@@ -161,40 +115,45 @@ func startService() {
|
|||||||
server.Logger(log),
|
server.Logger(log),
|
||||||
server.Config(activeConfig),
|
server.Config(activeConfig),
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("could not create server")
|
log.Error().Err(err).Msg("could not create server")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if activeConfig.LDAP.Enabled {
|
if activeConfig.LDAP.Enabled {
|
||||||
// Don't block if also starting a LDAPS server afterwards
|
go func() {
|
||||||
shouldBlock := !activeConfig.LDAPS.Enabled
|
|
||||||
|
|
||||||
if shouldBlock {
|
|
||||||
if err := s.ListenAndServe(); err != nil {
|
if err := s.ListenAndServe(); err != nil {
|
||||||
log.Error().Err(err).Msg("could not start LDAP server")
|
log.Error().Err(err).Msg("could not start LDAP server")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
} else {
|
}()
|
||||||
go func() {
|
|
||||||
if err := s.ListenAndServe(); err != nil {
|
|
||||||
log.Error().Err(err).Msg("could not start LDAP server")
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if activeConfig.LDAPS.Enabled {
|
if activeConfig.LDAPS.Enabled {
|
||||||
// Always block here
|
go func() {
|
||||||
if err := s.ListenAndServeTLS(); err != nil {
|
if err := s.ListenAndServeTLS(); err != nil {
|
||||||
log.Error().Err(err).Msg("could not start LDAPS server")
|
log.Error().Err(err).Msg("could not start LDAPS server")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||||
|
|
||||||
|
// Block until we receive our signal.
|
||||||
|
<-c
|
||||||
|
|
||||||
|
// Doesn't block if no connections, but will otherwise wait
|
||||||
|
// until the timeout deadline.
|
||||||
|
s.Shutdown()
|
||||||
|
|
||||||
|
// Optionally, you could run srv.Shutdown in a goroutine and block on
|
||||||
|
// <-ctx.Done() if your application should wait for other services
|
||||||
|
// to finalize based on context cancellation.
|
||||||
log.Info().Msg("AP exit")
|
log.Info().Msg("AP exit")
|
||||||
os.Exit(1)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func startConfigWatcher() {
|
func startConfigWatcher() {
|
||||||
@@ -250,7 +209,7 @@ func startConfigWatcher() {
|
|||||||
func parseArgs() error {
|
func parseArgs() error {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if args, err = docopt.Parse(usage, nil, true, getVersionString(), false); err != nil {
|
if args, err = docopt.Parse(usage, nil, true, version.GetVersion(), false); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,10 +228,17 @@ func parseConfigFile(configFileLocation string) (*config.Config, error) {
|
|||||||
|
|
||||||
// parse the config file
|
// parse the config file
|
||||||
if strings.HasPrefix(configFileLocation, "s3://") {
|
if strings.HasPrefix(configFileLocation, "s3://") {
|
||||||
if _, present := aws.Regions[args["-r"].(string)]; present == false {
|
region, present := aws.Regions[args["-r"].(string)]
|
||||||
|
if present == false {
|
||||||
return &cfg, fmt.Errorf("invalid AWS region: %s", args["-r"])
|
return &cfg, fmt.Errorf("invalid AWS region: %s", args["-r"])
|
||||||
}
|
}
|
||||||
region := aws.Regions[args["-r"].(string)]
|
if args["--aws_endpoint_url"] != nil {
|
||||||
|
region = aws.Region{
|
||||||
|
Name: "User defined",
|
||||||
|
S3Endpoint: args["--aws_endpoint_url"].(string),
|
||||||
|
}
|
||||||
|
present = true
|
||||||
|
}
|
||||||
auth, err := aws.EnvAuth()
|
auth, err := aws.EnvAuth()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if args["-K"] == nil || args["-S"] == nil {
|
if args["-K"] == nil || args["-S"] == nil {
|
||||||
@@ -328,11 +294,11 @@ func parseConfigFile(configFileLocation string) (*config.Config, error) {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
files, _ := ioutil.ReadDir(configFileLocation)
|
files, _ := os.ReadDir(configFileLocation)
|
||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
canonicalName := filepath.Join(configFileLocation, f.Name())
|
canonicalName := filepath.Join(configFileLocation, f.Name())
|
||||||
|
|
||||||
bs, _ := ioutil.ReadFile(canonicalName)
|
bs, _ := os.ReadFile(canonicalName)
|
||||||
var curRawCfgStruct interface{}
|
var curRawCfgStruct interface{}
|
||||||
if err := toml.Unmarshal(bs, &curRawCfgStruct); err != nil {
|
if err := toml.Unmarshal(bs, &curRawCfgStruct); err != nil {
|
||||||
return &cfg, err
|
return &cfg, err
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ require (
|
|||||||
github.com/prometheus/common v0.37.0 // indirect
|
github.com/prometheus/common v0.37.0 // indirect
|
||||||
github.com/prometheus/procfs v0.8.0 // indirect
|
github.com/prometheus/procfs v0.8.0 // indirect
|
||||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d // indirect
|
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d // indirect
|
||||||
golang.org/x/sys v0.1.0 // indirect
|
golang.org/x/sys v0.6.0 // indirect
|
||||||
google.golang.org/protobuf v1.28.1 // indirect
|
google.golang.org/protobuf v1.28.1 // indirect
|
||||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -370,8 +370,8 @@ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBc
|
|||||||
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
|
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
|
||||||
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||||
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package version
|
||||||
|
|
||||||
|
// Version is the tag of the latest release, it gets changed by the ci
|
||||||
|
// process when a release is happening
|
||||||
|
const Version = "v2.3.0" // x-release-please-version
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
package version
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"runtime/debug"
|
||||||
|
)
|
||||||
|
|
||||||
|
type gitInfo struct {
|
||||||
|
BuildTime string
|
||||||
|
Commit string
|
||||||
|
Dirty bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetVersion reads builtime vars and returns a full string containing info about
|
||||||
|
// the currently running version of the software. Primarily used by the
|
||||||
|
// --version flag at runtime.
|
||||||
|
func GetVersion() string {
|
||||||
|
|
||||||
|
// TODO @shipperizer see if it's worth replacing with info.Main.Path
|
||||||
|
// aka github.com/glauth/glauth/v2 - not great but worth checking
|
||||||
|
|
||||||
|
name := "GLauth"
|
||||||
|
|
||||||
|
info, ok := debug.ReadBuildInfo()
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
%s
|
||||||
|
Non-release build`,
|
||||||
|
name)
|
||||||
|
}
|
||||||
|
|
||||||
|
gitInfo := vcsInfo(info.Settings)
|
||||||
|
|
||||||
|
// If a release, use the tag
|
||||||
|
if !gitInfo.Dirty {
|
||||||
|
return fmt.Sprintf(`%s %s
|
||||||
|
Build time: %s
|
||||||
|
Commit: %s`, name, Version, gitInfo.BuildTime, gitInfo.Commit)
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf(`%s
|
||||||
|
Non-release build based on tag %s
|
||||||
|
Build time: %s
|
||||||
|
Commit: %s`, name, Version, gitInfo.BuildTime, gitInfo.Commit)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func vcsInfo(settings []debug.BuildSetting) *gitInfo {
|
||||||
|
info := new(gitInfo)
|
||||||
|
|
||||||
|
info.BuildTime = "unknown"
|
||||||
|
info.Commit = "unknown"
|
||||||
|
info.Dirty = false
|
||||||
|
|
||||||
|
for _, v := range settings {
|
||||||
|
switch v.Key {
|
||||||
|
case "vcs.revision":
|
||||||
|
info.Commit = v.Value
|
||||||
|
case "vcs.modified":
|
||||||
|
info.Dirty = v.Value == "true"
|
||||||
|
case "vcs.time":
|
||||||
|
info.BuildTime = v.Value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return info
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"regexp"
|
"regexp"
|
||||||
@@ -100,7 +100,7 @@ func (c *collector) Collect(ch chan<- prometheus.Metric) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error reading body of %q: %v", c.url, err)
|
log.Printf("Error reading body of %q: %v", c.url, err)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -371,7 +370,7 @@ func (l LDAPOpsHelper) searchMaybeSchemaQuery(h LDAPOpsHandler, baseDN string, s
|
|||||||
attrs = append(attrs, &ldap.EntryAttribute{Name: "modifiersName", Values: []string{"cn=Directory Manager"}})
|
attrs = append(attrs, &ldap.EntryAttribute{Name: "modifiersName", Values: []string{"cn=Directory Manager"}})
|
||||||
attrs = append(attrs, &ldap.EntryAttribute{Name: "modifyTimeStamp", Values: []string{"Mar 8, 2021, 12:46:29 PM PST (20210308204629Z)"}})
|
attrs = append(attrs, &ldap.EntryAttribute{Name: "modifyTimeStamp", Values: []string{"Mar 8, 2021, 12:46:29 PM PST (20210308204629Z)"}})
|
||||||
// Iterate through schema attributes provided in schema/ directory
|
// Iterate through schema attributes provided in schema/ directory
|
||||||
filenames, _ := ioutil.ReadDir("schema")
|
filenames, _ := os.ReadDir("schema")
|
||||||
for _, filename := range filenames {
|
for _, filename := range filenames {
|
||||||
attributename := new(string)
|
attributename := new(string)
|
||||||
*attributename = filename.Name()
|
*attributename = filename.Name()
|
||||||
@@ -623,7 +622,7 @@ func (l LDAPOpsHelper) findUser(h LDAPOpsHandler, bindDN string, checkGroup bool
|
|||||||
userName := ""
|
userName := ""
|
||||||
if len(parts) == 1 {
|
if len(parts) == 1 {
|
||||||
userName = strings.TrimPrefix(parts[0], h.GetBackend().NameFormat+"=")
|
userName = strings.TrimPrefix(parts[0], h.GetBackend().NameFormat+"=")
|
||||||
} else if len(parts) == 2 || (len(parts) == 3 && parts[2] == fmt.Sprintf("%s=users", h.GetBackend().GroupFormat)) {
|
} else if len(parts) == 2 || (len(parts) == 3 && parts[2] == "ou=users") {
|
||||||
userName = strings.TrimPrefix(parts[0], h.GetBackend().NameFormat+"=")
|
userName = strings.TrimPrefix(parts[0], h.GetBackend().NameFormat+"=")
|
||||||
groupName = strings.TrimPrefix(parts[1], h.GetBackend().GroupFormat+"=")
|
groupName = strings.TrimPrefix(parts[1], h.GetBackend().GroupFormat+"=")
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -133,7 +133,7 @@ func (h ownCloudHandler) Search(bindDN string, searchReq ldap.SearchRequest, con
|
|||||||
|
|
||||||
attrs = append(attrs, &ldap.EntryAttribute{Name: "memberUid", Values: members})
|
attrs = append(attrs, &ldap.EntryAttribute{Name: "memberUid", Values: members})
|
||||||
}
|
}
|
||||||
dn := fmt.Sprintf("cn=%s,%s=groups,%s", *g.ID, h.backend.GroupFormat, h.backend.BaseDN)
|
dn := fmt.Sprintf("%s=%s,ou=groups,%s", h.backend.GroupFormat, *g.ID, h.backend.BaseDN)
|
||||||
entries = append(entries, &ldap.Entry{DN: dn, Attributes: attrs})
|
entries = append(entries, &ldap.Entry{DN: dn, Attributes: attrs})
|
||||||
}
|
}
|
||||||
case "posixaccount", "":
|
case "posixaccount", "":
|
||||||
@@ -255,7 +255,7 @@ func (s ownCloudSession) getGroups() ([]msgraph.Group, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
b, err := ioutil.ReadAll(resp.Body)
|
b, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -326,7 +326,7 @@ func (s ownCloudSession) getUsers(userName string) ([]msgraph.User, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
b, err := ioutil.ReadAll(resp.Body)
|
b, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ type SqlBackend interface {
|
|||||||
// Create db/schema if necessary
|
// Create db/schema if necessary
|
||||||
CreateSchema(db *sql.DB)
|
CreateSchema(db *sql.DB)
|
||||||
// Migrate schema if necessary
|
// Migrate schema if necessary
|
||||||
MigrateSchema(db *sql.DB, checker func(*sql.DB, string) bool)
|
MigrateSchema(db *sql.DB, checker func(*sql.DB, string, string) bool)
|
||||||
//
|
//
|
||||||
GetPrepareSymbol() string
|
GetPrepareSymbol() string
|
||||||
}
|
}
|
||||||
@@ -88,14 +88,11 @@ func NewDatabaseHandler(sqlBackend SqlBackend, opts ...handler.Option) handler.H
|
|||||||
return handler
|
return handler
|
||||||
}
|
}
|
||||||
|
|
||||||
func ColumnExists(db *sql.DB, columnName string) bool {
|
func ColumnExists(db *sql.DB, tableName string, columnName string) bool {
|
||||||
var found string
|
var found string
|
||||||
err := db.QueryRow(fmt.Sprintf(`SELECT COUNT(%s) FROM users`, columnName)).Scan(
|
err := db.QueryRow(fmt.Sprintf(`SELECT COUNT(%s) FROM %s`, columnName, tableName)).Scan(
|
||||||
&found)
|
&found)
|
||||||
if err != nil {
|
return err == nil
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h databaseHandler) GetBackend() config.Backend {
|
func (h databaseHandler) GetBackend() config.Backend {
|
||||||
@@ -184,7 +181,7 @@ func (h databaseHandler) FindGroup(groupName string) (f bool, g config.Group, er
|
|||||||
found := false
|
found := false
|
||||||
|
|
||||||
err = h.database.cnx.QueryRow(fmt.Sprintf(`
|
err = h.database.cnx.QueryRow(fmt.Sprintf(`
|
||||||
SELECT g.gidnumber FROM groups g WHERE lower(name)=%s`, h.sqlBackend.GetPrepareSymbol()), groupName).Scan(
|
SELECT g.gidnumber FROM ldapgroups g WHERE lower(name)=%s`, h.sqlBackend.GetPrepareSymbol()), groupName).Scan(
|
||||||
&group.GIDNumber)
|
&group.GIDNumber)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
found = true
|
found = true
|
||||||
@@ -313,10 +310,10 @@ func (h databaseHandler) commaListToStringTable(commaList string) []string {
|
|||||||
func (h databaseHandler) memoizeGroups() ([]config.Group, error) {
|
func (h databaseHandler) memoizeGroups() ([]config.Group, error) {
|
||||||
workMemGroups := make([]*config.Group, 0)
|
workMemGroups := make([]*config.Group, 0)
|
||||||
rows, err := h.database.cnx.Query(`
|
rows, err := h.database.cnx.Query(`
|
||||||
SELECT g1.name,g1.gidnumber,ig.includegroupid
|
SELECT g1.name,g1.gidnumber,ig.includegroupid
|
||||||
FROM groups g1
|
FROM ldapgroups g1
|
||||||
LEFT JOIN includegroups ig ON g1.gidnumber=ig.parentgroupid
|
LEFT JOIN includegroups ig ON g1.gidnumber=ig.parentgroupid
|
||||||
LEFT JOIN groups g2 ON ig.includegroupid=g2.gidnumber`)
|
LEFT JOIN ldapgroups g2 ON ig.includegroupid=g2.gidnumber`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New("Unable to memoize groups list")
|
return nil, errors.New("Unable to memoize groups list")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user