Browse Source

Add auth label

master
Chris Smith 5 years ago
parent
commit
13fa96a57c
4 changed files with 19 additions and 5 deletions
  1. 1
    1
      certs/deployer.go
  2. 7
    1
      dotege.go
  3. 4
    1
      model/model.go
  4. 7
    2
      templates/haproxy.cfg.tpl

+ 1
- 1
certs/deployer.go View File

@@ -90,7 +90,7 @@ func (c *CertificateDeployer) deployFile(name string, content []byte, modTime ti
90 90
 	if err != nil {
91 91
 		c.logger.Warnf("Unable to write certificate %s - %s", target, err.Error())
92 92
 	} else {
93
-		c.logger.Info("Updated certificate file %s", target)
93
+		c.logger.Infof("Updated certificate file %s", target)
94 94
 	}
95 95
 }
96 96
 

+ 7
- 1
dotege.go View File

@@ -48,7 +48,8 @@ func main() {
48 48
 
49 49
 	config := model.Config{
50 50
 		Labels: model.LabelConfig{
51
-			Hostnames: "com.chameth.vhost",
51
+			Hostnames:   "com.chameth.vhost",
52
+			RequireAuth: "com.chameth.auth",
52 53
 		},
53 54
 		DefaultCertActions:     model.COMBINE | model.FLATTEN,
54 55
 		DefaultCertDestination: "/data/certs/",
@@ -125,6 +126,11 @@ func getHostnames(containers map[string]model.Container, config model.Config) (h
125 126
 				}
126 127
 			}
127 128
 			addAlternatives(hostnames[names[0]], names[1:])
129
+
130
+			if label, ok = container.Labels[config.Labels.RequireAuth]; ok {
131
+				hostnames[names[0]].RequiresAuth = true
132
+				hostnames[names[0]].AuthGroup = label
133
+			}
128 134
 		}
129 135
 	}
130 136
 	return

+ 4
- 1
model/model.go View File

@@ -24,7 +24,8 @@ type Container struct {
24 24
 
25 25
 // LabelConfig describes the labels used for various properties.
26 26
 type LabelConfig struct {
27
-	Hostnames string
27
+	Hostnames   string
28
+	RequireAuth string
28 29
 }
29 30
 
30 31
 // Hostname describes a DNS name used for proxying, retrieving certificates, etc.
@@ -34,6 +35,8 @@ type Hostname struct {
34 35
 	Containers      []Container
35 36
 	CertActions     CertActions
36 37
 	CertDestination string
38
+	RequiresAuth    bool
39
+	AuthGroup       string
37 40
 }
38 41
 
39 42
 // Config is the user-definable configuration for Dotege.

+ 7
- 2
templates/haproxy.cfg.tpl View File

@@ -26,8 +26,9 @@ frontend main
26 26
     use_backend {{ .Name | replace "." "_" }} if {hdr(host) -i {{ .Name }}
27 27
         {{- range $san, $_ := .Alternatives }} || hdr(host) -i {{ $san }} {{- end -}}
28 28
     }
29
-{{- end }}
30
-{{- range .Hostnames }}
29
+{{- end -}}
30
+
31
+{{ range .Hostnames }}
31 32
 
32 33
 backend {{ .Name | replace "." "_" }}
33 34
     mode http
@@ -36,4 +37,8 @@ backend {{ .Name | replace "." "_" }}
36 37
     server server1 {{ .Name }}:{{ index .Labels "com.chameth.proxy" }} check resolvers docker_resolver
37 38
         {{- end -}}
38 39
     {{- end -}}
40
+    {{- if .RequiresAuth }}
41
+    acl authed_{{ .Name | replace "." "_" }} http_auth({{ .AuthGroup }})
42
+    http-request auth if !authed_{{ .Name | replace "." "_" }}
43
+    {{- end -}}
39 44
 {{ end }}

Loading…
Cancel
Save