Skip to content

Commit 8a2e57c

Browse files
committed
Refactor SPIFFE from pkg/security to kit
Updates the `pkg/security` package to move the SPIFFE implementation to a new kit package. This new kit package is more modulated and fuller test coverage. This package has been moved so that it can be both imported by dapr & components-contrib, as well as making the package more suitable for further development to support X.509 Component auth. dapr/proposals#51 Also moves in test/utils from dapr to crypto/test for shared usage. Part of dapr/proposals#51 Uses go mod fork of dapr/kit#92 Signed-off-by: joshvanl <[email protected]>
1 parent 635dc49 commit 8a2e57c

File tree

30 files changed

+319
-3735
lines changed

30 files changed

+319
-3735
lines changed

cmd/injector/app/app.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func Run() {
9191
SentryAddress: cfg.SentryAddress,
9292
ControlPlaneTrustDomain: cfg.ControlPlaneTrustDomain,
9393
ControlPlaneNamespace: namespace,
94-
TrustAnchorsFile: cfg.TrustAnchorsFile,
94+
TrustAnchorsFile: &cfg.TrustAnchorsFile,
9595
AppID: "dapr-injector",
9696
MTLSEnabled: true,
9797
Mode: modes.KubernetesMode,
@@ -165,7 +165,7 @@ func Run() {
165165
return rerr
166166
}
167167

168-
caBundle, rErr := sec.CurrentTrustAnchors()
168+
caBundle, rErr := sec.CurrentTrustAnchors(ctx)
169169
if rErr != nil {
170170
return rErr
171171
}

cmd/placement/app/app.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func Run() {
7474
SentryAddress: opts.SentryAddress,
7575
ControlPlaneTrustDomain: opts.TrustDomain,
7676
ControlPlaneNamespace: security.CurrentNamespace(),
77-
TrustAnchorsFile: opts.TrustAnchorsFile,
77+
TrustAnchorsFile: &opts.TrustAnchorsFile,
7878
AppID: "dapr-placement",
7979
MTLSEnabled: opts.TLSEnabled,
8080
Mode: modes.DaprMode(opts.Mode),

go.mod

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ require (
4545
github.com/sony/gobreaker v0.5.0
4646
github.com/spf13/cast v1.6.0
4747
github.com/spf13/pflag v1.0.5
48-
github.com/spiffe/go-spiffe/v2 v2.1.6
48+
github.com/spiffe/go-spiffe/v2 v2.1.7
4949
github.com/stretchr/testify v1.9.0
5050
github.com/valyala/fasthttp v1.51.0
5151
go.mongodb.org/mongo-driver v1.12.1
@@ -66,7 +66,6 @@ require (
6666
google.golang.org/genproto/googleapis/api v0.0.0-20231120223509-83a465c0220f
6767
google.golang.org/genproto/googleapis/rpc v0.0.0-20231212172506-995d672761c0
6868
google.golang.org/grpc v1.60.1
69-
google.golang.org/grpc/examples v0.0.0-20230224211313-3775f633ce20
7069
google.golang.org/protobuf v1.33.0
7170
gopkg.in/yaml.v3 v3.0.1
7271
k8s.io/api v0.28.4
@@ -414,6 +413,7 @@ require (
414413
google.golang.org/api v0.149.0 // indirect
415414
google.golang.org/appengine v1.6.8 // indirect
416415
google.golang.org/genproto v0.0.0-20231211222908-989df2bf70f3 // indirect
416+
google.golang.org/grpc/examples v0.0.0-20230224211313-3775f633ce20 // indirect
417417
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
418418
gopkg.in/couchbase/gocb.v1 v1.6.7 // indirect
419419
gopkg.in/couchbase/gocbcore.v7 v7.1.18 // indirect
@@ -470,7 +470,8 @@ replace github.com/microcosm-cc/bluemonday => github.com/microcosm-cc/bluemonday
470470
// Don't commit with this uncommented!
471471
//
472472
// replace github.com/dapr/components-contrib => ../components-contrib
473-
// replace github.com/dapr/kit => ../kit
473+
replace github.com/dapr/kit => github.com/joshvanl/kit v0.0.0-20240403103913-969bdc7b9937
474+
474475
//
475476
// Then, run `make modtidy-all` in this repository.
476477
// This ensures that go.mod and go.sum are up-to-date for each go.mod file.

go.sum

Lines changed: 0 additions & 2470 deletions
This file was deleted.

pkg/actors/placement/client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func testSecurity(t *testing.T) security.Handler {
161161
ControlPlaneTrustDomain: "test.example.com",
162162
ControlPlaneNamespace: "default",
163163
MTLSEnabled: false,
164-
OverrideCertRequestSource: func(context.Context, []byte) ([]*x509.Certificate, error) {
164+
OverrideCertRequestFn: func(context.Context, []byte) ([]*x509.Certificate, error) {
165165
return []*x509.Certificate{nil}, nil
166166
},
167167
})

pkg/injector/service/handler_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ package service
1515

1616
import (
1717
"bytes"
18+
"context"
1819
"encoding/json"
1920
"io"
2021
"net/http"
@@ -52,7 +53,7 @@ func TestHandleRequest(t *testing.T) {
5253

5354
require.NoError(t, err)
5455
injector := i.(*injector)
55-
injector.currentTrustAnchors = func() ([]byte, error) {
56+
injector.currentTrustAnchors = func(context.Context) ([]byte, error) {
5657
return nil, nil
5758
}
5859

pkg/injector/service/injector.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ var AllowedServiceAccountInfos = []string{
5656
}
5757

5858
type (
59-
currentTrustAnchorsFn func() (ca []byte, err error)
59+
currentTrustAnchorsFn func(context.Context) (ca []byte, err error)
6060
)
6161

6262
// Injector is the interface for the Dapr runtime sidecar injection component.

pkg/injector/service/pod_patch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (i *injector) getPodPatchOperations(ctx context.Context, ar *admissionv1.Ad
5151
sentryAddress := patcher.ServiceSentry.Address(i.config.Namespace, i.config.KubeClusterDomain)
5252
operatorAddress := patcher.ServiceAPI.Address(i.config.Namespace, i.config.KubeClusterDomain)
5353

54-
trustAnchors, err := i.currentTrustAnchors()
54+
trustAnchors, err := i.currentTrustAnchors(ctx)
5555
if err != nil {
5656
return nil, err
5757
}

pkg/operator/api/api_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import (
4242
"github.com/dapr/dapr/pkg/operator/api/informer"
4343
informerfake "github.com/dapr/dapr/pkg/operator/api/informer/fake"
4444
operatorv1pb "github.com/dapr/dapr/pkg/proto/operator/v1"
45-
"github.com/dapr/dapr/tests/util"
45+
"github.com/dapr/kit/crypto/test"
4646
)
4747

4848
type mockComponentUpdateServer struct {
@@ -196,7 +196,7 @@ func TestProcessComponentSecrets(t *testing.T) {
196196
func TestComponentUpdate(t *testing.T) {
197197
appID := spiffeid.RequireFromString("spiffe://example.org/ns/ns1/app1")
198198
serverID := spiffeid.RequireFromString("spiffe://example.org/ns/dapr-system/dapr-operator")
199-
pki := util.GenPKI(t, util.PKIOptions{
199+
pki := test.GenPKI(t, test.PKIOptions{
200200
LeafID: serverID,
201201
ClientID: appID,
202202
})
@@ -317,7 +317,7 @@ func TestComponentUpdate(t *testing.T) {
317317
func TestHTTPEndpointUpdate(t *testing.T) {
318318
appID := spiffeid.RequireFromString("spiffe://example.org/ns/ns1/app1")
319319
serverID := spiffeid.RequireFromString("spiffe://example.org/ns/dapr-system/dapr-operator")
320-
pki := util.GenPKI(t, util.PKIOptions{
320+
pki := test.GenPKI(t, test.PKIOptions{
321321
LeafID: serverID,
322322
ClientID: appID,
323323
})
@@ -482,7 +482,7 @@ func TestListScopes(t *testing.T) {
482482
func TestListsNamespaced(t *testing.T) {
483483
appID := spiffeid.RequireFromString("spiffe://example.org/ns/namespace-a/app1")
484484
serverID := spiffeid.RequireFromString("spiffe://example.org/ns/dapr-system/dapr-operator")
485-
pki := util.GenPKI(t, util.PKIOptions{
485+
pki := test.GenPKI(t, test.PKIOptions{
486486
LeafID: serverID,
487487
ClientID: appID,
488488
})

pkg/operator/api/authz/authz_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ import (
2424
"google.golang.org/grpc/status"
2525

2626
"github.com/dapr/dapr/pkg/security/spiffe"
27-
"github.com/dapr/dapr/tests/util"
27+
"github.com/dapr/kit/crypto/test"
2828
)
2929

3030
func Test_Request(t *testing.T) {
3131
appID := spiffeid.RequireFromString("spiffe://example.org/ns/ns1/app1")
3232
serverID := spiffeid.RequireFromString("spiffe://example.org/ns/dapr-system/dapr-operator")
33-
pki := util.GenPKI(t, util.PKIOptions{LeafID: serverID, ClientID: appID})
33+
pki := test.GenPKI(t, test.PKIOptions{LeafID: serverID, ClientID: appID})
3434

3535
t.Run("no auth context should error", func(t *testing.T) {
3636
id, err := Request(context.Background(), "ns1")
@@ -55,7 +55,7 @@ func Test_Request(t *testing.T) {
5555

5656
t.Run("invalid SPIFFE path should error", func(t *testing.T) {
5757
appID := spiffeid.RequireFromString("spiffe://example.org/foo/bar")
58-
pki2 := util.GenPKI(t, util.PKIOptions{LeafID: serverID, ClientID: appID})
58+
pki2 := test.GenPKI(t, test.PKIOptions{LeafID: serverID, ClientID: appID})
5959
id, err := Request(pki2.ClientGRPCCtx(t), "ns1")
6060
require.Error(t, err)
6161
assert.Equal(t, codes.PermissionDenied, status.Code(err))

0 commit comments

Comments
 (0)