Skip to content

Commit 054061e

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 091a204 commit 054061e

File tree

30 files changed

+327
-1273
lines changed

30 files changed

+327
-1273
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
@@ -47,7 +47,7 @@ require (
4747
github.com/sony/gobreaker v0.5.0
4848
github.com/spf13/cast v1.6.0
4949
github.com/spf13/pflag v1.0.5
50-
github.com/spiffe/go-spiffe/v2 v2.1.6
50+
github.com/spiffe/go-spiffe/v2 v2.1.7
5151
github.com/stretchr/testify v1.8.4
5252
github.com/valyala/fasthttp v1.51.0
5353
go.mongodb.org/mongo-driver v1.12.1
@@ -68,7 +68,6 @@ require (
6868
google.golang.org/genproto/googleapis/api v0.0.0-20231120223509-83a465c0220f
6969
google.golang.org/genproto/googleapis/rpc v0.0.0-20231212172506-995d672761c0
7070
google.golang.org/grpc v1.60.1
71-
google.golang.org/grpc/examples v0.0.0-20230224211313-3775f633ce20
7271
google.golang.org/protobuf v1.33.0
7372
gopkg.in/yaml.v3 v3.0.1
7473
k8s.io/api v0.28.4
@@ -416,6 +415,7 @@ require (
416415
google.golang.org/api v0.149.0 // indirect
417416
google.golang.org/appengine v1.6.8 // indirect
418417
google.golang.org/genproto v0.0.0-20231211222908-989df2bf70f3 // indirect
418+
google.golang.org/grpc/examples v0.0.0-20230224211313-3775f633ce20 // indirect
419419
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
420420
gopkg.in/couchbase/gocb.v1 v1.6.7 // indirect
421421
gopkg.in/couchbase/gocbcore.v7 v7.1.18 // indirect
@@ -472,7 +472,8 @@ replace github.com/microcosm-cc/bluemonday => github.com/microcosm-cc/bluemonday
472472
// Don't commit with this uncommented!
473473
//
474474
// replace github.com/dapr/components-contrib => ../components-contrib
475-
// replace github.com/dapr/kit => ../kit
475+
replace github.com/dapr/kit => github.com/joshvanl/kit v0.0.0-20240403103913-969bdc7b9937
476+
476477
//
477478
// Then, run `make modtidy-all` in this repository.
478479
// This ensures that go.mod and go.sum are up-to-date for each go.mod file.

go.sum

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ github.com/HdrHistogram/hdrhistogram-go v1.1.2/go.mod h1:yDgFjdqOqDEKOvasDdhWNXY
121121
github.com/IBM/sarama v1.42.2 h1:VoY4hVIZ+WQJ8G9KNY/SQlWguBQXQ9uvFPOnrcu8hEw=
122122
github.com/IBM/sarama v1.42.2/go.mod h1:FLPGUGwYqEs62hq2bVG6Io2+5n+pS6s/WOXVKWSLFtE=
123123
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
124-
github.com/Microsoft/go-winio v0.6.0 h1:slsWYD/zyx7lCXoZVlvQrj0hPTM1HI4+v1sIda2yDvg=
125-
github.com/Microsoft/go-winio v0.6.0/go.mod h1:cTAf44im0RAYeL23bpB+fzCyDH2MJiz2BO69KH/soAE=
124+
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
125+
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
126126
github.com/Netflix/go-env v0.0.0-20220526054621-78278af1949d h1:wvStE9wLpws31NiWUx+38wny1msZ/tm+eL5xmm4Y7So=
127127
github.com/Netflix/go-env v0.0.0-20220526054621-78278af1949d/go.mod h1:9XMFaCeRyW7fC9XJOWQ+NdAv8VLG7ys7l3x4ozEGLUQ=
128128
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
@@ -437,8 +437,6 @@ github.com/danieljoos/wincred v1.1.2 h1:QLdCxFs1/Yl4zduvBdcHB8goaYk9RARS2SgLLRuA
437437
github.com/danieljoos/wincred v1.1.2/go.mod h1:GijpziifJoIBfYh+S7BbkdUTU4LfM+QnGqR5Vl2tAx0=
438438
github.com/dapr/components-contrib v1.13.0-rc.10 h1:d5xGjRAl2Gm23YsMfwa7Lwz5FFCb1ad4UqCmHTmtyV4=
439439
github.com/dapr/components-contrib v1.13.0-rc.10/go.mod h1:CFCvUwS2ClqTVyzfqHEGiXM3gftWOjOI73pxECoY/Iw=
440-
github.com/dapr/kit v0.13.1-0.20240402103809-0c7cfce53d9e h1:mLvqfGuppb6uhsijmwTlF5sZVtGvig+Ua5ESKF17SxA=
441-
github.com/dapr/kit v0.13.1-0.20240402103809-0c7cfce53d9e/go.mod h1:dons8V2bF6MPR2yFdxtTa86PfaE7EJtKAOkZ9hOavBQ=
442440
github.com/dave/jennifer v1.4.0/go.mod h1:fIb+770HOpJ2fmN9EPPKOqm1vMGhB+TwXKMZhrIygKg=
443441
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
444442
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -579,8 +577,8 @@ github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2
579577
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
580578
github.com/go-ini/ini v1.67.0 h1:z6ZrTEZqSWOTyH2FlglNbNgARyHG8oLW9gMELqKr06A=
581579
github.com/go-ini/ini v1.67.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
582-
github.com/go-jose/go-jose/v3 v3.0.0 h1:s6rrhirfEP/CGIoc6p+PZAeogN2SxKav6Wp7+dyMWVo=
583-
github.com/go-jose/go-jose/v3 v3.0.0/go.mod h1:RNkWWRld676jZEYoV3+XK8L2ZnNSvIsxFMht0mSX+u8=
580+
github.com/go-jose/go-jose/v3 v3.0.1 h1:pWmKFVtt+Jl0vBZTIpz/eAKwsm6LkIxDVVbFHKkchhA=
581+
github.com/go-jose/go-jose/v3 v3.0.1/go.mod h1:RNkWWRld676jZEYoV3+XK8L2ZnNSvIsxFMht0mSX+u8=
584582
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
585583
github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
586584
github.com/go-kit/kit v0.10.0 h1:dXFJfIHVvUcpSgDOV+Ne6t7jXri8Tfv2uOLHUZ2XNuo=
@@ -1014,6 +1012,8 @@ github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22
10141012
github.com/jonboulle/clockwork v0.2.2/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8=
10151013
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
10161014
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
1015+
github.com/joshvanl/kit v0.0.0-20240403103913-969bdc7b9937 h1:0Uw8Jhb/gNphz08pxL5ce+w2kAHE9/Pe6W1o8robFS8=
1016+
github.com/joshvanl/kit v0.0.0-20240403103913-969bdc7b9937/go.mod h1:LkPZyrSpa2xLBgYMwUhDbWZcZVt/WdL7FSPlN0PrSog=
10171017
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
10181018
github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
10191019
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
@@ -1522,8 +1522,8 @@ github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5q
15221522
github.com/spf13/viper v1.7.1/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg=
15231523
github.com/spf13/viper v1.15.0 h1:js3yy885G8xwJa6iOISGFwd+qlUo5AvyXb7CiihdtiU=
15241524
github.com/spf13/viper v1.15.0/go.mod h1:fFcTBJxvhhzSJiZy8n+PeW6t8l+KeT/uTARa0jHOQLA=
1525-
github.com/spiffe/go-spiffe/v2 v2.1.6 h1:4SdizuQieFyL9eNU+SPiCArH4kynzaKOOj0VvM8R7Xo=
1526-
github.com/spiffe/go-spiffe/v2 v2.1.6/go.mod h1:eVDqm9xFvyqao6C+eQensb9ZPkyNEeaUbqbBpOhBnNk=
1525+
github.com/spiffe/go-spiffe/v2 v2.1.7 h1:VUkM1yIyg/x8X7u1uXqSRVRCdMdfRIEdFBzpqoeASGk=
1526+
github.com/spiffe/go-spiffe/v2 v2.1.7/go.mod h1:QJDGdhXllxjxvd5B+2XnhhXB/+rC8gr+lNrtOryiWeE=
15271527
github.com/stealthrocket/wasi-go v0.8.1-0.20230912180546-8efbab50fb58 h1:mTC4gyv3lcJ1XpzZMAckqkvWUqeT5Bva4RAT1IoHAAA=
15281528
github.com/stealthrocket/wasi-go v0.8.1-0.20230912180546-8efbab50fb58/go.mod h1:ZAYCOqLJkc9P6fcq14TV4cf+gJ2fHthp9kCGxBViagE=
15291529
github.com/stealthrocket/wazergo v0.19.1 h1:BPrITETPgSFwiytwmToO0MbUC/+RGC39JScz1JmmG6c=

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)