Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d7513e0
Add disk cert manager
guilhermocc May 29, 2023
9a8c675
Add serving_cert_file config to oidc discovery provider in unix
guilhermocc May 29, 2023
cbef8cf
Add serving cert file config for windows
guilhermocc May 30, 2023
125d274
Fix update tests on linux
guilhermocc May 30, 2023
e5e56a9
Fix rebase conflicts
guilhermocc May 30, 2023
67b20fb
Update documentation
guilhermocc May 30, 2023
eddf53c
Fix race condition
guilhermocc May 30, 2023
91a7695
Fix lint in windows
guilhermocc May 30, 2023
c02a6da
Fix timed assertions
guilhermocc May 30, 2023
915b914
Fix windows test
guilhermocc May 30, 2023
09acd52
Print cert manager logs on failed test
guilhermocc May 31, 2023
fcba21a
Remove fsnotify usage
guilhermocc Jun 1, 2023
fb9bd71
Refactor tests
guilhermocc Jun 1, 2023
61d8e65
Fix tests on windows
guilhermocc Jun 1, 2023
e43b173
Fix file sync
guilhermocc Jun 1, 2023
af12dbe
Make file sync interval configurable
guilhermocc Jun 1, 2023
75123b3
Refactor some comments
guilhermocc Jun 1, 2023
e4f2e0c
Address comments for unix platform
guilhermocc Jun 7, 2023
85abb9a
Address comments for windows platform
guilhermocc Jun 7, 2023
50eb322
Address comments to use context for ending goroutines
guilhermocc Jun 9, 2023
9f5da60
Fix tests on windows
guilhermocc Jun 12, 2023
3d36f1f
Address PR comments
guilhermocc Jun 13, 2023
d47e082
Enable user to select the address for serving the https service
guilhermocc Jun 22, 2023
8cacc0a
Fix lint
guilhermocc Jun 23, 2023
996e427
Fix windows tests
guilhermocc Jun 23, 2023
dceafe0
Update default HTTPS port
guilhermocc Jun 30, 2023
c18537e
Fix flaky tests
guilhermocc Jun 30, 2023
c9c3612
Remove duplicated documentation
guilhermocc Jul 3, 2023
4b2b816
Merge branch 'main' into serving-cert-file-oidc-provider
rturner3 Jul 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions support/oidc-discovery-provider/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ The configuration file is **required** by the provider. It contains

#### Considerations for Unix platforms

[1]: One of `acme`, `serving_cert_file`, `listen_socket_path` must be defined.
[1]: One of `acme`, `serving_cert_file` or `listen_socket_path` must be defined.

[3]: The `allow_insecure_scheme` should only be used in a local development environment for testing purposes. It only works in conjunction with `insecure_addr` or `listen_socket_path`.

#### Considerations for Windows platforms

[1]: One of `acme`, `serving_cert_file`, `listen_named_pipe_name` must be defined.
[1]: One of `acme`, `serving_cert_file` or `listen_named_pipe_name` must be defined.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[1]: One of `acme`, `serving_cert_file` or `listen_named_pipe_name` must be defined.
[1]: One of `acme`, `serving_cert_file`, or `listen_named_pipe_name` must be defined.


[3]: The `allow_insecure_scheme` should only be used in a local development environment for testing purposes. It only works in conjunction with `insecure_addr` or `listen_named_pipe_name`.

Expand Down Expand Up @@ -91,11 +91,13 @@ will terminate if another domain is requested.

#### Serving Certificate Section

| Key | Type | Required? | Description | Default |
|----------------------|----------|-----------|--------------------------------------------------------------------|----------|
| `cert_file_path` | string | required | The certificate file path, the file must contain PEM encoded data. | |
| `key_file_path` | string | required | The private key file path, the file must contain PEM encoded data. | |
| `file_sync_interval` | duration | optional | Controls how frequently the service polls the files for changes. | 1 minute |
| Key | Type | Required? | Description | Default |
|----------------------|----------|-----------|--------------------------------------------------------------------|------------|
| `cert_file_path` | string | required | The certificate file path, the file must contain PEM encoded data. | |
| `key_file_path` | string | required | The private key file path, the file must contain PEM encoded data. | |
| `file_sync_interval` | duration | optional | Controls how frequently the service polls the files for changes. | 1 minute |
| `file_sync_interval` | duration | optional | Controls how frequently the service polls the files for changes. | 1 minute |
| `addr` | string | optional | Exposes the service on the given address. | :433 |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

443 should be the default (multiple places to fix)


#### Server API Section

Expand Down
16 changes: 16 additions & 0 deletions support/oidc-discovery-provider/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"net"
"os"
"time"

Expand All @@ -16,6 +17,7 @@ const (
defaultHealthChecksBindPort = 8008
defaultHealthChecksReadyPath = "/ready"
defaultHealthChecksLivePath = "/live"
defaultAddr = ":433"
)

type Config struct {
Expand Down Expand Up @@ -82,6 +84,10 @@ type ServingCertFileConfig struct {
// KeyFilePath is the path to the private key file. The provider will watch
// this file for changes and reload the key when it changes.
KeyFilePath string `hcl:"key_file_path"`
// Addr is the address to listen on. This is optional and defaults to ":433".
Addr *net.TCPAddr `hcl:"-"`
// RawAddr holds the string version of the Addr. Consumers should use Addr instead.
RawAddr string `hcl:"addr"`
// FileSyncInterval controls how frequently the service polls the certificate for changes.
FileSyncInterval time.Duration `hcl:"-"`
// RawFileSyncInterval holds the string version of the FileSyncInterval. Consumers
Expand Down Expand Up @@ -221,6 +227,16 @@ func ParseConfig(hclConfig string) (_ *Config, err error) {
return nil, errs.New("key_file_path must be configured in the serving_cert_file configuration section")
}

if c.ServingCertFile.RawAddr == "" {
c.ServingCertFile.RawAddr = defaultAddr
}

addr, err := net.ResolveTCPAddr("tcp", c.ServingCertFile.RawAddr)
if err != nil {
return nil, errs.New("invalid addr in the serving_cert_file configuration section: %v", err)
}
c.ServingCertFile.Addr = addr

c.ServingCertFile.FileSyncInterval, err = parseDurationField(c.ServingCertFile.RawFileSyncInterval, defaultFileSyncInterval)
if err != nil {
return nil, errs.New("invalid file_sync_interval in the serving_cert_file configuration section: %v", err)
Expand Down
59 changes: 57 additions & 2 deletions support/oidc-discovery-provider/config_posix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

package main

import "time"
import (
"net"
"time"
)

var (
minimalServerAPIConfig = `
Expand Down Expand Up @@ -107,13 +110,45 @@ func parseConfigCasesOS() []parseConfigCase {
},
},
{
name: "serving_cert_file configuration",
name: "serving_cert_file configuration with defaults",
in: `
domains = ["domain.test"]
serving_cert_file {
cert_file_path = "test"
key_file_path = "test"
}
server_api {
address = "unix:///some/socket/path"
}
`,
out: &Config{
LogLevel: defaultLogLevel,
Domains: []string{"domain.test"},
ServingCertFile: &ServingCertFileConfig{
CertFilePath: "test",
KeyFilePath: "test",
FileSyncInterval: time.Minute,
Addr: &net.TCPAddr{
IP: nil,
Port: 433,
},
RawAddr: ":433",
},
ServerAPI: &ServerAPIConfig{
Address: "unix:///some/socket/path",
PollInterval: defaultPollInterval,
},
},
},
{
name: "serving_cert_file configuration with optionals",
in: `
domains = ["domain.test"]
serving_cert_file {
cert_file_path = "test"
key_file_path = "test"
file_sync_interval = "5m"
addr = "127.0.0.1:9090"
}
server_api {
address = "unix:///some/socket/path"
Expand All @@ -127,6 +162,11 @@ func parseConfigCasesOS() []parseConfigCase {
KeyFilePath: "test",
FileSyncInterval: 5 * time.Minute,
RawFileSyncInterval: "5m",
Addr: &net.TCPAddr{
IP: net.ParseIP("127.0.0.1"),
Port: 9090,
},
RawAddr: "127.0.0.1:9090",
},
ServerAPI: &ServerAPIConfig{
Address: "unix:///some/socket/path",
Expand Down Expand Up @@ -160,6 +200,21 @@ func parseConfigCasesOS() []parseConfigCase {
`,
err: "key_file_path must be configured in the serving_cert_file configuration section",
},
{
name: "serving_cert_file configuration with invalid addr",
in: `
domains = ["domain.test"]
serving_cert_file {
cert_file_path = "test"
key_file_path = "test"
addr = "127.0.0.1.1:9090"
}
server_api {
address = "unix:///some/socket/path"
}
`,
err: "invalid addr in the serving_cert_file configuration section: lookup 127.0.0.1.1: no such host",
},
{
name: "both acme and insecure_addr configured",
in: `
Expand Down
62 changes: 55 additions & 7 deletions support/oidc-discovery-provider/config_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,48 @@ func parseConfigCasesOS() []parseConfigCase {
},
},
{
name: "serving_cert_file configuration",
name: "serving_cert_file configuration with defaults",
in: `
domains = ["domain.test"]
serving_cert_file {
cert_file_path = "test"
key_file_path = "test"
}
server_api {
address = "unix:///some/socket/path"
}
`,
out: &Config{
LogLevel: defaultLogLevel,
Domains: []string{"domain.test"},
ServingCertFile: &ServingCertFileConfig{
CertFilePath: "test",
KeyFilePath: "test",
FileSyncInterval: time.Minute,
Addr: &net.TCPAddr{
IP: nil,
Port: 433,
},
RawAddr: ":433",
},
ServerAPI: &ServerAPIConfig{
Address: "unix:///some/socket/path",
PollInterval: defaultPollInterval,
},
},
},
{
name: "serving_cert_file configuration with optionals",
in: `
domains = ["domain.test"]
serving_cert_file {
cert_file_path = "test"
key_file_path = "test"
file_sync_interval = "5m"
addr = "127.0.0.1:9090"
}
server_api {
experimental {
named_pipe_name = "\\name\\for\\server\\api"
}
address = "unix:///some/socket/path"
}
`,
out: &Config{
Expand All @@ -145,11 +175,14 @@ func parseConfigCasesOS() []parseConfigCase {
KeyFilePath: "test",
FileSyncInterval: 5 * time.Minute,
RawFileSyncInterval: "5m",
Addr: &net.TCPAddr{
IP: net.ParseIP("127.0.0.1"),
Port: 9090,
},
RawAddr: "127.0.0.1:9090",
},
ServerAPI: &ServerAPIConfig{
Experimental: experimentalServerAPIConfig{
NamedPipeName: "\\name\\for\\server\\api",
},
Address: "unix:///some/socket/path",
PollInterval: defaultPollInterval,
},
},
Expand Down Expand Up @@ -180,6 +213,21 @@ func parseConfigCasesOS() []parseConfigCase {
`,
err: "key_file_path must be configured in the serving_cert_file configuration section",
},
{
name: "serving_cert_file configuration with invalid addr",
in: `
domains = ["domain.test"]
serving_cert_file {
cert_file_path = "test"
key_file_path = "test"
addr = "127.0.0.1.1:9090"
}
server_api {
address = "unix:///some/socket/path"
}
`,
err: "invalid addr in the serving_cert_file configuration section: lookup 127.0.0.1.1: no such host",
},
{
name: "both acme and insecure_addr configured",
in: `
Expand Down
5 changes: 2 additions & 3 deletions support/oidc-discovery-provider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ func run(configPath string) error {

go func() {
<-ctx.Done()
err = server.Shutdown(context.Background())
if err != nil {
if err := server.Shutdown(context.Background()); err != nil {
log.Error(err)
}
}()
Expand Down Expand Up @@ -182,7 +181,7 @@ func newListenerWithServingCert(ctx context.Context, log logrus.FieldLogger, con

tlsConfig := certManager.TLSConfig()

tcpListener, err := net.ListenTCP("tcp", &net.TCPAddr{Port: 443})
tcpListener, err := net.ListenTCP("tcp", config.ServingCertFile.Addr)
if err != nil {
return nil, fmt.Errorf("failed to create listener using certificate from disk: %w", err)
}
Expand Down