feat: configurable ignore of tls verification for hydra connections
Cadoles/hydra-werther/pipeline/pr-develop This commit looks good
Details
Cadoles/hydra-werther/pipeline/pr-develop This commit looks good
Details
This commit is contained in:
parent
592749eebf
commit
271d62dc27
|
@ -14,6 +14,8 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"crypto/tls"
|
||||||
|
|
||||||
"github.com/i-core/rlog"
|
"github.com/i-core/rlog"
|
||||||
"github.com/i-core/routegroup"
|
"github.com/i-core/routegroup"
|
||||||
"github.com/i-core/werther/internal/identp"
|
"github.com/i-core/werther/internal/identp"
|
||||||
|
@ -30,11 +32,12 @@ var version = ""
|
||||||
|
|
||||||
// Config is a server's configuration.
|
// Config is a server's configuration.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
DevMode bool `envconfig:"dev_mode" default:"false" desc:"a development mode"`
|
DevMode bool `envconfig:"dev_mode" default:"false" desc:"Enable development mode"`
|
||||||
Listen string `default:":8080" desc:"a host and port to listen on (<host>:<port>)"`
|
Listen string `default:":8080" desc:"a host and port to listen on (<host>:<port>)"`
|
||||||
Identp identp.Config
|
InsecureSkipVerify bool `envconfig:"insecure_skip_verify" default:"false" desc:"Disable TLS verification on Hydra connection"`
|
||||||
LDAP ldapclient.Config
|
Identp identp.Config
|
||||||
Web web.Config
|
LDAP ldapclient.Config
|
||||||
|
Web web.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -80,6 +83,11 @@ func main() {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cnf.InsecureSkipVerify {
|
||||||
|
log.Warn("All ssl verifications are disabled !")
|
||||||
|
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
|
||||||
|
}
|
||||||
|
|
||||||
ldap := ldapclient.New(cnf.LDAP)
|
ldap := ldapclient.New(cnf.LDAP)
|
||||||
|
|
||||||
router := routegroup.NewRouter(nosurf.NewPure, rlog.NewMiddleware(log))
|
router := routegroup.NewRouter(nosurf.NewPure, rlog.NewMiddleware(log))
|
||||||
|
|
|
@ -123,3 +123,9 @@ WERTHER_LDAP_ROLE_BASEDN=ou=groups,dc=myorg,dc=com
|
||||||
# [type] Duration
|
# [type] Duration
|
||||||
# [default] 60s
|
# [default] 60s
|
||||||
# [required]
|
# [required]
|
||||||
|
|
||||||
|
# WERTHER_INSECURE_SKIP_VERIFY=
|
||||||
|
# [description] Disable TLS verification on Hydra connection
|
||||||
|
# [type] True or False
|
||||||
|
# [default] false
|
||||||
|
# [required]
|
|
@ -26,6 +26,8 @@ var (
|
||||||
ErrChallengeNotFound = errors.New("challenge not found")
|
ErrChallengeNotFound = errors.New("challenge not found")
|
||||||
// ErrChallengeExpired is an error that happens when a challenge is already used.
|
// ErrChallengeExpired is an error that happens when a challenge is already used.
|
||||||
ErrChallengeExpired = errors.New("challenge expired")
|
ErrChallengeExpired = errors.New("challenge expired")
|
||||||
|
//ErrServiceUnavailable is an error that happens when the hydra admin service is unavailable
|
||||||
|
ErrServiceUnavailable = errors.New("hydra service unavailable")
|
||||||
)
|
)
|
||||||
|
|
||||||
type reqType string
|
type reqType string
|
||||||
|
@ -52,6 +54,7 @@ func initiateRequest(typ reqType, hydraURL string, fakeTLSTermination bool, chal
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
u, err := parseURL(hydraURL)
|
u, err := parseURL(hydraURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -145,6 +148,8 @@ func checkResponse(resp *http.Response) error {
|
||||||
return ErrChallengeNotFound
|
return ErrChallengeNotFound
|
||||||
case 409:
|
case 409:
|
||||||
return ErrChallengeExpired
|
return ErrChallengeExpired
|
||||||
|
case 503:
|
||||||
|
return ErrServiceUnavailable
|
||||||
default:
|
default:
|
||||||
var rs struct {
|
var rs struct {
|
||||||
Message string `json:"error"`
|
Message string `json:"error"`
|
||||||
|
|
|
@ -11,6 +11,7 @@ package identp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -127,7 +128,8 @@ func newLoginStartHandler(rproc oa2LoginReqProcessor, tmplRenderer TemplateRende
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Infow("Failed to initiate an OAuth2 login request", zap.Error(err), "challenge", challenge)
|
log.Infow("Failed to initiate an OAuth2 login request", zap.Error(err), "challenge", challenge)
|
||||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
errMsg := fmt.Sprintf("%s - %s - %s", http.StatusText(http.StatusInternalServerError), err, errors.Cause(err))
|
||||||
|
http.Error(w, errMsg, http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Infow("A login request is initiated", "challenge", challenge, "username", ri.Subject)
|
log.Infow("A login request is initiated", "challenge", challenge, "username", ri.Subject)
|
||||||
|
|
Loading…
Reference in New Issue