Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding downstream support to CRD #2885

Merged
merged 2 commits into from
Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
2 changes: 2 additions & 0 deletions support/k8s/k8s-workload-registrar/mode-crd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ spec:
podName: my-pod-name
spiffeId: spiffe://example.org/my-spiffe-id
parentId: spiffe://example.org/spire/server
downstream: false
```

The supported selectors are:
Expand All @@ -470,6 +471,7 @@ The supported selectors are:

Notes:
* Specifying DNS Names is optional
* Specifying downstream is optional
* The metadata.namespace and selector.namespace must match

## CRD Security Considerations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type SpiffeIDSpec struct {
ParentId string `json:"parentId"`
SpiffeId string `json:"spiffeId"`
Selector Selector `json:"selector"`
Downstream bool `json:"downstream,omitempty"`
DnsNames []string `json:"dnsNames,omitempty"`
FederatesWith []string `json:"federatesWith,omitempty"`
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ spec:
type: array
parentId:
type: string
downstream:
type: boolean
selector:
properties:
arbitrary:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ func entryFromCRD(crd *spiffeidv1beta1.SpiffeID) (*types.Entry, error) {
Selectors: crd.TypesSelector(),
DnsNames: crd.Spec.DnsNames,
FederatesWith: crd.Spec.FederatesWith,
Downstream: crd.Spec.Downstream,
}, nil
}

Expand All @@ -301,7 +302,8 @@ func entryEqual(existing, current *types.Entry) bool {
return equalStringSlice(existing.DnsNames, current.DnsNames) &&
selectorSetsEqual(existing.Selectors, current.Selectors) &&
spiffeIDEqual(existing.SpiffeId, current.SpiffeId) &&
spiffeIDEqual(existing.ParentId, current.ParentId)
spiffeIDEqual(existing.ParentId, current.ParentId) &&
existing.Downstream == current.Downstream
}

func spiffeIDEqual(existing, current *types.SPIFFEID) bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func (s *SpiffeIDControllerTestSuite) TestCreateSpiffeID() {
Selector: spiffeidv1beta1.Selector{
Namespace: SpiffeIDNamespace,
},
Downstream: true,
},
}
err = s.k8sClient.Create(ctx, spiffeID)
Expand All @@ -99,12 +100,14 @@ func (s *SpiffeIDControllerTestSuite) TestCreateSpiffeID() {
})
s.Require().NoError(err)
s.Require().NotNil(entry)
s.Require().True(entry.Downstream)
s.Require().Equal(makeID(s.trustDomain, "%s", SpiffeIDName), stringFromID(entry.SpiffeId))

// Update SPIFFE ID
createdSpiffeID.Spec.SpiffeId = makeID(s.trustDomain, "%s/%s", SpiffeIDName, "new")
createdSpiffeID.Spec.ParentId = makeID(s.trustDomain, "%s/%s/%s", "spire", "server", "new")
createdSpiffeID.Spec.Selector.PodName = "test"
createdSpiffeID.Spec.Downstream = false
err = s.k8sClient.Update(ctx, createdSpiffeID)
s.Require().NoError(err)
_, err = s.r.Reconcile(ctx, ctrl.Request{NamespacedName: spiffeIDLookupKey})
Expand All @@ -118,6 +121,7 @@ func (s *SpiffeIDControllerTestSuite) TestCreateSpiffeID() {
s.Require().NotNil(entry)
s.Require().Equal(createdSpiffeID.Spec.SpiffeId, stringFromID(entry.SpiffeId))
s.Require().Equal(createdSpiffeID.Spec.ParentId, stringFromID(entry.ParentId))
s.Require().False(createdSpiffeID.Spec.Downstream)
s.Require().Equal(createdSpiffeID.Spec.Selector.PodName, "test")
}

Expand Down