Skip to content

Commit e7dc3dc

Browse files
authored
[Feature] Use Authorized communication (#625)
1 parent 9b5f145 commit e7dc3dc

File tree

9 files changed

+56
-3
lines changed

9 files changed

+56
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Change Log
22

33
## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
4+
- Always use JWT Authorized requests in internal communication
45
- Add Operator Maintenance Management feature
56

67
## [1.0.6](https://github.com/arangodb/kube-arangodb/tree/1.0.6) (2020-08-19)

pkg/deployment/client_cache.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ func (cc *clientCache) Get(ctx context.Context, group api.ServerGroup, id string
107107
return cc.get(ctx, group, id)
108108
}
109109

110+
func (cc clientCache) GetAuth() conn.Auth {
111+
return cc.factory.GetAuth()
112+
}
113+
110114
func (cc *clientCache) getDatabaseClient() (driver.Client, error) {
111115
if c := cc.databaseClient; c != nil {
112116
return c, nil

pkg/deployment/context_impl.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ import (
3131
"strconv"
3232
"time"
3333

34+
"github.com/arangodb/kube-arangodb/pkg/util/arangod/conn"
35+
3436
"github.com/arangodb/kube-arangodb/pkg/operator/scope"
3537

3638
monitoringClient "github.com/coreos/prometheus-operator/pkg/client/versioned/typed/monitoring/v1"
@@ -199,6 +201,11 @@ func (d *Deployment) GetServerClient(ctx context.Context, group api.ServerGroup,
199201
return c, nil
200202
}
201203

204+
// GetAuthentication return authentication for members
205+
func (d *Deployment) GetAuthentication() conn.Auth {
206+
return d.clientCache.factory.GetAuth()
207+
}
208+
202209
// GetAgencyClients returns a client connection for every agency member.
203210
// If the given predicate is not nil, only agents are included where the given predicate returns true.
204211
func (d *Deployment) GetAgencyClients(ctx context.Context, predicate func(id string) bool) ([]driver.Connection, error) {

pkg/deployment/reconcile/context.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ package reconcile
2525
import (
2626
"context"
2727

28+
"github.com/arangodb/kube-arangodb/pkg/util/arangod/conn"
29+
2830
"github.com/arangodb/kube-arangodb/pkg/deployment/resources/inspector"
2931

3032
backupApi "github.com/arangodb/kube-arangodb/pkg/apis/backup/v1"
@@ -116,4 +118,6 @@ type Context interface {
116118
GetBackup(backup string) (*backupApi.ArangoBackup, error)
117119
// GetName receives deployment name
118120
GetName() string
121+
// GetAuthentication return authentication for members
122+
GetAuthentication() conn.Auth
119123
}

pkg/deployment/reconcile/plan_builder_context.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ package reconcile
2525
import (
2626
"context"
2727

28+
"github.com/arangodb/kube-arangodb/pkg/util/arangod/conn"
29+
2830
"github.com/arangodb/go-driver/agency"
2931

3032
"github.com/arangodb/kube-arangodb/pkg/deployment/resources/inspector"
@@ -65,6 +67,8 @@ type PlanBuilderContext interface {
6567
GetDatabaseClient(ctx context.Context) (driver.Client, error)
6668
// GetServerClient returns a cached client for a specific server.
6769
GetServerClient(ctx context.Context, group api.ServerGroup, id string) (driver.Client, error)
70+
// GetAuthentication return authentication for members
71+
GetAuthentication() conn.Auth
6872
// SecretsInterface return secret interface
6973
SecretsInterface() k8sutil.SecretInterface
7074
// GetBackup receives information about a backup resource

pkg/deployment/reconcile/plan_builder_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import (
2828
"io/ioutil"
2929
"testing"
3030

31+
"github.com/arangodb/kube-arangodb/pkg/util/arangod/conn"
32+
3133
monitoring "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1"
3234

3335
"github.com/pkg/errors"
@@ -64,6 +66,12 @@ type testContext struct {
6466
RecordedEvent *k8sutil.Event
6567
}
6668

69+
func (c *testContext) GetAuthentication() conn.Auth {
70+
return func() (authentication driver.Authentication, err error) {
71+
return nil, nil
72+
}
73+
}
74+
6775
func (c *testContext) RenderPodForMember(cachedStatus inspector.Inspector, spec api.DeploymentSpec, status api.DeploymentStatus, memberID string, imageInfo api.ImageInfo) (*core.Pod, error) {
6876
panic("implement me")
6977
}

pkg/deployment/reconcile/plan_builder_tls.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ import (
3232
"reflect"
3333
"time"
3434

35+
"github.com/arangodb/go-driver"
36+
3537
"github.com/arangodb/kube-arangodb/pkg/deployment/features"
3638

3739
"github.com/arangodb/kube-arangodb/pkg/deployment/client"
@@ -399,7 +401,7 @@ func createKeyfileRenewalPlanMode(
399401
return mode
400402
}
401403

402-
func checkServerValidCertRequest(ctx context.Context, apiObject k8sutil.APIObject, group api.ServerGroup, member api.MemberStatus, ca resources.Certificates) (*tls.ConnectionState, error) {
404+
func checkServerValidCertRequest(ctx context.Context, context PlanBuilderContext, apiObject k8sutil.APIObject, group api.ServerGroup, member api.MemberStatus, ca resources.Certificates) (*tls.ConnectionState, error) {
403405
endpoint := fmt.Sprintf("https://%s:%d", k8sutil.CreatePodDNSName(apiObject, group.AsRole(), member.ID), k8sutil.ArangoPort)
404406

405407
tlsConfig := &tls.Config{
@@ -408,7 +410,23 @@ func checkServerValidCertRequest(ctx context.Context, apiObject k8sutil.APIObjec
408410
transport := &http.Transport{TLSClientConfig: tlsConfig}
409411
client := &http.Client{Transport: transport, Timeout: time.Second}
410412

411-
resp, err := client.Get(endpoint)
413+
auth, err := context.GetAuthentication()()
414+
if err != nil {
415+
return nil, err
416+
}
417+
418+
req, err := http.NewRequest(http.MethodGet, endpoint, nil)
419+
if err != nil {
420+
return nil, err
421+
}
422+
423+
if auth != nil && auth.Type() == driver.AuthenticationTypeRaw {
424+
if h := auth.Get("value"); h != "" {
425+
req.Header.Add("Authorization", h)
426+
}
427+
}
428+
429+
resp, err := client.Do(req)
412430
if err != nil {
413431
return nil, err
414432
}
@@ -437,7 +455,7 @@ func keyfileRenewalRequired(ctx context.Context,
437455
return false, false
438456
}
439457

440-
res, err := checkServerValidCertRequest(ctx, apiObject, group, member, ca)
458+
res, err := checkServerValidCertRequest(ctx, context, apiObject, group, member, ca)
441459
if err != nil {
442460
switch v := err.(type) {
443461
case *url.Error:

pkg/deployment/resources/pod_termination.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ func (r *Resources) prepareDBServerPodTermination(ctx context.Context, log zerol
218218
}
219219
}
220220
}
221+
return maskAny(err)
221222
}
222223
cleanedOut, err := cluster.IsCleanedOut(ctx, memberStatus.ID)
223224
if err != nil {

pkg/util/arangod/conn/factory.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ type Factory interface {
3737

3838
Client(hosts ...string) (driver.Client, error)
3939
Agency(hosts ...string) (agency.Agency, error)
40+
41+
GetAuth() Auth
4042
}
4143

4244
func NewFactory(auth Auth, config Config) Factory {
@@ -51,6 +53,10 @@ type factory struct {
5153
config Config
5254
}
5355

56+
func (f factory) GetAuth() Auth {
57+
return f.auth
58+
}
59+
5460
func (f factory) AgencyConnection(hosts ...string) (driver.Connection, error) {
5561
cfg, err := f.config()
5662
if err != nil {

0 commit comments

Comments
 (0)