Compare commits
6 Commits
pkg/dev/ub
...
1.2.1-2-4-
Author | SHA1 | Date | |
---|---|---|---|
592749eebf | |||
24b66a12ef | |||
194c1864c4 | |||
b940aae071 | |||
eab0b72431 | |||
3525b4bcb5 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
||||
/bin
|
||||
/dist
|
50
Jenkinsfile
vendored
Normal file
50
Jenkinsfile
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
@Library('cadoles') _
|
||||
|
||||
pipeline {
|
||||
agent {
|
||||
dockerfile {
|
||||
label 'docker'
|
||||
filename 'Dockerfile'
|
||||
dir 'misc/ci'
|
||||
}
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Build and publish packages') {
|
||||
when {
|
||||
anyOf {
|
||||
branch 'master'
|
||||
branch 'develop'
|
||||
}
|
||||
}
|
||||
steps {
|
||||
script {
|
||||
List<String> packagers = ['deb', 'rpm']
|
||||
packagers.each { pkgr ->
|
||||
sh "make NFPM_PACKAGER='${pkgr}' build package"
|
||||
}
|
||||
|
||||
List<String> attachments = sh(returnStdout: true, script: "find dist -type f -name '*.deb' -or -name '*.rpm' -or -name '*.ipk'").split(' ')
|
||||
String releaseVersion = sh(returnStdout: true, script: "git describe --always | rev | cut -d '/' -f 1 | rev").trim()
|
||||
|
||||
String releaseBody = """
|
||||
_Publication automatisée réalisée par Jenkins._ [Voir le job](${env.RUN_DISPLAY_URL})
|
||||
"""
|
||||
|
||||
gitea.release('forge-jenkins', 'Cadoles', 'hydra-werther', [
|
||||
'attachments': attachments,
|
||||
'body': releaseBody,
|
||||
'releaseName': "${releaseVersion}",
|
||||
'releaseVersion': "${releaseVersion}"
|
||||
])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
post {
|
||||
always {
|
||||
cleanWs()
|
||||
}
|
||||
}
|
||||
}
|
20
Makefile
20
Makefile
@ -1,7 +1,23 @@
|
||||
build: clean
|
||||
misc/script/build
|
||||
PACKAGE_VERSION ?= $(shell git describe --always | rev | cut -d '/' -f 1 | rev)
|
||||
NFPM_PACKAGER ?= deb
|
||||
|
||||
build: clean generate
|
||||
CGO_ENABLED=0 misc/script/build
|
||||
|
||||
generate:
|
||||
go generate ./...
|
||||
|
||||
clean:
|
||||
rm -rf bin
|
||||
|
||||
package: dist
|
||||
PACKAGE_VERSION=$(PACKAGE_VERSION) \
|
||||
nfpm package \
|
||||
--config misc/packaging/nfpm.yml \
|
||||
--target ./dist \
|
||||
--packager $(NFPM_PACKAGER)
|
||||
|
||||
dist:
|
||||
mkdir -p dist
|
||||
|
||||
.PHONY: build
|
@ -117,3 +117,9 @@ WERTHER_LDAP_ROLE_BASEDN=ou=groups,dc=myorg,dc=com
|
||||
# [type] String
|
||||
# [default] /
|
||||
# [required]
|
||||
|
||||
#WERTHER_LDAP_CONNECTION_TIMEOUT=
|
||||
# [description] LDAP server connection timeout
|
||||
# [type] Duration
|
||||
# [default] 60s
|
||||
# [required]
|
@ -171,7 +171,7 @@ func newLoginEndHandler(ra oa2LoginReqAcceptor, auther authenticator, tmplRender
|
||||
data := LoginTmplData{
|
||||
CSRFToken: nosurf.Token(r),
|
||||
Challenge: challenge,
|
||||
LoginURL: r.URL.String(),
|
||||
LoginURL: strings.TrimPrefix(r.URL.String(), "/"),
|
||||
}
|
||||
|
||||
username, password := r.Form.Get("username"), r.Form.Get("password")
|
||||
|
@ -48,19 +48,20 @@ type connector interface {
|
||||
|
||||
// Config is a LDAP configuration.
|
||||
type Config struct {
|
||||
Endpoints []string `envconfig:"endpoints" required:"true" desc:"a LDAP's server URLs as \"<address>:<port>\""`
|
||||
BindDN string `envconfig:"binddn" desc:"a LDAP bind DN"`
|
||||
BindPass string `envconfig:"bindpw" json:"-" desc:"a LDAP bind password"`
|
||||
BaseDN string `envconfig:"basedn" required:"true" desc:"a LDAP base DN for searching users"`
|
||||
UserSearchQuery string `envconfig:"user_search_query" desc:"the user search query" default:"(&(|(objectClass=organizationalPerson)(objectClass=inetOrgPerson))(|(uid=%[1]s)(mail=%[1]s)(userPrincipalName=%[1]s)(sAMAccountName=%[1]s)))"`
|
||||
AttrClaims map[string]string `envconfig:"attr_claims" default:"name:name,sn:family_name,givenName:given_name,mail:email" desc:"a mapping of LDAP attributes to OpenID connect claims"`
|
||||
RoleBaseDN string `envconfig:"role_basedn" required:"true" desc:"a LDAP base DN for searching roles"`
|
||||
RoleSearchQuery string `envconfig:"role_search_query" desc:"the role search query" default:"(|(&(|(objectClass=group)(objectClass=groupOfNames))(member=%[1]s))(&(objectClass=groupOfUniqueNames)(uniqueMember=%[1]s)))"`
|
||||
RoleAttr string `envconfig:"role_attr" default:"description" desc:"a LDAP group's attribute that contains a role's name"`
|
||||
RoleClaim string `envconfig:"role_claim" default:"https://github.com/i-core/werther/claims/roles" desc:"a name of an OpenID Connect claim that contains user roles"`
|
||||
CacheSize int `envconfig:"cache_size" default:"512" desc:"a user info cache's size in KiB"`
|
||||
CacheTTL time.Duration `envconfig:"cache_ttl" default:"30m" desc:"a user info cache TTL"`
|
||||
IsTLS bool `envconfig:"is_tls" default:"false" desc:"should LDAP connection be established via TLS"`
|
||||
Endpoints []string `envconfig:"endpoints" required:"true" desc:"a LDAP's server URLs as \"<address>:<port>\""`
|
||||
BindDN string `envconfig:"binddn" desc:"a LDAP bind DN"`
|
||||
BindPass string `envconfig:"bindpw" json:"-" desc:"a LDAP bind password"`
|
||||
BaseDN string `envconfig:"basedn" required:"true" desc:"a LDAP base DN for searching users"`
|
||||
UserSearchQuery string `envconfig:"user_search_query" desc:"the user search query" default:"(&(|(objectClass=organizationalPerson)(objectClass=inetOrgPerson))(|(uid=%[1]s)(mail=%[1]s)(userPrincipalName=%[1]s)(sAMAccountName=%[1]s)))"`
|
||||
AttrClaims map[string]string `envconfig:"attr_claims" default:"name:name,sn:family_name,givenName:given_name,mail:email" desc:"a mapping of LDAP attributes to OpenID connect claims"`
|
||||
RoleBaseDN string `envconfig:"role_basedn" required:"true" desc:"a LDAP base DN for searching roles"`
|
||||
RoleSearchQuery string `envconfig:"role_search_query" desc:"the role search query" default:"(|(&(|(objectClass=group)(objectClass=groupOfNames))(member=%[1]s))(&(objectClass=groupOfUniqueNames)(uniqueMember=%[1]s)))"`
|
||||
RoleAttr string `envconfig:"role_attr" default:"description" desc:"a LDAP group's attribute that contains a role's name"`
|
||||
RoleClaim string `envconfig:"role_claim" default:"https://github.com/i-core/werther/claims/roles" desc:"a name of an OpenID Connect claim that contains user roles"`
|
||||
CacheSize int `envconfig:"cache_size" default:"512" desc:"a user info cache's size in KiB"`
|
||||
CacheTTL time.Duration `envconfig:"cache_ttl" default:"30m" desc:"a user info cache TTL"`
|
||||
IsTLS bool `envconfig:"is_tls" default:"false" desc:"should LDAP connection be established via TLS"`
|
||||
ConnectionTimeout time.Duration `envconfig:"connection_timeout" default:"60s" desc:"LDAP server connection timeout"`
|
||||
}
|
||||
|
||||
// Client is a LDAP client (compatible with Active Directory).
|
||||
@ -75,11 +76,12 @@ func New(cnf Config) *Client {
|
||||
return &Client{
|
||||
Config: cnf,
|
||||
connector: &ldapConnector{
|
||||
BaseDN: cnf.BaseDN,
|
||||
UserSearchQuery: cnf.UserSearchQuery,
|
||||
RoleBaseDN: cnf.RoleBaseDN,
|
||||
IsTLS: cnf.IsTLS,
|
||||
RoleSearchQuery: cnf.RoleSearchQuery,
|
||||
BaseDN: cnf.BaseDN,
|
||||
UserSearchQuery: cnf.UserSearchQuery,
|
||||
RoleBaseDN: cnf.RoleBaseDN,
|
||||
IsTLS: cnf.IsTLS,
|
||||
RoleSearchQuery: cnf.RoleSearchQuery,
|
||||
ConnectionTimeout: cnf.ConnectionTimeout,
|
||||
},
|
||||
cache: freecache.NewCache(cnf.CacheSize * 1024),
|
||||
}
|
||||
@ -291,15 +293,16 @@ func (cli *Client) findBasicUserDetails(cn conn, username string, attrs []string
|
||||
}
|
||||
|
||||
type ldapConnector struct {
|
||||
BaseDN string
|
||||
RoleBaseDN string
|
||||
IsTLS bool
|
||||
UserSearchQuery string
|
||||
RoleSearchQuery string
|
||||
BaseDN string
|
||||
RoleBaseDN string
|
||||
IsTLS bool
|
||||
UserSearchQuery string
|
||||
RoleSearchQuery string
|
||||
ConnectionTimeout time.Duration
|
||||
}
|
||||
|
||||
func (c *ldapConnector) Connect(ctx context.Context, addr string) (conn, error) {
|
||||
d := net.Dialer{Timeout: ldap.DefaultTimeout}
|
||||
d := net.Dialer{Timeout: c.ConnectionTimeout}
|
||||
tcpcn, err := d.DialContext(ctx, "tcp", addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
9
misc/ci/Dockerfile
Normal file
9
misc/ci/Dockerfile
Normal file
@ -0,0 +1,9 @@
|
||||
FROM alpine:3.16
|
||||
|
||||
RUN apk add --no-cache make git curl jq bash openssl go zip
|
||||
|
||||
RUN curl -k https://forge.cadoles.com/Cadoles/Jenkins/raw/branch/master/resources/com/cadoles/common/add-letsencrypt-ca.sh | bash
|
||||
|
||||
RUN wget https://github.com/goreleaser/nfpm/releases/download/v2.20.0/nfpm_2.20.0_Linux_x86_64.tar.gz \
|
||||
&& tar -xzf nfpm_2.20.0_Linux_x86_64.tar.gz -C /usr/local/bin \
|
||||
&& chmod +x /usr/local/bin/nfpm
|
21
misc/packaging/nfpm.yml
Normal file
21
misc/packaging/nfpm.yml
Normal file
@ -0,0 +1,21 @@
|
||||
name: "hydra-werther"
|
||||
arch: "amd64"
|
||||
platform: "linux"
|
||||
version: "${PACKAGE_VERSION}"
|
||||
section: "default"
|
||||
priority: "extra"
|
||||
maintainer: "Cadoles <contact@cadoles.com>"
|
||||
description: |
|
||||
PostgreSQL automated backup scripts
|
||||
vendor: "Cadoles"
|
||||
homepage: "https://forge.cadoles.com/Cadoles/postgres-backup"
|
||||
license: "AGPL-3.0"
|
||||
contents:
|
||||
- src: bin/werther_linux_amd64
|
||||
dst: /usr/bin/hydra-werther
|
||||
- src: conf/hydra-werther.conf
|
||||
dst: /etc/hydra-werther/hydra-werther.conf
|
||||
- src: misc/packaging/systemd/hydra-werther.service
|
||||
dst: /usr/lib/systemd/system/hydra-werther.service
|
||||
|
||||
|
12
misc/packaging/systemd/hydra-werther.service
Normal file
12
misc/packaging/systemd/hydra-werther.service
Normal file
@ -0,0 +1,12 @@
|
||||
[Unit]
|
||||
Description=Run Hydra Werther login/consent/logout app
|
||||
After=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
EnvironmentFile=/etc/hydra-werther/hydra-werther.conf
|
||||
ExecStart=/usr/bin/hydra-werther
|
||||
Restart=on-failure
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
Reference in New Issue
Block a user