Skip to content

Commit d3ff2c4

Browse files
authored
Merge pull request #155 from SenseUnit/combined_auth
Combined Auth
2 parents dc42943 + 913c73e commit d3ff2c4

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ Authentication parameters are passed as URI via `-auth` parameter. Scheme of URI
264264
* `cert` - use mutual TLS authentication with client certificates. In order to use this auth provider server must listen sockert in TLS mode (`-cert` and `-key` options) and client CA file must be specified (`-cacert`). Example: `cert://`. Parameters of this scheme are:
265265
* `blacklist` - location of file with list of serial numbers of blocked certificates, one per each line in form of hex-encoded colon-separated bytes. Example: `ab:01:02:03`. Empty lines and comments starting with `#` are ignored.
266266
* `reload` - interval for certificate blacklist file reload, if it was modified since last load. Use negative duration to disable autoreload. Default: `15s`.
267+
* `next` - optional URL specifying the next auth provider to chain to, if cert authentication succeeded. Example: `-auth 'cert://?next=static%3A%2F%2F%3Fusername%3Dadmin%26password%3D123456'`.
267268
* `redis` - use external Redis database to lookup password verifiers for users. The password format is similar to `basicfile` mode or `htpasswd` encoding except username goes into Redis key name, colon is skipped and the rest goes to value of this key. For example, login-password pair `test` / `123456` can be encoded as Redis key `test` with value `$2y$05$zs1EJayCIyYtG.NQVzu9SeNvMP0XYWa42fQv.XNDx33wwbg98SnUq`. Example of auth parameter: `-auth 'redis://?url=redis%3A//default%3A123456Y%40redis-14623.c531.europe-west3-1.gce.redns.redis-cloud.com%3A17954/0&key_prefix=auth_'`. Parameters:
268269
* `url` - URL specifying Redis instance to connect to. See [ParseURL](https://pkg.go.dev/github.com/redis/go-redis/v9#ParseURL) documentation for the complete specification of Redis URL format.
269270
* `key_prefix` - prefix to prepend to each key before lookup. Helps isolate keys under common prefix. Default is empty string (`""`).

auth/cert.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type CertAuth struct {
3131
logger *clog.CondLogger
3232
stopOnce sync.Once
3333
stopChan chan struct{}
34+
next Auth
3435
}
3536

3637
func NewCertAuth(param_url *url.URL, logger *clog.CondLogger) (*CertAuth, error) {
@@ -62,11 +63,18 @@ func NewCertAuth(param_url *url.URL, logger *clog.CondLogger) (*CertAuth, error)
6263
go auth.reloadLoop(reloadInterval)
6364
}
6465
}
66+
if nextAuth := values.Get("next"); nextAuth != "" {
67+
nap, err := NewAuth(nextAuth, logger)
68+
if err != nil {
69+
return nil, fmt.Errorf("chained auth provider construction failed: %w", err)
70+
}
71+
auth.next = nap
72+
}
6573

6674
return auth, nil
6775
}
6876

69-
func (auth *CertAuth) Validate(_ context.Context, wr http.ResponseWriter, req *http.Request) (string, bool) {
77+
func (auth *CertAuth) Validate(ctx context.Context, wr http.ResponseWriter, req *http.Request) (string, bool) {
7078
if req.TLS == nil || len(req.TLS.VerifiedChains) < 1 || len(req.TLS.VerifiedChains[0]) < 1 {
7179
http.Error(wr, BAD_REQ_MSG, http.StatusBadRequest)
7280
return "", false
@@ -76,6 +84,9 @@ func (auth *CertAuth) Validate(_ context.Context, wr http.ResponseWriter, req *h
7684
http.Error(wr, BAD_REQ_MSG, http.StatusBadRequest)
7785
return "", false
7886
}
87+
if auth.next != nil {
88+
return auth.next.Validate(ctx, wr, req)
89+
}
7990
return fmt.Sprintf(
8091
"Subject: %s, Serial Number: %s",
8192
eeCert.Subject.String(),

0 commit comments

Comments
 (0)