Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
2eb6746
add option status code log from origin (#4)
t4niwa Nov 30, 2022
2afba0b
fix error & fatal in normal shutdown (#6)
WindzCUHK Dec 7, 2022
74f011f
add resource prefix config (#12)
WindzCUHK Dec 26, 2022
150d873
new `noAuthPaths` option supporting wildcard characters (#15)
WindzCUHK Jan 18, 2023
67a3c7d
Add cert refresh period configulation
kyfujisa Feb 1, 2023
d3d6a18
Add parse cert refresh period and Add Refresh logic
kyfujisa Feb 1, 2023
ac32012
Run cert refresh logic
kyfujisa Feb 1, 2023
0c786f2
Load certificate
kyfujisa Feb 1, 2023
8e3ac7b
Add new server struct option
kyfujisa Feb 1, 2023
4af61cf
Add TLSCertificateCache, New function
kyfujisa Feb 1, 2023
54a97d4
Move TLS config setting to authz_proxyd.go
kyfujisa Feb 1, 2023
ee84eab
Add comments
kyfujisa Feb 1, 2023
d907cb1
Move TLS cert invalid test
kyfujisa Feb 2, 2023
0fe265d
Add WithTLSConfig test
kyfujisa Feb 2, 2023
4755b3a
Move hash() function
kyfujisa Feb 2, 2023
8bcf715
Add enable / tlsConfig check
kyfujisa Feb 2, 2023
cdc7e63
Add HTTPS server test
kyfujisa Feb 3, 2023
e78e495
Use atomic.Value cache
kyfujisa Feb 6, 2023
7303bc6
Add NewServer error test
kyfujisa Feb 6, 2023
f5f796f
Add lock for update
kyfujisa Feb 6, 2023
6511e47
Delete comment
kyfujisa Feb 6, 2023
17aa462
Add TestNewTLSConfigWithTLSCertificateCache
kyfujisa Feb 6, 2023
9930e24
Implement test for authz_proxyd.New
thgm3116 Feb 6, 2023
6a7dff0
Fix typo
thgm3116 Feb 6, 2023
56170d1
Add test for authz_proxyd.Start
thgm3116 Feb 6, 2023
a1ba82f
Add TestTLSCertificateCache_getCertificate
kyfujisa Feb 6, 2023
56a9862
Add TLSCertificateCache_RefreshCertificate template
kyfujisa Feb 7, 2023
0029638
Fix param format for test
thgm3116 Feb 7, 2023
98ef5ec
Add refresh testcase(still in progress)
kyfujisa Feb 7, 2023
75247f1
fix server.go unit test
Feb 7, 2023
8b87f4b
Revert "Add refresh testcase(still in progress)"
kyfujisa Feb 7, 2023
54184d1
Revert "Revert "Add refresh testcase(still in progress)""
kyfujisa Feb 7, 2023
a03adb8
Commentout work in progress test
kyfujisa Feb 7, 2023
8f7e551
Fix error message
kyfujisa Feb 8, 2023
ab7a24e
Add TestTLSCertificateCache_RefreshCertificate
kyfujisa Feb 8, 2023
2ccaf6e
Add CertRefreshPeriod 0 check
kyfujisa Feb 8, 2023
0764566
Add comment
kyfujisa Feb 8, 2023
22ca473
Add certRefreshPeriod option
kyfujisa Feb 8, 2023
ed05411
Add comment
kyfujisa Feb 8, 2023
bbd299a
Fix test for config(add CertRefreshPeriod)
kyfujisa Feb 8, 2023
b247331
Fix typo
kyfujisa Feb 8, 2023
b653f3c
Fix typo
kyfujisa Feb 8, 2023
e214e9a
Fix comment
kyfujisa Feb 8, 2023
3596735
Fix CertRefreshPeriod 0 check logic
kyfujisa Feb 8, 2023
a94e93d
Remove dot
kyfujisa Feb 8, 2023
c3100c8
Use NewTLSConfig in NewTLSConfigWithTLSCertificateCache
kyfujisa Feb 9, 2023
beed8a6
Revert "Use NewTLSConfig in NewTLSConfigWithTLSCertificateCache"
kyfujisa Feb 9, 2023
2b5cccd
Use NewTLSConfigWithTLSCertificateCache in NewTLSConfig
kyfujisa Feb 9, 2023
d0cb64d
Move CertRefreshPeriod check to NewTLSConfigWithTLSCertificateCache
kyfujisa Feb 9, 2023
19667a7
Fix comment and log
kyfujisa Feb 9, 2023
76edebd
Add process for compatibility
kyfujisa Feb 9, 2023
04c9cdc
Fix test for tls.go
kyfujisa Feb 9, 2023
736f266
Fix condition for running cert refresh daemon
kyfujisa Feb 9, 2023
45c5d58
Fix tests for authz_proxyd_test.go
kyfujisa Feb 9, 2023
29dec34
Fix initialization
kyfujisa Feb 9, 2023
240c2ed
Fix use modified config
kyfujisa Feb 13, 2023
f8c6e4a
Remove TLSConfigWithTLSCertificateCache
kyfujisa Feb 13, 2023
66aab41
Add not refreshed log
kyfujisa Feb 13, 2023
4592f4f
Merge branch 'master' of github.com:AthenZ/authorization-proxy into a…
kyfujisa Feb 14, 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
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ type TLS struct {

// CAPath represents the CA certificate chain file path for verifying client certificates.
CAPath string `yaml:"caPath"`

// CertRefreshPeriod represents the duration to read the server certificate again.
CertRefreshPeriod string `yaml:"certRefreshPeriod"`
}

// HealthCheck represents the health check server configuration.
Expand Down
9 changes: 5 additions & 4 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,11 @@ func TestNew(t *testing.T) {
ShutdownTimeout: "10s",
ShutdownDelay: "9s",
TLS: TLS{
Enable: true,
CertPath: "test/data/dummyServer.crt",
KeyPath: "test/data/dummyServer.key",
CAPath: "test/data/dummyCa.pem",
Enable: true,
CertPath: "test/data/dummyServer.crt",
KeyPath: "test/data/dummyServer.key",
CAPath: "test/data/dummyCa.pem",
CertRefreshPeriod: "24h",
},
HealthCheck: HealthCheck{
Port: 6082,
Expand Down
8 changes: 8 additions & 0 deletions service/option.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package service

import (
"crypto/tls"
"io"
"net/http"

Expand Down Expand Up @@ -39,6 +40,13 @@ func WithGRPCCloser(c io.Closer) Option {
}
}

// WithTLSConfig returns a TLS Config functional option
func WithTLSConfig(t *tls.Config) Option {
return func(s *server) {
s.tlsConfig = t
}
}

// WithGRPCServer returns a gRPC Server functional option
func WithGRPCServer(srv *grpc.Server) Option {
return func(s *server) {
Expand Down
37 changes: 37 additions & 0 deletions service/option_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package service

import (
"crypto/tls"
"io"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -206,6 +207,42 @@ func TestWithGRPCServer(t *testing.T) {
}
}

func TestWithTLSConfig(t *testing.T) {
type args struct {
t *tls.Config
}
tests := []struct {
name string
args args
checkFunc func(Option) error
}{
{
name: "set success",
args: args{
t: &tls.Config{
MinVersion: tls.VersionTLS12,
},
},
checkFunc: func(o Option) error {
srv := &server{}
o(srv)
if srv.tlsConfig.MinVersion != tls.VersionTLS12 {
return errors.New("value cannot set")
}
return nil
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := WithTLSConfig(tt.args.t)
if err := tt.checkFunc(got); err != nil {
t.Errorf("WithTLSConfig() error = %v", err)
}
})
}
}

func TestWithDebugHandler(t *testing.T) {
type args struct {
h http.Handler
Expand Down
24 changes: 11 additions & 13 deletions service/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package service

import (
"context"
"crypto/tls"
"fmt"
"io"
"net"
Expand Down Expand Up @@ -51,6 +52,8 @@ type server struct {
grpcSrvRunning bool
grpcCloser io.Closer

tlsConfig *tls.Config

// Health Check server
hcsrv *http.Server
hcRunning bool
Expand Down Expand Up @@ -100,19 +103,18 @@ func NewServer(opts ...Option) (Server, error) {
o(s)
}

if s.cfg.TLS.Enable && s.tlsConfig == nil {
return nil, errors.New("s.cfg.TLS.Enable is true, but s.tlsConfig is nil.")
}

if s.grpcSrvEnable() {
gopts := []grpc.ServerOption{
grpc.CustomCodec(proxy.Codec()),
grpc.UnknownServiceHandler(s.grpcHandler),
}

if s.cfg.TLS.Enable {
cfg, err := NewTLSConfig(s.cfg.TLS)
if err != nil {
return nil, err
}

gopts = append(gopts, grpc.Creds(credentials.NewTLS(cfg)))
gopts = append(gopts, grpc.Creds(credentials.NewTLS(s.tlsConfig)))
}

s.grpcSrv = grpc.NewServer(gopts...)
Expand All @@ -122,6 +124,9 @@ func NewServer(opts ...Option) (Server, error) {
Handler: s.srvHandler,
}
s.srv.SetKeepAlivesEnabled(true)
if s.cfg.TLS.Enable {
s.srv.TLSConfig = s.tlsConfig
}
}

if s.hcSrvEnable() {
Expand Down Expand Up @@ -394,13 +399,6 @@ func (s *server) listenAndServeAPI() error {
return s.srv.ListenAndServe()
}

cfg, err := NewTLSConfig(s.cfg.TLS)
if err == nil && cfg != nil {
s.srv.TLSConfig = cfg
}
if err != nil {
glg.Error(errors.Wrap(err, "cannot NewTLSConfig(s.cfg.TLS)"))
}
return s.srv.ListenAndServeTLS("", "")
}

Expand Down
Loading