-
Notifications
You must be signed in to change notification settings - Fork 71
/
main.go
45 lines (38 loc) · 1.35 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"log"
"net/http"
"github.com/sirupsen/logrus"
"github.com/stripe/smokescreen/cmd"
"github.com/stripe/smokescreen/pkg/smokescreen"
)
// This default implementation of RoleFromRequest uses the CommonName of the
// client's certificate. If no certificate is provided, the AllowMissingRole
// configuration option will control whether the request is rejected, or the
// default ACL is applied.
func defaultRoleFromRequest(req *http.Request) (string, error) {
if req.TLS == nil {
return "", smokescreen.MissingRoleError("defaultRoleFromRequest requires TLS")
}
if len(req.TLS.PeerCertificates) == 0 {
return "", smokescreen.MissingRoleError("client did not provide certificate")
}
return req.TLS.PeerCertificates[0].Subject.CommonName, nil
}
func main() {
conf, err := cmd.NewConfiguration(nil, nil)
if err != nil {
logrus.Fatalf("Could not create configuration: %v", err)
} else if conf != nil {
conf.RoleFromRequest = defaultRoleFromRequest
conf.Log.Formatter = &logrus.JSONFormatter{}
adapter := &smokescreen.Log2LogrusWriter{
Entry: conf.Log.WithField("stdlog", "1"),
}
// Set the standard logger to use our logger's writer as output.
log.SetOutput(adapter)
log.SetFlags(0)
smokescreen.StartWithConfig(conf, nil)
}
// Otherwise, --help or --version was passed and handled by NewConfiguration, so do nothing
}