Skip to content

Commit

Permalink
add service instance id to request context (#712)
Browse files Browse the repository at this point in the history
  • Loading branch information
nirbenrey authored Oct 20, 2021
1 parent 8d681b0 commit 1a3ed39
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
9 changes: 8 additions & 1 deletion api/osb/context_signature_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import (
"github.com/Peripli/service-manager/pkg/web"
)

const ContextSignaturePluginName = "ContextSignaturePlugin"
const (
ContextSignaturePluginName = "ContextSignaturePlugin"
ServiceInstanceIDFieldName = "service_instance_id"
)

type ContextSignaturePlugin struct {
contextSigner *ContextSigner
Expand Down Expand Up @@ -69,6 +72,10 @@ func (s *ContextSignaturePlugin) signContext(req *web.Request, next web.Handler)
}
contextMap := reqBodyMap["context"].(map[string]interface{})

if instanceID, ok := req.PathParams[InstanceIDPathParam]; ok {
contextMap[ServiceInstanceIDFieldName] = instanceID
}

err = s.contextSigner.Sign(req.Context(), contextMap)
if err != nil {
log.C(req.Context()).Errorf("failed to sign request context: %v", err)
Expand Down
1 change: 1 addition & 0 deletions storage/interceptors/smaap_service_binding_interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ func (i *ServiceBindingInterceptor) prepareBindRequest(ctx context.Context, inst

//in case the private key is not provided we continue without adding the signature. this is useful in case we want to toggle off the feature
if i.contextSigner.ContextPrivateKey != "" {
context[osb.ServiceInstanceIDFieldName] = instance.ID
err := i.contextSigner.Sign(ctx, context)
if err != nil {
log.C(ctx).Errorf("failed to sign context: %v", err)
Expand Down
2 changes: 2 additions & 0 deletions storage/interceptors/smaap_service_instance_interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,7 @@ func (i *ServiceInstanceInterceptor) prepareProvisionRequest(ctx context.Context

//in case the private key is not provided we continue without adding the signature. this is useful in case we want to toggle off the feature
if i.contextSigner.ContextPrivateKey != "" {
instanceContext[osb.ServiceInstanceIDFieldName] = instance.ID
err = i.contextSigner.Sign(ctx, instanceContext)
if err != nil {
log.C(ctx).Errorf("failed to sign context: %v", err)
Expand Down Expand Up @@ -872,6 +873,7 @@ func (i *ServiceInstanceInterceptor) prepareUpdateInstanceRequest(ctx context.Co

//in case the private key is not provided we continue without adding the signature. this is useful in case we want to toggle off the feature
if i.contextSigner.ContextPrivateKey != "" {
instanceContext[osb.ServiceInstanceIDFieldName] = instance.ID
err := i.contextSigner.Sign(ctx, instanceContext)
if err != nil {
log.C(ctx).Errorf("failed to sign context: %v", err)
Expand Down
4 changes: 4 additions & 0 deletions test/common/context_signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ func GetVerifyContextHandlerFunc(publicKeyStr string) func(http.ResponseWriter,
signature, err := base64.StdEncoding.DecodeString(signatureBytes.String())
Expect(err).ToNot(HaveOccurred())

//verify service_instance_id is in the context
instanceID := gjson.GetBytes(bytes, "context.service_instance_id")
Expect(instanceID.Exists()).To(Equal(true), "context should have a service_instance_id field")

//decode the public key
key, err := base64.StdEncoding.DecodeString(publicKeyStr)
Expect(err).ToNot(HaveOccurred())
Expand Down

0 comments on commit 1a3ed39

Please sign in to comment.