Skip to content

Commit 2c112de

Browse files
authored
ENH: Adds CRT_LIST_PATH (#40)
1 parent 58c1052 commit 2c112de

3 files changed

Lines changed: 61 additions & 4 deletions

File tree

docs/config.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ The following environment variables can be used to configure the *Docker Flow Pr
2020
|COMPRESSION_ALGO |Enable HTTP compression. The currently supported algorithms are:<br>**identity**: this is mostly for debugging.<br>**gzip**: applies gzip compression. This setting is only available when support for zlib or libslz was built in.<br>**deflate**: same as *gzip*, but with deflate algorithm and zlib format. Note that this algorithm has ambiguous support on many browsers and no support at all from recent ones. It is strongly recommended not to use it for anything else than experimentation. This setting is only available when support for zlib or libslz was built in.<br>**raw-deflate**: same as *deflate* without the zlib wrapper, and used as an alternative when the browser wants "deflate". All major browsers understand it and despite violating the standards, it is known to work better than *deflate*, at least on MSIE and some versions of Safari. This setting is only available when support for zlib or libslz was built in.<br>Compression will be activated depending on the Accept-Encoding request header. With identity, it does not take care of that header. If backend servers support HTTP compression, these directives will be no-op: haproxy will see the compressed response and will not compress again. If backend servers do not support HTTP compression and there is Accept-Encoding header in request, haproxy will compress the matching response.<br>Compression is disabled when:<br>* the request does not advertise a supported compression algorithm in the "Accept-Encoding" header<br>* the response message is not HTTP/1.1<br>* HTTP status code is not 200<br>* response header "Transfer-Encoding" contains "chunked" (Temporary Workaround)<br>* response contain neither a "Content-Length" header nor a "Transfer-Encoding" whose last value is "chunked"<br>* response contains a "Content-Type" header whose first value starts with "multipart"<br>* the response contains the "no-transform" value in the "Cache-control" header<br>* User-Agent matches "Mozilla/4" unless it is MSIE 6 with XP SP2, or MSIE 7 and later<br>* The response contains a "Content-Encoding" header, indicating that the response is already compressed (see compression offload)<br>**Example:** gzip|
2121
|COMPRESSION_TYPE |The type of files that will be compressed.<br>**Example:** text/css text/html text/javascript application/javascript text/plain text/xml application/json|
2222
|CONNECTION_MODE |HAProxy supports 5 connection modes.<br><br>`http-keep-alive`: all requests and responses are processed.<br>`http-tunnel`: only the first request and response are processed, everything else is forwarded with no analysis.<br>`httpclose`: tunnel with "Connection: close" added in both directions.<br>`http-server-close`: the server-facing connection is closed after the response.<br>`forceclose`: the connection is actively closed after end of response.<br><br>In general, it is preferred to use `http-server-close` with application servers, and some static servers might benefit from `http-keep-alive`.<br>**Example:** `http-server-close`<br>**Default value:** `http-keep-alive`|
23+
|CRT_LIST_PATH |When defined, DFP will not generated `crt-list.txt` file to be used by ssl. `CRT_LIST_PATH` will be used in HAProxy's `ssl crt-list` configuration.|
2324
|DEBUG |Enables logging of each request sent through the proxy. Please consult [Debug Format](#debug-format) for info about the log entries. This feature should be used with caution. **Do not enable debugging in production unless necessary.**<br>**Example:** true<br>**Default value:** `false`|
2425
|DEBUG_ERRORS_ONLY |If set to `true`, only requests that resulted in an error, timeout, retry, and redispatch will be logged. If a request is HTTP, responses with a status 5xx will be logged too. This variable will take effect only if `DEBUG` is set to `true`.<br>**Example:** `true`<br>**Default value:** `false`|
2526
|DEBUG_HTTP_FORMAT |Logging format that will be used with HTTP requests. Please consult [Custom log format](https://cbonte.github.io/haproxy-dconv/1.7/configuration.html#8.2.4) for more info about the available options.|

proxy/ha_proxy.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,15 +338,23 @@ func (m HaProxy) getConfigData() configData {
338338
func (m *HaProxy) getCertsConfigSnippet() string {
339339
certPaths := m.GetCertPaths()
340340
certs := ""
341+
crtListPathEnv := os.Getenv("CRT_LIST_PATH")
341342
if len(certPaths) > 0 {
342343
h2 := ""
344+
crtListPathDefault := "/cfg/crt-list.txt"
345+
if len(crtListPathEnv) > 0 {
346+
crtListPathDefault = crtListPathEnv
347+
}
343348
if strings.EqualFold(os.Getenv("ENABLE_H2"), "true") {
344349
h2 = "h2,"
345350
}
346-
certs = fmt.Sprintf(" ssl crt-list /cfg/crt-list.txt alpn %shttp/1.1", h2)
347-
certMu.Lock()
348-
defer certMu.Unlock()
349-
writeFile("/cfg/crt-list.txt", []byte(strings.Join(certPaths, "\n")), 0664)
351+
certs = fmt.Sprintf(" ssl crt-list %s alpn %shttp/1.1", crtListPathDefault, h2)
352+
353+
if len(crtListPathEnv) == 0 {
354+
certMu.Lock()
355+
defer certMu.Unlock()
356+
writeFile(crtListPathDefault, []byte(strings.Join(certPaths, "\n")), 0664)
357+
}
350358
}
351359
if len(os.Getenv("CA_FILE")) > 0 {
352360
if len(certs) == 0 {

proxy/ha_proxy_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2385,6 +2385,54 @@ func (s HaProxyTestSuite) Test_CreateConfigFromTemplates_DoesNotAddH2_WhenEnable
23852385
s.Equal(expectedData, actualData)
23862386
}
23872387

2388+
func (s HaProxyTestSuite) Test_CreateConfigFromTemplates_CustomCrtListPath() {
2389+
readDirOrig := readDir
2390+
crtListPathOrig := os.Getenv("CRT_LIST_PATH")
2391+
defer func() {
2392+
readDir = readDirOrig
2393+
os.Setenv("CRT_LIST_PATH", crtListPathOrig)
2394+
}()
2395+
os.Setenv("CRT_LIST_PATH", "/cfg/custom-crt-list.txt")
2396+
mockedFiles := []os.FileInfo{}
2397+
file := FileInfoMock{
2398+
NameMock: func() string {
2399+
return "my-cert"
2400+
},
2401+
IsDirMock: func() bool {
2402+
return false
2403+
},
2404+
}
2405+
mockedFiles = append(mockedFiles, file)
2406+
readDir = func(dir string) ([]os.FileInfo, error) {
2407+
if dir == "/certs" {
2408+
return mockedFiles, nil
2409+
}
2410+
return []os.FileInfo{}, nil
2411+
}
2412+
var actualData string
2413+
writeFileCnt := 0
2414+
tmpl := strings.Replace(
2415+
s.TemplateContent,
2416+
"\n bind *:80\n bind *:443",
2417+
"\n bind *:80\n bind *:443 ssl crt-list /cfg/custom-crt-list.txt alpn http/1.1",
2418+
-1)
2419+
expectedData := fmt.Sprintf(
2420+
`%s%s`,
2421+
tmpl,
2422+
s.ServicesContent,
2423+
)
2424+
writeFile = func(filename string, data []byte, perm os.FileMode) error {
2425+
writeFileCnt += 1
2426+
actualData = string(data)
2427+
return nil
2428+
}
2429+
2430+
NewHaProxy(s.TemplatesPath, s.ConfigsPath).CreateConfigFromTemplates()
2431+
2432+
s.Equal(expectedData, actualData)
2433+
s.Equal(1, writeFileCnt)
2434+
}
2435+
23882436
func (s HaProxyTestSuite) Test_CreateConfigFromTemplates_AddsCaFile_WhenEnvVarIsSet() {
23892437
caFile := "my-ca-file"
23902438
caFileOrig := os.Getenv("CA_FILE")

0 commit comments

Comments
 (0)