Skip to content

Commit fdc8e0f

Browse files
authored
Unify file watching strategy in TLS config pool (#297)
Signed-off-by: Ignasi Barrera <[email protected]>
1 parent 2d7a8e2 commit fdc8e0f

31 files changed

+451
-776
lines changed

cmd/main.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,21 @@ import (
2424
"github.com/tetratelabs/telemetry"
2525

2626
"github.com/istio-ecosystem/authservice/internal"
27+
"github.com/istio-ecosystem/authservice/internal/http"
2728
"github.com/istio-ecosystem/authservice/internal/k8s"
2829
"github.com/istio-ecosystem/authservice/internal/oidc"
2930
"github.com/istio-ecosystem/authservice/internal/server"
31+
"github.com/istio-ecosystem/authservice/internal/watch"
3032
)
3133

3234
func main() {
3335
var (
34-
lifecycle = run.NewLifecycle()
3536
configFile = &internal.LocalConfigFile{}
3637
logging = internal.NewLogSystem(log.New(), &configFile.Config)
37-
tlsPool = internal.NewTLSConfigPool(lifecycle.Context())
38+
fileWatcher = &watch.FileWatcherService{}
39+
tlsPool = http.NewTLSConfigPool(fileWatcher)
3840
jwks = oidc.NewJWKSProvider(&configFile.Config, tlsPool)
39-
sessions = oidc.NewSessionStoreFactory(&configFile.Config)
41+
sessions = oidc.NewSessionStoreFactory(&configFile.Config, fileWatcher)
4042
envoyAuthz = server.NewExtAuthZFilter(&configFile.Config, tlsPool, jwks, sessions)
4143
authzServer = server.New(&configFile.Config, envoyAuthz.Register)
4244
healthz = server.NewHealthServer(&configFile.Config)
@@ -58,9 +60,9 @@ func main() {
5860
g := run.Group{Logger: internal.Logger(internal.Default)}
5961

6062
g.Register(
61-
lifecycle, // manage the lifecycle of the run.Services
6263
configFile, // load the configuration
6364
logging, // Set up the logging system
65+
fileWatcher, // watch for file changes
6466
secretCtrl, // watch for secret updates and update the configuration
6567
configLog, // log the configuration
6668
fipsLog, // log whether FIPS is enabled

config/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ via the standard authorization code grant flow from an OIDC Provider.
8787
| idle_session_timeout | [uint32](#uint32) | | The Authservice associates obtained OIDC tokens with a session ID in a session store. It also stores some temporary information during the login process into the session store, which will be removed when the user finishes the login. This configuration option sets the number of seconds since the most recent incoming request from that user until the user's session with the Authservice should expire. When configured to `0`, which is the default value, session expiration will not consider idle time, but can still consider timeout based on maximum absolute time since added. When both `absolute_session_timeout` and `idle_session_timeout` are zero, then sessions will never expire. These settings do not affect how quickly the OIDC tokens contained inside the user's session expire. Optional. |
8888
| trusted_certificate_authority | [string](#string) | | String PEM-encoded certificate authority to trust when performing HTTPS calls to the OIDC Identity Provider. Optional. |
8989
| trusted_certificate_authority_file | [string](#string) | | The file path to the PEM-encoded certificate authority to trust when performing HTTPS calls to the OIDC Identity Provider. Optional. |
90-
| trusted_certificate_authority_refresh_interval | [google.protobuf.Duration](#google-protobuf-Duration) | | The duration between refreshes of the trusted certificate authority if `trusted_certificate_authority_file` is set. Unset or 0 (the default) disables the refresh, useful is no rotation is expected. Is a String that ends in `s` to indicate seconds and is preceded by the number of seconds, e.g. `120s` (represents 2 minutes). Optional. |
90+
| trusted_certificate_authority_refresh_interval | [google.protobuf.Duration](#google-protobuf-Duration) | | The duration between refreshes of the trusted certificate authority if `trusted_certificate_authority_file` is set. Unset or 0 (the default) disables the refresh, useful is no rotation is expected. Is a String that ends in `s` to indicate seconds and is preceded by the number of seconds, e.g. `120s` (represents 2 minutes). Optional. Deprecated. The file will be automatically reloaded when it changes. |
9191
| proxy_uri | [string](#string) | | The Authservice makes two kinds of direct network connections directly to the OIDC Provider. Both are POST requests to the configured `token_uri` of the OIDC Provider. The first is to exchange the authorization code for tokens, and the other is to use the refresh token to obtain new tokens. Configure the `proxy_uri` when both of these requests should be made through a web proxy. The format of `proxy_uri` is `http://proxyserver.example.com:8080`, where `:<port_number>` is optional. Userinfo (usernames and passwords) in the `proxy_uri` setting are not yet supported. The `proxy_uri` should always start with `http://`. The Authservice will upgrade the connection to the OIDC provider to HTTPS using an HTTP CONNECT request to the proxy server. The proxy server will see the hostname and port number of the OIDC provider in plain text in the CONNECT request, but all other communication will occur over an encrypted HTTPS connection negotiated directly between the Authservice and the OIDC provider. See also the related `trusted_certificate_authority` configuration option. Optional. |
9292
| redis_session_store_config | [RedisConfig](#authservice-config-v1-oidc-RedisConfig) | | When specified, the Authservice will use the configured Redis server to store session data. Optional. |
9393
| skip_verify_peer_cert | [google.protobuf.Value](#google-protobuf-Value) | | If set to true, the verification of the destination certificate will be skipped when making a request to the Token Endpoint. This option is useful when you want to use a self-signed certificate for testing purposes, but basically should not be set to true in any other cases. Optional. keep this field out from the trusted_ca_config one of for backward compatibility. |

config/gen/go/v1/oidc/config.pb.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/v1/oidc/config.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ message OIDCConfig {
338338
// Unset or 0 (the default) disables the refresh, useful is no rotation is expected.
339339
// Is a String that ends in `s` to indicate seconds and is preceded by the number of seconds, e.g. `120s` (represents 2 minutes).
340340
// Optional.
341+
// Deprecated. The file will be automatically reloaded when it changes.
341342
google.protobuf.Duration trusted_certificate_authority_refresh_interval = 22;
342343

343344
// The Authservice makes two kinds of direct network connections directly to the OIDC Provider.

e2e/istio/suite_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package istio
1616

1717
import (
18-
"context"
1918
"fmt"
2019
"os"
2120
"os/exec"
@@ -82,7 +81,7 @@ func (i *IstioSuite) SetupSuite() {
8281

8382
i.T().Log("deploying the test services...")
8483
for _, f := range testManifests {
85-
i.MustApply(context.Background(), manifestsDir+"/"+f)
84+
i.MustApply(i.T().Context(), manifestsDir+"/"+f)
8685
}
8786
i.WaitForPods(client, "keycloak", "job-name=setup-keycloak", corev1.PodSucceeded, e2e.PodInitialized)
8887
i.WaitForPods(client, "redis", "", corev1.PodRunning, e2e.PodReady)
@@ -113,7 +112,7 @@ func (i *IstioSuite) installIstio() {
113112
}
114113

115114
func (i *IstioSuite) istioInstalled(client kubernetes.Interface) bool {
116-
_, err := client.CoreV1().Services("istio-system").Get(context.Background(), "istiod", metav1.GetOptions{})
115+
_, err := client.CoreV1().Services("istio-system").Get(i.T().Context(), "istiod", metav1.GetOptions{})
117116
return err == nil
118117
}
119118

e2e/k8s_suite.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func (k *K8sSuite) WaitForPods(client kubernetes.Interface, namespace, selector
177177
opts := metav1.ListOptions{
178178
LabelSelector: selector,
179179
}
180-
pods, err := client.CoreV1().Pods(namespace).List(context.Background(), opts)
180+
pods, err := client.CoreV1().Pods(namespace).List(k.T().Context(), opts)
181181
if err != nil || len(pods.Items) == 0 {
182182
return false
183183
}

e2e/redis/store_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package mock
1616

1717
import (
18-
"context"
1918
"os"
2019
"testing"
2120
"time"
@@ -66,7 +65,7 @@ func TestRedisTokenResponse(t *testing.T) {
6665
store, err := oidc.NewRedisStore(&oidc.Clock{}, client, 0, 1*time.Minute)
6766
require.NoError(t, err)
6867

69-
ctx := context.Background()
68+
ctx := t.Context()
7069

7170
tr, err := store.GetTokenResponse(ctx, "s1")
7271
require.NoError(t, err)
@@ -102,7 +101,7 @@ func TestRedisAuthorizationState(t *testing.T) {
102101
store, err := oidc.NewRedisStore(&oidc.Clock{}, client, 0, 1*time.Minute)
103102
require.NoError(t, err)
104103

105-
ctx := context.Background()
104+
ctx := t.Context()
106105

107106
as, err := store.GetAuthorizationState(ctx, "s1")
108107
require.NoError(t, err)
@@ -134,7 +133,7 @@ func TestSessionExpiration(t *testing.T) {
134133
store, err := oidc.NewRedisStore(&oidc.Clock{}, client, 2*time.Second, 0)
135134
require.NoError(t, err)
136135

137-
ctx := context.Background()
136+
ctx := t.Context()
138137

139138
t.Run("expire-token", func(t *testing.T) {
140139
tr := &oidc.TokenResponse{

internal/authz/mock_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package authz
1616

1717
import (
18-
"context"
1918
"testing"
2019

2120
envoy "github.com/envoyproxy/go-control-plane/envoy/service/auth/v3"
@@ -42,7 +41,7 @@ func TestProcessMock(t *testing.T) {
4241
req = &envoy.CheckRequest{}
4342
resp = &envoy.CheckResponse{}
4443
)
45-
err := m.Process(context.Background(), req, resp)
44+
err := m.Process(t.Context(), req, resp)
4645
require.NoError(t, err)
4746
require.Equal(t, int32(tt.want), resp.Status.Code)
4847
})

internal/authz/oidc.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ var (
6565
type oidcHandler struct {
6666
log telemetry.Logger
6767
config *oidcv1.OIDCConfig
68-
tlsPool internal.TLSConfigPool
68+
tlsPool inthttp.TLSConfigPool
6969
jwks oidc.JWKSProvider
7070
sessions oidc.SessionStoreFactory
7171
sessionGen oidc.SessionGenerator
@@ -74,7 +74,7 @@ type oidcHandler struct {
7474
}
7575

7676
// NewOIDCHandler creates a new OIDC implementation of the Handler interface.
77-
func NewOIDCHandler(cfg *oidcv1.OIDCConfig, tlsPool internal.TLSConfigPool, jwks oidc.JWKSProvider,
77+
func NewOIDCHandler(cfg *oidcv1.OIDCConfig, tlsPool inthttp.TLSConfigPool, jwks oidc.JWKSProvider,
7878
sessions oidc.SessionStoreFactory, clock oidc.Clock, sessionGen oidc.SessionGenerator) (Handler, error) {
7979

8080
client, err := inthttp.NewHTTPClient(cfg, tlsPool, internal.Logger(internal.IDP))
@@ -599,7 +599,7 @@ func (o *oidcHandler) refreshToken(ctx context.Context, log telemetry.Logger, ex
599599
}
600600

601601
// validate the id token
602-
if ok, _ := o.isValidIDToken(context.Background(), log, newTokenResponse.IDToken, expectedNonce, false); !ok {
602+
if ok, _ := o.isValidIDToken(ctx, log, newTokenResponse.IDToken, expectedNonce, false); !ok {
603603
return nil
604604
}
605605

0 commit comments

Comments
 (0)